:root {
  --bg: #FBF8F3;
  --surface: #FFFFFF;
  --surface-2: #F4EFE6;
  --border: #E5DDCB;
  --text: #1A1A1A;
  --muted: #6B5D4F;
  --accent: #1F4E5F;
  --accent-2: #2C7A78;
  --gold: #C9A961;
  --soft: #E8DCC4;
  --warn: #B45309;
  --danger: #9B2C2C;
  --ok: #2F6B3E;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow-sm: 0 1px 2px rgba(31, 36, 50, 0.06);
  --shadow-md: 0 10px 30px rgba(31, 36, 50, 0.08);
  --shadow-lg: 0 30px 60px rgba(31, 36, 50, 0.12);
  --pad: 22px;
  --gap: 18px;
  --font: 'Tajawal', 'IBM Plex Sans Arabic', 'Noto Sans Arabic', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 20px;
  line-height: 1.7;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--pad);
  padding-top: calc(14px + env(safe-area-inset-top));
  background: rgba(251, 248, 243, 0.92);
  backdrop-filter: saturate(180%) blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 900;
  font-size: 24px;
  letter-spacing: 0.5px;
  color: var(--accent);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-row .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
}

.firstrun-dialog {
  max-width: 480px;
}

.firstrun-dialog .dialog-form {
  padding: 40px 28px;
  text-align: center;
}

.firstrun-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 28px;
}

.firstrun-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 28px 14px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 24px;
  font-weight: 800;
  color: var(--accent);
  box-shadow: var(--shadow-sm);
  min-height: 180px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.firstrun-choice:active {
  transform: scale(0.97);
}

.firstrun-choice:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.firstrun-icon {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 42px;
  font-weight: 900;
  box-shadow: var(--shadow-sm);
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 17px;
  box-shadow: var(--shadow-sm);
  min-height: 44px;
}

.ghost-btn .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px var(--pad) 80px;
}

.mic-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 40px 16px 24px;
}

.mic {
  position: relative;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #2A6F86, var(--accent) 60%, #143840 100%);
  color: var(--soft);
  display: grid;
  place-items: center;
  box-shadow:
    0 20px 50px rgba(31, 78, 95, 0.35),
    inset 0 -8px 24px rgba(0, 0, 0, 0.22),
    inset 0 8px 24px rgba(255, 255, 255, 0.08);
  transition: transform 120ms ease;
}

.mic:active { transform: scale(0.98); }

.mic.listening {
  background: radial-gradient(circle at 30% 30%, #C9A961, #A8762E 60%, #5E3F12 100%);
  color: #fff;
}

.mic .pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}

.mic.listening .pulse::before,
.mic.listening .pulse::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(201, 169, 97, 0.6);
  animation: ping 1.6s cubic-bezier(0, 0, 0.2, 1) infinite;
}
.mic.listening .pulse::after { animation-delay: 0.8s; }

@keyframes ping {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.35); opacity: 0; }
}

.mic-hint {
  margin: 22px 0 8px;
  font-size: 22px;
  color: var(--muted);
  font-weight: 500;
}

.transcript {
  min-height: 36px;
  margin: 8px 0 4px;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.transcript.interim { color: var(--muted); font-weight: 500; }

.text-toggle {
  margin-top: 6px;
  font-size: 16px;
  color: var(--muted);
  background: none;
  text-decoration: underline;
  padding: 8px 4px;
}

[hidden] { display: none !important; }

.text-fallback {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 520px;
  margin: 12px auto 0;
}

.text-fallback input {
  flex: 1;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 20px;
  text-align: right;
}

.text-fallback button {
  padding: 14px 22px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--surface);
  font-weight: 700;
}

.response {
  margin: 18px 0 8px;
}

.response:empty { display: none; }

.response-bubble {
  --text: #1A1A1A;
  --muted: #6B5D4F;
  --surface: #FFFFFF;
  --surface-2: #F4EFE6;
  --border: #E5DDCB;
  --accent: #1F4E5F;
  --soft: #E8DCC4;
  background: linear-gradient(180deg, #FFFFFF, #FAF3E3);
  border: 1px solid #E5D6A8;
  border-radius: var(--radius);
  padding: 22px;
  font-size: 22px;
  line-height: 1.85;
  color: #1A1A1A;
  box-shadow: var(--shadow-md);
}
.response-bubble h3 { color: #1F4E5F; }
.response-bubble p,
.response-bubble li,
.response-bubble b { color: #1A1A1A; }

.response-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.action-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 17px;
  color: var(--accent);
  min-height: 44px;
  box-shadow: var(--shadow-sm);
}

.action-chip.primary {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
}

.action-chip.warn {
  background: #FEF3E2;
  border-color: #F0C57A;
  color: var(--warn);
}

.card-stack {
  display: grid;
  gap: var(--gap);
  margin-top: 8px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.card .kicker {
  font-size: 14px;
  letter-spacing: 1.5px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 6px;
}

.card h3 {
  font-size: 24px;
  margin: 0 0 8px;
  font-weight: 800;
  color: var(--accent);
}

.card p { margin: 6px 0; font-size: 20px; }

.card .row {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.card .row .action-chip {
  min-height: 50px;
  padding: 12px 18px;
  font-size: 18px;
}

.card.accent {
  background: linear-gradient(135deg, #1F4E5F, #143840);
  color: var(--soft);
  border: none;
}

.card.accent h3 { color: #fff; }
.card.accent .kicker { color: rgba(232, 220, 196, 0.7); }
.card.accent .action-chip {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.18);
}

.card.gold {
  background: linear-gradient(135deg, #C9A961, #A8762E);
  color: #fff;
  border: none;
}
.card.gold h3 { color: #fff; }
.card.gold .kicker { color: rgba(255, 255, 255, 0.85); }
.card.gold .action-chip {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.card.warn {
  background: linear-gradient(135deg, #FFF7E6, #F8E7C0);
  border: 1px solid #ECC880;
}

.card.danger {
  background: linear-gradient(135deg, #FFF1F1, #F8DADA);
  border: 1px solid #E29F9F;
  color: var(--danger);
}
.card.danger h3 { color: var(--danger); }

.card.grandkid {
  background: linear-gradient(135deg, #FFFBF1, #F4E9CC);
  border: 1px solid #E5D6A8;
}
.card.grandkid .kicker { color: #8A6A26; }
.card.grandkid h3 { color: #4A3614; font-size: 28px; font-weight: 900; }
.card.grandkid p { color: #4A3614; }

.gk-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 6px 0 8px;
}
.gk-av {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #E8DCC4, #C9A961 60%, #8A6A26 100%);
  display: grid;
  place-items: center;
  font-size: 30px;
  font-weight: 900;
  color: #2A1E08;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.gk-meta { display: flex; flex-direction: column; }

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }

.tag {
  display: inline-block;
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 14px;
  margin-inline-start: 6px;
}

.more-row {
  display: grid;
  place-items: center;
  margin: 28px 0 0;
}

.more-btn {
  padding: 14px 38px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 19px;
  color: var(--accent);
  font-weight: 700;
  min-height: 56px;
  box-shadow: var(--shadow-sm);
}

.more-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.more-grid button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 22px 14px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  min-height: 80px;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.dialog {
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0;
  max-width: 560px;
  width: calc(100% - 28px);
  max-height: 86vh;
  box-shadow: var(--shadow-lg);
  color: var(--text);
}

.dialog::backdrop {
  background: rgba(20, 30, 36, 0.45);
  backdrop-filter: blur(6px);
}

.dialog-form {
  padding: 24px;
  display: grid;
  gap: 16px;
  max-height: 86vh;
  overflow: auto;
}

.dialog-form h2 {
  margin: 0;
  color: var(--accent);
  font-size: 26px;
  font-weight: 900;
}

.dialog fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px 14px;
}

.dialog legend {
  font-weight: 700;
  color: var(--muted);
  padding: 0 6px;
}

.dialog label {
  display: block;
  margin: 8px 0;
  font-size: 17px;
}

.dialog input,
.dialog select {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  margin-top: 6px;
  font-size: 18px;
  text-align: right;
}

.dialog .row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.dialog .row button {
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 6px;
}

.dialog-actions button {
  padding: 14px 22px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 700;
}

.dialog-actions button[value="save"] {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
}

.overlay-dialog {
  max-width: 720px;
}

#overlay-body h2 {
  color: var(--accent);
  margin: 0 0 12px;
  font-size: 26px;
}
#overlay-body p { font-size: 20px; line-height: 1.85; }

.note {
  font-size: 14px;
  color: var(--muted);
  margin: 6px 0 0;
}

.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 30, 36, 0.94);
  color: #fff;
  padding: 14px 22px;
  border-radius: 999px;
  font-size: 17px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 220ms ease, transform 220ms ease;
  z-index: 99;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.tasbeeh-stage {
  display: grid;
  place-items: center;
  gap: 22px;
}

.tasbeeh-orb {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #E8DCC4, #C9A961 60%, #8A6A26 100%);
  display: grid;
  place-items: center;
  color: #2A1E08;
  font-weight: 900;
  font-size: 36px;
  user-select: none;
  box-shadow: var(--shadow-md);
}

.tasbeeh-count { font-size: 64px; font-weight: 900; color: var(--accent); }

.meal-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 10px 14px;
  margin-top: 6px;
}

.meal-grid .label { color: var(--muted); font-weight: 700; }

.kbd {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-family: ui-monospace, SF Mono, Consolas, monospace;
  font-size: 16px;
}

.movement-stage {
  display: grid;
  gap: 18px;
  text-align: center;
}
.movement-stage .video {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 18px;
}
.movement-stage .countdown {
  font-size: 72px;
  font-weight: 900;
  color: var(--accent);
}

.video-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow-md);
}
.video-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.video-stage {
  text-align: right;
}
.video-stage h2 { text-align: center; }
.video-stage .row { justify-content: center; }

.feed-grid { display: grid; gap: 12px; }
.feed-row {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.feed-row .av {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--surface-2);
  display: grid; place-items: center;
  font-weight: 900;
  color: var(--accent);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 24px;
  font-size: 18px;
}

@media (max-width: 480px) {
  body { font-size: 19px; }
  .mic { width: 200px; height: 200px; }
  .mic svg { width: 56px; height: 56px; }
  .card h3 { font-size: 22px; }
  .card p { font-size: 19px; }
}

@media (prefers-reduced-motion: reduce) {
  .mic.listening .pulse::before,
  .mic.listening .pulse::after { animation: none; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181B;
    --surface: #1B2125;
    --surface-2: #232A2F;
    --border: #2D353B;
    --text: #F4EFE6;
    --muted: #A89F8E;
    --accent: #6FB0B7;
    --soft: #E8DCC4;
  }
  .card.accent { background: linear-gradient(135deg, #103440, #0A2128); }
}
