/* Hearth on a phone.
 *
 * The palette, the pixel animations and the header/stamp styling come from
 * design/hearth-kiln.html; where a rule is the mock-up's own it says so. The
 * layout is the phone's: a full-height dark stage per screen, figures in the
 * top part, the 48x48 scene anchored to the bottom, a tab bar for chapters.
 *
 * The one hard layout rule, from PROJECT.md §6: text never sits on the art,
 * and there is no scrim to make it. Each screen's text box stops above the
 * scene's top half (row 24 of 48; the art itself starts at row 27), and
 * tests/test_layout.py checks the bounding boxes at 360 and 430 px.
 */

/* Jersey 25 (OFL), one weight. Chosen in design/readability/NOTES.md: Pixelify
 * Sans drew 5 like S and 2 like Z, so $2,500 read as $2,S00 on a real phone. */
@font-face {
  font-family: 'Jersey 25';
  src: url('../fonts/Jersey25.ttf') format('truetype');
  font-weight: 400;
  font-display: block;
}

:root {
  /* The mock-up's palette. */
  --page: #EFE6DA; --ink: #2A1E1C; --soft: #6B5A52; --brick: #B86A4B; --brickD: #8C4A33;
  --mortar: #D9A98A; --knob: #E76F51; --knobD: #B9503A; --cream: #FFF1E0; --peach: #F4B183;
  --ember: #FF8C42; --gold: #FFD166; --cool: #7FB0D8;
  /* From its scene library (H) and its CSS. */
  --bg: #2A1E1C; --dark: #1C1412; --wall: #3A2A26; --amber: #FFB454; --red: #E5484D;
  --pixel: 'Jersey 25', ui-monospace, monospace;
  --prose: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* Jersey 25 draws on a 150-unit pixel in a 1230-unit em: 8.2 font pixels
   * per em. A pixel font only looks like pixels when each of those is a whole
   * number of device pixels, so the type sizes below are rounded to --fpx,
   * one font pixel in CSS px on this screen. The density is read from media
   * queries; --dpr is 1 where none matches. */
  --dpr: 1;
  --fpx: calc(8.2px / var(--dpr));
}
@media (min-resolution: 1.5dppx) { :root { --dpr: 2; } }
@media (min-resolution: 2.5dppx) { :root { --dpr: 3; } }
@media (min-resolution: 3.5dppx) { :root { --dpr: 4; } }

* { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--dark);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0 auto;
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  /* minmax(0, …): nothing inside may widen the page. On a phone, anything
   * wider than the screen makes the browser zoom the whole app out. */
  grid-template-columns: minmax(0, 1fr);
  background: var(--dark);
  color: var(--cream);
  font-family: var(--pixel);
  /* One weight: never let the browser smear a fake bold or slant over it. */
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  overflow: hidden;
}

button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--ember); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---- the bar: wordmark, coals, sync stamp ---- */

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 52px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px 8px;
  background: var(--dark);
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 8px; flex: none; }
.wordmark { font-weight: 700; font-size: 24px; line-height: 1; }
.mode {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--peach); border: 1px solid rgba(244, 177, 131, .5); border-radius: 8px; padding: 1px 6px;
}

/* The coals: the mock-up's physical flame, as five embers in the bar.
 * Steady when fine, low on a tight month, cool blue when stale or offline. */
.coals { display: flex; gap: 7px; margin-right: auto; padding-left: 4px; }
.coals i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ember);
  box-shadow: 0 0 7px 2px rgba(255, 140, 66, .55);
  animation: glow 1.6s ease-in-out infinite alternate;
}
.coals i:nth-child(2) { animation-delay: .3s; } .coals i:nth-child(3) { animation-delay: .6s; }
.coals i:nth-child(4) { animation-delay: .2s; } .coals i:nth-child(5) { animation-delay: .5s; }
.coals.low i { background: #B85C1E; box-shadow: 0 0 4px 1px rgba(184, 92, 30, .5); animation-duration: 3.2s; }
.coals.cool i { background: var(--cool); box-shadow: 0 0 5px 1px rgba(127, 176, 216, .5); animation: none; }

/* The stamp: the mock-up's pill, dot and colours. Peach dot when live; cool
 * text and dot when stale or offline; a red dot only when the backend
 * answered with a failure. */
.stamp {
  display: inline-flex; align-items: center; gap: 6px; flex: 0 1 auto; min-width: 0;
  height: 28px; padding: 0 12px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--bg); color: rgba(255, 241, 224, .7); font-size: 13px; white-space: nowrap;
}
.stamp i { width: 6px; height: 6px; border-radius: 50%; background: var(--peach); flex: none; }
.stamp span { overflow: hidden; text-overflow: ellipsis; }

/* Narrow phones (400 px and under): the same bar, packed tighter, so the
 * wordmark, the fixture tag, five coals and "as of 23:58" all fit. */
@media (max-width: 400px) {
  .bar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .wordmark { font-size: 21px; }
  .brand { gap: 6px; }
  .mode { font-size: 10px; padding: 1px 4px; }
  .coals { gap: 5px; padding-left: 2px; }
  .stamp { padding: 0 10px; font-size: 12px; }
}
@media (max-width: 330px) {
  .coals { display: none; }
}
.stamp.stale { color: var(--cool); }
.stamp.stale i { background: var(--cool); }
.stamp.failed i { background: var(--red); }
.stamp.syncing i { animation: glowk 1s ease-in-out infinite; }
.stamp.flash { color: var(--gold); }

/* ---- the stage ---- */

.stage {
  position: relative;
  overflow: hidden;
  background: var(--bg);
  container-type: size;
}

.hdr {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding-top: 12px; pointer-events: none;
}
/* The mock-up's .hicon, at phone size. */
.hicon {
  font-weight: 600; font-size: clamp(12px, 3.9cqw, 17px); letter-spacing: .1em;
  color: var(--peach); white-space: nowrap; line-height: 1.2;
}
.dots { display: flex; pointer-events: auto; min-height: 18px; }
.dots button {
  width: 20px; height: 18px; padding: 0; border: 0; background: none; cursor: pointer;
  display: grid; place-items: center;
}
.dots button i { display: block; width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 241, 224, .22); }
.dots button[aria-current="true"] i { background: var(--peach); }

.pager {
  position: absolute; inset: 0;
  display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
  scrollbar-width: none; touch-action: pan-x;
}
.pager::-webkit-scrollbar { display: none; }

.screen {
  --scene-w: min(100cqw, 90cqh);
  --text-top: 64px;
  position: relative; flex: 0 0 100%; height: 100%; overflow: hidden;
  scroll-snap-align: start; scroll-snap-stop: always;
}

.scene {
  position: absolute; left: 50%; bottom: 0;
  width: var(--scene-w); aspect-ratio: 1 / 1; transform: translateX(-50%);
  pointer-events: none;
}
.scene svg { display: block; width: 100%; height: 100%; shape-rendering: crispEdges; }

/* Stale data never looks live: the fire stops moving. */
.stage.stale .scene * { animation-play-state: paused !important; }

.text {
  position: absolute; left: 0; right: 0; top: var(--text-top);
  max-height: calc(100cqh - var(--scene-w) / 2 - var(--text-top) - 8px);
  padding: 0 24px; overflow: hidden;
  display: flex; flex-direction: column; align-items: stretch;
}
.text.hero { align-items: center; text-align: center; padding-top: 2.5cqh; }
/* Nothing in the column shrinks: when it doesn't fit, rows go (app.js
 * fitRows), rather than the flexbox quietly squashing a line in half. */
.text > * { flex-shrink: 0; }

/* One line each, always: ellipsise rather than wrap or shrink. */
.lab, .big, .sub, .rows .l, .rows .r {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; max-width: 100%;
}
/* The mock-up's .lab, .big and .sub, scaled from its 268 px screen. Each
 * size is declared twice: the plain value, then the same value rounded to
 * the font's pixel grid (CSS round(); a browser without it keeps the first). */
.lab { font-weight: 600; font-size: clamp(12px, 4.66cqw, 20px); font-size: round(clamp(12px, 4.66cqw, 20px), var(--fpx)); letter-spacing: .08em; color: var(--peach); line-height: 1.3; }
.big { font-weight: 700; font-size: calc(14.5cqw * var(--big-scale, 1)); font-size: round(calc(14.5cqw * var(--big-scale, 1)), var(--fpx)); line-height: 1.2; margin-top: 0; }
.big.amber { color: var(--amber); }
.sub { font-size: clamp(12px, 4.48cqw, 19px); font-size: round(clamp(12px, 4.48cqw, 19px), var(--fpx)); line-height: 1.35; margin-top: .3em; opacity: .92; }
.empty .big { color: rgba(255, 241, 224, .5); }

.d { font-weight: 700; }
.d.up { color: var(--cream); }
.d.dn { color: var(--peach); }

/* ▲ and ▼: drawn as pixel triangles, as the Kiln draws them, whatever the
 * font has. The character stays in the text, unseen, so
 * the string is still exactly what the backend sent. */
.arw {
  display: inline-block; width: .7em; height: .4em; margin-right: .3em;
  vertical-align: .08em; overflow: hidden; text-indent: 200%; white-space: nowrap;
  background-color: currentColor;
  -webkit-mask: var(--tri) center / 100% 100% no-repeat;
  mask: var(--tri) center / 100% 100% no-repeat;
}
.arw.up { --tri: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 4'%3E%3Cpath d='M3 0h1v1h1v1h1v1h1v1H0V3h1V2h1V1h1z'/%3E%3C/svg%3E"); }
.arw.dn { --tri: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 4'%3E%3Cpath d='M0 0h7v1H6v1H5v1H4v1H3V3H2V2H1V1H0z'/%3E%3C/svg%3E"); }

.text.list .lab { margin-bottom: .1em; }
.rows { list-style: none; margin: .55em 0 0; padding: 0; font-size: clamp(12px, 4.3cqw, 18px); font-size: round(clamp(12px, 4.3cqw, 18px), var(--fpx)); }
.rows li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: .16em 0; line-height: 1.3; }
.rows li.over { color: var(--amber); }
.rows li.more { opacity: .6; justify-content: flex-end; }
.rows .l { flex: 1 1 auto; }
.rows .r { flex: 0 0 auto; }
.rows .sw { display: inline-block; width: .6em; height: .6em; margin-right: .45em; }
/* An account's emoji: an 8x8 pixel drawing, or the phone's own glyph. */
.emo { display: inline-block; margin-right: .45em; }
.emo svg { width: 1em; height: 1em; vertical-align: -.12em; shape-rendering: crispEdges; }
.emo.typed { font-size: .9em; line-height: 1; letter-spacing: 0; font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif; }
/* The mock-up's proportional strip under the accounts total. */
.strip { display: flex; height: 4px; border-radius: 2px; overflow: hidden; margin: .6em 0 .1em; background: rgba(255, 241, 224, .15); flex: none; }
.strip i { display: block; height: 100%; }

/* ---- pull to refresh ---- */

.ptr {
  position: absolute; top: 0; left: 0; right: 0; z-index: 4; height: 36px;
  display: flex; align-items: center; justify-content: center;
  transform: translateY(-40px); pointer-events: none;
  font-size: 13px; color: var(--peach);
}
.ptr span { background: var(--dark); border-radius: 12px; padding: 4px 12px; }
.ptr.ready { color: var(--gold); }
.ptr.settle { transition: transform .2s ease-out; }

/* ---- tabs ---- */

.tabs {
  display: flex; overflow-x: auto; scrollbar-width: none;
  background: var(--dark); border-top: 1px solid rgba(255, 241, 224, .08);
  padding: 4px 4px calc(env(safe-area-inset-bottom, 0px) + 4px);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 68px; min-height: 54px; padding: 6px 2px; border: 0; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  color: rgba(244, 177, 131, .65); font-weight: 600; font-size: 12px; letter-spacing: .02em; white-space: nowrap;
}
.tab svg { width: 20px; height: 20px; shape-rendering: crispEdges; opacity: .55; }
.tab[aria-selected="true"] { color: var(--gold); }
.tab[aria-selected="true"] svg { opacity: 1; }

/* ---- settings (read-only) ---- */

.settings {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  padding: 16px 16px 40px; font-family: var(--prose); font-size: 15px; line-height: 1.45;
}
.settings h2 {
  font-family: var(--pixel); font-weight: 600; font-size: 14px; letter-spacing: .1em;
  color: var(--peach); margin: 26px 0 8px;
}
.settings h2:first-child { margin-top: 4px; }
.settings .lede { color: rgba(255, 241, 224, .7); margin: 0 0 4px; font-size: 14px; }
.settings .kv { list-style: none; margin: 0; padding: 0; }
.settings .kv li { border-top: 1px solid rgba(255, 241, 224, .08); padding: 9px 0; }
.settings .kv li:first-child { border-top: 0; }
.settings .row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.settings .k, .settings .v { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.settings .k { flex: 1 1 auto; }
.settings .v { flex: 0 1 auto; font-family: var(--pixel); color: var(--cream); text-align: right; }
.settings .v.unset { color: rgba(255, 241, 224, .5); font-family: var(--prose); }
.settings .k code, .settings .v code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.settings .note { color: rgba(255, 241, 224, .6); font-size: 13px; margin-top: 2px; }
.settings .group { font-family: var(--pixel); color: rgba(244, 177, 131, .8); font-size: 13px; margin: 12px 0 2px; }
.settings .warn {
  border: 1px solid rgba(255, 180, 84, .6); border-radius: 10px; padding: 10px 12px; margin: 0 0 10px;
  color: var(--cream); background: rgba(255, 180, 84, .08);
}
.settings .warn b { color: var(--amber); font-family: var(--pixel); font-weight: 600; display: block; margin-bottom: 2px; }
.settings .status { font-size: 13px; color: rgba(255, 241, 224, .6); margin: 0 0 12px; }
.settings .status.stale { color: var(--cool); }
.settings .pref { border-top: 1px solid rgba(255, 241, 224, .08); padding: 9px 0; }
.settings .seg { display: flex; gap: 6px; margin-top: 6px; }
.settings .seg button {
  flex: 1 1 0; padding: 8px 6px; border-radius: 10px; cursor: pointer; white-space: nowrap;
  border: 1px solid rgba(255, 241, 224, .2); background: none; color: var(--cream); font-family: var(--pixel); font-size: 13px;
}
.settings .seg button[aria-pressed="true"] { background: var(--cream); color: var(--ink); border-color: var(--cream); }
.settings button.danger {
  margin-top: 10px; padding: 10px 14px; border-radius: 10px; cursor: pointer;
  border: 1px solid rgba(244, 177, 131, .6); background: none; color: var(--peach); font-family: var(--pixel);
}

/* ---- sheets: pairing and data details ---- */

.sheet {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(20, 12, 10, .85);
}
.sheet .card {
  width: 100%; max-width: 520px; background: var(--bg); color: var(--cream);
  border-radius: 18px 18px 0 0; padding: 22px 20px calc(env(safe-area-inset-bottom, 0px) + 22px);
  font-family: var(--prose); font-size: 15px; line-height: 1.45;
}
.sheet.pair { align-items: center; background: var(--dark); }
.sheet.pair .card { border-radius: 18px; margin: 16px; }
.sheet h2 { font-family: var(--pixel); font-weight: 700; font-size: 22px; margin: 0 0 8px; }
.sheet p { margin: 0 0 12px; color: rgba(255, 241, 224, .85); }
.sheet code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--peach); }
.sheet label { display: block; font-family: var(--pixel); color: var(--peach); font-size: 13px; letter-spacing: .06em; margin-bottom: 6px; }
.sheet input {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid rgba(255, 241, 224, .25);
  background: var(--dark); color: var(--cream); font: 16px ui-monospace, Menlo, monospace;
}
.sheet .err { color: var(--amber); min-height: 1.4em; margin: 8px 0; }
.sheet button {
  padding: 12px 18px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--gold); color: var(--ink); font-family: var(--pixel); font-weight: 700; font-size: 16px;
}
.sheet button[disabled] { opacity: .6; cursor: default; }
.sheet button.quiet { background: none; color: var(--peach); border: 1px solid rgba(244, 177, 131, .5); }
.sheet .hint { font-size: 13px; color: rgba(255, 241, 224, .6); margin: 14px 0 0; }
.sheet .actions { display: flex; gap: 10px; margin-top: 14px; }
.sheet dl { margin: 0; }
.sheet dt { font-family: var(--pixel); color: var(--peach); font-size: 13px; letter-spacing: .06em; margin-top: 10px; }
.sheet dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.sheet dd.bad { color: var(--red); }
.sheet dd.cool { color: var(--cool); }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 76px); z-index: 30;
  transform: translateX(-50%); max-width: calc(100vw - 32px);
  background: var(--dark); color: var(--cream); border: 1px solid rgba(255, 241, 224, .15);
  border-radius: 12px; padding: 8px 14px; font-family: var(--prose); font-size: 14px;
}
.noscript { padding: 24px; font-family: var(--prose); }

/* ---- the mock-up's pixel animations, verbatim ---- */

@keyframes fA{0%,49%{opacity:1}50%,100%{opacity:0}}@keyframes fB{0%,49%{opacity:0}50%,100%{opacity:1}}
.f1{animation:fA .55s steps(1) infinite}.f2{animation:fB .55s steps(1) infinite}
@keyframes blink{0%,91%,97%,100%{opacity:1}92%,96%{opacity:0}}.eyes{animation:blink 4.2s steps(1) infinite}
@keyframes bob{0%,100%{transform:translateY(0)}50%{transform:translateY(-1px)}}.bob{animation:bob 2.4s ease-in-out infinite}
@keyframes rise{0%{transform:translateY(0);opacity:.8}100%{transform:translateY(-5px);opacity:0}}.steam{animation:rise 1.8s linear infinite}
@keyframes drop{0%{transform:translateY(0);opacity:1}70%{transform:translateY(5px);opacity:1}71%,100%{opacity:0}}.coin{animation:drop 2.6s steps(5) infinite}
@keyframes dripk{0%,60%{transform:translateY(0);opacity:0}61%{opacity:1}100%{transform:translateY(6px);opacity:0}}.drip{animation:dripk 3s steps(6) infinite}
@keyframes glowk{0%,100%{opacity:.5}50%{opacity:1}}.glow{animation:glowk 2.2s ease-in-out infinite}
@keyframes tossk{0%{transform:translate(18px,-16px) rotate(20deg);opacity:1}60%{transform:translate(0,0) rotate(0);opacity:1}100%{transform:translate(0,0);opacity:0}}.toss{animation:tossk 1.6s steps(8) 1 forwards}
@keyframes leank{0%,100%{transform:translateX(0)}50%{transform:translateX(1px)}}.lean{animation:leank 1.2s ease-in-out infinite}
@keyframes wavek{0%,100%{opacity:.3}50%{opacity:1}}.wave{animation:wavek .7s steps(2) infinite}
@keyframes glow{from{opacity:.75}to{opacity:1}}
@media (prefers-reduced-motion:reduce){.f1,.f2,.eyes,.bob,.steam,.coin,.drip,.glow,.toss,.lean,.wave,.coals i,.stamp i{animation:none}.f2{opacity:0}}
