:root {
  --bg: #faf7f0; --surface: #ffffff; --ink: #1c2321; --muted: #5d6763; --line: #e2ddd0;
  --brand: #0b6e4f; --on-brand: #ffffff; --brand-soft: #dff1ea;
  --warm: #fff3d6; --warm-ink: #5a3d00;
  --bad: #b3261e; --bad-soft: #fde7e5;
  --tap: 52px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715; --surface: #1b2320; --ink: #eef2ef; --muted: #a9b4af; --line: #2e3a35;
    --brand: #5fd0a6; --on-brand: #06261b; --brand-soft: #173b2e;
    --warm: #3a2e10; --warm-ink: #ffe2a0;
    --bad: #ffb4ab; --bad-soft: #4a1c18;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  /* System fonts only: nothing to download, and Android ships Devanagari and Gujarati faces. */
  font: 17px/1.6 system-ui, "Noto Sans", "Noto Sans Devanagari", "Noto Sans Gujarati", sans-serif;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
  background: var(--brand); color: var(--on-brand);
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.15rem; }
.lang select {
  min-height: 44px; padding: 0 10px; border-radius: 10px; border: 1px solid transparent;
  background: var(--surface); color: var(--ink); font: inherit;
}

main {
  max-width: 640px; margin: 0 auto; outline: none;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
h1 { font-size: 1.5rem; line-height: 1.35; margin: 4px 0 12px; }
h2 { font-size: 1.05rem; margin: 24px 0 8px; color: var(--muted); font-weight: 600; }
p { margin: 0 0 8px; }
.loading, .muted { color: var(--muted); }
.small { font-size: .88rem; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; min-height: 56px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none; font-weight: 600; border-top: 3px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--brand); border-top-color: var(--brand); }

.progress { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.track { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin-top: 8px; }
.track i { display: block; height: 100%; background: var(--brand); border-radius: 5px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  color: inherit; text-decoration: none;
}
.row .n {
  flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: .9rem;
}
.row.done .n { background: var(--brand); color: var(--on-brand); }
.row span:last-child { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 12px 0; }
.card.warm { background: var(--warm); color: var(--warm-ink); border-color: transparent; }
.card.good { background: var(--brand-soft); border-color: transparent; }
.card.bad { background: var(--bad-soft); border-color: transparent; }
.label { font-size: .82rem; font-weight: 700; letter-spacing: .02em; opacity: .8; margin-bottom: 4px; }

button, .btn {
  min-height: var(--tap); padding: 10px 18px; border-radius: 14px; border: 2px solid var(--brand);
  background: var(--brand); color: var(--on-brand); font: inherit; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; text-align: center; text-decoration: none;
  touch-action: manipulation;
}
button.ghost, .btn.ghost { background: transparent; color: var(--brand); }
button.wide, .btn.wide { width: 100%; }
button:disabled { opacity: .6; cursor: default; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--warm-ink); outline-offset: 2px;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.actions > * { flex: 1 1 140px; }

.narr { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 4px; }
.narr button { min-height: 46px; padding: 6px 16px; }

.opts { display: grid; gap: 10px; margin: 16px 0; }
.opt {
  width: 100%; justify-content: flex-start; text-align: start; background: var(--surface); color: var(--ink);
  border: 2px solid var(--line); font-weight: 500; padding: 12px 14px;
}
.opt:disabled { opacity: 1; }
.opt.right { border-color: var(--brand); background: var(--brand-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.err { color: var(--bad); }

input[type="search"] {
  width: 100%; min-height: var(--tap); padding: 0 14px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit;
}
details { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; margin: 8px 0; }
summary { min-height: var(--tap); padding: 12px 14px; cursor: pointer; font-weight: 600; display: flex; align-items: center; }
details > div { padding: 0 14px 14px; }
details .like { color: var(--warm-ink); background: var(--warm); border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.note { margin-top: 28px; text-align: center; }

/* ----- Theme toggle: an explicit choice overrides the phone's setting ----- */
:root { color-scheme: light dark; --s1: #2a78d6; --s2: #eb6834; }
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #faf7f0; --surface: #ffffff; --ink: #1c2321; --muted: #5d6763; --line: #e2ddd0;
  --brand: #0b6e4f; --on-brand: #ffffff; --brand-soft: #dff1ea; --warm: #fff3d6; --warm-ink: #5a3d00;
  --bad: #b3261e; --bad-soft: #fde7e5; --s1: #2a78d6; --s2: #eb6834;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --s1: #3987e5; --s2: #d95a27; } }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111715; --surface: #1b2320; --ink: #eef2ef; --muted: #a9b4af; --line: #2e3a35;
  --brand: #5fd0a6; --on-brand: #06261b; --brand-soft: #173b2e; --warm: #3a2e10; --warm-ink: #ffe2a0;
  --bad: #ffb4ab; --bad-soft: #4a1c18; --s1: #3987e5; --s2: #d95a27;
}
.grow { flex: 1; }
.bar { gap: 8px; }
button.icon {
  min-height: 44px; width: 44px; padding: 0; border-radius: 10px; font-size: 1.2rem;
  background: var(--surface); border-color: transparent; color: var(--ink);
}

/* ----- MOOSHA button and chat ----- */
.fab {
  position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 6;
  width: 64px; height: 64px; border-radius: 50%; background: var(--brand); color: var(--on-brand);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .28); line-height: 1;
}
.fab[hidden] { display: none; }
.fab span { font-size: 1.6rem; }
.fab small { font-size: .56rem; font-weight: 700; letter-spacing: .04em; margin-top: 2px; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; margin: 10px 0; background: var(--surface); border: 1px solid var(--line); }
.msg.u { margin-left: auto; background: var(--brand-soft); border-color: transparent; }
.msg p:last-child { margin-bottom: 0; }
.msg .actions { margin: 8px 0 0; }
.msg .actions > * { min-height: 42px; padding: 4px 12px; flex: 0 1 auto; }
.chips { display: grid; gap: 8px; margin: 12px 0; }
.chips button { justify-content: flex-start; text-align: start; font-weight: 500; }
.chatbar {
  position: fixed; left: 0; right: 0; bottom: calc(56px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; gap: 8px; padding: 8px max(12px, env(safe-area-inset-left)); background: var(--bg); border-top: 1px solid var(--line);
}
.chatbar input {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 0 14px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit;
}
.chatbar button { padding: 10px 14px; }
#chatlog { padding-bottom: 76px; }

/* ----- Simulator ----- */
.big { font-size: 1.7rem; font-weight: 700; margin: 0 0 6px; }
.chart { width: 100%; height: auto; display: block; }
.chart .c1 { fill: none; stroke: var(--s1); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .c2 { fill: none; stroke: var(--s2); stroke-width: 2; stroke-dasharray: 5 4; stroke-linejoin: round; }
.chart .d1 { fill: var(--s1); stroke: var(--surface); stroke-width: 2; }
.chart .d2 { fill: var(--s2); stroke: var(--surface); stroke-width: 2; }
.chart .cg { stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .cm { fill: var(--muted); font-size: 10px; }
.chart .cl { fill: var(--ink); font-size: 11px; font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 22px; height: 0; vertical-align: middle; margin-right: 6px; border-top: 3px solid var(--s1); }
.legend i.k2 { border-top: 3px dashed var(--s2); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }

/* ----- Sources and help ----- */
.res { margin-top: 32px; padding-top: 8px; border-top: 1px solid var(--line); }
.res ul { padding-left: 18px; margin: 8px 0; display: grid; gap: 8px; }
.res a { display: inline-block; padding: 4px 0; }
.tabs a { font-size: .95rem; }
.legend i.k0 { border-top: 2px dotted var(--muted); }

/* ----- Microphone is open: banner with a moving sound wave ----- */
.listening {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(70px + env(safe-area-inset-top)); z-index: 8;
  display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 16px; border-radius: 999px;
  background: var(--bad); color: var(--bg); box-shadow: 0 4px 16px rgba(0, 0, 0, .3); white-space: nowrap;
}
.listening[hidden] { display: none; }
.listening button { min-height: 40px; padding: 4px 14px; border-radius: 999px; background: var(--bg); color: var(--bad); border-color: transparent; }
.wave { display: inline-flex; align-items: center; gap: 3px; height: 24px; }
.wave i { width: 4px; height: 8px; border-radius: 2px; background: currentColor; animation: wave 0.9s ease-in-out infinite; }
.wave i:nth-child(2) { animation-delay: .15s; } .wave i:nth-child(3) { animation-delay: .3s; }
.wave i:nth-child(4) { animation-delay: .45s; } .wave i:nth-child(5) { animation-delay: .6s; }
@keyframes wave { 0%, 100% { height: 6px; } 50% { height: 24px; } }
button.live, [data-act="mic"]:disabled { border-color: var(--bad); color: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bad) 45%, transparent); } 50% { box-shadow: 0 0 0 9px transparent; } }
@media (prefers-reduced-motion: reduce) { .wave i { animation: none; height: 16px; } button.live, [data-act="mic"]:disabled { animation: none; } }
.tabs a { text-align: center; line-height: 1.2; padding: 4px 6px; font-size: .86rem; }
.row .small { line-height: 1.35; display: inline-block; }
/* Keep the listening banner clear of the question, the chat box and the MOOSHA button. */
.listening { top: auto; bottom: calc(142px + env(safe-area-inset-bottom)); }

/* ----- Listen / Pause / Stop next to every Listen button ----- */
.saybox { display: contents; }
.actions .saybox > * { flex: 1 1 110px; }
.msg .actions .saybox > * { min-height: 42px; padding: 4px 12px; flex: 0 1 auto; }

/* ----- MOOSHA question box: wraps and grows instead of scrolling sideways ----- */
.chatbar { align-items: flex-end; }
.chatbar textarea {
  flex: 1; min-width: 0; min-height: var(--tap); max-height: 132px; padding: 13px 14px; border-radius: 14px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; line-height: 1.4;
  resize: none; overflow-y: auto; display: block;
}
.chatbar textarea:focus-visible { outline: 3px solid var(--warm-ink); outline-offset: 2px; }
#chatlog { padding-bottom: 160px; }
.msg p { white-space: pre-wrap; }
