/* MoatGoat — mobile.
 *
 * Palette and faces come from the app's own tokens (--accent: #16514C, Fraunces as the display
 * serif, mono for data chrome), so the phone reads as the same product rather than a companion
 * app someone else designed.
 *
 * Tokens are defined light-first on :root, then redefined for system-dark and for an explicit
 * dark stamp. No component rule lives inside a theme block — a colour whose only definition sits
 * behind a media query renders one theme's text on the other theme's ground.
 */

:root {
  --paper:      #FBFAF7;
  --surface:    #FFFFFF;
  --surface-2:  #F2F2ED;
  --ink:        #0F1614;
  --ink-2:      #46534F;
  --ink-3:      #7C8783;
  --green:      #16514C;
  --on-green:   #FFFFFF;
  --green-soft: rgba(22, 81, 76, 0.10);
  --ember:      #B4531F;
  --ember-soft: rgba(180, 83, 31, 0.12);
  --rule:       rgba(15, 22, 20, 0.09);
  --rule-2:     rgba(15, 22, 20, 0.17);

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", Palatino, Georgia, serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --tabh: 58px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0B100F; --surface: #131A19; --surface-2: #1B2423;
    --ink: #E9EEEC; --ink-2: #A3B0AC; --ink-3: #74827E;
    --green: #3FA394; --on-green: #08110F; --green-soft: rgba(63,163,148,.14);
    --ember: #E58A52; --ember-soft: rgba(229,138,82,.16);
    --rule: rgba(233,238,236,.10); --rule-2: rgba(233,238,236,.19);
  }
}
:root[data-theme="dark"] {
  --paper: #0B100F; --surface: #131A19; --surface-2: #1B2423;
  --ink: #E9EEEC; --ink-2: #A3B0AC; --ink-3: #74827E;
  --green: #3FA394; --on-green: #08110F; --green-soft: rgba(63,163,148,.14);
  --ember: #E58A52; --ember-soft: rgba(229,138,82,.16);
  --rule: rgba(233,238,236,.10); --rule-2: rgba(233,238,236,.19);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { max-width: 100vw; overflow-x: hidden; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom, 0px));
}

/* ── Bar ──────────────────────────────────────────────────────────────────────────────── */
#bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: baseline; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 18px 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
#bar-title { font: 600 25px/1.1 var(--serif); letter-spacing: -0.01em; }
#bar-sub { font: 500 11px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin-left: auto; }

/* ── Screens ──────────────────────────────────────────────────────────────────────────── */
.screen { display: none; padding: 16px 16px 28px; }
.screen.on { display: block; }
.lede { color: var(--ink-2); font-size: 15px; margin: 2px 0 16px; }

.divider { display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; }
.divider span { font: 500 10px/1 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); white-space: nowrap; }
.divider i { height: 1px; background: var(--rule); flex: 1; }

/* ── Cards ────────────────────────────────────────────────────────────────────────────── */
.card {
  border: 1px solid var(--rule); border-radius: 14px;
  padding: 14px; margin-bottom: 10px; background: var(--surface);
  display: block; width: 100%; text-align: left; color: inherit; font: inherit;
}
button.card, a.card { cursor: pointer; }
button.card:active { background: var(--surface-2); }
.card.flat { background: var(--surface-2); border-color: transparent; }
.card h3 { font: 600 16.5px/1.32 var(--sans); margin: 0 0 5px; letter-spacing: -0.005em; }
.card p { margin: 0; font-size: 14px; line-height: 1.55; color: var(--ink-2); }

.kicker { display: flex; align-items: center; gap: 7px; font: 500 10px/1 var(--mono);
          letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 9px; }
.dot { width: 5px; height: 5px; border-radius: 50%; background: var(--green); flex: none; }
.dot.new { background: var(--ember); }
.meta { margin-top: 10px; font: 400 11.5px/1.5 var(--mono); color: var(--ink-3);
        display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.meta .src { color: var(--green); overflow-wrap: anywhere; }

.pill { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px;
        font: 500 10px/1.5 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.pill.new { background: var(--ember-soft); color: var(--ember); }
.pill.quiet { background: var(--green-soft); color: var(--green); }

/* The one card with different texture — today's subject. */
.lesson { border: 1px solid var(--green); border-radius: 14px; padding: 16px;
          margin-bottom: 10px; background: var(--green-soft); }
.lesson h3 { font: 600 18px/1.28 var(--serif); margin: 0 0 6px; }
.lesson p { font-size: 14px; color: var(--ink-2); margin: 0 0 12px; }

/* ── Forms ────────────────────────────────────────────────────────────────────────────── */
form { display: flex; gap: 8px; margin-bottom: 6px; }
#ask-form { flex-direction: column; }
input, textarea, button {
  font: 16px/1.4 var(--sans);   /* 16px: iOS zooms the page on focus below this, and never undoes it */
  color: inherit;
}
input, textarea {
  width: 100%; padding: 12px 13px; border-radius: 11px;
  border: 1px solid var(--rule-2); background: var(--surface);
  resize: none; min-width: 0;
}
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--green); outline-offset: 2px;
}
form button, .btn {
  padding: 12px 16px; border: 0; border-radius: 11px;
  background: var(--green); color: var(--on-green); font-weight: 600; cursor: pointer;
  flex: none;
}
#ask-go { width: 100%; padding: 14px; font-size: 16px; }
form button:disabled { opacity: .55; }

/* ── Topics ───────────────────────────────────────────────────────────────────────────── */
.chips { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 12px; }
.chip { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--rule-2);
        background: transparent; font: 500 12.5px/1 var(--mono); color: var(--ink-2); cursor: pointer; }
.chip.on { background: var(--green); border-color: var(--green); color: var(--on-green); }
.chip .x { margin-left: 6px; opacity: .6; }

/* ── States ───────────────────────────────────────────────────────────────────────────── */
.empty { color: var(--ink-3); font-size: 14.5px; padding: 18px 2px; line-height: 1.6; }
.empty b { color: var(--ink-2); }
.err { color: var(--ember); font-size: 14px; padding: 14px 2px; }
.note { font-size: 13px; color: var(--ink-3); margin-top: 10px; line-height: 1.55; }

.skel-card { height: 84px; border-radius: 14px; background: var(--surface-2); margin-bottom: 10px; }
.skel-line { height: 13px; border-radius: 4px; background: var(--surface-2); margin: 10px 0; }
.skel-card, .skel-line { animation: pulse 1.5s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .skel-card, .skel-line { animation: none; } }

.queued {
  border: 1px solid var(--green); background: var(--green-soft);
  border-radius: 12px; padding: 14px; margin-top: 12px;
}
.queued b { display: block; margin-bottom: 4px; }
.queued p { margin: 0; font-size: 14px; color: var(--ink-2); }

/* ── Tab bar ──────────────────────────────────────────────────────────────────────────── */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
  background: none; border: 0; padding: 9px 0 10px; cursor: pointer;
  font: 500 10px/1.5 var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3);
}
.tab.on { color: var(--green); }
.tab .ic { display: block; font-size: 15px; margin-bottom: 2px; }
.tab .badge {
  display: inline-block; min-width: 16px; padding: 0 4px; margin-left: 4px;
  border-radius: 999px; background: var(--ember); color: #fff;
  font: 700 9.5px/16px var(--mono); vertical-align: 1px;
}

/* A phone design should still be reasonable on a laptop that hits the same URL. */
@media (min-width: 720px) {
  #bar, .screen { max-width: 620px; margin-left: auto; margin-right: auto; }
  #tabs { max-width: 620px; margin: 0 auto; border-left: 1px solid var(--rule); border-right: 1px solid var(--rule); }
}

/* ── The end of things ─────────────────────────────────────────────────────────────────
   Most apps are built so this moment never arrives. Here it is the product: you finished,
   nothing is waiting, put the phone down. Quiet by design — it must not read as a call to
   action, because it is the opposite of one. */
.done {
  margin: 22px 0 8px; padding: 16px 16px 18px;
  border-top: 1px solid var(--rule); text-align: center;
}
.done b { display: block; font: 600 17px/1.3 var(--serif); margin-bottom: 5px; }
.done p { margin: 0; font-size: 13.5px; line-height: 1.6; color: var(--ink-3); max-width: 40ch; margin-inline: auto; }

/* ── Curriculum track ──────────────────────────────────────────────────────────────────
   Nine stages, one at a time. Shown as progress, never as a menu — you cannot skip ahead,
   and the design should not suggest you could. */
.track { display: flex; gap: 3px; margin: 9px 0 2px; }
.track i { flex: 1; height: 3px; border-radius: 2px; background: var(--rule-2); }
.track i.on { background: var(--green); }

.back {
  background: none; border: 0; padding: 4px 0 12px; cursor: pointer;
  font: 500 13px/1 var(--mono); color: var(--ink-3);
}
.back:active { color: var(--green); }

/* Reading a lesson: measure and rhythm matter more here than anywhere else in the app. */
.reading {
  font: 16px/1.72 var(--serif);
  color: var(--ink); margin-top: 14px; max-width: 66ch;
  overflow-wrap: anywhere;
}

/* ── Shaping ───────────────────────────────────────────────────────────────────────────
   Two words, not five stars. The control is quiet because it is an invitation, not a demand
   for engagement — and once used it says what it did and stops asking. */
.fb { display: flex; gap: 14px; margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--rule); }
.fb-b {
  background: none; border: 0; padding: 2px 0; cursor: pointer;
  font: 500 12px/1.4 var(--mono); color: var(--ink-3); letter-spacing: .02em;
}
.fb-b:active, .fb-b:focus-visible { color: var(--green); }
.fb.done-fb { display: block; font: 500 12px/1.4 var(--mono); color: var(--green); }

/* ── Speaking ──────────────────────────────────────────────────────────────────────────
   Sits inside the field rather than beside it, so the textarea keeps full width on a narrow
   phone. Hidden by default — mobile.js only reveals it when recognition actually exists. */
.ask-wrap { position: relative; }
.ask-wrap textarea { padding-right: 52px; }
.mic {
  position: absolute; right: 8px; bottom: 8px;
  width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid var(--rule-2); border-radius: 10px;
  background: var(--surface); color: var(--ink-3); cursor: pointer; padding: 0;
}
.mic.on { background: var(--green); border-color: var(--green); color: var(--on-green); }
.mic.on svg { animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .mic.on svg { animation: none; } }

/* ── Quick look ────────────────────────────────────────────────────────────────────────
   A sheet over the app, not a tab. It is reachable in one tap and disappears completely when
   closed — the middle speed should feel like a tool you pick up, not a place you live. */
#bar-look {
  background: none; border: 0; padding: 6px; margin-left: 10px; cursor: pointer;
  color: var(--ink-3); display: grid; place-items: center;
}
#bar-look:active, #bar-look:focus-visible { color: var(--green); }
body.look-on { overflow: hidden; }

#look {
  position: fixed; inset: 0; z-index: 40; background: var(--paper);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
}
.look-head { padding: 12px 14px; border-bottom: 1px solid var(--rule); }
#look-form { display: flex; gap: 8px; margin: 0; align-items: center; }
#look-close {
  background: none; border: 0; font-size: 20px; color: var(--ink-3);
  padding: 6px 4px; cursor: pointer; flex: none;
}
#look-body { flex: 1; overflow-y: auto; padding: 14px 14px 40px; }
.look-meta {
  font: 500 10.5px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-3); margin-bottom: 12px;
}
#look-body .btn { display: inline-block; margin-top: 10px; }

/* ── Long-tail results: a basic SERP row ───────────────────────────────────────────────
   Scanned, not read. The card treatment used for Today is wrong here — it gave each result a
   border, a big title and full-bleed underlines, so a single result filled the phone. Host
   first (it is how you decide whether to tap), then a clamped title, then two lines of snippet. */
.serp { display: flex; flex-direction: column; }
.serp-row {
  display: block; padding: 14px 0; border-bottom: 1px solid var(--rule);
  text-decoration: none; color: inherit;
}
.serp-row:active { background: var(--surface-2); }
.serp-host {
  font: 400 12px/1.4 var(--mono); color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 3px;
}
.serp-title {
  font: 600 16px/1.35 var(--sans); color: var(--green);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.serp-snip {
  font: 400 14px/1.5 var(--sans); color: var(--ink-2); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* The sheet's resting state. Quiet and explanatory — it is the one screen a person can reach
   that has nothing on it, so it has to say what it is rather than look empty. */
.look-rest { padding: 26px 4px; color: var(--ink-3); font-size: 14.5px; line-height: 1.65; max-width: 42ch; }
.look-rest p { margin: 0 0 14px; }
.look-rest b { color: var(--ink-2); }

/* ── Pairing ──────────────────────────────────────────────────────────────────────────────
   Lives inside a .card on YOU, so it inherits the card's ground and only needs to lay its own
   fields out. Stacked rather than inline: an address and a code are different lengths and a row
   of two inputs on a 360px phone gives both of them too little. */
.pair-f { display: flex; flex-direction: column; gap: 9px; margin-top: 13px; }
.pair-f .btn { width: 100%; text-align: center; }

/* A second action next to a primary one has to be visibly secondary, or the pair reads as two
   equal choices and neither looks like the thing to do. */
.btn.ghost {
  background: transparent; color: var(--ink-2);
  border: 1px solid var(--rule-2); font-weight: 500;
}
.btn.ghost:active { color: var(--green); border-color: var(--green); }

/* The QR viewfinder. Capped rather than full-bleed: it sits inside a card, and a camera feed that
   fills the screen looks like the app switched modes when it only opened a scanner. */
#pair-cam {
  width: 100%; max-height: 46vh; margin-top: 12px;
  border-radius: 12px; background: #000; object-fit: cover; display: block;
}
#pair-cam[hidden] { display: none; }
#pair-msg:empty { display: none; }
#pair-msg { margin-top: 4px; }
