:root {
  --ink: #42384f;
  --paper: #fff3da;
  --gold: #ffcd62;
  --mint: #68b9ac;
  --berry: #ba7198;
  --focus: #3f6f8f;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* No pull-to-refresh or rubber-band scrolling: a downward swipe is a slide. */
html, body { margin: 0; height: 100%; overscroll-behavior: none; }

body {
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: radial-gradient(ellipse at 30% 10%, #c3e5e9 0, #8fa7bf 50%, #5f6d8b 100%);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
  touch-action: manipulation;
  transition: transform .13s, filter .13s;
}

a { touch-action: manipulation; }

button:hover:not(:disabled) { filter: brightness(1.04); }
button:active:not(:disabled) { transform: translateY(2px) scale(.98); }
button:disabled { cursor: not-allowed; opacity: .6; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
#app[data-input="pointer"] :focus-visible { outline: none; }

.desktop-wordmark {
  position: fixed;
  left: max(22px, calc(50% - 580px));
  top: 43%;
  font-size: 38px;
  font-weight: 1000;
  line-height: 1.1;
  color: #f7edd49c;
  transform: rotate(-5deg);
  letter-spacing: 2px;
  pointer-events: none;
  user-select: none;
}

#app {
  position: relative;
  width: min(100vw, calc(var(--vh, 1vh) * 58));
  height: calc(var(--vh, 1vh) * 100);
  margin: 0 auto;
  overflow: hidden;
  background: #b9dce1;
  box-shadow: 0 0 100px #31465c5c;
  isolation: isolate;
  /* Long presses on a phone must not select text or open callouts mid-run. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app input { -webkit-user-select: text; user-select: text; }

/* During a run every touch is a swipe or a button press: no scrolling or zooming. */
#app[data-view="game"] { touch-action: none; }

#world {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- Visibility per view ---------- */
#app:not([data-view="game"]) .top,
#app:not([data-view="game"]) .zone-hud,
#app:not([data-view="game"]) .ability-dock { display: none; }

#app:not([data-view="menu"]) .home-screen { display: none; }

[hidden] { display: none !important; }

/* ---------- In-game HUD ---------- */
/* Moves use swipes or keys. Skills show an automatic timer; pause and mounts are buttons. */
.top, .zone-hud { position: absolute; z-index: 5; }

.top {
  top: calc(3% + env(safe-area-inset-top, 0px));
  left: 3%;
  right: 3%;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pause-button {
  flex: 0 0 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: linear-gradient(#b3d8ce, #78a9aa);
  border: 2px solid #e9f0de;
  border-radius: 11px;
  box-shadow: 0 3px 0 #4d77786b;
}

.pause-button span { width: 5px; height: 16px; border-radius: 2px; background: #fffbeb; }

.top-score, .coin-stat {
  display: flex;
  align-items: baseline;
  gap: 4px;
  height: 42px;
  padding: 0 12px;
  align-items: center;
  background: linear-gradient(#5c788ace, #43566bdb);
  border: 2px solid #dbede591;
  border-radius: 14px;
  color: #fffbeb;
  font-weight: 900;
  box-shadow: 0 3px 10px #1d2b3a33;
}

.top-score { flex: 1; }
.top-score strong { font-size: 22px; font-style: italic; letter-spacing: 1px; }
.top-score small { font-size: 11px; opacity: .85; }
.top-score span { margin-left: auto; font-size: 13px; opacity: .9; letter-spacing: 1px; }

.coin-stat b {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gold);
  color: #7a4d18;
  font-size: 12px;
}

.coin-stat strong { font-size: 18px; }
.multiplier { color: #ffe19a; font-size: 12px; }

.zone-hud {
  top: 11%;
  left: 3%;
  width: 52%;
  padding: 6px 10px;
  border-radius: 12px;
  background: #43566ba8;
  color: #fffbeb;
  font-size: 11px;
  font-weight: 900;
}

.track {
  position: relative;
  height: 5px;
  margin-top: 5px;
  border-radius: 5px;
  background: #ffffff40;
  overflow: hidden;
}

.track i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: #e6c184;
  transition: width .2s;
}

/* Skill over mount, at the right edge where only scenery passes: clear of the lanes, of
   the runner's head and of the bottom strip that phones swipe from. */
.ability-dock {
  position: absolute;
  z-index: 5;
  right: 3%;
  bottom: calc(33% + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* The ring (a conic gradient to --fill) is the meter while charging, the time left while active. */
.ability-button {
  --fill: 0;
  --ring: #ffe19a;
  position: relative;
  width: 58px;
  height: 58px;
  padding: 4px;
  border-radius: 50%;
  background: conic-gradient(var(--ring) calc(var(--fill) * 1turn), #ffffff3d 0);
  box-shadow: 0 3px 10px #1d2b3a44;
  transition-duration: .06s;
}

.ability-button canvas {
  display: block;
  width: 100%;
  height: 100%;
  padding: 5px;
  border: 2px solid #dbede5b0;
  border-radius: 50%;
  background: radial-gradient(#5c788af2, #43566bf2);
}

.ability-status { cursor: default; }
.ability-auto {
  position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  min-width: 34px; padding: 2px 5px; border: 1px solid #dbede5;
  border-radius: 8px; background: #33475c; color: #fff3da;
  text-align: center; font: 800 11px/1.2 var(--font);
}

.ability-button[data-state="charging"] canvas,
.ability-button[data-state="empty"] canvas { opacity: .6; }
.ability-button[data-state="active"] { --ring: #8fe0cf; }
.ability-button[data-state="empty"] { --ring: #ffffff3d; }

/* Ready: a halo pulses round the ring (opacity and transform only, cheap to animate). */
.ability-button::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 3px solid #ffe19a;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}

.ability-button[data-state="ready"]::after { animation: ability-ready 1.1s ease-in-out infinite; }

@keyframes ability-ready {
  0%, 100% { opacity: 0; transform: scale(.92); }
  50% { opacity: 1; transform: scale(1.04); }
}

.ability-count {
  position: absolute;
  right: -3px;
  bottom: -3px;
  min-width: 20px;
  padding: 1px 5px;
  background: #d9939a;
  border: 2px solid #fff0d6;
  border-radius: 9px;
  color: #fff;
  font-size: 11px;
  line-height: 1.3;
}

.ability-button .key-hint {
  position: absolute;
  left: -3px;
  top: -3px;
  min-width: 18px;
  padding: 0 4px;
  background: #fff5df;
  border-radius: 6px;
  color: #6a949d;
  font-size: 10px;
  font-weight: 1000;
  line-height: 16px;
}

/* ---------- Home menu ---------- */
.home-screen {
  /* Bottom nav height; the start dock sits on top of it. Short phones keep room for icon and label. */
  --nav-h: max(54px, 8.1%);
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.home-screen button,
.home-screen .wallet-pill { pointer-events: auto; }

/* Line icons (top bar, bottom nav); the shapes marked .fill get a soft tint. */
.icon {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon .fill { fill: currentColor; fill-opacity: .16; }

.wallet {
  position: absolute;
  top: calc(2.3% + env(safe-area-inset-top, 0px));
  left: 4%;
  right: 4%;
  height: clamp(40px, 5.4%, 50px);
  display: flex;
  gap: 8px;
}

.wallet > * {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  background: linear-gradient(#fffaf0, #eedbbd);
  border: 2px solid #fff8ea;
  border-radius: 999px;
  box-shadow: 0 3px 0 #8e7e7859, 0 8px 16px #4a3a3a1a;
  color: #605064;
  font-weight: 900;
}

.wallet .wallet-pill { flex: 1; }
.wallet small { font-size: 11px; }

.icon-button { flex: none; height: 100%; aspect-ratio: 1; }
.icon-button svg { width: 54%; height: 54%; }
.crown { color: #c08a3a; }

.wallet-pill b {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 50%;
  background: var(--gold);
  color: #7a4d18;
  font-size: 12px;
}

.wallet-pill strong { font-size: 16px; font-variant-numeric: tabular-nums; }

.music-button { color: #a79aa2; }
.music-button[aria-pressed="true"] { color: #4e8f82; }
.music-button[aria-pressed="true"] .mute-slash { display: none; }
.music-button .music-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.graffiti-title {
  position: absolute;
  top: calc(10.5% + env(safe-area-inset-top, 0px));
  left: 13%;
  width: 74%;
  text-align: center;
  transform: rotate(-4deg);
  user-select: none;
}

.season-label {
  display: inline-block;
  padding: 3px 14px;
  background: linear-gradient(#b991be, #99719e);
  border: 2px solid #fff1d6;
  border-radius: 16px;
  color: #fff8ea;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 2px;
}

.graffiti-title h1 {
  position: relative;
  margin: 2px 0 0;
  font-size: clamp(43px, calc(var(--vh, 1vh) * 7.5), 73px);
  font-weight: 1000;
  line-height: 1.08;
  letter-spacing: -4px;
  color: #fff0ae;
  -webkit-text-stroke: 1px #b08059;
  text-shadow: 1px 3px #d99553, 2px 5px #916464, 0 -2px #fffadb;
}

.graffiti-title h1::before {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  z-index: -1;
  -webkit-text-stroke: 8px #fff7e5;
  color: #fff7e5;
  text-shadow: none;
}

.logo-splash {
  position: absolute;
  top: 22%;
  right: 1%;
  color: #ffe5a1;
  font-size: 30px;
  text-shadow: 0 2px #c08b4e;
  animation: twinkle 2.6s ease-in-out infinite;
}

@keyframes twinkle {
  0%, 100% { transform: rotate(0) scale(1); }
  50% { transform: rotate(18deg) scale(1.15); }
}

/* Start, difficulty and the controls hint, stacked just above the bottom nav. The runner
   stands on this block's top edge (src/game.js measures it). */
.start-dock {
  position: absolute;
  left: 9%;
  right: 9%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + clamp(8px, calc(var(--vh, 1vh) * 1.6), 16px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, calc(var(--vh, 1vh) * 1.1), 10px);
}

.start-button {
  position: relative;
  isolation: isolate;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  height: clamp(52px, calc(var(--vh, 1vh) * 7.2), 68px);
  overflow: hidden;
  background: linear-gradient(#ffe98c, #ffc94f 55%, #f6a53a);
  border: 3px solid #fff6cc;
  border-radius: 999px;
  box-shadow: 0 5px 0 #c67a2f, 0 12px 24px #6a40204d, inset 0 -4px 0 #e98f2c80;
  color: #6b3c1d;
  font-weight: 1000;
  transition: transform .12s, box-shadow .12s, filter .12s;
}

.start-button:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #c67a2f, 0 5px 12px #6a40204d, inset 0 -3px 0 #e98f2c80;
}

/* Gloss over the top half. */
.start-button::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 3px;
  left: 7%;
  right: 7%;
  height: 42%;
  border-radius: 999px;
  background: linear-gradient(#ffffffb3, #fff0);
  pointer-events: none;
}

/* A glint sweeps across every few seconds; it only moves, so it stays off the main thread. */
.start-button::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 22%;
  background: linear-gradient(105deg, #fff0, #fffc 50%, #fff0);
  transform: translateX(-120%) skewX(-20deg);
  animation: glint 3.6s ease-in-out infinite;
  pointer-events: none;
}

@keyframes glint {
  0%, 60% { transform: translateX(-120%) skewX(-20deg); }
  90%, 100% { transform: translateX(520%) skewX(-20deg); }
}

.start-label {
  margin-right: -5px;
  font-size: clamp(19px, calc(var(--vh, 1vh) * 2.9), 27px);
  letter-spacing: 5px;
  text-shadow: 0 1px 0 #fff3c4;
}

.start-play {
  display: grid;
  place-items: center;
  flex: none;
  width: clamp(30px, calc(var(--vh, 1vh) * 4.3), 40px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: linear-gradient(#ff9d62, #e8663d);
  box-shadow: inset 0 -3px 0 #c24e2a, 0 2px 0 #fff4c4;
  color: #fff8ec;
}

.start-play svg { width: 52%; height: 52%; margin-left: 8%; fill: currentColor; }

.difficulty-switch {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: #fff7e8eb;
  border: 2px solid #fffdf6;
  border-radius: 999px;
  box-shadow: 0 3px 0 #8e7e7840;
}

.difficulty-switch button {
  min-width: 58px;
  height: clamp(26px, calc(var(--vh, 1vh) * 3.5), 32px);
  padding: 0 14px;
  border-radius: 999px;
  color: #7e6071;
  font-size: 12px;
  font-weight: 900;
}

.difficulty-switch .is-active {
  background: linear-gradient(#b49bc8, #8d74a3);
  color: #fff;
  box-shadow: inset 0 -2px 0 #6f5a8566;
}

/* 校园篇 / 研学篇 / 环球篇: the map the next run tours. */
.chapter-switch {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: #fff7e8eb;
  border: 2px solid #fffdf6;
  border-radius: 999px;
  box-shadow: 0 3px 0 #8e7e7840;
}

.chapter-switch button {
  min-width: 72px;
  height: clamp(28px, calc(var(--vh, 1vh) * 3.7), 34px);
  padding: 0 13px;
  border-radius: 999px;
  color: #7e6071;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 2px;
}

.chapter-switch .is-active {
  background: linear-gradient(#78c7b8, #3f9384);
  color: #fff;
  box-shadow: inset 0 -2px 0 #2f6f6466;
}

.chapter-switch [data-chapter="study"].is-active {
  background: linear-gradient(#ef8a5c, #c4473a);
  box-shadow: inset 0 -2px 0 #8a2f2866;
}

.chapter-switch [data-chapter="globe"].is-active {
  background: linear-gradient(#6aa8e8, #2f63b8);
  box-shadow: inset 0 -2px 0 #1f3f7a66;
}

.start-hint {
  margin: 0;
  padding: 3px 12px;
  border-radius: 999px;
  background: #fff5dec7;
  color: #4d6977;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.bottom-nav {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 5px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(#fffbf2fa, #f3e6cff2);
  border-top: 2px solid #fffdf7;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -6px 20px #4a3a3a1f;
  pointer-events: auto;
}

.bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 16px;
  color: #9a8290;
}

.bottom-nav svg { width: 24px; height: 24px; }
.bottom-nav small { font-size: 11px; font-weight: 900; letter-spacing: 1px; }

.bottom-nav .selected {
  background: linear-gradient(#fff3d2, #f9dfa6);
  box-shadow: inset 0 0 0 2px #fffaf0, 0 3px 0 #d8ae6c66;
  color: #8a5a2c;
}

.bottom-nav .selected .fill { fill-opacity: 1; }

/* ---------- Shared buttons ---------- */
.primary, .secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 900;
}

.primary {
  background: linear-gradient(#ffe99e, #efc274);
  border: 2px solid #fff4be;
  border-bottom: 4px solid #bc8850;
  color: #765348;
}

.secondary {
  background: linear-gradient(#a6cfc5, #6ca89d);
  border: 2px solid #d6ece5;
  border-bottom: 4px solid #4c7f76;
  color: #fffbeb;
}

/* ---------- Dialog overlays ---------- */
.dialog, .message-card {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 88%;
  max-height: 82%;
  overflow-y: auto;
  transform: translate(-50%, -50%);
  padding: 0 16px 16px;
  background: linear-gradient(135deg, #fff8e9, #f1dfc6);
  border: 3px solid #fff5df;
  border-radius: 25px;
  box-shadow: 0 0 0 100vmax #354b697d, 0 16px 40px #2a3a4c66;
  color: #5d4a5c;
  animation: pop .22s ease-out;
}

.dialog { z-index: 20; }

@keyframes pop {
  from { opacity: 0; transform: translate(-50%, -46%) scale(.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.dialog-cap {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 -16px 12px;
  padding: 12px 16px;
  background: linear-gradient(#92b1b9, #6a949d);
  color: #fffbeb;
}

.dialog-cap h2 { margin: 0; font-size: 18px; font-weight: 1000; letter-spacing: 1px; }

.close-button {
  flex: 0 0 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff5df;
  color: #6a949d;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

/* Launch notice: a gate before the home menu, so it gets the strongest backdrop */
.notice-dialog { z-index: 40; width: min(88%, 420px); box-shadow: 0 0 0 100vmax #2b3b55b3, 0 16px 40px #2a3a4c66; }
.notice-tag {
  flex: 0 0 auto;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--gold);
  color: #765348;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1px;
}
.notice-body p { margin: 0 0 10px; font-size: 13.5px; line-height: 1.75; color: #6d5a68; }
.notice-body p:last-child { margin-bottom: 0; }
.notice-body b { color: var(--berry); }

.dialog-lead { margin: 0 0 12px; font-size: 13px; line-height: 1.6; color: #6d5a68; }

.dialog > .primary, .dialog > .secondary { width: 100%; margin-top: 14px; }

.mission-list, .record-list, .contact-list, .move-list {
  display: grid;
  gap: 8px;
}

.mission-row, .record-row, .contact-list > *, .move-list li, .about-card {
  background: #fff8e8;
  border: 2px solid #dcc8ab;
  border-radius: 16px;
}

.mission-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
}

.medal {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(#ffe99e, #efc274);
  color: #8a5a2c;
  font-size: 18px;
}

.mission-row strong { font-size: 14px; }
.mission-row small { display: block; font-size: 11px; color: #806f78; }
.mission-row b { color: #4e8f82; }
.mission-row .track, .record-list .track { background: #e6d6bd; }
.mission-row .track i { background: #7fb593; }

/* 任务 bonus: 学分 to come, or 已领取 once paid (src/economy.js). */
.mission-reward { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; white-space: nowrap; }
.mission-row.is-done { background: #f3f0e2; }
.mission-row.is-done .mission-reward { color: #9a8c94; font-size: 12px; }
.mission-row.is-done .mission-reward .coin { display: none; }
.mission-row.is-done .track i { background: #b8c9b4; }

.record-row {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.record-row span { font-weight: 1000; color: #a26b33; }
.record-row b { font-variant-numeric: tabular-nums; }
.record-row.is-you { background: #fff3cf; border-color: #e9b85f; }

.about-card {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 2px 12px;
  margin-bottom: 4px;
  padding: 12px;
}

.about-mark {
  display: grid;
  grid-row: span 2;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: linear-gradient(#72b9aa, #518e8a);
  color: #fffbeb;
  font-size: 22px;
}

.about-card strong { font-size: 14px; }
.about-card small { font-size: 11.5px; line-height: 1.55; color: #806f78; }

.dialog-section { margin: 14px 2px 8px; font-size: 14px; font-weight: 1000; color: #5d4a5c; }

.move-list { margin: 0; padding: 0; list-style: none; }

.move-list li {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
}

.move-key {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #d59aa6, #a8627a);
  color: #fff5df;
  font-size: 20px;
  font-weight: 1000;
}

.move-list strong { display: block; font-size: 14px; }
.move-list small { display: block; margin-top: 1px; font-size: 11px; line-height: 1.5; color: #806f78; }
.move-list small > span { color: #a26b33; font-weight: 900; }

.about-tip { margin: 10px 2px 14px; font-size: 11.5px; line-height: 1.7; color: #6d5a68; }

.contact-list > * {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 900;
  color: #5d4a5c;
  text-decoration: none;
}

.contact-list b { color: #4e8f82; font-size: 12px; }

/* ---------- Game message ---------- */
.game-message { position: absolute; inset: 0; z-index: 30; }
.game-message.is-hidden { display: none; }

/* Collision rescue: the frozen track remains visible through the open ring. */
.revival-dialog {
  --revival-wheel-size: min(72vw, 380px, 42dvh);
  --revival-center: 46%;
  position: fixed; inset: 0; width: 100vw; height: 100dvh;
  max-width: 100vw; max-height: 100dvh; margin: auto; padding: 0;
  border: 0; background: transparent; color: white; overflow: hidden;
  font-family: inherit; touch-action: none; user-select: none;
}
.revival-dialog::backdrop { background: rgb(2 12 22 / 84%); }
.revival-dialog::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 32%; pointer-events: none;
  background: radial-gradient(circle 2.2px, rgb(2 9 18 / .72) 98%, transparent) 0 0 / 10px 10px;
  mask:
    linear-gradient(40deg, black 0 16%, transparent 48%) bottom left / 50% 100% no-repeat,
    linear-gradient(-40deg, black 0 16%, transparent 48%) bottom right / 50% 100% no-repeat;
}
.revival-content { position: relative; height: 100%; cursor: pointer; }
.revival-close {
  position: absolute; left: calc(50% + var(--revival-wheel-size) / 2 - 24px);
  top: max(16px, env(safe-area-inset-top), calc(var(--revival-center) - var(--revival-wheel-size) * .76)); z-index: 5;
  width: 52px; height: 52px; border: 3px solid #f5faff; border-radius: 50%; padding: 0;
  background: radial-gradient(circle at 38% 30%, #ed6559, #cf3446 65%, #9e2536);
  box-shadow: 0 0 0 3px #597597, inset 0 0 0 3px rgb(255 255 255 / .25), 0 5px 0 rgb(7 13 24 / .55);
}
.revival-close::before {
  content: ''; position: absolute; left: 20px; top: 44px; z-index: -1;
  width: 13px; height: 18px; border-radius: 0 0 8px 8px; background: #849eed;
}
.revival-close span::before, .revival-close span::after {
  content: ''; position: absolute; left: 19%; top: 41%; width: 62%; height: 18%;
  background: white; border: 1px solid #284266; border-radius: 4px; transform: rotate(45deg);
}
.revival-close span::after { transform: rotate(-45deg); }
.revival-wheel {
  position: absolute; left: 50%; top: var(--revival-center);
  width: var(--revival-wheel-size); aspect-ratio: 1; transform: translate(-50%, -50%);
}
.revival-beams {
  position: absolute; inset: -52% -35% 5%; z-index: 0; pointer-events: none;
  background: repeating-conic-gradient(at 50% 29%, rgb(255 220 61 / .24) 0deg 9deg, transparent 9deg 23deg);
  mask: radial-gradient(ellipse 50% 28% at 50% 29%, black 0 12%, transparent 100%);
}
.revival-ring {
  position: absolute; inset: 0; z-index: 1; border-radius: 50%;
  background: conic-gradient(from calc(-1 * var(--revival-green-half)),
    #92c90c 0deg calc(var(--revival-green-half) - var(--revival-prize-half)),
    #ffd137 0deg calc(var(--revival-green-half) + var(--revival-prize-half)),
    #92c90c 0deg calc(var(--revival-green-half) * 2), #ec2841 0deg 360deg);
  box-shadow: inset 0 -8px 0 rgb(119 9 49 / .55), inset 0 8px 0 rgb(255 231 136 / .48);
  mask: radial-gradient(circle closest-side, transparent 73%, black 73.5%);
}
.revival-ring::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background:
    radial-gradient(circle closest-side, transparent 78%, rgb(255 221 107 / .23) 78.5% 83%, transparent 83.5%),
    radial-gradient(circle closest-side, transparent 91%, rgb(83 10 48 / .17) 91.5%);
}
.revival-wheel::before, .revival-wheel::after {
  content: ''; position: absolute; z-index: 2; border: 3px solid #f8fcff; border-radius: 50%; pointer-events: none;
  box-shadow: 0 0 0 3px #27394c;
}
.revival-wheel::before { inset: 0; box-shadow: 0 0 0 3px #27394c, 0 7px 0 rgb(0 7 14 / .6); }
.revival-wheel::after { inset: 13%; }
.revival-prize {
  position: absolute; top: -18%; left: 50%; width: var(--revival-prize-width); height: 31%; z-index: 3;
  transform: translateX(-50%); filter: drop-shadow(0 0 2px #203149);
}
.revival-prize::before, .revival-prize::after {
  content: ''; position: absolute; inset: 0; background: #f9fbff;
  clip-path: polygon(0 0, 100% 0, 77.2% 100%, 22.8% 100%);
}
.revival-prize::after { inset: 4px 4px 0; background: linear-gradient(#fff0a0, #ffd238 50%, #eca513); }
.revival-prize img {
  position: absolute; left: -15%; top: -44%; z-index: 1; width: 130%; height: 100%; object-fit: contain;
  transform: rotate(-18deg); filter: drop-shadow(0 3px 1px #695210) drop-shadow(0 0 14px #ffd846);
}
.revival-pointer { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.revival-pointer span {
  position: absolute; left: 50%; top: -17%; width: 13%; height: 24%;
  transform: translateX(-50%);
  background: white; clip-path: polygon(8% 0, 92% 0, 100% 9%, 50% 100%, 0 9%);
  filter: drop-shadow(0 3px 0 #1d344b);
}
.revival-pointer span::after {
  content: ''; position: absolute; inset: 4px 5px 7px;
  background: linear-gradient(110deg, #07d0f3, #0480c5); clip-path: polygon(8% 0, 92% 0, 100% 9%, 50% 100%, 0 9%);
}
.revival-actions {
  position: absolute; top: calc(var(--revival-center) + var(--revival-wheel-size) * .73);
  left: 8px; right: 8px; z-index: 3; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.revival-stop {
  margin: 0; padding: 0 8px; border: 0; background: transparent; color: white;
  font: 1000 clamp(44px, 12vw, 60px)/1.2 system-ui; letter-spacing: 4px;
  -webkit-text-stroke: 7px #172736; paint-order: stroke fill; text-shadow: 0 5px 0 #08151f;
}
.revival-dialog button:focus-visible { outline: 3px solid #ffdb62; outline-offset: 6px; }
#revivalInstructions, #revivalRewards, .revival-count, .revival-speed { margin: 0; text-align: center; font-size: 13px; line-height: 1.4; text-shadow: 0 2px 0 #06141e; }
#revivalInstructions { font-weight: 700; color: #e7f0f5; }
#revivalRewards { display: flex; justify-content: center; gap: 12px; font-size: 12px; font-weight: 800; }
.revival-green-label { color: #c5ee78; }
.revival-gold-label { color: #ffdb69; }
.revival-count { font-weight: 800; letter-spacing: 2px; color: #eaf4ff; }
.revival-speed { font-size: 12px; color: #b4c7d6; }
@media (max-height: 640px) {
  .revival-dialog { --revival-center: 44.5%; }
  .revival-actions { top: calc(var(--revival-center) + var(--revival-wheel-size) * .7); gap: 6px; }
  .revival-stop { font-size: 44px; }
  #revivalInstructions, .revival-count { font-size: 12px; }
  .revival-speed { font-size: 11px; }
}
@media (max-height: 560px) and (min-aspect-ratio: 5/4) {
  .revival-dialog { --revival-wheel-size: min(42vw, 60dvh, 260px); --revival-center: 55%; }
  .revival-wheel { left: 30%; }
  .revival-close { left: auto; right: 20px; top: max(16px, env(safe-area-inset-top)); width: 44px; height: 44px; }
  .revival-close::before { top: 36px; left: 15px; }
  .revival-actions { top: 53%; left: 56%; right: 12px; transform: translateY(-50%); gap: 8px; }
  .revival-stop { font-size: 40px; }
  #revivalRewards { flex-direction: column; gap: 2px; }
}

.message-card { text-align: center; }
.message-card .dialog-cap { flex-direction: column; gap: 2px; }
.message-kicker { font-size: 11px; font-weight: 800; letter-spacing: 1px; opacity: .9; }
.message-title { margin: 0; font-size: 22px; font-weight: 1000; }
.message-copy { margin: 0 0 12px; font-size: 13px; line-height: 1.7; }

.message-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.message-stats:empty { display: none; }

.message-stats span {
  display: grid;
  padding: 8px 4px;
  background: #fff8e8;
  border: 2px solid #dcc8ab;
  border-radius: 12px;
}

.message-stats small { font-size: 10px; color: #806f78; }
.message-stats b { font-size: 17px; color: #765348; }

.message-actions { display: grid; gap: 8px; }

/* Under the results: the 学分 balance and the next thing to save up for. */
.message-note { margin: -4px 0 12px; font-size: 12px; line-height: 1.6; color: #8a6a3c; font-weight: 800; }

/* ---------- Shop overlay ---------- */
.shop-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: linear-gradient(#b9dce1cc 0, #b9dce100 22%);
}

.shop-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--vh, 1vh) * 2.3) 4% 0;
}

.back-button {
  flex: 0 0 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(#fff9e9, #edd7b7);
  border: 2px solid #fff7e6;
  box-shadow: 0 4px 0 #8e7e7866;
  color: #605064;
  font-size: 26px;
  font-weight: 900;
  line-height: 1;
}

.shop-header h2 {
  flex: 1;
  margin: 0;
  color: #fffbeb;
  font-size: 20px;
  font-weight: 1000;
  letter-spacing: 1px;
  text-shadow: 0 2px 0 #6a949d, 0 3px 8px #354b6977;
}

.shop-header .wallet-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 12px;
  background: linear-gradient(#fff9e9, #edd7b7);
  border: 2px solid #fff7e6;
  border-radius: 17px;
  color: #605064;
  font-weight: 900;
}

.shop-name {
  align-self: center;
  flex-shrink: 0;
  max-width: 92%;
  margin-top: 10px;
  padding: 6px 18px;
  border-radius: 16px;
  background: #fff5dee8;
  text-align: center;
  box-shadow: 0 3px 0 #8e7e7855;
}

.shop-name strong { display: block; font-size: 15px; color: #6d5364; }
.shop-name small { font-size: 11px; color: #806f78; }

.shop-showcase { flex: 1; min-height: 72px; margin: 8px 0 0; }

.shop-drawer {
  position: relative;
  flex: 0 0 54%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 4% calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(#fff8e9, #f1dfc6);
  border-top: 3px solid #fff5df;
  border-radius: 27px 27px 0 0;
  box-shadow: 0 -8px 24px #354b6944;
}

.shop-filters { display: flex; flex-shrink: 0; gap: 6px; margin-bottom: 8px; }

.shop-filters button {
  padding: 6px 14px;
  border-radius: 14px;
  background: #efe0c8;
  color: #7e6071;
  font-size: 12px;
  font-weight: 900;
}

.shop-filters .active { background: linear-gradient(#a98fbd, #8e76a4); color: #fff; }

.outfit-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-content: start;
  gap: 8px;
  overflow-y: auto;
  padding: 4px 3px 6px;
  overscroll-behavior: contain;
}

.outfit-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 140px;
  padding: 8px 4px;
  background: #fff8e8;
  border: 2px solid #dcc8ab;
  border-radius: 17px;
  text-align: center;
}

.outfit-card canvas { width: 100%; max-width: 106px; height: 88px; object-fit: contain; }
.outfit-card.is-selected { outline: 2px solid var(--focus); outline-offset: 0; }
.outfit-card.is-locked canvas { opacity: .8; }
.outfit-card.is-locked small { color: #756879; }
.outfit-card small { line-height: 1.4; }
.outfit-summary { flex-shrink: 0; margin: 0 0 6px; font-size: 10px; color: #71616c; line-height: 1.5; }
.outfit-actions { flex-shrink: 0; padding-top: 8px; text-align: center; border-top: 1px solid #d8c4a7; }
.outfit-actions p { min-height: 16px; margin: 0 0 6px; font-size: 11px; line-height: 1.5; color: #685464; }
.outfit-actions .primary { width: 100%; min-height: 40px; }
.outfit-actions > small { display: block; margin-top: 6px; font-size: 10px; color: #756471; }

.outfit-card span {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: linear-gradient(135deg, #e7c6cf, #c797a8);
  color: #fff8ea;
  font-size: 26px;
}

.outfit-card strong { font-size: 13px; color: #5d4a5c; }
.outfit-card small { font-size: 10px; color: #806f78; }

.outfit-card.is-equipped {
  background: #fff3cf;
  border-color: #e9b85f;
  box-shadow: inset 0 0 0 2px #ffe19a;
}

.outfit-card.is-equipped span { background: linear-gradient(#ffe99e, #efc274); color: #8a5a2c; }

/* 角色: a short drawer, so the character gets most of the screen. */
.character-drawer { flex: 0 0 auto; gap: 10px; }

.drawer-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.drawer-head strong { font-size: 15px; color: #5d4a5c; }
.drawer-head small { font-size: 11px; color: #8a7784; }

.character-roster { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.character-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 9px;
  background: #fff8e8;
  border: 2px solid #dcc8ab;
  border-radius: 17px;
  text-align: center;
}

.character-card canvas,
.character-slot { width: 100%; max-width: 96px; height: clamp(62px, calc(var(--vh, 1vh) * 10), 92px); }
.character-card canvas { object-fit: contain; }
.character-card strong { font-size: 13px; color: #5d4a5c; }
.character-card small { font-size: 10px; color: #806f78; }

.character-card.is-current {
  background: #fff3cf;
  border-color: #e9b85f;
  box-shadow: inset 0 0 0 2px #ffe19a;
}

.character-card.is-current small { color: #4e8f82; font-weight: 900; }
.character-card.is-empty { background: #fbf2e2; border-style: dashed; }
.character-card.is-empty strong { color: #a8969f; }

.character-slot {
  display: grid;
  place-items: center;
  color: #dccbb6;
  font-size: 40px;
  font-weight: 1000;
}

.character-drawer > .primary { width: 100%; min-height: 46px; }
.character-drawer > .loadout-entry { width: 100%; min-height: 38px; font-size: 13px; }

/* 技能与坐骑: a card per skill and mount, two to a row, under the preview. */
.loadout-drawer { flex: 0 0 auto; gap: 8px; }
.loadout-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.loadout-card {
  display: grid;
  grid-template-columns: 40px 1fr;
  align-items: center;
  column-gap: 8px;
  padding: 8px 10px;
  background: #fff8e8;
  border: 2px solid #dcc8ab;
  border-radius: 17px;
  text-align: left;
}

.loadout-card canvas { grid-row: 1 / 3; width: 40px; height: 40px; }
.loadout-card strong { font-size: 13px; color: #5d4a5c; }
.loadout-card em { font-size: 10px; font-style: normal; font-weight: 900; color: #8a7784; }
.loadout-card.is-selected { background: #fff3cf; border-color: #e9b85f; box-shadow: inset 0 0 0 2px #ffe19a; }
.loadout-card.is-selected em { color: #4e8f82; }
.loadout-card.is-locked canvas { opacity: .55; }
.loadout-card.is-locked em { color: #a26b33; }
.loadout-drawer .drawer-head small { text-align: right; }
.loadout-note { margin: 2px 0 0; font-size: 10.5px; color: #806f78; text-align: center; }
.loadout-card.is-trying { outline: 2px solid var(--focus); outline-offset: 0; }
.loadout-drawer > [data-buy] { width: 100%; min-height: 40px; }

/* ---------- 学分 prices and buying (src/economy.js) ---------- */
/* The 学 coin, as on the wallet pills, before a price. */
.coin {
  display: inline-grid;
  place-items: center;
  width: 1.45em;
  height: 1.45em;
  flex: none;
  margin-right: 3px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 -1px 0 #d9a13f;
  color: #7a4d18;
  font-size: .82em;
  font-style: normal;
  font-weight: 1000;
  line-height: 1;
  vertical-align: -.2em;
}

/* A card's price, in place of its state line. */
.outfit-card.is-locked small,
.character-card.is-locked small,
.loadout-card.is-locked em { display: inline-flex; align-items: center; color: #8a5a2c; font-weight: 900; font-variant-numeric: tabular-nums; }
.character-card.is-locked canvas { opacity: .8; }
.character-card.is-selected { outline: 2px solid var(--focus); outline-offset: 0; }

/* Buying spends 学分, so it does not look like wearing or picking. */
.primary.is-buy {
  background: linear-gradient(#ffb9a0, #ec8a7b);
  border-color: #ffd9c8;
  border-bottom-color: #b45c5c;
  color: #fffaf0;
  text-shadow: 0 1px 0 #b45c5c88;
}

.primary.is-buy .coin { font-size: .9em; text-shadow: none; }

/* Not enough 学分 yet: readable, but plainly not a button to press. */
.primary.is-buy:disabled {
  opacity: 1;
  background: #eee1cb;
  border-color: #f7ecda;
  border-bottom-color: #cbb28e;
  color: #9a7a66;
  text-shadow: none;
}

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  top: 19%;
  left: 50%;
  z-index: 40;
  /* Sized to its text: from left: 50% it would otherwise shrink to half the width and wrap. */
  width: max-content;
  max-width: 80%;
  padding: 8px 18px;
  transform: translate(-50%, -8px);
  background: linear-gradient(#fff2bd, #eecf96);
  border: 2px solid #fff7e6;
  border-radius: 16px;
  box-shadow: 0 4px 0 #a88c6788;
  color: #6d5364;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .2s, transform .2s, visibility .2s;
}

#toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */
.touch-hint { display: none; }

/* Touch-first screens: swipe hints instead of keys. */
@media (hover: none) and (pointer: coarse) {
  .key-hint { display: none; }
  .touch-hint { display: inline; }
}

@media (max-width: 650px) {
  .desktop-wordmark { display: none; }
  #app { width: 100vw; box-shadow: none; }
}

@media (max-height: 700px) {
  .outfit-card { min-height: 118px; }
  .outfit-card canvas { height: 64px; }
  .outfit-actions { padding-top: 5px; }
  .outfit-actions > small { display: none; }
  .shop-name { margin-top: 6px; padding: 4px 10px; }
  .shop-drawer { padding-top: 10px; }
  .loadout-drawer { gap: 6px; }
  .loadout-grid { gap: 6px; }
  .loadout-card { grid-template-columns: 32px 1fr; column-gap: 6px; min-height: 44px; padding: 4px 8px; border-radius: 14px; }
  .loadout-card canvas { width: 32px; height: 32px; }
  .outfit-card span { width: 42px; height: 42px; font-size: 20px; }
  .bottom-nav small { font-size: 10px; }
}

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

/* Reserved leaderboard panel (currently unavailable). */
.board-tabs {
  display: flex;
  gap: 2px;
  margin: 0 0 10px;
  padding: 3px;
  background: #fff7e8;
  border: 2px solid #dcc8ab;
  border-radius: 999px;
}

.board-tabs button {
  flex: 1;
  min-height: 34px;
  border-radius: 999px;
  color: #7e6071;
  font-size: 13px;
  font-weight: 900;
}

.board-tabs .is-active {
  background: linear-gradient(#b49bc8, #8d74a3);
  color: #fff;
  box-shadow: inset 0 -2px 0 #6f5a8566;
}

.board-status { min-height: 18px; margin: 8px 2px 0; font-size: 12px; color: #806f78; text-align: center; }
.record-row strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
