:root {
  --bg: #f5efe3;
  --surface: #fffaf1;
  --surface-2: #efe6d6;
  --ink: #2a1f17;
  --muted: #7a6a58;
  --line: #e2d5bf;
  --accent: #c4501d;
  --accent-ink: #fff8f0;
  --gold: #d9962b;
  --good: #3c8a4c;
  --warn: #d48a1c;
  --bad: #c0392b;
  --fig: #2a1f17;
  --shadow: 0 1px 2px rgba(60, 40, 20, .08), 0 6px 20px rgba(60, 40, 20, .08);
  --radius: 18px;   /* cards */
  --r-btn: 14px;    /* buttons */
  --r-chip: 10px;   /* chips and tags */
  --r-flag: 6px;    /* small labels */
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15100c;
    --surface: #211912;
    --surface-2: #2b2118;
    --ink: #f3e9da;
    --muted: #a8957f;
    --line: #3a2d22;
    --accent: #f06a2c;
    --accent-ink: #1a0f08;
    --gold: #f0b350;
    --fig: #f3e9da;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15100c; --surface: #211912; --surface-2: #2b2118; --ink: #f3e9da; --muted: #a8957f;
  --line: #3a2d22; --accent: #f06a2c; --accent-ink: #1a0f08; --gold: #f0b350; --fig: #f3e9da;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: -.01em; margin: 0; }
p { margin: 0; }
[hidden] { display: none !important; }

.screen {
  max-width: 760px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
}

.ico { width: 20px; height: 20px; fill: currentColor; flex: none; }

/* ---------- Buttons ---------- */
.btn {
  border: 1.5px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-btn);
  padding: 12px 22px;
  font-weight: 600;
  min-height: 48px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.big { width: 100%; font-size: 1.15rem; min-height: 58px; letter-spacing: .02em; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn:active { transform: scale(.98); }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: transparent;
}
.icon-btn:hover { background: var(--surface-2); }
.text-btn {
  border: 0; background: none; color: var(--accent); font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 4px;
}
.row { display: flex; gap: 10px; justify-content: center; }
.row.wrap { flex-wrap: wrap; justify-content: flex-start; }
.small { font-size: .85rem; color: var(--muted); }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
/* Your monk, rank and progress: a full row of their own under the name and coins. */
.home-rank { width: 100%; margin-bottom: 14px; }
.home-rank .rank-text { flex: 1; }
.home-rank .xpbar { width: 100%; }
.home-rank .avatar-mini { width: 39px; height: 60px; }  /* 3 screen pixels per art pixel */
.rank {
  display: flex; align-items: center; gap: 10px;
  border: 0; background: none; padding: 4px; text-align: left; min-width: 0;
}
.rank-text { display: grid; gap: 3px; min-width: 0; }
.rank-text strong { font-family: var(--display); font-size: 1.05rem; }
.rank-text small { color: var(--muted); font-size: .75rem; }
.sash {
  width: 14px; height: 38px; border-radius: 4px; flex: none;
  /* Black sash degrees: a gold band per degree at the tail. */
  background: repeating-linear-gradient(to top, #e5b13a 0 2px, transparent 2px 4px) bottom 2px center / 100% calc(var(--deg, 0) * 4px) no-repeat, var(--sash, #f4efe6);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15);
  position: relative;
}
.sash::after { content: ""; position: absolute; left: -4px; right: -4px; top: 14px; height: 7px; border-radius: 3px; background: var(--sash, #f4efe6); box-shadow: inherit; }
.sash.big { width: 20px; height: 56px; }
.sash.big::after { top: 20px; height: 10px; left: -6px; right: -6px; }
.avatar-mini { width: 26px; height: 40px; flex: none; image-rendering: pixelated; image-rendering: crisp-edges; }
.avatar-big { width: 104px; height: 160px; flex: none; image-rendering: pixelated; image-rendering: crisp-edges; }
.monk-stage {
  display: flex; align-items: center; gap: 16px; padding: 14px; margin-bottom: 6px;
  background: var(--surface-2); border-radius: var(--radius);
}
.monk-stage .shop-intro { margin-bottom: 10px; }
.xpbar { display: block; width: 130px; max-width: 100%; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); border-radius: inherit; transition: width .6s; }
.chips { display: flex; align-items: center; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 12px; font-size: .9rem;
}
.chip .ico { width: 16px; height: 16px; color: var(--gold); }
.ico.coin { color: var(--gold); }
.chip .flame { color: var(--accent); }

/* ---------- Intro ---------- */
/* ---------- Name and welcome ---------- */
.brand { display: flex; align-items: baseline; gap: 8px; margin: 0; }
.brand b { font-family: var(--display); font-size: 1.55rem; letter-spacing: .01em; }
.brand span { color: var(--accent); font-size: 1rem; font-weight: 600; }
.brand i, .dotfit { font-style: normal; color: var(--muted); font-weight: 600; }
.welcome-kicker { color: var(--accent); font-weight: 700; font-size: .85rem; letter-spacing: .04em; }
.welcome-steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.credit { font-size: .82rem; color: var(--muted); text-align: center; }
.credit a { color: var(--accent); font-weight: 600; }

/* ---------- Hero ---------- */
.hero {
  background: var(--surface);
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 5px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}
.hero-label {
  display: flex; justify-content: space-between; align-items: center;
  text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--muted); font-weight: 700;
}
.hero-label .text-btn { text-transform: none; letter-spacing: 0; font-size: .9rem; }
#hero-kicker { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }
.hero-label .mult {
  padding: 2px 8px; border-radius: var(--r-flag); letter-spacing: .04em; white-space: nowrap;
  background: var(--gold); color: #1a0f08;
}
.hero.daily { border-color: color-mix(in srgb, var(--gold) 60%, var(--line)); }
.back-daily { display: block; margin: 8px auto 0; }
.hero-body { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 16px; align-items: center; margin: 6px 0 16px; }
.hero-fig { cursor: pointer; background: var(--surface-2); border-radius: 16px; padding: 10px; aspect-ratio: 4 / 5; display: grid; place-items: center; }
.hero h1 { font-size: clamp(1.6rem, 6vw, 2.3rem); line-height: 1.05; }
.native { color: var(--accent); font-family: var(--display); font-style: italic; font-size: 1.05rem; }
.level-line { margin-top: 8px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.desc { color: var(--muted); margin-top: 6px; font-size: .95rem; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.tag { font-size: .8rem; padding: 4px 10px; border-radius: var(--r-chip); background: var(--surface-2); color: var(--muted); }
.tag.strong { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); font-weight: 700; }

.pips { display: inline-flex; gap: 4px; align-items: center; }
.pips i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--gold); }
.pips i.on { background: var(--gold); }
.pips em { font-style: normal; font-size: .72rem; font-weight: 800; color: var(--good); margin-left: 4px; white-space: nowrap; }
.lvl-bar { display: inline-block; width: 44px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; vertical-align: middle; }
.lvl-bar i { display: block; height: 100%; background: var(--gold); border-radius: inherit; }
.lvl-progress .lvl-bar { width: 64px; height: 8px; }
.lvl-rule { flex-basis: 100%; font-size: .8rem; color: var(--muted); }
.pips small { margin-left: 4px; font-size: .78rem; font-weight: 600; color: var(--muted); }
.pips.mastered { font-size: .75rem; font-weight: 700; color: var(--gold); text-transform: uppercase; letter-spacing: .08em; }

/* ---------- Figures ---------- */
.figure { width: 100%; height: 100%; max-height: 220px; overflow: visible; }
.figure .bones line { stroke: var(--fig); stroke-width: 3.2; stroke-linecap: round; }
.figure .head { fill: none; stroke: var(--fig); stroke-width: 3.2; }
.figure .ground { stroke: var(--line); stroke-width: 2; stroke-linecap: round; }
.figure .prop { fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-dasharray: 3 2; }
.figure.big .prop, .ref .figure .prop { stroke: rgba(255, 255, 255, .45); }

/* ---------- Grid ---------- */
.section-title { font-size: 1.2rem; margin: 26px 0 12px; }
.group-title { font-family: var(--sans); font-size: .82rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 20px 0 10px; }
.group-title:first-child { margin-top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card {
  display: grid; justify-items: start; gap: 4px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow);
}
.card .figure { height: 96px; width: 100%; background: var(--surface-2); border-radius: 12px; padding: 8px; margin-bottom: 6px; }
.card-name { font-family: var(--display); font-weight: 700; font-size: 1.05rem; }
.card-sub { font-size: .8rem; color: var(--muted); }
.card:active { transform: scale(.98); }
.card { position: relative; }
.card.daily { border-color: var(--gold); }
.card-flag {
  position: absolute; top: 8px; right: 8px; z-index: 1; font-size: .72rem; font-weight: 700;
  padding: 2px 8px; border-radius: var(--r-flag); background: var(--gold); color: #1a0f08;
}
.card.locked .figure { opacity: .3; }
.card.locked .card-name { color: var(--muted); }
.card-sub.price { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: .9rem; }
.card-sub.price .ico { width: 15px; height: 15px; }
.card.affordable { border-color: var(--gold); }
.card.affordable .price { color: var(--gold); }
.unlock-box { display: grid; gap: 10px; }
.unlock-box .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.unlock-box .btn .ico { color: currentColor; }
.foot { text-align: center; margin-top: 18px; }

/* ---------- Sheets ---------- */
.sheet {
  border: 0; padding: 0; width: min(560px, 100%); max-height: 92vh;
  border-radius: 24px; background: var(--surface); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.sheet::backdrop { background: rgba(20, 12, 6, .55); backdrop-filter: blur(2px); }
@media (max-width: 600px) {
  .sheet { margin: auto 0 0; max-width: 100%; border-radius: 24px 24px 0 0; }
}
.sheet-inner { padding: 22px 18px max(22px, env(safe-area-inset-bottom)); display: grid; gap: 12px; position: relative; }
.sheet-x { position: absolute; top: 10px; right: 10px; }
.sheet h2 { font-size: 1.6rem; padding-right: 44px; }
.about { color: var(--muted); }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.lv {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px;
  min-height: 44px; font-weight: 700; display: grid; place-items: center;
}
.lv.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.lv:disabled { opacity: .45; cursor: not-allowed; }
.lv .ico { width: 16px; height: 16px; }
.hs-body { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: start; }
.hs-fig { background: var(--surface-2); border-radius: 14px; padding: 8px; aspect-ratio: 4 / 5; display: grid; place-items: center; }
.hs-body h3 { font-size: 1.1rem; margin-bottom: 4px; }
.toggle { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.field { display: grid; gap: 4px; }
.field select { font: inherit; padding: 10px 12px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); min-height: 44px; }

/* ---------- Session ---------- */
.screen.session {
  position: fixed; inset: 0; max-width: none; padding: 0;
  background: #0d0906; color: #fff; overflow: hidden; z-index: 5;
}
.stage { position: absolute; inset: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
/* Sized and positioned from JS (auto-framing); see placeVideo in app.js. */
.stage video { position: absolute; left: 0; top: 0; transform-origin: 0 0; opacity: .9; }
body.demo .stage video { display: none; }
.honour-fig { position: absolute; inset: 22% 10% 22%; display: grid; place-items: center; }
.figure.big { max-height: none; }
.figure.big .bones line, .figure.big .head { stroke: #f3e9da; stroke-width: 2.6; }
.figure.big .ground { stroke: rgba(255, 255, 255, .25); }

.hud {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
  pointer-events: none;
  background: linear-gradient(rgba(0, 0, 0, .55), transparent 30%, transparent 62%, rgba(0, 0, 0, .65));
}
.hud > * { pointer-events: auto; }
.hud-top { width: 100%; display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; }
.hud-x { color: #fff; background: rgba(255, 255, 255, .12); }
.hud-title { display: grid; text-align: center; line-height: 1.2; }
.hud-title strong { font-family: var(--display); font-size: 1.1rem; }
.hud-title small { opacity: .75; }
.hud-coins {
  display: grid; grid-template-columns: auto auto; align-items: center; gap: 2px 6px;
  font-variant-numeric: tabular-nums; justify-items: end;
}
.hud-coins .coin { width: 26px; height: 26px; color: #ffcf73; }
.hud-coins b { font-size: 1.6rem; color: #ffcf73; line-height: 1; }
.coin-next { grid-column: 1 / -1; width: 100%; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .2); overflow: hidden; }
.coin-next i { display: block; height: 100%; width: 0; background: #ffcf73; }
.hud-coins.pop { animation: coinpop .45s cubic-bezier(.2, 1.8, .4, 1); }
@keyframes coinpop { 40% { transform: scale(1.35); } }

.timer {
  font-variant-numeric: tabular-nums; font-weight: 800; line-height: 1;
  font-size: clamp(64px, 24vw, 200px); margin-top: 2vh;
  text-shadow: 0 4px 24px rgba(0, 0, 0, .5);
}
.timer .of { font-size: .28em; opacity: .6; font-weight: 600; }
.tbar { width: min(560px, 90%); height: 10px; border-radius: 5px; background: rgba(255, 255, 255, .2); overflow: hidden; margin-top: 6px; }
.tbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #f0b350, #f06a2c); transition: width .2s linear; }
.tbar i.over { background: linear-gradient(90deg, #7bd88f, #f0b350, #f06a2c); animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow { to { filter: brightness(1.35); } }

.status {
  margin-top: 14px; padding: 8px 20px; border-radius: var(--r-btn);
  font-weight: 800; font-size: clamp(18px, 5.5vw, 36px); text-align: center; max-width: 94%;
  background: rgba(0, 0, 0, .45); backdrop-filter: blur(6px);
}
.status:empty { display: none; }
.status.good { background: rgba(60, 160, 85, .85); }
.status.bonus { background: linear-gradient(90deg, #d9962b, #f06a2c); color: #1a0f08; }
.status.bad { background: rgba(200, 55, 45, .88); animation: pulse .8s ease-in-out infinite alternate; }
.status.wait { background: rgba(0, 0, 0, .5); }
@keyframes pulse { to { transform: scale(1.04); } }
.cue {
  /* Big enough to read from 2–3 m away. */
  margin-top: 10px; font-size: clamp(21px, 6.4vw, 40px); font-weight: 700; line-height: 1.2; text-align: center;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .8); max-width: 92%; min-height: 1.4em;
}

.hud-bottom { margin-top: auto; width: 100%; display: grid; grid-template-columns: 76px 1fr; grid-template-rows: auto auto; gap: 10px 12px; align-items: center; }
.ref { grid-row: span 2; background: rgba(255, 255, 255, .1); border-radius: 12px; padding: 6px; height: 96px; }
.ref .figure .bones line, .ref .figure .head { stroke: #fff; }
.ref .figure .ground { stroke: rgba(255, 255, 255, .3); }
.meter { position: relative; height: 34px; border-radius: 17px; background: rgba(255, 255, 255, .16); overflow: hidden; }
.meter .fill { position: absolute; inset: 0 auto 0 0; width: 0; transition: width .15s linear, background .3s; }
.meter .fill.good { background: #4fbf6a; }
.meter .fill.warn { background: #e9a23b; }
.meter .fill.bad { background: #d6493d; }
.meter .tick { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(255, 255, 255, .7); }
.meter span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem; text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.hud-btns { display: flex; gap: 10px; justify-content: center; grid-column: 1 / -1; }
.hud-btns:empty { display: none; }
.hud-btns .btn { min-width: 130px; min-height: 56px; font-size: 1.1rem; background: rgba(255, 255, 255, .14); border-color: transparent; color: #fff; }
.hud-btns .btn.primary { background: #f06a2c; color: #1a0f08; }
.session .hud-bottom:has(.meter[hidden]) { grid-template-columns: 1fr; }

.error-panel {
  position: absolute; inset: auto 16px 50% 16px; transform: translateY(50%);
  background: #211912; border-radius: 20px; padding: 22px; display: grid; gap: 12px; text-align: center;
  max-width: 460px; margin: 0 auto;
}
.error-panel .btn { color: #f3e9da; background: #2b2118; border-color: #3a2d22; }
.error-panel .btn.primary { background: #f06a2c; color: #1a0f08; border-color: #f06a2c; }

/* Landscape phones: the controls move into a panel down the left, leaving the
   rest of the screen for your body (auto-framing keeps clear of the panel). */
@media (orientation: landscape) and (max-height: 600px) {
  .hud {
    display: grid; grid-template-columns: min(38%, 300px) 1fr; grid-auto-rows: min-content;
    align-items: start; justify-items: stretch; row-gap: 8px;
    padding-left: max(14px, env(safe-area-inset-left));
    background: linear-gradient(90deg, rgba(0, 0, 0, .65), rgba(0, 0, 0, .35) 38%, transparent 55%);
  }
  .hud > * { grid-column: 1; }
  .hud-top { grid-column: 1 / -1; }
  .timer { font-size: min(17vh, 12vw); margin-top: 0; text-align: left; }
  .tbar { width: 100%; margin-top: 0; }
  .status { margin-top: 2px; font-size: clamp(15px, 4.5vh, 24px); justify-self: start; max-width: 100%; }
  .cue { margin-top: 0; font-size: clamp(17px, 6vh, 28px); text-align: left; max-width: 100%; }
  .hud-bottom { margin-top: 4px; grid-template-columns: 56px 1fr; }
  .ref { height: 64px; }
  .meter { height: 28px; }
}

/* ---------- Summary ---------- */
.summary { text-align: center; }
.sum-inner { display: grid; gap: 14px; padding-top: 4vh; }
.sum-kicker { text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; color: var(--muted); font-weight: 700; }
.summary h1 { font-size: clamp(2rem, 8vw, 3rem); line-height: 1.05; }
.sum-points { display: grid; }
.sum-points span {
  font-size: clamp(64px, 22vw, 120px); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums;
  background: linear-gradient(180deg, var(--gold), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.sum-points small { color: var(--muted); font-weight: 600; }
.sum-breakdown { color: var(--muted); font-size: .9rem; min-height: 1em; }
.sum-stats, .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stats { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.sum-stats > div, .stats > div {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 12px 8px; display: grid; gap: 2px;
}
.sum-stats b, .stats b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.sum-stats small, .stats small { color: var(--muted); font-size: .78rem; }
.banner {
  background: color-mix(in srgb, var(--gold) 18%, var(--surface)); border: 1px solid var(--gold);
  border-radius: 16px; padding: 14px; font-weight: 500;
}
.lvl-progress { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); flex-wrap: wrap; }
.lvl-progress .pips i { width: 12px; height: 12px; }
.sum-badges { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.sum-badges .badge { animation: pop .5s cubic-bezier(.2, 1.6, .4, 1) both; width: 150px; }
.sum-badges .badge:nth-child(2) { animation-delay: .15s; }
.sum-badges .badge:nth-child(3) { animation-delay: .3s; }
@keyframes pop { from { transform: scale(.5); opacity: 0; } }
.sum-msg { color: var(--muted); }

/* ---------- Progress ---------- */
.subbar { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.subbar h1 { font-size: 1.6rem; }
.rank-card {
  display: flex; align-items: center; gap: 18px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.rank-card > div { display: grid; gap: 6px; flex: 1; }
.rank-card .xpbar { width: 100%; height: 8px; }
.rank-card small { color: var(--muted); }
.heatmap {
  display: grid; grid-template-rows: repeat(7, 1fr); grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
}
.heatmap i { aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); }
.heatmap i.l1 { background: color-mix(in srgb, var(--accent) 30%, var(--surface-2)); }
.heatmap i.l2 { background: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); }
.heatmap i.l3 { background: color-mix(in srgb, var(--accent) 78%, var(--surface-2)); }
.heatmap i.l4 { background: var(--accent); }
.heatmap i.future { background: transparent; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.badge {
  display: grid; justify-items: center; gap: 2px; text-align: center; padding: 14px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
}
.badge b { font-size: .92rem; }
.badge small { color: var(--muted); font-size: .75rem; line-height: 1.3; }
.medal { width: 38px; height: 38px; margin-bottom: 4px; }
.medal circle { fill: var(--gold); stroke: color-mix(in srgb, var(--gold) 60%, #000); stroke-width: 1.2; }
.medal path { fill: var(--accent); }
.badge.locked { opacity: .45; }
.badge.locked .medal circle { fill: var(--surface-2); stroke: var(--line); }
.badge.locked .medal path { fill: var(--line); }
.badge.rank .sash { margin: 0 0 8px; }
.history { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.history li {
  display: grid; grid-template-columns: 1fr auto 2.5em 4em; gap: 4px 10px; align-items: center;
  padding: 10px 14px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; font-size: .92rem;
}
.history li:first-child { border-top: 0; }
.history li > span:nth-child(n+2) { text-align: right; }
.history li > span:nth-child(3) { color: var(--muted); }
.history li > span:nth-child(4) { color: var(--accent); font-weight: 700; }
.history .when { grid-column: 1 / -1; color: var(--muted); margin-top: -4px; }
.history small { color: var(--muted); }
.history .empty { display: block; color: var(--muted); text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px; z-index: 20; font-weight: 600;
  box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Temple scene ---------- */
.temple-banner {
  display: block; width: 100%; padding: 0; border: 0; margin: 0 0 14px; position: relative;
  border-radius: var(--radius); overflow: hidden; background: #000; box-shadow: var(--shadow); cursor: pointer;
}
.temple-banner.static { cursor: default; }
.temple-banner canvas { display: block; width: 100%; height: auto; image-rendering: pixelated; image-rendering: crisp-edges; }
button.chip { cursor: pointer; }
.freezes, .ss-head .freezes { color: #7fc8ff; font-weight: 800; }
.freezes:empty { display: none; }

/* ---------- Home cards ---------- */
/* ---------- Streak strip ---------- */
.streak-strip {
  display: grid; gap: 10px; width: 100%; margin: 0 0 14px; padding: 12px 14px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); font: inherit;
}
.ss-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ss-head b { font-size: 1rem; }
.ss-head span { font-size: .82rem; font-weight: 700; color: var(--gold); }
.ss-days { display: flex; align-items: flex-start; justify-content: space-between; gap: 2px; }
.ss-day { display: grid; justify-items: center; gap: 3px; flex: 1; min-width: 0; }
.ss-day i {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-style: normal;
  font-size: .72rem; font-weight: 800; border: 2px solid var(--line); color: var(--muted); background: transparent;
}
.ss-day small { font-size: .62rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.ss-day.trained i { background: var(--accent); border-color: var(--accent); color: var(--accent-ink, #fff); }
.ss-day.repair i { background: color-mix(in srgb, var(--accent) 45%, var(--surface)); border-color: transparent; color: var(--ink); }
.ss-day.rest i { border-color: var(--muted); border-style: dashed; }
.ss-day.freeze i { background: #7fc8ff; border-color: #7fc8ff; color: #0e2a40; }
.ss-day.missed i { background: var(--surface-2); border-color: transparent; }
.ss-day.open i { border-style: dashed; }
.ss-day.today i { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--gold); }
.ss-day.today small { color: var(--ink); font-weight: 800; }
.ss-day.goal i { border: 2px solid var(--gold); background: color-mix(in srgb, var(--gold) 18%, var(--surface)); font-size: .8rem; }
.ss-day.goal small { color: var(--gold); font-weight: 800; }
.ss-gap { align-self: center; margin-top: -14px; color: var(--muted); font-weight: 800; letter-spacing: .1em; }
.ss-next { font-size: .85rem; color: var(--muted); line-height: 1.35; }
.ss-next b { color: var(--ink); }

.home-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px; display: grid; gap: 10px;
}
.home-card.warn { border-color: color-mix(in srgb, var(--bad) 50%, var(--line)); }
.home-card.bet { border-color: var(--gold); }
.home-card.test-mode { border: 1.5px dashed var(--accent); }
.home-card .row { justify-content: flex-end; flex-wrap: wrap; }
.home-card .btn { display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 8px 16px; }
.home-card small { color: var(--muted); }
.progress { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); }

/* ---------- Shop ---------- */
.subbar .shop-wallet { margin-left: auto; }
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 5px; margin-bottom: 14px; }
.tabs button {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; min-height: 42px; font-weight: 700;
  padding: 0 4px; font-size: clamp(.78rem, 3.6vw, .95rem); min-width: 0;
}
.tabs button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.shop-intro { color: var(--muted); margin-bottom: 12px; font-size: .92rem; }
.shop-note { color: var(--muted); font-size: .88rem; }
.shop-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.shop-list li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.shop-list li:first-child { border-top: 0; }
.shop-list li > div { display: grid; gap: 2px; flex: 1; }
.shop-list small { color: var(--muted); font-size: .82rem; }
.shop-list small.blocked { color: var(--bad); }
.shop-list li.owned b { color: var(--muted); }
.btn.buy { display: inline-flex; align-items: center; gap: 5px; min-height: 40px; padding: 6px 14px; white-space: nowrap; }
.owned-tag { font-size: .78rem; font-weight: 700; color: var(--good); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.theme-card { background: var(--surface); border: 1.5px solid var(--line); border-radius: 16px; padding: 8px; display: grid; gap: 4px; justify-items: start; }
.theme-card.active { border-color: var(--accent); }
.theme-card canvas { width: 100%; height: auto; border-radius: 10px; image-rendering: pixelated; }
.theme-card small { color: var(--muted); font-size: .78rem; }
#shop-body h3 { font-size: 1.05rem; margin: 20px 0 6px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
#shop-body h3 small { font-family: var(--sans); font-weight: 600; font-size: .8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
#shop-body h3 small .ico { width: 14px; height: 14px; }
.streak-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; font-weight: 600; }
.streak-head small { color: var(--muted); font-weight: 500; }
.big-flame { font-size: 2rem; font-weight: 800; white-space: nowrap; }
.rest-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 8px; }
.rest-day {
  display: grid; justify-items: center; padding: 6px 0; border-radius: 12px;
  border: 1.5px solid var(--line); background: var(--surface); line-height: 1.2;
}
.rest-day b { font-size: 1.1rem; }
.rest-day small { font-size: .7rem; color: var(--muted); }
.rest-day.on { background: color-mix(in srgb, #7fc8ff 25%, var(--surface)); border-color: #7fc8ff; }
.rest-day:disabled { opacity: .4; cursor: not-allowed; }
.shop-row { display: flex; align-items: center; gap: 12px; }
.shop-row p { flex: 1; }
.milestones { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.milestones li { display: flex; justify-content: space-between; padding: 8px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); font-size: .9rem; }
.milestones li.done { color: var(--muted); text-decoration: line-through; }

/* ---------- Level test, summary extras ---------- */
.lv.test { border-style: dashed; border-color: var(--gold); opacity: 1; }
.lv.test.on { background: var(--gold); border-color: var(--gold); color: #1a0f08; }
.test-msg { font-size: .9rem; background: color-mix(in srgb, var(--gold) 14%, var(--surface)); border: 1px dashed var(--gold); border-radius: 12px; padding: 10px 12px; }
.sum-extra { display: grid; gap: 8px; }
.sum-extra:empty { display: none; }
.banner.good { background: color-mix(in srgb, var(--good) 18%, var(--surface)); border-color: var(--good); }
.banner.bad { background: color-mix(in srgb, var(--bad) 14%, var(--surface)); border-color: var(--bad); }
.banner.gold { background: color-mix(in srgb, var(--gold) 22%, var(--surface)); border-color: var(--gold); font-weight: 700; }

/* ---------- Theme accents (set from the temple theme) ---------- */
:root[data-scene="day"] { --accent: #2f8a55; --gold: #e0a83a; }
:root[data-scene="dusk"] { --accent: #b8406e; --gold: #f0a040; }
:root[data-scene="autumn"] { --accent: #c4561c; --gold: #e8a040; }
:root[data-scene="night"] { --accent: #5b74e8; --gold: #f0c860; }
:root[data-scene="snow"] { --accent: #3a7ab8; --gold: #d8a848; }

/* ---------- Install ---------- */
.install-box {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface)); border: 1px solid var(--line);
}
.install-box > div { display: grid; gap: 2px; flex: 1; }
.install-box small { color: var(--muted); font-size: .85rem; }
.install-box .btn { min-height: 42px; padding: 8px 18px; }

/* ---------- Video links ---------- */
.video-link {
  display: inline-flex; align-items: center; gap: 6px; justify-self: start; margin-top: 6px;
  color: var(--accent); font-weight: 600; text-decoration: none; font-size: .92rem;
}
.video-link .ico { width: 20px; height: 20px; color: #e33; }

/* ---------- Celebrations ---------- */
.celebrate {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: rgba(15, 9, 5, .72); backdrop-filter: blur(3px); animation: fadein .25s ease-out;
}
@keyframes fadein { from { opacity: 0; } }
.cel-card {
  position: relative; width: min(380px, 100%); text-align: center; display: grid; gap: 10px;
  background: var(--surface); border: 2px solid var(--gold); border-radius: 24px; padding: 28px 22px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5); animation: pop .5s cubic-bezier(.2, 1.6, .4, 1) both;
}
.celebrate.lose .cel-card { border-color: var(--line); }
.cel-kicker { text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; font-weight: 800; color: var(--gold); }
.celebrate.lose .cel-kicker { color: var(--muted); }
.cel-card h2 { font-size: 1.7rem; }
.cel-coins { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 3.2rem; font-weight: 800; color: var(--gold); line-height: 1; }
.cel-coins .ico { width: 44px; height: 44px; }
.cel-msg { color: var(--muted); }
.cel-card .row { margin-top: 6px; }
.cel-burst { position: absolute; left: 50%; top: 38%; width: 0; height: 0; pointer-events: none; }
.cel-burst i {
  position: absolute; left: -12px; top: -12px; width: 24px; height: 24px; opacity: 0;
  animation: burst 1.1s cubic-bezier(.15, .8, .3, 1) var(--d) forwards;
}
.cel-burst .ico { width: 24px; height: 24px; color: var(--gold); }
@keyframes burst {
  0% { transform: translate(0, 0) scale(.4); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(200deg); opacity: 0; }
}
.bets-log li { grid-template-columns: 1fr auto; }
.bets-log .bet-result { font-weight: 700; }
.bets-log li.won .bet-result { color: var(--good); }
.bets-log li.lost .bet-result { color: var(--muted); }

/* ---------- Body areas ---------- */
.card-kind { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.card-kind.soft { color: #5aa89a; }
.card.tired .figure { opacity: .55; }
.card-flag.rest { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.tag.style-soft { background: color-mix(in srgb, #5aa89a 20%, transparent); color: #3f8f80; font-weight: 700; }
.tag.style-hard { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); font-weight: 700; }
.home-card.rest-hint { border-color: color-mix(in srgb, #5aa89a 55%, var(--line)); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn {
  border: 1.5px solid var(--line); background: var(--surface-2); border-radius: var(--r-chip);
  padding: 8px 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
}
.chip-btn .ico { width: 14px; height: 14px; }
.area-bars { display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.area-row { display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: 10px; font-size: .9rem; }
.area-bar { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.area-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--accent)); border-radius: inherit; }

/* ---------- Live checklist ----------
   A column of round ticks down the left. A check that needs fixing slides open to the
   right with what to do, and closes back to a tick once it's right again. */
.checks {
  position: absolute; left: max(10px, env(safe-area-inset-left)); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; pointer-events: none;
  max-width: calc(100% - 20px);
}
.checks:empty { display: none; }
.chk {
  --c: #4fbf6a; --t: #a8f0b8;
  display: flex; align-items: center; min-height: 40px; max-width: 100%; border-radius: 20px;
  background: rgba(0, 0, 0, .6); color: var(--t); border: 2px solid var(--c);
  font-size: clamp(15px, 4.4vw, 20px); font-weight: 700; line-height: 1.2;
  transition: border-radius .25s, border-color .25s, color .25s;
}
.chk.meh { --c: #e9a23b; --t: #ffd38a; }
.chk.bad { --c: #d6493d; --t: #ffb3aa; }
.chk i { flex: none; width: 36px; text-align: center; font-style: normal; font-size: 18px; font-weight: 900; }
.chk span {
  max-width: 0; opacity: 0; overflow: hidden; white-space: nowrap;
  transition: max-width .35s ease, opacity .25s ease, padding .35s ease;
}
.chk.open { border-radius: 14px; }
.chk.open span { max-width: calc(100vw - 80px); opacity: 1; white-space: normal; padding: 6px 14px 6px 0; }
@media (orientation: landscape) and (max-height: 600px) {
  /* Landscape: the checks sit in the side panel with the other controls. */
  .checks { position: static; transform: none; max-width: 100%; }
  .chk { font-size: 15px; min-height: 34px; }
  .chk i { width: 30px; font-size: 15px; }
  .chk.open span { max-width: 100%; }
}

/* ---------- Version ---------- */
.version { font-size: .82rem; color: var(--muted); text-align: center; margin-top: 4px; }
.version .fresh { color: var(--good); }
.version .stale { color: var(--warn); font-weight: 700; }
.chk small { font-weight: 600; opacity: .8; font-variant-numeric: tabular-nums; }

/* ---------- Segmented switch (Settings > Appearance) ---------- */
.appearance { border: 0; margin: 0; padding: 0; display: grid; gap: 6px; }
.appearance legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--surface-2); border-radius: 14px; padding: 4px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; border-radius: 11px;
  font-weight: 600; font-size: .92rem; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.segmented .ico { width: 18px; height: 18px; }
.segmented input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.version #version { cursor: default; user-select: none; -webkit-user-select: none; }
