/* serve/machi_ui/machi.css — heymachi.live research preview.
 * 台灣風土民情 look: warm rice-paper ground (宣紙/大同電鍋米白), Ming-serif display, kaishu tagline,
 * cinnabar seal accents (印泥朱紅), Tatung/鐵窗花 green on the mic — 紅燈停、綠燈行: green when it is
 * your turn to talk, red while Machi records. zh-TW first with English subtitles, huge Han glyphs.
 * One screen: the page never scrolls — only the transcript pane does (about.html opts out via
 * body.page). All colors/sizes are custom props so the whole look is retunable from :root.
 * Zero dependencies, zero external requests, no build step. */

:root {
  color-scheme: light;
  --bg: #f7f2e8;         /* 宣紙 rice-paper warm white / 電鍋 cream enamel */
  --surface: #fffdf8;    /* fresh paper sheet — finalized turns */
  --surface-2: #edf3ec;  /* 青瓷 celadon wash — the in-progress turn */
  --line: #e3daca;       /* deckle-edge beige hairlines */
  --text: #2b2a26;       /* 墨色 calligraphy ink, never pure black */
  --muted: #6b6355;      /* 茶湯褐 steeped-oolong brown */
  --faint: #736a5a;      /* aged cement — timestamps, placeholder (AA at small sizes) */
  --brand: #1c6b54;      /* 大同電鍋綠／鐵窗花綠 — idle mic, live accents, focus */
  --brand-ink: #fffdf8;  /* text on brand */
  --rec: #b3402a;        /* 印泥朱紅 cinnabar seal red — recording + errors */
  --warn: #8f5b12;       /* 龍眼蜜 longan-honey amber — busy / limits */
  --warn-ink: #fffdf8;   /* text on warn */
  --link: #2b5a8a;       /* 花磚 Majolica-tile cobalt — links */
  --gold: #b8862b;       /* 金紙 joss gold — decorative hairlines only, never body text */
  --radius: 16px;
  --maxw: 720px;
  --serif: "Songti TC", "Noto Serif TC", "Noto Serif CJK TC", "PMingLiU", serif;
  --kai: "Kaiti TC", "BiauKai", "DFKai-SB", "Kaiti SC", "Songti TC", "Noto Serif TC", serif;
  --sans: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC",
          system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { height: 100%; }
body {
  height: 100vh;   /* fallback */
  height: 100dvh;  /* stable under the mobile URL-bar collapse */
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  /* 磨石子 terrazzo speckle — felt, not seen; transcript text always sits on opaque cards */
  background-image:
    radial-gradient(rgba(159, 174, 155, 0.16) 1px, transparent 1.5px),
    radial-gradient(rgba(184, 134, 43, 0.10) 1px, transparent 1.5px),
    radial-gradient(rgba(179, 64, 42, 0.07) 1.2px, transparent 1.7px);
  background-size: 46px 46px, 34px 34px, 74px 74px;
  background-position: 0 0, 17px 23px, 39px 11px;
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;  /* the transcript pane scrolls, never the page */
}

a { color: var(--link); text-underline-offset: 3px; }
a:hover { color: var(--text); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 3px; border-radius: 6px; }
::selection { background: var(--brand); color: var(--brand-ink); }

/* ---- hero ------------------------------------------------------------------------------------ */
.hero {
  text-align: center;
  padding: max(env(safe-area-inset-top), 14px) 20px 6px;
}
.badge {
  /* 印章 seal chip: cinnabar outline, squarish like a carved stamp */
  display: inline-block;
  font-family: var(--serif);
  border: 1.5px solid var(--rec);
  color: var(--rec);
  background: rgba(179, 64, 42, 0.06);
  border-radius: 7px;
  padding: 3px 12px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}
.brand {
  margin-top: 8px;
  font-family: var(--serif);
  font-size: clamp(2.4rem, 9vw, 3.6rem);
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.02em;
}
.brand .latin { color: var(--brand); font-weight: 700; }
.tag-zh {
  margin-top: 2px;
  font-family: var(--kai);
  font-size: clamp(1.15rem, 4.6vw, 1.5rem);
  font-weight: 700;
  letter-spacing: 0.04em;
}
.greet {
  margin-top: 3px;
  font-family: var(--kai);
  color: var(--muted);
  font-size: clamp(0.95rem, 3.6vw, 1.1rem);
}
.greet .en {
  display: block;
  font-family: var(--sans);
  font-size: clamp(0.72rem, 2.8vw, 0.82rem);
  color: var(--faint);
}
/* 鐵窗花 window-grille fan divider — inline SVG in the page, tinted here */
.grille {
  width: min(320px, 72vw);
  margin: 4px auto 0;
  color: var(--brand);
  opacity: 0.5;
}
.grille svg { display: block; width: 100%; height: auto; }

/* ---- transcript pane (the only scrolling region) ---------------------------------------------- */
#transcript {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}
#transcript::-webkit-scrollbar { width: 8px; }
#transcript::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.placeholder {
  margin: auto;             /* centers when it is the only visible child */
  text-align: center;
  color: var(--faint);
  font-size: 1.05rem;
  line-height: 1.8;
}
.placeholder .en { display: block; font-size: 0.85rem; }

/* turns are <article class="utt">; the chat-style bottom alignment rides first-of-type so the
 * placeholder <div> never picks up the auto margin */
article.utt:first-of-type { margin-top: auto; }

.utt {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 1px 3px rgba(43, 42, 38, 0.05);
}
.utt .time {
  color: var(--faint);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.utt .text {
  font-size: clamp(1.25rem, 4.5vw, 1.6rem);
  line-height: 1.6;
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* the in-progress turn: bigger, celadon-washed, grille-green edge, blinking caret */
.utt.live {
  background: var(--surface-2);
  border-color: var(--brand);
}
.utt.live .text {
  font-size: clamp(1.6rem, 6.5vw, 2.2rem);
  font-weight: 600;
  min-height: 1.5em;
}
.utt.live .text::after {
  content: "";
  display: inline-block;
  width: 0.09em;
  height: 1.05em;
  margin-left: 0.12em;
  vertical-align: -0.15em;
  background: var(--brand);
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* ---- status strip ------------------------------------------------------------------------------ */
.status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 16px;
  font-size: 0.84rem;
  color: var(--muted);
  text-align: center;
}
.status .dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}
.status.ok .dot   { background: var(--brand); }
.status.live .dot { background: var(--rec); animation: dotpulse 1.4s ease-in-out infinite; }
.status.warn .dot { background: var(--warn); }
.status.err .dot  { background: var(--rec); }
.status.warn { color: var(--warn); }
.status.err  { color: var(--rec); }
@keyframes dotpulse { 50% { opacity: 0.35; } }

.latency {
  border: 1px solid var(--gold);   /* 金紙 gold hairline — ornament, text stays readable oolong */
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: var(--surface);
  white-space: nowrap;
}

/* ---- the mic ----------------------------------------------------------------------------------- */
/* 紅燈停、綠燈行 — 電鍋 cooker-switch green when it is your turn to talk, seal-red while recording. */
.micRow {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 8px 0 10px;
}
#mic {
  position: relative;
  width: 92px;
  height: 92px;
  border: none;
  border-radius: 50%;
  background: var(--brand);
  color: var(--brand-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 3px 12px rgba(43, 42, 38, 0.28), inset 0 -3px 0 rgba(0, 0, 0, 0.14);
  transition: transform 0.15s ease, background-color 0.2s ease, color 0.2s ease;
}
#mic svg { width: 42px; height: 42px; }
#mic:active { transform: scale(0.94); }
#mic:disabled {
  background: var(--line);
  color: var(--muted);
  cursor: default;
  box-shadow: none;
}
#mic.rec { background: var(--rec); color: #fffdf8; }
#mic.rec::before,
#mic.rec::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--rec);
  animation: ring 1.8s ease-out infinite;
  pointer-events: none;
}
#mic.rec::after { animation-delay: 0.9s; }
@keyframes ring {
  from { transform: scale(1);   opacity: 0.8; }
  to   { transform: scale(1.9); opacity: 0; }
}
#mic.reconnect { background: var(--warn); color: var(--warn-ink); }
.micLabel { font-size: 0.88rem; color: var(--muted); }

/* ---- footer ------------------------------------------------------------------------------------ */
footer {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  border-top: 1px solid var(--line);
  padding: 8px 20px calc(8px + env(safe-area-inset-bottom));
  text-align: center;
  color: var(--faint);
  font-size: 0.78rem;
  line-height: 1.55;
}
footer p + p { margin-top: 3px; }

/* ---- memory panel 「麻吉記得 · Machi remembers」 ------------------------------------------------- */
/* Populated by machi.js from GET /memory; the whole section is [hidden] until the sidecar answers.
 * Toggle = the same 印章 seal chip as .badge (stamped solid while open); body = a .utt rice card.
 * Tokens only — no colors beyond the ones :root and .badge/.utt already use. */
.memory {
  flex: none;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2px 20px 4px;
}
.memoryToggle {
  display: inline-block;
  font-family: var(--serif);
  border: 1.5px solid var(--rec);
  color: var(--rec);
  background: rgba(179, 64, 42, 0.06);   /* .badge's seal-ink wash */
  border-radius: 7px;
  padding: 3px 12px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.memoryToggle[aria-expanded="true"] {
  background: var(--rec);                /* stamped: ink-filled seal while the panel is open */
  color: var(--brand-ink);
}
.memoryBody {
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  max-height: min(26vh, 220px);          /* the page never scrolls — this card does */
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 1px 3px rgba(43, 42, 38, 0.05);   /* same lift as .utt */
}
.memoryBody::-webkit-scrollbar { width: 8px; }
.memoryBody::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.memoryProfile {
  font-size: 0.95rem;
  line-height: 1.75;
  overflow-wrap: anywhere;
}
.memoryLast {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.memoryProfile:not([hidden]) + .memoryLast {
  margin-top: 6px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
}
.memoryEmpty {
  font-family: var(--kai);
  color: var(--faint);
  font-size: 0.9rem;
  text-align: center;
}

/* ---- toast (turn_capped etc.) ------------------------------------------------------------------ */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(150px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 3px 14px rgba(43, 42, 38, 0.16);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- about page (body.page opts out of the one-screen app shell) -------------------------------- */
body.page {
  display: block;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: auto;
  overflow-x: hidden;
}
.page-main {
  max-width: 620px;
  margin: 0 auto;
  padding: 6px 22px calc(48px + env(safe-area-inset-bottom));
}
.page-title {
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(1.7rem, 6.5vw, 2.3rem);
  text-align: center;
  margin-top: 10px;
}
.page-title .en {
  display: block;
  font-family: var(--sans);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-top: 4px;
}
.story { margin-top: 1.6em; }
.story p {
  font-family: var(--serif);
  font-size: clamp(1.06rem, 2.8vw, 1.2rem);
  line-height: 2.05;
  letter-spacing: 0.015em;
  text-align: justify;
}
.story p + p { margin-top: 1.5em; }
.story .kong { font-family: var(--kai); font-weight: 700; }   /* 阿公's spoken Taigi */
.coda {
  margin-top: 2.4em;
  text-align: center;
  font-style: italic;
  font-size: 0.92rem;
  color: var(--muted);
}
.byline {
  margin-top: 1.8em;
  text-align: right;
  font-family: var(--serif);
  font-size: 1.02rem;
}
.byline a { color: var(--link); }
.backlink { margin-top: 2.6em; text-align: center; font-size: 0.95rem; }

/* ---- small/short screens ------------------------------------------------------------------------ */
@media (max-height: 640px) {
  .hero { padding-bottom: 2px; }
  .brand { font-size: clamp(1.8rem, 7vw, 2.6rem); }
  .greet { display: none; }
  .grille { display: none; }
  .memoryBody { max-height: 18vh; }
  #mic { width: 72px; height: 72px; }
  #mic svg { width: 34px; height: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  .utt.live .text::after { animation: none; }
  .status.live .dot { animation: none; }
  #mic.rec::before, #mic.rec::after { animation: none; opacity: 0; }
  .toast { transition: none; }
}
