/* RIVAL v2 — mobile-first pixel UI. Frames, icons and scenes are PNGs from the asset pack; all text is live. */
@font-face {
  font-family: 'Rival Pixel';
  /* Repaired by scripts/fix-font.js: the supplied file maps isolated ت ذ ر ز و ى ي and لا to blank glyphs. */
  /* ?v must match ASSET_V in src/views/layout.js, which preloads the same URL. */
  src: url('/rival/fonts/ArabicPixel2-rival.woff?v=7') format('woff');
  font-display: swap;
}
:root {
  --bg: #120f24;
  --bg-2: #171329;
  --panel: #19152c;
  --field: #100d1f;
  --line: #554071;
  --line-2: #655084;
  --ink: #f6eeda;
  --text: #e6e0f5;
  --muted: #b5abd8;
  --pink: #f34b99;
  --pink-hi: #ff7db8;
  --pink-ink: #24081a;
  --link: #ffb1d3;
  --amber: #f2c14e;
  --good: #63e3aa;
  --bad: #ff9aa5;
  --pixel: 'Rival Pixel', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --body: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bar: 56px;
  --tab: 64px;
  --col: 620px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scrollbar-color: var(--line) var(--bg); scroll-padding-top: calc(var(--bar) + 12px); }
body { margin: 0; background: var(--bg) url(/static/stars.svg); color: var(--text); font: 400 1rem/1.7 var(--body); caret-color: var(--pink); overflow-wrap: anywhere; min-height: 100dvh; }
html[lang='en'] body { line-height: 1.55; }
::selection { background: var(--pink); color: var(--pink-ink); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--line); border: 2px solid var(--bg); }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
main:focus { outline: none; }
h1, h2, h3, p, ul, ol, dl, dd, figure, blockquote, fieldset, legend { margin: 0; padding: 0; }
ul, ol { list-style: none; }
fieldset { border: 0; min-width: 0; }
a { color: var(--link); text-underline-offset: 0.2em; }
a:hover { color: var(--ink); }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
table { border-collapse: collapse; width: 100%; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; inset-inline-start: 0.75rem; top: -4rem; z-index: 60; background: var(--amber); color: var(--bg); padding: 0.5rem 1rem; font-weight: 600; }
.skip:focus { top: 0.5rem; }

/* Pixel type: headings and short interface labels use the supplied font; body text stays in a clear Arabic face. */
h1, h2, h3, .btn, .seg a, .seg label span, .tabbar span, .chip, .topbar-title, .num, .rank, .step-num, .qnode, .hero-tag, .top-link, .lang-btn, .balance-num, .score td, .error-code, .score-line, .reward-points, .opt-label, .pick-title, .rows-head, .section-title {
  font-family: var(--pixel); font-weight: 400; letter-spacing: 0; line-height: 1.5;
}
h1 { font-size: 2rem; color: var(--ink); text-wrap: balance; }
h2 { font-size: 1.5rem; color: var(--ink); }
h3 { font-size: 1.25rem; color: var(--ink); }
.num { font-variant-numeric: tabular-nums; color: var(--ink); }
.num.gold, .gold { color: var(--amber); }
.num.big { font-size: 1.75rem; }
.meta, .hint { color: var(--muted); font-size: 0.875rem; }
.hint { max-width: 70ch; }
.pi { inline-size: 24px; block-size: 24px; flex: none; image-rendering: pixelated; display: inline-block; vertical-align: middle; }
.hint .pi, .foot-note .pi, .chip .pi, .callout > .pi, .card-line .pi { inline-size: 16px; block-size: 16px; }
.section-title { font-size: 1.25rem; color: var(--muted); margin-block: 0.5rem 0; }

/* ---- shell ---- */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 0.5rem; block-size: var(--bar); padding-inline: max(0.75rem, calc((100vw - var(--col)) / 2 + 0.75rem)); background: #100d20; border-block-end: 2px solid #2c2449; }
.logo { display: inline-flex; align-items: center; min-block-size: 44px; }
.logo img { block-size: 30px; inline-size: auto; image-rendering: pixelated; }
.topbar-title { font-size: 1.25rem; color: var(--ink); min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; }
.topbar-end { display: flex; align-items: center; gap: 0.4rem; margin-inline-start: auto; }
/* flex: none + nowrap: the body's `overflow-wrap: anywhere` was splitting a two-digit balance
   down the middle ("1" over "0") once the bar ran out of room. The title ellipsizes instead. */
.hud { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem; min-inline-size: 44px; block-size: 40px; padding-inline: 0.5rem; background: var(--panel); border: 2px solid var(--line); color: var(--ink); text-decoration: none; flex: none; white-space: nowrap; overflow-wrap: normal; }
.hud .num { white-space: nowrap; overflow-wrap: normal; }
.hud:hover { border-color: var(--pink); }
.hud.back { background: none; }
.hud.coin .num { color: var(--amber); font-size: 1.125rem; }
.hud.me { padding: 0; inline-size: 40px; overflow: hidden; }
.pt { display: inline-block; inline-size: 40px; block-size: 40px; flex: none; overflow: hidden; background: #2a2145; }
.pt img { inline-size: 100%; block-size: 100%; object-fit: cover; object-position: 50% 20%; image-rendering: pixelated; }
.pt.lg { inline-size: 72px; block-size: 72px; border: 2px solid var(--line); }
.badge { display: inline-grid; place-items: center; min-inline-size: 18px; block-size: 18px; padding-inline: 4px; background: var(--pink); color: var(--pink-ink); font: 700 0.6875rem/1 var(--body); font-variant-numeric: tabular-nums; }
.hud .badge, .tabbar .badge { position: absolute; top: -6px; inset-inline-end: -6px; }
.top-link { color: var(--ink); text-decoration: none; min-block-size: 44px; display: inline-flex; align-items: center; padding-inline: 0.5rem; font-size: 1.125rem; }
.lang-btn { display: inline-flex; align-items: center; gap: 0.3rem; min-block-size: 40px; padding-inline: 0.6rem; background: var(--panel); border: 2px solid var(--line); cursor: pointer; color: var(--ink); }
.lang-btn:hover { border-color: var(--pink); }
.lang-btn .pi { inline-size: 16px; block-size: 16px; }

main { max-inline-size: var(--col); margin-inline: auto; }
.is-app main { padding-block-end: calc(var(--tab) + env(safe-area-inset-bottom) + 1rem); }
.page { padding: 1rem 0.875rem 1.5rem; display: grid; gap: 0.875rem; align-content: start; }
.page > * { min-inline-size: 0; }
.stack { display: grid; gap: 0.875rem; }

.tabbar { position: fixed; inset-inline: 0; inset-block-end: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 6px max(8px, calc((100vw - var(--col)) / 2 + 8px)) calc(6px + env(safe-area-inset-bottom)); background: #100d20; border-block-start: 2px solid #2c2449; }
.tabbar a { position: relative; display: grid; justify-items: center; align-content: center; gap: 0; min-block-size: 52px; color: var(--muted); text-decoration: none; font-size: 0.9375rem; border: 2px solid transparent; }
.tabbar a span { line-height: 1.3; white-space: nowrap; }
/* "Challenges" must not break in two on a 360px phone. */
@media (max-width: 400px) { .tabbar a { font-size: 0.8125rem; } }
.tabbar a:hover { color: var(--ink); }
.tabbar a[aria-current='page'] { color: var(--pink-hi); background: #2a1a3a; border-color: #8a3a72; }

/* ---- frames (9-slice PNGs from the pack) ---- */
.card, .callout, .row, .words, .empty, .ms-edit { border: 8px solid transparent; border-image: url(/rival/ui/frames/panel.png) 8 fill / 8px / 0 stretch; image-rendering: pixelated; }
.card { padding: 0.5rem 0.625rem 0.625rem; display: grid; gap: 0.5rem; align-content: start; }
.card > * { image-rendering: auto; min-inline-size: 0; }
.card-title { display: flex; align-items: flex-start; gap: 0.5rem; font-size: 1.375rem; }
.card-title .pi { margin-block-start: 0.3rem; }
.card-line { color: var(--text); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; min-block-size: 48px; padding: 0 0.75rem;
  border: 8px solid transparent; border-image: url(/rival/ui/frames/secondary.png) 8 fill / 8px / 0 stretch; image-rendering: pixelated;
  background: none; color: var(--ink); cursor: pointer; text-decoration: none; text-align: center; font-size: 1.25rem; line-height: 1.3;
  /* Labels are ours and short: never break one mid-word the way body text may (`overflow-wrap: anywhere`). */
  overflow-wrap: normal;
  transition: transform 90ms var(--ease), filter 120ms linear;
}
.btn:hover { filter: brightness(1.18); color: var(--ink); }
.btn:active { transform: translateY(2px); }
.btn.primary { border-image-source: url(/rival/ui/frames/primary.png); color: var(--pink-ink); }
.btn.primary .pi { filter: brightness(0) saturate(100%) opacity(0.8); }
.btn.danger { border-image-source: url(/rival/ui/frames/danger.png); color: #ffd3da; }
.btn.big { min-block-size: 56px; font-size: 1.5rem; }
.btn.small { min-block-size: 44px; font-size: 1.0625rem; }
.btn.block { display: flex; inline-size: 100%; }
.btn[disabled], .btn[aria-disabled='true'] { border-image-source: url(/rival/ui/frames/disabled.png); color: #8d84ad; cursor: not-allowed; transform: none; filter: none; }
.btn[disabled] .pi { filter: grayscale(1) opacity(0.5); }
.btn.is-busy { cursor: progress; filter: saturate(0.6); }
/* 150px is what the longest label ("Finished", "استمرار") needs beside its icon at 1.25rem;
   below that the row stacks rather than squeezing the words. */
.btn-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.625rem; }
.btn-row > form { display: grid; }
.btn-row .btn, form > .btn.block { inline-size: 100%; }

.row { display: flex; align-items: center; gap: 0.625rem; min-block-size: 56px; padding: 0.125rem 0.375rem; color: var(--text); text-decoration: none; inline-size: 100%; background: none; cursor: pointer; text-align: start; }
a.row:hover, button.row:hover { filter: brightness(1.2); color: var(--text); }
.row.static { cursor: default; }
.row-main { flex: 1 1 auto; min-inline-size: 0; display: grid; }
.row-title { font-weight: 600; color: var(--ink); }
.row-sub { color: var(--muted); font-size: 0.875rem; }
.row .chev { inline-size: 20px; block-size: 20px; opacity: 0.8; }
.row.is-done .row-title { color: var(--muted); }
.row.unread { border-image-source: url(/rival/ui/frames/selected.png); }
.rows { display: grid; gap: 0.5rem; }
.rows-head { font-size: 1.125rem; color: var(--amber); padding-block-start: 0.25rem; }
.rank { inline-size: 2ch; text-align: center; font-size: 1.375rem; color: var(--muted); flex: none; }

/* Tabs share the width evenly while they fit; past that the row scrolls sideways rather than
   truncating a label ("Completed" -> "Comple" tells the user nothing). minmax(max-content, 1fr)
   does both: 1fr when there is room, the label's own width when there is not. */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(max-content, 1fr); gap: 0.375rem;
  overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: none; padding-block: 3px; }
.seg::-webkit-scrollbar { display: none; }
.seg a, .seg label span { display: grid; place-items: center; min-block-size: 44px; padding-inline: 0.3125rem; white-space: nowrap; border: 8px solid transparent; border-image: url(/rival/ui/frames/secondary.png) 8 fill / 8px / 0 stretch; image-rendering: pixelated; color: var(--text); text-decoration: none; font-size: clamp(0.875rem, 3.6vw, 1.0625rem); text-align: center; cursor: pointer; line-height: 1.2; }
.seg a[aria-current='page'], .seg input:checked + span { border-image-source: url(/rival/ui/frames/primary.png); color: var(--pink-ink); }
.seg label { position: relative; display: grid; }
.seg input { position: absolute; inset: 0; opacity: 0; inline-size: 100%; block-size: 100%; margin: 0; cursor: pointer; }
.seg input:focus-visible + span { outline: 3px solid var(--amber); outline-offset: 2px; }

.chip { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.9375rem; line-height: 1.5; padding: 0 0.5rem; border: 2px solid var(--line); color: var(--muted); background: var(--field); white-space: nowrap; vertical-align: middle; }
.chip.s-draft, .chip.warn, .chip.demo, .chip.gold { border-color: #8f7636; color: var(--amber); }
.chip.demo { border-style: dashed; }
.chip.s-active { border-color: #2f7c74; color: #7fe3d6; }
.chip.s-completed { border-color: #2f7c5c; color: var(--good); }
.chip.pink { border-color: #9b3a73; color: var(--pink-hi); }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }

.callout { padding: 0.5rem 0.625rem; display: grid; gap: 0.4rem; }
.callout h2 { font-size: 1.375rem; }
.callout.good { border-image-source: url(/rival/ui/frames/node-finished.png); }
.callout.warn, .callout.bad { border-image-source: url(/rival/ui/frames/danger.png); }
.callout.demo { color: var(--muted); font-size: 0.9375rem; }
.flash { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; border: 2px solid; background: var(--panel); font-weight: 600; }
.flash.ok { border-color: #2f7c5c; color: var(--good); }
.flash.bad { border-color: #9b4a5c; color: var(--bad); }
.words { padding: 0.4rem 0.625rem 0.5rem; }
.words figcaption { color: var(--muted); font-size: 0.8125rem; font-weight: 600; }
.words blockquote { font-size: 1.0625rem; color: var(--ink); white-space: pre-wrap; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.5rem 1rem; }
.facts.trio { grid-template-columns: repeat(3, 1fr); text-align: center; }
.facts dt { color: var(--muted); font-size: 0.8125rem; font-weight: 600; }
.facts dd { color: var(--ink); font-weight: 600; }
.basis { font-weight: 600; color: var(--ink); }
.bullets { display: grid; gap: 0.25rem; }
.bullets li { position: relative; padding-inline-start: 1rem; }
.bullets li::before { content: ''; position: absolute; inset-inline-start: 0; top: 0.7em; inline-size: 6px; block-size: 6px; background: var(--pink); }
.foot-note { color: var(--muted); font-size: 0.875rem; text-align: center; }
.empty { text-align: center; padding: 1.25rem 0.75rem; display: grid; justify-items: center; gap: 0.5rem; }
.empty p { color: var(--muted); max-inline-size: 40ch; }
.empty-ic .pi { inline-size: 48px; block-size: 48px; }
.error-code { font-size: 4rem; color: var(--pink); }
.pager, .group-nav { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }

/* ---- forms ---- */
.form { display: grid; gap: 0.875rem; }
.field label, .field legend { display: block; font-weight: 600; margin-block-end: 0.3rem; color: var(--ink); }
.opt { color: var(--muted); font-weight: 400; }
input[type='text'], input[type='email'], input[type='password'], input[type='date'], select, textarea {
  inline-size: 100%; min-block-size: 48px; padding: 0.55rem 0.75rem; background: var(--field); border: 2px solid var(--line); border-radius: 0; color: var(--ink);
}
textarea { resize: vertical; line-height: 1.7; display: block; }
input::placeholder, textarea::placeholder { color: #9f95c4; opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: var(--line-2); }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--pink); outline-offset: 1px; }
.has-error input, .has-error textarea, [aria-invalid='true'] { border-color: var(--bad); }
.field-error { color: var(--bad); font-weight: 600; }
.input-ic { position: relative; }
.input-ic .pi { position: absolute; inset-inline-end: 0.75rem; top: 12px; pointer-events: none; opacity: 0.85; }
.input-ic input, .input-ic select { padding-inline-end: 2.75rem; }
.inline-fields { display: flex; gap: 0.5rem; }
.inline-fields select { inline-size: auto; }
input.narrow { inline-size: 7rem; flex: none; }
.check { display: flex; align-items: flex-start; gap: 0.6rem; cursor: pointer; padding-block: 0.3rem; min-block-size: 44px; }
.check input { flex: none; inline-size: 22px; block-size: 22px; margin-block-start: 0.2rem; accent-color: var(--pink); }
.check.small { font-size: 0.875rem; align-items: center; white-space: nowrap; }
.check.small input { margin: 0; }
.toggle { position: relative; display: flex; align-items: center; gap: 0.75rem; min-block-size: 48px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; inline-size: 100%; block-size: 100%; inset: 0; margin: 0; cursor: pointer; }
.toggle-ui { flex: none; inline-size: 48px; block-size: 26px; background: var(--field); border: 2px solid var(--line); position: relative; }
.toggle-ui::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; inline-size: 16px; block-size: 16px; background: #7d74a0; transition: inset-inline-start 120ms var(--ease); }
.toggle input:checked + .toggle-ui { border-color: #2f7c5c; }
.toggle input:checked + .toggle-ui::after { inset-inline-start: 25px; background: var(--good); }
.toggle input:focus-visible + .toggle-ui { outline: 3px solid var(--amber); outline-offset: 2px; }
.toggle-text { display: grid; font-weight: 600; color: var(--ink); }
.toggle-text .hint { font-weight: 400; }
.ms-edit { padding: 0.5rem; }
.ms-edit legend { padding-inline: 0.4rem; color: var(--muted); font-size: 0.875rem; font-weight: 600; }
.ms-edit ul { margin-block-start: 0.6rem; display: grid; gap: 0.5rem; }
.task-edit { display: grid; grid-template-columns: minmax(0, 1fr) 4.75rem; gap: 0.4rem; align-items: center; }
.task-edit .check { grid-column: 1 / -1; }
.task-edit input.narrow { inline-size: 100%; }
.mode-pick { display: grid; gap: 0.5rem; }
.pick { position: relative; display: block; cursor: pointer; }
.pick input { position: absolute; inset: 0; opacity: 0; inline-size: 100%; block-size: 100%; margin: 0; cursor: pointer; }
.pick-body { display: grid; gap: 0.1rem; padding: 0.4rem 0.6rem 0.5rem; border: 8px solid transparent; border-image: url(/rival/ui/frames/panel.png) 8 fill / 8px / 0 stretch; image-rendering: pixelated; }
.pick input:checked + .pick-body { border-image-source: url(/rival/ui/frames/selected.png); }
.pick input:focus-visible + .pick-body { outline: 3px solid var(--amber); outline-offset: 2px; }
.pick-title { display: flex; align-items: center; gap: 0.5rem; font-size: 1.375rem; color: var(--ink); }

details.more, details.confirm { border-block-start: 2px solid #2c2449; }
details > summary { cursor: pointer; padding-block: 0.6rem; min-block-size: 48px; list-style: none; display: flex; align-items: center; gap: 0.5rem; font-weight: 600; color: var(--link); }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: '+'; margin-inline-start: auto; font: 400 1.5rem/1 var(--pixel); color: var(--amber); }
details[open] > summary::after { content: '–'; }
details.confirm > summary { color: var(--muted); }
details.more > *:not(summary) { margin-block-end: 0.875rem; }
.confirm-body { display: grid; gap: 0.6rem; padding-block-end: 0.875rem; }

/* ---- progress ---- */
.pbar { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; block-size: 14px; flex: 1 1 140px; }
.pbar i { background: #2a2444; border: 2px solid #3a3160; }
.pbar i.on { background: var(--good); border-color: #2f9c74; }
.pbar-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem; }
.dots { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.dots li { inline-size: 22px; block-size: 22px; background: #2a2444; border: 2px solid #3a3160; }
.dots li.on { background: var(--good); border-color: #2f9c74; }
.dots li.now { border-color: var(--pink); }
.dots li.none { inline-size: auto; block-size: auto; background: none; border: 0; color: var(--muted); font-size: 0.875rem; }
.steps-list { display: grid; gap: 0.5rem; }
.steps-list li { display: flex; gap: 0.6rem; align-items: flex-start; }
.step-num { flex: none; display: grid; place-items: center; inline-size: 28px; block-size: 28px; border: 2px solid var(--line); background: var(--field); color: var(--amber); font-size: 1.125rem; }
.step-main { display: grid; color: var(--ink); }
.next-step { display: flex; gap: 0.5rem; align-items: center; justify-content: center; font: 400 1.375rem/1.4 var(--pixel); color: var(--ink); text-align: center; }
.balance-num { font-size: 2.5rem; color: var(--amber); line-height: 1.3; }
.score-line { font-size: 1.75rem; color: var(--ink); text-align: center; }
.score-line .sep { color: var(--muted); margin-inline: 0.25rem; }
.who { display: flex; align-items: center; gap: 0.75rem; }

/* ---- scenes ---- */
.scene { position: relative; block-size: clamp(170px, 46vw, 290px); overflow: hidden; background: var(--bg-2); isolation: isolate; }
.scene-img { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; object-fit: cover; object-position: 50% 58%; z-index: -2; }
.scene::after { content: ''; position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, rgb(18 15 36 / 0.1) 30%, rgb(18 15 36 / 0.88) 100%); }
/* Above .sprite (z-index 1): on the wardrobe scene the preview figure stands over the title,
   and the heading was being painted through ("Your Chä...ter"). The heavy outline on the text
   keeps it readable where it crosses the art. */
.scene-title { position: absolute; inset-inline: 0.875rem; inset-block-end: 0.5rem; display: grid; gap: 0; z-index: 2; }
.scene-title h1, .board-title { text-shadow: 0 3px 0 #0c0a18, 3px 0 0 #0c0a18, -3px 0 0 #0c0a18, 0 -3px 0 #0c0a18; }
.scene-title p { color: var(--text); text-shadow: 0 2px 0 #0c0a18; }
.scene-chip { position: absolute; inset-inline-start: 0.875rem; top: 0.625rem; z-index: 1; }
.scene-portrait { position: absolute; inset-inline-start: 0.875rem; inset-block-end: 3.6rem; inline-size: 64px; block-size: 64px; border: 2px solid var(--line); }
.scene-planner-chamber-wide .scene-img { object-position: 30% 55%; }
.scene-account-gate-wide .scene-img { object-position: 78% 60%; }
.scene-wardrobe-atelier-wide .scene-img, .scene-profile-quarters-wide .scene-img { object-position: 50% 62%; }
.scene-quest-route-wide .scene-img { object-position: 22% 40%; }
.sprite { position: absolute; inline-size: auto; max-inline-size: none; image-rendering: pixelated; transform: translate(-50%, -97.3%); z-index: 1; }
.reward { block-size: clamp(260px, 70vw, 380px); }
.reward-sprite { block-size: 42%; left: 50%; top: 58%; }
.reward .scene-title { text-align: center; justify-items: center; }
.reward-points { font-size: 1.75rem; color: var(--amber) !important; }
.wardrobe-scene { block-size: clamp(250px, 66vw, 360px); }
.wardrobe-sprite { block-size: 62%; left: 50%; top: 82%; }

/* Boards: a tall mobile scene cropped to a window; children are placed in image coordinates. */
.board { position: relative; overflow: hidden; background: var(--bg-2); isolation: isolate; }
.stage { position: absolute; inset-inline: auto; left: 0; inline-size: 100%; direction: ltr; }
.stage-bg { display: block; inline-size: 100%; block-size: 100%; max-inline-size: none; }
.board-title { position: absolute; inset-inline: 0.875rem; top: 0.5rem; z-index: 2; font-size: 1.75rem; }
.quest-board { aspect-ratio: 4 / 5; }
.quest-stage { aspect-ratio: 853 / 1844; top: -16.8%; }
.trail { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; opacity: 0.85; }
.quest-sprite { block-size: 6.8%; }
.qnodes li { position: absolute; transform: translate(-50%, -50%); z-index: 2; }
.qnode { display: grid; place-items: center; inline-size: 44px; block-size: 44px; border: 8px solid transparent; border-image: url(/rival/ui/frames/node-locked.png) 8 fill / 8px / 0 stretch; image-rendering: pixelated; color: var(--muted); text-decoration: none; font-size: 1.25rem; line-height: 1; }
.qnode.is-current { border-image-source: url(/rival/ui/frames/node-current.png); color: var(--ink); }
.qnode.is-done { border-image-source: url(/rival/ui/frames/node-finished.png); }
.qnode .pi { inline-size: 20px; block-size: 20px; }
.qnode:hover { filter: brightness(1.25); }
.quest .group-nav { padding: 0.5rem 0.875rem 0; }
.duel-board, .arena-board { aspect-ratio: 5 / 4; }
.duel-stage { aspect-ratio: 853 / 1844; top: -45.6%; }
.duel-me, .duel-rival { block-size: 10%; }
.duel-me { left: 18%; top: 46.5%; }
.duel-rival { left: 79%; top: 46%; transform: translate(-50%, -97.3%) scaleX(-1); }
.duel-trophy { position: absolute; left: 49%; top: 44.5%; inline-size: 20%; block-size: auto; transform: translate(-50%, -100%); image-rendering: pixelated; }
.duel-stage .scene-chip { position: absolute; left: 4%; top: 29%; inset-inline-start: auto; direction: rtl; }
html[lang='en'] .duel-stage .scene-chip { direction: ltr; }
.arena-stage { aspect-ratio: 852 / 1846; top: -47.3%; }
.board::after { content: ''; position: absolute; inset-inline: 0; inset-block-end: 0; block-size: 22%; background: linear-gradient(180deg, transparent, var(--bg)); pointer-events: none; z-index: 1; }

/* ---- home: the hub scene is the game screen behind the greeting ---- */
.home { display: flex; flex-direction: column; min-block-size: calc(100dvh - var(--bar) - var(--tab) - env(safe-area-inset-bottom) - 1rem); }
.home-stage { position: relative; flex: 1 1 auto; min-block-size: 300px; overflow: hidden; isolation: isolate; }
.stage-wrap { position: absolute; inset: 0; container-type: size; z-index: -1; }
.home-art { --w: max(100cqw, calc(100cqh * 898 / 1751)); --h: calc(var(--w) * 1751 / 898); inline-size: var(--w); block-size: var(--h);
  left: calc((100cqw - var(--w)) * 0.45); top: clamp(calc(100cqh - var(--h)), calc(76cqh - var(--h) * 0.67), 0px); }
.home-sprite { block-size: 9.6%; left: 45%; top: 67%; }
.home-greet { padding: 1rem 0.875rem; }
.home-greet h1 { font-size: 2.5rem; text-shadow: 0 3px 0 #0c0a18, 3px 0 0 #0c0a18, -3px 0 0 #0c0a18, 0 -3px 0 #0c0a18; }
.home-greet p { color: var(--text); text-shadow: 0 2px 0 #0c0a18; font-weight: 600; }
.home-stage::after { content: ''; position: absolute; inset-inline: 0; inset-block-end: 0; block-size: 18%; background: linear-gradient(180deg, transparent, var(--bg)); z-index: 0; pointer-events: none; }
.home-panel { padding-block-start: 0.25rem; }

/* ---- wardrobe ---- */
.opt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 0.625rem; }
.opt { position: relative; display: grid; gap: 0.15rem; cursor: pointer; }
.opt.static { cursor: default; }
.opt input { position: absolute; inset: 0; inline-size: 100%; block-size: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
/* Bounded image area. The sprites are tall full-body PNGs (about 180x360): sizing them with
   `max-block-size: 100%` left the HTML height attribute in charge, so each one ran ~250px past
   its card and sat on top of the label, the next row and the Save button. object-fit does the
   proportional fit, overflow: hidden guarantees containment whatever an asset's size turns out
   to be, and `50% 100%` puts the feet on the floor of the card so a row of them lines up. */
/* --fit is the image area; the card adds 28px for its 8px frame and 6px padding on each side.
   A percentage block-size does not resolve against a centred grid area here (Chrome falls back
   to the intrinsic aspect ratio), which is what let the sprites run past the card, so the
   height is stated in pixels and the two values are kept in step through the one property. */
.opt-art { --fit: 96px; display: grid; place-items: center; block-size: calc(var(--fit) + 28px); padding: 6px; overflow: hidden; border: 8px solid transparent; border-image: url(/rival/ui/frames/panel.png) 8 fill / 8px / 0 stretch; image-rendering: pixelated; }
.opt-art img { inline-size: 100%; block-size: var(--fit); object-fit: contain; object-position: 50% 100%; image-rendering: pixelated; }
/* Portraits are already head-and-shoulders crops (reference: character selection), so they are
   centred and need less height than a standing figure. */
.opt-grid.portraits .opt-art { --fit: 88px; }
.opt-grid.portraits .opt-art img { object-position: 50% 50%; }
/* Outfit cards show the whole figure, head to feet, because the clothes are what is being chosen. */
.opt-grid.figures { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.opt-grid.figures .opt-art { --fit: 136px; }
/* Gear is a loose object rather than a standing figure, so it centres instead of standing on the floor. */
.gear .opt-art { --fit: 68px; }
.gear .opt-art img { object-position: 50% 50%; }
.opt input:checked + .opt-art { border-image-source: url(/rival/ui/frames/selected.png); }
.opt input:focus-visible + .opt-art { outline: 3px solid var(--amber); outline-offset: 2px; }
.opt:hover .opt-art { filter: brightness(1.2); }
.opt-label { text-align: center; font-size: 0.9375rem; color: var(--text); line-height: 1.3; }
.opt-none { color: var(--muted); font-size: 0.875rem; }

/* ---- chat ---- */
.chat-page main { padding-block-end: 0; }
.chat { display: flex; flex-direction: column; block-size: calc(100dvh - var(--bar) - var(--tab) - env(safe-area-inset-bottom)); padding-inline: 0.75rem; }
.chat-head { display: flex; align-items: center; gap: 0.6rem; padding-block: 0.5rem; border-block-end: 2px solid #2c2449; }
.chat-title { font-size: 1.375rem; min-inline-size: 0; flex: 1 1 auto; }
.chat-scroll { flex: 1 1 auto; overflow-y: auto; padding-block: 0.75rem; display: flex; flex-direction: column; overscroll-behavior: contain; }
.older { align-self: center; margin-block-end: 0.75rem; }
.chat-empty { margin: auto; display: grid; gap: 0.5rem; justify-items: center; color: var(--muted); text-align: center; max-inline-size: 32ch; }
.chat-empty img { inline-size: 100%; block-size: 120px; object-fit: cover; object-position: 50% 60%; border: 2px solid var(--line); }
.msgs { display: flex; flex-direction: column; gap: 0.5rem; margin-block-start: auto; }
.msg { max-inline-size: min(84%, 30rem); padding: 0.45rem 0.7rem; background: var(--panel); border: 2px solid var(--line); align-self: flex-start; }
.msg.mine { align-self: flex-end; background: #3a1740; border-color: #8a3a72; }
.msg-body { white-space: pre-wrap; color: var(--ink); line-height: 1.6; }
.msg-time, .msg-state { display: block; font-size: 0.75rem; color: var(--muted); }
.msg.pending { opacity: 0.7; }
.msg.failed { border-color: var(--bad); }
.msg.failed .msg-state { color: var(--bad); }
.msg-retry { background: none; border: 0; padding: 0.3rem 0; color: var(--link); text-decoration: underline; cursor: pointer; font-weight: 600; min-block-size: 44px; }
.chat-status { text-align: center; font-size: 0.875rem; color: var(--amber); }
.composer { display: flex; align-items: flex-end; gap: 0.5rem; padding-block: 0.5rem; border-block-start: 2px solid #2c2449; }
.composer textarea { flex: 1; resize: none; max-block-size: 8rem; min-block-size: 48px; }
.composer .btn { min-inline-size: 56px; }
.composer-closed { padding: 0.75rem; border: 2px dashed var(--line); color: var(--muted); margin-block: 0.5rem; }
.chat-manage { margin: 0; }

/* ---- landing ---- */
.landing main { max-inline-size: none; }
.hero { position: relative; isolation: isolate; display: flex; flex-direction: column; min-block-size: calc(100svh - var(--bar)); overflow: hidden; background: var(--bg); }
.hero-art { position: absolute; inset: 0; z-index: -1; container-type: size; overflow: hidden; direction: ltr; --aw: 1672; --ah: 941; --fx: 0.5; --fy: 0.84; }
.hero-art .stage { --w: max(100cqw, calc(100cqh * var(--aw) / var(--ah))); inline-size: var(--w); block-size: calc(var(--w) * var(--ah) / var(--aw)); left: calc((100cqw - var(--w)) * var(--fx)); top: calc((100cqh - var(--w) * var(--ah) / var(--aw)) * var(--fy)); }
.hero-art picture { display: block; inline-size: 100%; block-size: 100%; }
.hero-sprite { position: absolute; block-size: 17.5%; inline-size: auto; max-inline-size: none; image-rendering: pixelated; transform: translate(-50%, -97.3%); }
.hero-sprite.at-left { left: 20%; top: 87.8%; }
.hero-sprite.at-right { left: 79%; top: 87.8%; transform: translate(-50%, -97.3%) scaleX(-1); }
.hero-tag { position: absolute; transform: translate(-50%, -100%); padding: 0 0.6em; background: #0d0b1f; color: var(--ink); border: 2px solid #4a4291; font-size: clamp(14px, 1.5cqw, 22px); white-space: nowrap; direction: rtl; line-height: 1.5; }
html[lang='en'] .hero-tag { direction: ltr; }
.hero-tag.at-left { left: 20%; top: 69.5%; }
.hero-tag.at-right { left: 79%; top: 69.5%; }
.hero-path { position: absolute; left: 27.5%; inline-size: 44%; top: 81.5%; display: flex; justify-content: space-between; align-items: center; }
.hero-path::before { content: ''; position: absolute; inset-inline: 0; top: 50%; border-block-start: 3px dashed var(--amber); opacity: 0.75; transform: translateY(-50%); }
.hero-path i { position: relative; inline-size: clamp(9px, 1.05cqw, 16px); aspect-ratio: 1; background: #c9a15a; transform: rotate(45deg); }
.hero-path i.now { inline-size: clamp(12px, 1.45cqw, 22px); background: var(--pink); }
.hero-tag.next { left: 50%; top: -1.2em; }
.hero-copy { position: relative; display: grid; justify-items: center; gap: 0.75rem; text-align: center; padding: clamp(1.25rem, 5vh, 3.5rem) 1rem 1rem; }
.hero-title { display: grid; font-size: clamp(2.5rem, 9vw, 4.5rem); line-height: 1.35; text-shadow: 0 4px 0 #0c0a18; }
.hero-title .accent { color: var(--pink); }
.hero-sub { font-size: clamp(1.0625rem, 2.2vw, 1.25rem); max-inline-size: 34ch; color: var(--text); text-shadow: 0 2px 0 var(--bg); }
.hero-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.625rem; }
.band { max-inline-size: 760px; margin-inline: auto; padding: clamp(2.5rem, 8vw, 4.5rem) 1rem; display: grid; gap: 1rem; }
.display { font-size: clamp(2rem, 6vw, 2.75rem); }
.steps { display: grid; gap: 1rem; }
.steps li { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 0.75rem; align-items: start; }
.steps .step-num { inline-size: 44px; block-size: 44px; font-size: 1.5rem; }
.steps h3 { display: flex; gap: 0.5rem; align-items: center; }
.steps p, .band > p { color: var(--muted); max-inline-size: 60ch; }
.duo { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.875rem; }
.note { color: var(--muted); }
.score { border: 2px solid var(--line); background: var(--panel); }
.score th, .score td { padding: 0.6rem 0.875rem; text-align: start; border-block-end: 2px dashed #2c2449; }
.score thead th { color: var(--muted); font-size: 0.875rem; }
.score tbody th { font-weight: 600; color: var(--ink); }
.score td { font-size: 2rem; color: var(--amber); text-align: end; }
.band.final { text-align: center; justify-items: center; }
.site-footer { display: flex; justify-content: center; align-items: center; gap: 0.5rem; padding: 1.25rem 1rem; color: var(--muted); font-size: 0.875rem; border-block-start: 2px solid #2c2449; }
.site-footer img { block-size: 20px; inline-size: auto; image-rendering: pixelated; }
.switch { text-align: center; color: var(--muted); }

/* ---- motion: idle bob for the hero character and a pulse on the current stop ---- */
@media (prefers-reduced-motion: no-preference) {
  .home-sprite, .quest-sprite { animation: idle 1.4s steps(2, jump-none) infinite; }
  .qnode.is-current { animation: glow 1.6s steps(2, jump-none) infinite; }
  .hero-path i.now { animation: pulse 1.6s steps(3, jump-none) infinite; }
  .blink { animation: blink 1.4s steps(2, jump-none) infinite; }
}
@keyframes idle { 50% { transform: translate(-50%, calc(-97.3% - 2px)); } }
@keyframes glow { 50% { filter: brightness(1.35); } }
@keyframes pulse { 50% { transform: rotate(45deg) scale(1.35); } }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---- small and large screens ---- */
@media (max-width: 760px) {
  .hero-art { --aw: 1024; --ah: 1536; --fy: 1; }
  .hero-sprite { block-size: 13.2%; }
  .hero-sprite.at-left, .hero-tag.at-left { left: 25%; }
  .hero-sprite.at-right, .hero-tag.at-right { left: 75%; }
  .hero-sprite.at-left, .hero-sprite.at-right { top: 82%; }
  .hero-tag.at-left, .hero-tag.at-right { top: 68.4%; }
  .hero-tag { font-size: clamp(13px, 3.8cqw, 17px); }
  .hero-path { left: 36%; inline-size: 28%; top: 77.5%; }
  .hero-path i { inline-size: 8px; }
  .hero-path i.now { inline-size: 11px; }
  .hero-tag.next { top: -1.7em; }
}
@media (max-width: 380px) {
  h1 { font-size: 1.75rem; }
  .home-greet h1 { font-size: 2rem; }
  .btn { font-size: 1.125rem; }
  .btn.big { font-size: 1.375rem; }
  .tabbar a { font-size: 0.875rem; }
  .hud { padding-inline: 0.35rem; }
  .opt-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
}
@media (max-height: 520px) {
  /* short viewport, e.g. on-screen keyboard open: keep the form reachable */
  .scene { block-size: 96px; }
  .home-stage { min-block-size: 160px; }
  .tabbar { position: static; }
  .is-app main { padding-block-end: 1rem; }
  /* Keyboard open on a chat: the top bar's back link is enough, so give the thread the whole screen. */
  .chat-page { --tab: 0px; }
  .chat-page .tabbar { display: none; }
}
@media (min-width: 761px) {
  .scene { block-size: 300px; }
  .quest-board { aspect-ratio: 5 / 4; }
  .quest-stage { top: -26.25%; }
}
@media (forced-colors: active) {
  .card, .btn, .row, .seg a { border: 2px solid CanvasText; border-image: none; }
}

/* ---- the wait while a plan is being made ---- */
.planning { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 1.25rem; background: rgba(10, 8, 22, 0.86); }
.planning[hidden] { display: none; }
.planning-card {
  inline-size: min(22rem, 100%); display: grid; gap: 0.5rem; justify-items: center; text-align: center;
  padding: 1rem 0.875rem 1.125rem; border: 8px solid transparent;
  border-image: url(/rival/ui/frames/panel.png) 8 fill / 8px / 0 stretch; image-rendering: pixelated;
}
.planning-card > * { image-rendering: auto; }
.planning-title { margin: 0; font-family: var(--pixel); font-size: 1.375rem; color: var(--ink); }
.planning-step { margin: 0; min-block-size: 3.4em; color: var(--muted); }
.planning-slow { margin: 0; color: var(--muted); font-size: 0.875rem; }
.planning-bar { inline-size: 100%; block-size: 12px; overflow: hidden; background: var(--field); border: 2px solid var(--line); }
.planning-bar span { display: block; block-size: 100%; inline-size: 35%; background: var(--amber); animation: planning-slide 1.5s linear infinite; }
@keyframes planning-slide { from { transform: translateX(-110%); } to { transform: translateX(400%); } }
@media (prefers-reduced-motion: reduce) { .planning-bar span { animation: none; inline-size: 100%; opacity: 0.55; } }
body.is-planning { overflow: hidden; }
