/* ===========================================================================
   أذكاري — styles
   Car-screen-first: high contrast, huge tap targets, dark default.
   No Tailwind in PoC: keeps zero-build, served as-is from nginx.
   =========================================================================== */

:root {
  /* Tokens */
  --bg: #fafaf9;
  --bg-elev: #ffffff;
  --bg-elev-2: #f5f5f4;
  --text: #1c1917;
  --text-muted: #57534e;
  --border: #e7e5e4;
  --accent: #059669;        /* emerald */
  --accent-soft: #d1fae5;
  --danger: #dc2626;

  --tile-amber: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  --tile-indigo: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
  --tile-emerald: linear-gradient(135deg, #10b981 0%, #047857 100%);
  --tile-sky: linear-gradient(135deg, #0ea5e9 0%, #0369a1 100%);
  --tile-rose: linear-gradient(135deg, #f43f5e 0%, #be123c 100%);
  --tile-violet: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  --tile-slate: linear-gradient(135deg, #64748b 0%, #334155 100%);

  --radius: 1.25rem;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-2: 0 4px 14px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-3: 0 20px 40px rgba(0,0,0,0.18);

  /* Reading font sizes — driver-readable at distance. User-selectable. */
  --reading-size: 2.6rem;
  --reading-line: 1.9;
}

html.dark {
  --bg: #020617;
  --bg-elev: #0f172a;
  --bg-elev-2: #1e293b;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #1e293b;
  --accent: #34d399;
  --accent-soft: #064e3b;
}

html[data-fontsize="l"]  { --reading-size: 3.4rem; --reading-line: 1.95; }
html[data-fontsize="xl"] { --reading-size: 4.4rem; --reading-line: 2.0;  }

/* Base reset additions */
* { box-sizing: border-box; }
body { min-height: 100dvh; }

/* ---------- Safe-area utilities (composed with max()) ---------- */
.safe-top    { padding-top:    max(0.75rem, env(safe-area-inset-top)); }
.safe-bottom { padding-bottom: max(0.5rem,  env(safe-area-inset-bottom)); }
.safe-x      { padding-left:   max(1rem, env(safe-area-inset-left));
               padding-right:  max(1rem, env(safe-area-inset-right)); }

/* ---------- App header (Home + Settings) ---------- */
.app-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: max(1rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 1rem max(1.25rem, env(safe-area-inset-left));
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-title {
  flex: 1;
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
}
.icon-btn {
  width: 56px;
  height: 56px;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  display: grid;
  place-items: center;
  touch-action: manipulation;
  transition: transform 120ms, background 160ms;
}
.icon-btn:active { transform: scale(0.95); background: var(--bg-elev-2); }
.icon-btn svg { width: 28px; height: 28px; }
.text-btn {
  background: transparent;
  color: var(--accent);
  border: 0;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.75rem 1rem;
  touch-action: manipulation;
}
.text-btn:active { opacity: 0.65; }

/* ---------- Home view ---------- */
.view-home {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
.greeting {
  padding: 0.5rem 1.5rem 1.5rem;
  font-size: 1.15rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}

.home-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  padding: 0.5rem max(1.25rem, env(safe-area-inset-right)) 6rem max(1.25rem, env(safe-area-inset-left));
}

/* Car / wide screen: use 3-4 columns */
@media (min-width: 720px) {
  .home-grid { grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
}
@media (min-width: 1100px) {
  .home-grid { grid-template-columns: repeat(4, 1fr); gap: 1.5rem; padding-bottom: 7rem; }
}

.category-tile {
  position: relative;
  border: 0;
  border-radius: var(--radius);
  padding: 1.5rem 1.25rem;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: right;
  color: white;
  font-family: inherit;
  font-weight: 700;
  touch-action: manipulation;
  box-shadow: var(--shadow-2);
  transition: transform 120ms, box-shadow 200ms;
  overflow: hidden;
}
@media (min-width: 720px) { .category-tile { min-height: 190px; padding: 1.75rem 1.5rem; } }
@media (min-width: 1100px) { .category-tile { min-height: 220px; padding: 2rem 1.75rem; } }

.category-tile:active { transform: scale(0.97); box-shadow: var(--shadow-1); }
.category-tile[data-color="amber"]   { background: var(--tile-amber); }
.category-tile[data-color="indigo"]  { background: var(--tile-indigo); }
.category-tile[data-color="emerald"] { background: var(--tile-emerald); }
.category-tile[data-color="sky"]     { background: var(--tile-sky); }
.category-tile[data-color="rose"]    { background: var(--tile-rose); }
.category-tile[data-color="violet"]  { background: var(--tile-violet); }
.category-tile[data-color="slate"]   { background: var(--tile-slate); }

.tile-icon { font-size: 3rem; line-height: 1; align-self: flex-end; }
@media (min-width: 720px) { .tile-icon { font-size: 3.75rem; } }
.tile-name { font-size: 1.5rem; line-height: 1.3; }
@media (min-width: 720px) { .tile-name { font-size: 1.85rem; } }
.tile-count {
  margin-top: 0.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  opacity: 0.85;
}

/* FAB — create new category. Bottom-end. */
.fab {
  position: fixed;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  left: max(1.5rem, env(safe-area-inset-left));   /* RTL: left edge of viewport */
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: white;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-3);
  touch-action: manipulation;
  transition: transform 120ms;
}
.fab:active { transform: scale(0.92); }
.fab svg { width: 32px; height: 32px; }

/* ---------- Player view ---------- */
.view-player {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  z-index: 20;
}
.player-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: max(1rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) 0.75rem max(1.25rem, env(safe-area-inset-left));
}
.player-title {
  flex: 1;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
}
.player-progress {
  background: var(--bg-elev-2);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}
.progress-bar {
  height: 6px;
  background: var(--bg-elev-2);
  margin: 0 max(1.25rem, env(safe-area-inset-right)) 0 max(1.25rem, env(safe-area-inset-left));
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 280ms ease-out;
  border-radius: 999px;
}

.player-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1.5rem max(1.5rem, env(safe-area-inset-right)) 1rem max(1.5rem, env(safe-area-inset-left));
  text-align: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  overflow-y: auto;
  touch-action: manipulation;
}
.player-source {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  font-weight: 500;
}
.player-text {
  font-size: var(--reading-size);
  line-height: var(--reading-line);
  font-weight: 600;
  color: var(--text);
  max-width: 100%;
  word-break: break-word;
  white-space: pre-line;
  letter-spacing: 0;
  /* Pleasant easing for size/text changes */
  transition: opacity 180ms;
}
.player-text.changing { opacity: 0.2; }

.player-counter-wrap {
  margin-top: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.player-counter-label {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.player-counter {
  font-size: 3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  min-width: 5rem;
  text-align: center;
  transition: transform 120ms, color 120ms;
}
.player-counter.bump { transform: scale(1.15); }
.player-counter.done { color: var(--accent); }

.player-controls {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 0.75rem;
  padding: 1rem max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.ctrl-btn {
  border: 0;
  border-radius: var(--radius);
  min-height: 80px;
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  touch-action: manipulation;
  transition: transform 120ms, opacity 120ms;
}
.ctrl-btn:active { transform: scale(0.97); }
.ctrl-btn svg { width: 32px; height: 32px; }
.ctrl-secondary {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
}
.ctrl-primary {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-2);
}

/* ---------- Settings view ---------- */
.view-settings { min-height: 100dvh; }
.settings-body {
  padding: 0.5rem max(1.25rem, env(safe-area-inset-right)) 4rem max(1.25rem, env(safe-area-inset-left));
}
.settings-section {
  margin-bottom: 2rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.settings-section h2 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  font-weight: 700;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  min-height: 56px;
}
.setting-row.stacked {
  flex-direction: column;
  align-items: stretch;
}
.setting-row label {
  font-weight: 600;
  font-size: 1.05rem;
}
.hint {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0 0 0.75rem;
  display: block;
}

/* Segmented control */
.seg-control {
  display: inline-flex;
  background: var(--bg-elev-2);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.seg-control button {
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  touch-action: manipulation;
  min-height: 44px;
  transition: background 160ms, color 160ms;
}
.seg-control button[data-active="true"] {
  background: var(--accent);
  color: white;
}

/* Reorder list (categories) */
.reorder-list, .custom-cat-list, .item-picker {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}
.reorder-list li, .custom-cat-list li, .item-picker li {
  background: var(--bg-elev-2);
  border-radius: 0.875rem;
  padding: 0.875rem 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 64px;
  touch-action: manipulation;
}
.reorder-list .handle {
  cursor: grab;
  opacity: 0.5;
  font-size: 1.5rem;
  user-select: none;
  -webkit-user-select: none;
}
.reorder-list .row-icon { font-size: 1.75rem; }
.reorder-list .row-name { flex: 1; font-weight: 600; font-size: 1.05rem; }
.toggle-btn {
  border: 0;
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  min-height: 40px;
  touch-action: manipulation;
}
.toggle-btn[data-on="true"] { background: var(--accent); color: white; }

.reorder-list li.dragging {
  opacity: 0.6;
  background: var(--accent-soft);
}

/* Custom category row */
.custom-cat-list li .row-name { font-weight: 700; }
.custom-cat-list .meta {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.row-action {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  border-radius: 0.5rem;
}
.row-action.danger { color: var(--danger); }
.row-action:active { background: var(--bg-elev); }
.row-action svg { width: 22px; height: 22px; }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 0.875rem;
  padding: 0.9rem 1.25rem;
  font-family: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  min-height: 56px;
  width: 100%;
  touch-action: manipulation;
}
.btn-primary:active { transform: scale(0.98); }

/* Edit category view */
.view-edit { min-height: 100dvh; }
.edit-body {
  padding: 0.5rem max(1.25rem, env(safe-area-inset-right)) 4rem max(1.25rem, env(safe-area-inset-left));
}
.edit-body input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 0.875rem;
  padding: 1rem;
  font-size: 1.1rem;
  font-family: inherit;
  min-height: 56px;
}
.edit-body input[type="text"]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.icon-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.icon-picker button {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 0.875rem;
  font-size: 1.75rem;
  padding: 0.75rem 0;
  font-family: inherit;
  min-height: 60px;
  touch-action: manipulation;
}
.icon-picker button[data-active="true"] {
  background: var(--accent);
  border-color: var(--accent);
}

.item-picker li {
  cursor: pointer;
}
.item-picker .row-title { flex: 1; font-weight: 600; }
.item-picker .row-meta { font-size: 0.85rem; color: var(--text-muted); }
.item-picker .check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.item-picker li[data-checked="true"] .check {
  background: var(--accent);
  border-color: var(--accent);
}
.item-picker li[data-checked="true"] .check::after {
  content: "✓";
  color: white;
  font-weight: 900;
  font-size: 1.05rem;
  line-height: 1;
}

/* ---------- Modal & toast ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fade-in 180ms ease-out;
}
@media (min-width: 720px) {
  .modal-overlay { align-items: center; padding: 1rem; }
}
.modal-sheet {
  width: 100%;
  max-width: 28rem;
  background: var(--bg-elev);
  border-radius: 1.25rem 1.25rem 0 0;
  padding: 1.5rem 1.5rem max(1.5rem, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: slide-up 240ms cubic-bezier(.4,0,.2,1);
}
@media (min-width: 720px) {
  .modal-sheet { border-radius: 1.25rem; }
}
.modal-sheet h3 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.modal-sheet p  { margin: 0; color: var(--text-muted); line-height: 1.5; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.5rem; }
.modal-btn {
  border: 0;
  border-radius: 0.75rem;
  padding: 0.875rem 1.25rem;
  font-family: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  min-height: 52px;
  touch-action: manipulation;
}
.modal-btn.secondary { background: var(--bg-elev-2); color: var(--text); }
.modal-btn.primary   { background: var(--accent); color: white; }
.modal-btn.danger    { background: var(--danger); color: white; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .modal-overlay, .modal-sheet { animation: none; }
}

/* Toast */
#toast-host {
  position: fixed;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  background: #0f172a;
  color: #f8fafc;
  padding: 0.875rem 1.25rem;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: var(--shadow-3);
  pointer-events: auto;
  opacity: 0;
  transition: opacity 200ms;
}
html.dark .toast { background: #f8fafc; color: #0f172a; }
.toast[data-shown="true"] { opacity: 1; }

/* Done state — when finished a category */
.done-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 5;
  animation: fade-in 240ms;
  text-align: center;
  padding: 2rem;
}
.done-overlay .done-icon {
  font-size: 6rem;
  margin-bottom: 1rem;
}
.done-overlay h2 {
  font-size: 2rem;
  margin: 0 0 0.5rem;
}
.done-overlay p {
  color: var(--text-muted);
  margin: 0 0 2rem;
  font-size: 1.15rem;
}

/* Empty state on home */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
