*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b1220;
  --panel: rgba(12, 24, 42, 0.92);
  --ice: #a8d8ff;
  --ice-deep: #3d7ea6;
  --text: #e8f4ff;
  --muted: #8ab0c8;
  --accent: #5ec8ff;
  --danger: #ff6b7a;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;

  /* Sprite-matched accents (same values game.js paints with) */
  --player: #3dd68c;
  --player-lit: #7aefc0;
  --raider: #e83840;
  --dropper: #ffc820;
  --wood: #c89840;
  --wing: #c8b9ff;
}

html,
body {
  min-height: 100%;
  /* No pull-to-refresh / rubber-band while tapping fast on the canvas. */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, #163050 0%, transparent 55%),
    linear-gradient(180deg, #0b1220 0%, #061018 100%);
  color: var(--text);
  font-family: var(--font);
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 32px 16px 48px;
}

.app {
  width: min(940px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.header {
  text-align: center;
}

.header h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #e8f7ff, #5ec8ff 60%, #a8d8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 4px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.game-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid rgba(94, 200, 255, 0.18);
  background: #0a1524;
  line-height: 0;
}

/* While a full-screen panel is up, keep a floor so it never gets clipped
   on short/narrow viewports (the canvas scales down with the page). */
.game-wrap--menu {
  min-height: 320px;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  background: #0a1524;
  cursor: pointer;
  /* A game surface owns its gestures: no scroll, pan, zoom or double-tap. */
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.btn,
.icon-btn,
.hud-m-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Input-flavoured copy ────────────────────────────────────────
   Every hint exists twice; the body class picks which one is real. */
.k-touch {
  display: none;
}

body.is-touch .k-pointer {
  display: none;
}

body.is-touch .k-touch {
  display: inline;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 12, 22, 0.72);
  backdrop-filter: blur(4px);
  z-index: 2;
  transition: opacity 0.2s ease, visibility 0s;
}

/* visibility (not just opacity) so its buttons leave the tab order mid-run */
.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.panel {
  max-width: 420px;
  margin: 16px;
  padding: 28px 32px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid rgba(94, 200, 255, 0.25);
  box-shadow: var(--shadow);
  text-align: center;
  line-height: 1.5;
}

.panel h2 {
  font-size: 1.6rem;
  margin-bottom: 12px;
  color: var(--accent);
}

.panel p {
  color: var(--muted);
  font-size: 0.98rem;
}

.panel .hint {
  margin-top: 18px;
  color: var(--text);
  font-weight: 600;
}

kbd {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(94, 200, 255, 0.12);
  border: 1px solid rgba(94, 200, 255, 0.35);
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  font-weight: 600;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(12, 24, 42, 0.65);
  border: 1px solid rgba(94, 200, 255, 0.12);
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 90px;
}

.stat .label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat span:last-child {
  font-variant-numeric: tabular-nums;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--ice);
}

.stat.controls {
  gap: 16px;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.9rem;
}

.stat.controls span:last-child {
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  opacity: 0.85;
  line-height: 1.45;
}

/* ══════════════════════════════════════════════════════════════
   ENTRANCE SCREEN
   Sits over the canvas so the live idle world (sky, aurora,
   mountains, snow, bobbing player) is the moving backdrop.
   ══════════════════════════════════════════════════════════════ */
.menu-screen {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.4;
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0s;
}

.menu-screen.hidden {
  opacity: 0;
  transform: scale(1.06);
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease, visibility 0s linear 0.28s;
}

/* Kept light on purpose — the live world behind it is the backdrop. */
.menu-veil {
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 62% 72% at 50% 44%,
    rgba(6, 16, 30, 0.74) 0%,
    rgba(6, 14, 26, 0.44) 58%,
    rgba(3, 9, 18, 0.62) 100%
  );
  backdrop-filter: blur(2px);
}

.menu-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 18px 20px;
  width: 100%;
}

/* Floating ice shards behind the wordmark */
.menu-crest {
  position: absolute;
  inset: -10% -5%;
  pointer-events: none;
}

.crest-shard {
  position: absolute;
  width: 78px;
  height: 78px;
  border-radius: 12px;
  background: linear-gradient(140deg, rgba(200, 232, 255, 0.16), rgba(94, 200, 255, 0.04));
  border: 1px solid rgba(160, 220, 255, 0.18);
  box-shadow: 0 0 30px rgba(60, 160, 230, 0.16);
}

.crest-shard:nth-child(1) {
  top: 6%;
  left: 12%;
  transform: rotate(18deg);
}

.crest-shard:nth-child(2) {
  top: 52%;
  right: 10%;
  width: 54px;
  height: 54px;
  transform: rotate(-14deg);
}

.crest-shard:nth-child(3) {
  bottom: 4%;
  left: 26%;
  width: 34px;
  height: 34px;
  transform: rotate(32deg);
}

/* ── Wordmark ────────────────────────────────────────────────── */
.logo {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.16em;
  font-size: clamp(2.1rem, 8.5vw, 4.1rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1;
  filter: drop-shadow(0 6px 22px rgba(20, 120, 190, 0.55));
}

.logo-line {
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo-line--ice {
  background-image: linear-gradient(100deg, #cfeaff 0%, #ffffff 28%, #9fd6ff 52%, #eaf8ff 76%, #bfe4ff 100%);
}

.logo-line--slide {
  background-image: linear-gradient(100deg, #43b9f0 0%, #a8f0ff 26%, #5ec8ff 52%, #e6fbff 74%, #4fb6f0 100%);
}

.logo-sub {
  margin-top: 10px;
  color: var(--ice);
  font-size: clamp(0.68rem, 2.2vw, 0.85rem);
  letter-spacing: 0.42em;
  text-transform: uppercase;
  text-indent: 0.42em;
  opacity: 0.9;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.menu-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 26px;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 14px 34px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  transition: transform 0.16s cubic-bezier(0.2, 0.9, 0.3, 1.4), box-shadow 0.2s ease,
    background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

@media (hover: hover) {
  .btn:hover {
    transform: translateY(-3px);
  }
}

.btn:active {
  transform: translateY(1px) scale(0.98);
}

.btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.btn-label,
.btn-icon {
  position: relative;
  z-index: 1;
}

/* Primary: the green player square's palette */
.btn-run {
  color: #06301d;
  background: linear-gradient(140deg, var(--player-lit) 0%, var(--player) 48%, #1faa68 100%);
  box-shadow:
    0 10px 26px rgba(31, 170, 104, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.55),
    inset 0 -3px 0 rgba(9, 80, 48, 0.35);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

@media (hover: hover) {
  .btn-run:hover {
    box-shadow:
      0 16px 34px rgba(31, 170, 104, 0.55),
      inset 0 1px 0 rgba(255, 255, 255, 0.6),
      inset 0 -3px 0 rgba(9, 80, 48, 0.35);
  }
}

.btn-run--sm {
  padding: 11px 24px;
  font-size: 0.92rem;
}

/* Sheen that sweeps across the primary button */
.btn-sheen {
  position: absolute;
  top: -60%;
  left: -60%;
  width: 45%;
  height: 220%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.55) 50%, rgba(255, 255, 255, 0) 100%);
  transform: rotate(18deg);
  pointer-events: none;
}

/* Secondary: frosted ice glass */
.btn-ghost {
  color: var(--ice);
  background: rgba(94, 200, 255, 0.09);
  border: 1px solid rgba(140, 215, 255, 0.4);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(6px);
}

@media (hover: hover) {
  .btn-ghost:hover {
    color: #ffffff;
    background: rgba(94, 200, 255, 0.2);
    border-color: rgba(180, 235, 255, 0.7);
  }
}

.btn-ghost--sm {
  padding: 11px 22px;
  font-size: 0.92rem;
}

.btn-icon {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: rgba(255, 200, 32, 0.9);
  color: #5a3008;
  font-size: 0.8rem;
  font-weight: 900;
}

/* Shop button: the gold of the milestone signs it sells */
.btn-icon--shop {
  background: linear-gradient(140deg, #ffd060 0%, #ffb457 55%, #d08020 100%);
  color: #3a2000;
  font-size: 0.72rem;
}

/* Skins button wears the player square instead of a glyph */
.btn-icon--skin {
  background: linear-gradient(140deg, var(--player-lit) 0%, var(--player) 52%, #1faa68 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
  border-radius: 5px;
  width: 16px;
  height: 16px;
}

.menu-hint {
  margin-top: 20px;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
}

.menu-best {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 14px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(12, 24, 42, 0.6);
  border: 1px solid rgba(94, 200, 255, 0.2);
  font-size: 0.95rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ice);
}

.menu-best-label {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ── Game-over panel actions ─────────────────────────────────── */
.panel-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.panel .hint {
  margin-top: 12px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}

/* ══════════════════════════════════════════════════════════════
   INSTRUCTIONS — FIELD MANUAL
   ══════════════════════════════════════════════════════════════ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  background:
    radial-gradient(ellipse 70% 55% at 50% 0%, rgba(22, 48, 80, 0.9) 0%, transparent 60%),
    rgba(4, 10, 20, 0.88);
  backdrop-filter: blur(8px);
  transition: opacity 0.24s ease, visibility 0s;
}

.modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0s linear 0.22s;
}

.modal-card {
  width: min(920px, 100%);
  margin: auto;
  padding: 24px clamp(18px, 3vw, 30px) 20px;
  border-radius: 20px;
  background:
    linear-gradient(160deg, rgba(18, 38, 62, 0.96) 0%, rgba(10, 21, 36, 0.97) 60%, rgba(8, 16, 28, 0.98) 100%);
  border: 1px solid rgba(94, 200, 255, 0.28);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(94, 200, 255, 0.15);
}

.modal-head h2 {
  font-size: clamp(1.3rem, 3.4vw, 1.7rem);
  font-weight: 800;
  letter-spacing: 0.03em;
  background: linear-gradient(135deg, #e8f7ff, #5ec8ff 65%, #a8d8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.85rem;
}

.icon-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(94, 200, 255, 0.1);
  border: 1px solid rgba(94, 200, 255, 0.28);
  color: var(--ice);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

@media (hover: hover) {
  .icon-btn:hover {
    background: rgba(255, 107, 122, 0.22);
    border-color: rgba(255, 140, 150, 0.5);
    color: #fff;
    transform: rotate(90deg);
  }
}

.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.manual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px clamp(16px, 3vw, 32px);
  padding: 18px 0 4px;
}

.manual-col {
  min-width: 0;
}

/* Vertical frost divider between the two columns */
.manual-col:first-child {
  position: relative;
}

.manual-col:first-child::after {
  content: "";
  position: absolute;
  top: 6px;
  bottom: 6px;
  right: clamp(-16px, -1.5vw, -8px);
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(94, 200, 255, 0.28), transparent);
}

.col-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 12px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.col-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.col-title--danger .col-dot {
  background: var(--raider);
  box-shadow: 0 0 12px rgba(232, 56, 64, 0.8);
}

.col-title--power .col-dot {
  background: var(--player);
  box-shadow: 0 0 12px rgba(61, 214, 140, 0.8);
}

.entry-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.entry {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 12px;
  background: rgba(94, 200, 255, 0.045);
  border: 1px solid rgba(94, 200, 255, 0.12);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

@media (hover: hover) {
  .entry:hover {
    background: rgba(94, 200, 255, 0.1);
    border-color: rgba(94, 200, 255, 0.3);
    transform: translateX(3px);
  }
}

.entry-icon {
  width: 62px;
  height: 62px;
  flex: none;
  border-radius: 10px;
  background:
    radial-gradient(ellipse 70% 70% at 50% 40%, rgba(94, 200, 255, 0.12), transparent 70%),
    rgba(6, 16, 28, 0.55);
  border: 1px solid rgba(94, 200, 255, 0.14);
}

.entry-body {
  min-width: 0;
}

.entry-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.entry-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.entry-tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  background: rgba(94, 200, 255, 0.12);
  border: 1px solid rgba(94, 200, 255, 0.3);
  color: var(--accent);
}

.entry-tag--danger {
  background: rgba(255, 107, 122, 0.12);
  border-color: rgba(255, 107, 122, 0.38);
  color: #ff97a3;
}

.entry-tag--gold {
  background: rgba(255, 200, 32, 0.12);
  border-color: rgba(255, 200, 32, 0.4);
  color: #ffd75e;
}

.entry-desc {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.45;
}

.entry-desc strong {
  color: var(--ice);
  font-weight: 700;
}

.col-note {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 200, 32, 0.07);
  border: 1px solid rgba(255, 200, 32, 0.22);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.col-note strong {
  color: var(--dropper);
}

.modal-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(94, 200, 255, 0.15);
}

.keyline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  color: var(--muted);
  font-size: 0.82rem;
}

/* ══════════════════════════════════════════════════════════════
   SKINS — THE WARDROBE
   A .modal variant, so it inherits the frosted card, the scroll
   behaviour on short landscape and the reduced-motion blanket.
   Every card carries its own --skin-accent, set by game.js from
   the SKIN_DEFS entry, and that one variable drives the glow, the
   tag pill and the equipped ring.
   ══════════════════════════════════════════════════════════════ */
.skins-card {
  width: min(880px, 100%);
}

.skin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 12px;
  padding: 18px 0 4px;
}

.skin-card {
  --skin-accent: #5ec8ff;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 14px;
  border-radius: 16px;
  border: 1px solid rgba(94, 200, 255, 0.14);
  background:
    linear-gradient(180deg, rgba(94, 200, 255, 0.06), rgba(6, 16, 28, 0.35));
  color: var(--text);
  font-family: inherit;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.4),
    border-color 0.22s ease, background 0.22s ease, box-shadow 0.22s ease;
}

/* Accent wash that only wakes up on hover / when equipped */
.skin-card::before {
  content: "";
  position: absolute;
  inset: -40% -10% auto;
  height: 120%;
  background: radial-gradient(ellipse 55% 60% at 50% 30%, var(--skin-accent), transparent 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

@media (hover: hover) {
  .skin-card:hover {
    transform: translateY(-5px);
    border-color: color-mix(in srgb, var(--skin-accent) 55%, transparent);
  }

  .skin-card:hover::before {
    opacity: 0.12;
  }
}

.skin-card:active {
  transform: translateY(-1px) scale(0.985);
}

.skin-card:focus-visible {
  outline: 2px solid var(--skin-accent);
  outline-offset: 2px;
}

.skin-card--on {
  border-color: color-mix(in srgb, var(--skin-accent) 70%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--skin-accent) 35%, transparent),
    0 14px 34px -14px var(--skin-accent);
}

.skin-card--on::before {
  opacity: 0.16;
}

/* ── The little stage each square poses on ───────────────────── */
.skin-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 96px;
  border-radius: 13px;
  background:
    radial-gradient(ellipse 78% 62% at 50% 42%, rgba(94, 200, 255, 0.09), transparent 72%),
    rgba(4, 12, 22, 0.5);
  border: 1px solid rgba(94, 200, 255, 0.1);
  overflow: hidden;
}

/* Ice floor the square stands on */
.skin-stage::after {
  content: "";
  position: absolute;
  left: 14%;
  right: 14%;
  bottom: 12px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(168, 216, 255, 0.4), transparent);
}

.skin-canvas {
  width: 96px;
  height: 96px;
  position: relative;
  z-index: 1;
}

/* ── Card copy ───────────────────────────────────────────────── */
.skin-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  position: relative;
}

.skin-name {
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.skin-tag {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--skin-accent);
  background: color-mix(in srgb, var(--skin-accent) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--skin-accent) 38%, transparent);
}

.skin-blurb {
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.42;
}

/* ── Equip / Equipped pill ───────────────────────────────────── */
.skin-state {
  position: relative;
  margin-top: auto;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 1px solid rgba(140, 215, 255, 0.28);
  color: var(--muted);
  transition: background 0.22s ease, color 0.22s ease, border-color 0.22s ease;
}

.skin-state-on {
  display: none;
  align-items: center;
  gap: 6px;
}

.skin-check {
  font-size: 0.75rem;
  line-height: 1;
}

.skin-card--on .skin-state {
  color: #04121c;
  background: var(--skin-accent);
  border-color: transparent;
}

.skin-card--on .skin-state-off {
  display: none;
}

.skin-card--on .skin-state-on {
  display: inline-flex;
}

/* ══════════════════════════════════════════════════════════════
   SHOP — FREE MODIFIERS
   Another .modal variant, so it inherits the frosted card and the
   scroll behaviour on short landscape. Two shelves: nine head-start
   chips (mutually exclusive) and five full modification cards.
   Every card carries its own --shop-accent, set by game.js from the
   SHOP_DEFS entry, and that one variable drives glow and ring.
   ══════════════════════════════════════════════════════════════ */
.shop-card-panel {
  width: min(900px, 100%);
}

/* The deal, stated before anything can be equipped */
.shop-warn {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: 16px;
  padding: 11px 14px;
  border-radius: 12px;
  background: rgba(255, 170, 60, 0.09);
  border: 1px solid rgba(255, 170, 60, 0.34);
  color: #ffd9a8;
  font-size: 0.84rem;
  line-height: 1.5;
}

.shop-warn strong {
  color: #ffb457;
  font-weight: 800;
}

.shop-warn-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 170, 60, 0.9);
  color: #3a2000;
  font-size: 0.85rem;
  font-weight: 900;
}

.shop-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 0 2px;
}

.shop-section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.shop-section-note {
  letter-spacing: 0.04em;
  text-transform: none;
  font-size: 0.74rem;
  font-weight: 600;
  color: rgba(168, 200, 230, 0.6);
}

/* ── Head-start chips ────────────────────────────────────────── */
.shop-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  gap: 9px;
}

.shop-chip {
  --shop-accent: #ffd060;
  /* The wardrobe's equipped-glow keyframes read --skin-accent; alias it so
     the shop can reuse that animation instead of duplicating it. */
  --skin-accent: var(--shop-accent);
  position: relative;
  display: grid;
  place-items: center;
  padding: 6px 4px 8px;
  border-radius: 13px;
  border: 1px solid rgba(94, 200, 255, 0.14);
  background: linear-gradient(180deg, rgba(94, 200, 255, 0.05), rgba(6, 16, 28, 0.35));
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.4),
    border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.shop-chip-canvas {
  width: 64px;
  height: 50px;
}

/* The tick only exists once the rung is taken */
.shop-chip-tick {
  position: absolute;
  top: 5px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--shop-accent);
  color: #2a1c00;
  font-size: 0.62rem;
  font-weight: 900;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.2s ease, transform 0.24s cubic-bezier(0.22, 1.2, 0.36, 1);
}

/* ── Modification cards ──────────────────────────────────────── */
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 12px;
}

.shop-card {
  --shop-accent: #5ec8ff;
  --skin-accent: var(--shop-accent);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 10px 14px;
  border-radius: 16px;
  border: 1px solid rgba(94, 200, 255, 0.14);
  background: linear-gradient(180deg, rgba(94, 200, 255, 0.06), rgba(6, 16, 28, 0.35));
  color: var(--text);
  font-family: inherit;
  text-align: center;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.4),
    border-color 0.22s ease, background 0.22s ease, box-shadow 0.22s ease;
}

/* Accent wash, asleep until hover / equipped — same rule as the wardrobe */
.shop-card::before {
  content: "";
  position: absolute;
  inset: -40% -10% auto;
  height: 120%;
  background: radial-gradient(ellipse 55% 60% at 50% 30%, var(--shop-accent), transparent 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

@media (hover: hover) {
  .shop-card:hover,
  .shop-chip:hover {
    transform: translateY(-4px);
    border-color: color-mix(in srgb, var(--shop-accent) 55%, transparent);
  }

  .shop-card:hover::before {
    opacity: 0.12;
  }
}

.shop-card:active,
.shop-chip:active {
  transform: translateY(-1px) scale(0.985);
}

.shop-card:focus-visible,
.shop-chip:focus-visible {
  outline: 2px solid var(--shop-accent);
  outline-offset: 2px;
}

.shop-card--on {
  border-color: color-mix(in srgb, var(--shop-accent) 70%, transparent);
  box-shadow:
    0 0 0 1px color-mix(in srgb, var(--shop-accent) 35%, transparent),
    0 14px 34px -14px var(--shop-accent);
}

.shop-card.shop-card--on::before {
  opacity: 0.16;
}

.shop-chip.shop-card--on {
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--shop-accent) 14%, transparent), rgba(6, 16, 28, 0.35));
}

.shop-chip.shop-card--on .shop-chip-tick {
  opacity: 1;
  transform: scale(1);
}

.shop-stage {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 84px;
  border-radius: 13px;
  background:
    radial-gradient(ellipse 78% 62% at 50% 42%, rgba(94, 200, 255, 0.09), transparent 72%),
    rgba(4, 12, 22, 0.5);
  border: 1px solid rgba(94, 200, 255, 0.1);
  overflow: hidden;
}

.shop-canvas {
  position: relative;
  z-index: 1;
  width: 84px;
  height: 84px;
}

.shop-meta {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.shop-name {
  font-size: 0.92rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.shop-tag {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--shop-accent);
  background: color-mix(in srgb, var(--shop-accent) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--shop-accent) 38%, transparent);
}

.shop-blurb {
  color: var(--muted);
  font-size: 0.73rem;
  line-height: 1.42;
}

.shop-state {
  position: relative;
  margin-top: auto;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border: 1px solid rgba(140, 215, 255, 0.28);
  color: var(--muted);
  transition: background 0.22s ease, color 0.22s ease, border-color 0.22s ease;
}

.shop-state-on {
  display: none;
  align-items: center;
  gap: 6px;
}

.shop-check {
  font-size: 0.75rem;
  line-height: 1;
}

.shop-card--on .shop-state {
  color: #04121c;
  background: var(--shop-accent);
  border-color: transparent;
}

.shop-card--on .shop-state-off {
  display: none;
}

.shop-card--on .shop-state-on {
  display: inline-flex;
}

/* ── Footer: the running tally of what this run has become ───── */
.shop-foot-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

#shop-summary {
  font-variant-numeric: tabular-nums;
}

.shop-summary--hot {
  color: #ffb457;
  font-weight: 700;
}

#btn-clear-shop:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

/* ── The badge that rides along with a modified run ──────────── */
.forfun-badge {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 4;
  display: none;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(8, 18, 30, 0.72);
  border: 1px solid rgba(255, 170, 60, 0.42);
  color: #ffcf95;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

body.is-running.is-modified .forfun-badge {
  display: flex;
}

/* Fullscreen puts the score pill in that exact corner — sit under it. */
body.is-fullscreen .forfun-badge {
  top: calc(46px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  font-size: 0.6rem;
  padding: 4px 9px;
}

.forfun-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffb457;
  box-shadow: 0 0 10px rgba(255, 180, 87, 0.9);
  animation: forfun-pulse 1.6s ease-in-out infinite;
}

/* Same note, restated on the game-over panel */
.msg-forfun {
  display: inline-block;
  margin-top: 8px;
  color: #ffb457;
  font-size: 0.86rem;
  font-weight: 700;
}

/* ══════════════════════════════════════════════════════════════
   ANIMATION
   ══════════════════════════════════════════════════════════════ */
@keyframes forfun-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

@keyframes ice-shimmer {
  0%,
  62% {
    background-position: 120% 0;
  }
  100% {
    background-position: -60% 0;
  }
}

@keyframes logo-drop {
  0% {
    opacity: 0;
    transform: translateY(-34px) scale(0.86) rotate(-4deg);
    filter: blur(6px);
  }
  60% {
    opacity: 1;
    filter: blur(0);
  }
  78% {
    transform: translateY(4px) scale(1.03) rotate(0.6deg);
  }
  100% {
    opacity: 1;
    transform: none;
    filter: blur(0);
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes run-pulse {
  0%,
  100% {
    box-shadow:
      0 10px 26px rgba(31, 170, 104, 0.42),
      0 0 0 0 rgba(61, 214, 140, 0.5),
      inset 0 1px 0 rgba(255, 255, 255, 0.55),
      inset 0 -3px 0 rgba(9, 80, 48, 0.35);
  }
  55% {
    box-shadow:
      0 12px 30px rgba(31, 170, 104, 0.5),
      0 0 0 14px rgba(61, 214, 140, 0),
      inset 0 1px 0 rgba(255, 255, 255, 0.55),
      inset 0 -3px 0 rgba(9, 80, 48, 0.35);
  }
}

@keyframes sheen-sweep {
  0%,
  55% {
    left: -60%;
  }
  100% {
    left: 130%;
  }
}

@keyframes shard-drift {
  0%,
  100% {
    transform: translate3d(0, 0, 0) rotate(var(--spin, 18deg));
  }
  50% {
    transform: translate3d(6px, -14px, 0) rotate(calc(var(--spin, 18deg) + 6deg));
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(22px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes entry-in {
  from {
    opacity: 0;
    transform: translateX(-14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Entrance choreography — re-runs every time the menu comes back,
   because the rules only apply while :not(.hidden). */
.menu-screen:not(.hidden) .logo-line {
  animation:
    logo-drop 0.66s cubic-bezier(0.22, 1.2, 0.36, 1) backwards,
    ice-shimmer 4.5s 1.1s ease-in-out infinite;
}

.menu-screen:not(.hidden) .logo-line--slide {
  animation-delay: 0.12s, 1.35s;
}

.menu-screen:not(.hidden) .logo-sub {
  animation: rise-in 0.5s 0.34s ease-out backwards;
}

.menu-screen:not(.hidden) .menu-actions {
  animation: rise-in 0.5s 0.46s cubic-bezier(0.22, 1.2, 0.36, 1) backwards;
}

.menu-screen:not(.hidden) .menu-hint {
  animation: rise-in 0.5s 0.58s ease-out backwards;
}

.menu-screen:not(.hidden) .menu-best {
  animation: rise-in 0.5s 0.68s ease-out backwards;
}

.menu-screen:not(.hidden) .crest-shard {
  animation: shard-drift 7s ease-in-out infinite;
}

.menu-screen:not(.hidden) .crest-shard:nth-child(1) {
  --spin: 18deg;
}

.menu-screen:not(.hidden) .crest-shard:nth-child(2) {
  --spin: -14deg;
  animation-duration: 9s;
  animation-delay: -3s;
}

.menu-screen:not(.hidden) .crest-shard:nth-child(3) {
  --spin: 32deg;
  animation-duration: 6s;
  animation-delay: -1.5s;
}

.btn-run .btn-sheen {
  animation: sheen-sweep 3.6s ease-in-out infinite;
}

.menu-screen:not(.hidden) .btn-run {
  animation: run-pulse 2.4s ease-out infinite;
}

.modal:not(.hidden) .modal-card {
  animation: card-in 0.36s cubic-bezier(0.22, 1.1, 0.36, 1) backwards;
}

.modal:not(.hidden) .entry {
  animation: entry-in 0.34s ease-out backwards;
}

.modal:not(.hidden) .entry:nth-child(1) { animation-delay: 0.1s; }
.modal:not(.hidden) .entry:nth-child(2) { animation-delay: 0.15s; }
.modal:not(.hidden) .entry:nth-child(3) { animation-delay: 0.2s; }
.modal:not(.hidden) .entry:nth-child(4) { animation-delay: 0.25s; }
.modal:not(.hidden) .entry:nth-child(5) { animation-delay: 0.3s; }
.modal:not(.hidden) .entry:nth-child(6) { animation-delay: 0.35s; }

/* ── Wardrobe choreography ───────────────────────────────────── */
@keyframes skin-card-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* The equipped card breathes, so the choice is never in doubt */
@keyframes skin-equipped-glow {
  0%,
  100% {
    box-shadow:
      0 0 0 1px color-mix(in srgb, var(--skin-accent) 35%, transparent),
      0 14px 34px -14px var(--skin-accent);
  }
  50% {
    box-shadow:
      0 0 0 1px color-mix(in srgb, var(--skin-accent) 60%, transparent),
      0 18px 42px -12px var(--skin-accent);
  }
}

@keyframes skin-equip-pop {
  0% {
    transform: none;
  }
  35% {
    transform: translateY(-6px) scale(1.05);
  }
  100% {
    transform: none;
  }
}

.modal:not(.hidden) .skin-card {
  animation: skin-card-in 0.4s cubic-bezier(0.22, 1.1, 0.36, 1) backwards;
}

.modal:not(.hidden) .skin-card:nth-child(1) { animation-delay: 0.08s; }
.modal:not(.hidden) .skin-card:nth-child(2) { animation-delay: 0.14s; }
.modal:not(.hidden) .skin-card:nth-child(3) { animation-delay: 0.2s; }
.modal:not(.hidden) .skin-card:nth-child(4) { animation-delay: 0.26s; }
.modal:not(.hidden) .skin-card:nth-child(5) { animation-delay: 0.32s; }

/* Once the entrance has played, the equipped card takes over the slot */
.modal:not(.hidden) .skin-card--on {
  animation:
    skin-card-in 0.4s cubic-bezier(0.22, 1.1, 0.36, 1) backwards,
    skin-equipped-glow 2.8s 0.5s ease-in-out infinite;
}

/* Doubled class so it outranks the nth-child stagger delays above */
.modal:not(.hidden) .skin-card.skin-card--pop {
  animation:
    skin-equip-pop 0.42s cubic-bezier(0.22, 1.1, 0.36, 1),
    skin-equipped-glow 2.8s ease-in-out infinite;
  animation-delay: 0s, 0.42s;
}

/* The shop borrows the wardrobe's entrance. Its shelves hold nine and five,
   so the stagger is written as a step per position rather than one rule per
   card — adding a shop item must not mean adding a line here. */
.modal:not(.hidden) .shop-chip,
.modal:not(.hidden) .shop-card {
  animation: skin-card-in 0.4s cubic-bezier(0.22, 1.1, 0.36, 1) backwards;
}

.modal:not(.hidden) .shop-chip:nth-child(n + 1) { animation-delay: 0.08s; }
.modal:not(.hidden) .shop-chip:nth-child(n + 4) { animation-delay: 0.13s; }
.modal:not(.hidden) .shop-chip:nth-child(n + 7) { animation-delay: 0.18s; }
.modal:not(.hidden) .shop-card:nth-child(n + 1) { animation-delay: 0.2s; }
.modal:not(.hidden) .shop-card:nth-child(n + 3) { animation-delay: 0.26s; }
.modal:not(.hidden) .shop-card:nth-child(n + 5) { animation-delay: 0.32s; }

.modal:not(.hidden) .shop-card.shop-card--on {
  animation:
    skin-card-in 0.4s cubic-bezier(0.22, 1.1, 0.36, 1) backwards,
    skin-equipped-glow 2.8s 0.5s ease-in-out infinite;
}

.modal:not(.hidden) .shop-card.shop-card--pop {
  animation:
    skin-equip-pop 0.42s cubic-bezier(0.22, 1.1, 0.36, 1),
    skin-equipped-glow 2.8s ease-in-out infinite;
  animation-delay: 0s, 0.42s;
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  .manual {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  .manual-col:first-child::after {
    display: none;
  }
}

@media (max-width: 600px) {
  .menu-content {
    padding: 12px;
  }

  .logo-sub {
    margin-top: 6px;
    letter-spacing: 0.3em;
    text-indent: 0.3em;
  }

  .menu-actions {
    margin-top: 18px;
    gap: 10px;
  }

  .btn {
    padding: 12px 24px;
    font-size: 0.95rem;
  }

  .menu-hint {
    margin-top: 14px;
    font-size: 0.75rem;
  }

  .menu-best {
    margin-top: 10px;
  }

  .crest-shard {
    display: none;
  }

  .modal {
    padding: 12px 10px;
  }

  .modal-card {
    padding: 18px 14px 16px;
  }

  .entry-icon {
    width: 54px;
    height: 54px;
  }

  .modal-foot {
    justify-content: center;
  }

  .skin-grid {
    grid-template-columns: repeat(auto-fit, minmax(126px, 1fr));
    gap: 9px;
  }

  .skin-stage {
    height: 78px;
  }

  .skin-canvas {
    width: 78px;
    height: 78px;
  }

  .skin-blurb {
    font-size: 0.68rem;
  }

  .shop-chips {
    grid-template-columns: repeat(auto-fit, minmax(66px, 1fr));
    gap: 7px;
  }

  .shop-chip-canvas {
    width: 56px;
    height: 44px;
  }

  .shop-grid {
    grid-template-columns: repeat(auto-fit, minmax(134px, 1fr));
    gap: 9px;
  }

  .shop-stage {
    height: 70px;
  }

  .shop-canvas {
    width: 70px;
    height: 70px;
  }

  .shop-blurb {
    font-size: 0.68rem;
  }

  .shop-warn {
    font-size: 0.78rem;
    padding: 9px 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu-screen *,
  .modal * {
    animation: none !important;
    transition: none !important;
  }

  .logo-line {
    background-position: 50% 0;
  }
}

@media (max-width: 600px) {
  body {
    padding: 16px 10px 32px;
  }

  .hud {
    flex-direction: column;
    align-items: flex-start;
  }

  .stat.controls {
    margin-left: 0;
  }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE
   Three body classes, all owned by game.js (see initResponsive) so
   the CSS and the JS can never disagree about what mode we're in:

     .is-touch          coarse pointer — swap copy, grow tap targets
     .is-portrait-locked  coarse + portrait — show the rotate gate,
                          freeze the simulation
     .is-fullscreen     coarse + landscape — the game eats the viewport
   ══════════════════════════════════════════════════════════════ */

/* ── Portrait gate ───────────────────────────────────────────── */
.rotate-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px calc(24px + env(safe-area-inset-right)) 24px calc(24px + env(safe-area-inset-left));
  text-align: center;
  background:
    radial-gradient(ellipse 90% 45% at 50% 30%, #163050 0%, transparent 62%),
    linear-gradient(180deg, #0b1220 0%, #061018 100%);
}

body.is-portrait-locked .rotate-gate {
  display: flex;
}

.rotate-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 360px;
}

/* A phone outline that tips over on a loop — the instruction, drawn. */
.rotate-phone {
  position: relative;
  width: 74px;
  height: 128px;
  border-radius: 14px;
  border: 3px solid rgba(168, 216, 255, 0.85);
  background: linear-gradient(150deg, rgba(94, 200, 255, 0.16), rgba(94, 200, 255, 0.04));
  box-shadow: 0 0 34px rgba(60, 160, 230, 0.28);
  animation: rotate-hint 2.6s ease-in-out infinite;
}

.rotate-phone-screen {
  position: absolute;
  inset: 9px;
  border-radius: 6px;
  background: linear-gradient(160deg, rgba(200, 240, 255, 0.22), rgba(61, 214, 140, 0.16));
}

.rotate-phone-notch {
  position: absolute;
  top: 4px;
  left: 50%;
  width: 22px;
  height: 3px;
  border-radius: 999px;
  transform: translateX(-50%);
  background: rgba(168, 216, 255, 0.85);
}

.rotate-title {
  margin-top: 12px;
  font-size: clamp(1.4rem, 6vw, 1.9rem);
  font-weight: 800;
  letter-spacing: 0.03em;
  background: linear-gradient(135deg, #e8f7ff, #5ec8ff 62%, #a8d8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.rotate-sub {
  color: var(--ice);
  font-size: 0.98rem;
  line-height: 1.5;
}

.rotate-note {
  color: var(--muted);
  font-size: 0.8rem;
  opacity: 0.8;
}

@keyframes rotate-hint {
  0%, 26% { transform: rotate(0deg); }
  56%, 88% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}

/* Nothing behind the gate should be reachable, or rubber-band under it. */
body.is-portrait-locked {
  overflow: hidden;
}

body.is-portrait-locked .app,
body.is-portrait-locked .modal {
  visibility: hidden;
  pointer-events: none;
}

/* ── Landscape: the game takes the whole screen ──────────────── */
body.is-fullscreen {
  padding: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

body.is-fullscreen .app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  gap: 0;
}

body.is-fullscreen .header,
body.is-fullscreen .footer,
body.is-fullscreen .hud {
  display: none;
}

/* Sized to the playfield's own aspect (set by layout()) and centred, so any
   letterboxing lands on the page background instead of inside the frame. */
body.is-fullscreen .game-wrap {
  flex: none;
  margin: auto;
  width: min(100vw, calc(100vh * var(--play-aspect, 2.25)));
  width: min(100vw, calc(100dvh * var(--play-aspect, 2.25)));
  aspect-ratio: var(--play-aspect, 2.25);
  max-height: 100vh;
  max-height: 100dvh;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: #06101a;
}

/* min-height was a desktop safety net; in fullscreen it would overflow. */
body.is-fullscreen .game-wrap--menu {
  min-height: 0;
}

body.is-fullscreen #game {
  width: 100%;
  height: 100%;
  /* JS matches the backing store to this box; contain covers the
     residual sliver on aspect ratios outside the playable clamp. */
  object-fit: contain;
}

/* ── In-canvas HUD (score / best / restart) ──────────────────── */
.hud-mobile {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left));
  pointer-events: none; /* taps fall through to the canvas = jump */
  line-height: 1.2; /* .game-wrap zeroes it for the canvas — undo that here */
}

body.is-fullscreen.is-running .hud-mobile {
  display: flex;
}

.hud-m-stats {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 5px 13px;
  border-radius: 999px;
  background: rgba(6, 16, 30, 0.55);
  border: 1px solid rgba(94, 200, 255, 0.18);
  backdrop-filter: blur(4px);
}

.hud-m-label {
  color: var(--muted);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hud-m-value {
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ice);
}

.hud-m-sep {
  width: 1px;
  align-self: stretch;
  margin: 0 3px;
  background: rgba(94, 200, 255, 0.25);
}

.hud-m-btn {
  pointer-events: auto; /* the one thing in here that is not a jump */
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(6, 16, 30, 0.55);
  border: 1px solid rgba(94, 200, 255, 0.28);
  color: var(--ice);
  font-family: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.hud-m-btn:active {
  background: rgba(94, 200, 255, 0.25);
  color: #fff;
}

.hud-m-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Resume gate (after rotating back into landscape) ────────── */
.resume-gate {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 12, 22, 0.72);
  backdrop-filter: blur(4px);
  cursor: pointer;
  line-height: 1.4; /* .game-wrap zeroes it for the canvas — undo that here */
}

.resume-gate.hidden {
  display: none;
}

.resume-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 34px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid rgba(94, 200, 255, 0.25);
  box-shadow: var(--shadow);
  text-align: center;
}

.resume-title {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.resume-sub {
  color: var(--muted);
  font-size: 0.88rem;
  letter-spacing: 0.04em;
}

/* ── Touch ergonomics ────────────────────────────────────────── */
body.is-touch .icon-btn {
  width: 44px;
  height: 44px;
}

body.is-touch .btn {
  min-height: 46px;
}

body.is-touch .btn-run--sm,
body.is-touch .btn-ghost--sm {
  min-height: 44px;
  padding-inline: 22px;
}

/* Game-over panel says "tap anywhere", so the backdrop must be tappable
   without the panel swallowing an errant tap on its own padding. */
body.is-touch .overlay {
  cursor: pointer;
}

/* ── Short landscape viewports (phones held sideways) ─────────
   ~330–430px of height: the menu and the field manual both have to
   fit without the page itself ever scrolling. */
@media (orientation: landscape) and (max-height: 500px) {
  .menu-content {
    padding: 8px 14px;
  }

  .logo {
    font-size: clamp(1.7rem, 7vh, 2.8rem);
  }

  .logo-sub {
    margin-top: 4px;
    font-size: 0.62rem;
    letter-spacing: 0.3em;
    text-indent: 0.3em;
  }

  .menu-actions {
    margin-top: 12px;
    gap: 10px;
  }

  /* Four buttons now, and the narrowest landscape phone is ~667px wide:
     at the full-size padding they wrap onto a second row. Trim the sides
     (not the height — these stay comfortable thumb targets). */
  .menu-actions .btn {
    padding: 12px 20px;
    font-size: 0.85rem;
  }

  .menu-actions .btn-run {
    padding: 12px 26px;
  }

  .menu-hint {
    margin-top: 10px;
    font-size: 0.72rem;
  }

  .menu-best {
    margin-top: 8px;
    padding: 3px 12px;
    font-size: 0.85rem;
  }

  .crest-shard {
    display: none;
  }

  .panel {
    margin: 8px;
    padding: 16px 22px;
  }

  .panel h2 {
    font-size: 1.25rem;
    margin-bottom: 6px;
  }

  .panel p {
    font-size: 0.85rem;
  }

  .panel-actions {
    margin-top: 12px;
  }

  /* Field manual: one column, and the card — not the page — scrolls. */
  .modal {
    padding: 8px calc(8px + env(safe-area-inset-right)) 8px calc(8px + env(safe-area-inset-left));
    overflow: hidden;
  }

  .modal-card {
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 14px 14px 12px;
    border-radius: 14px;
  }

  /* Keep the ✕ reachable no matter how far the list has scrolled. */
  .modal-head {
    position: sticky;
    top: -14px;
    z-index: 1;
    padding-top: 14px;
    margin-top: -14px;
    background: linear-gradient(180deg, rgba(16, 34, 56, 0.99) 78%, rgba(16, 34, 56, 0.9));
  }

  .modal-sub {
    display: none;
  }

  .manual {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 12px 0 4px;
  }

  .manual-col:first-child::after {
    display: none;
  }

  .entry-icon {
    width: 48px;
    height: 48px;
  }

  .entry-desc {
    font-size: 0.78rem;
  }

  /* Wardrobe: five squat cards across, blurbs dropped for height. The
     whole shop has to clear a ~330px-tall viewport without scrolling. */
  .skin-grid {
    grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
    gap: 7px;
    padding: 10px 0 2px;
  }

  .skin-card {
    gap: 5px;
    padding: 7px 6px 8px;
    border-radius: 12px;
  }

  .skin-stage {
    height: 56px;
  }

  .skin-canvas {
    width: 56px;
    height: 56px;
  }

  .skin-stage::after {
    bottom: 6px;
  }

  .skin-blurb {
    display: none;
  }

  .skin-meta {
    gap: 4px;
  }

  .skin-name {
    font-size: 0.78rem;
  }

  .skin-tag {
    padding: 1px 7px;
    font-size: 0.55rem;
  }

  .skin-state {
    padding: 3px 9px;
    font-size: 0.58rem;
  }

  /* Shop: fourteen items on a ~330px-tall viewport. The chips shrink to a
     row of number plates, the cards drop their blurbs, and the card — not
     the page — takes the scroll (see .modal-card above). */
  .shop-warn {
    margin-top: 10px;
    padding: 7px 10px;
    gap: 8px;
    font-size: 0.72rem;
    line-height: 1.4;
  }

  .shop-warn-icon {
    width: 18px;
    height: 18px;
    font-size: 0.72rem;
  }

  .shop-body {
    gap: 12px;
    padding: 10px 0 2px;
  }

  .shop-section-title {
    margin-bottom: 7px;
    font-size: 0.66rem;
  }

  .shop-section-note {
    font-size: 0.64rem;
  }

  .shop-chips {
    grid-template-columns: repeat(9, 1fr);
    gap: 5px;
  }

  .shop-chip {
    padding: 3px 2px 4px;
    border-radius: 10px;
  }

  /* height:auto keeps the canvas' own 64×50 aspect, so the sign never
     stretches however narrow the nine columns get. */
  .shop-chip-canvas {
    width: 100%;
    max-width: 64px;
    height: auto;
  }

  .shop-chip-tick {
    top: 2px;
    right: 2px;
    width: 13px;
    height: 13px;
    font-size: 0.52rem;
  }

  .shop-grid {
    grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
    gap: 7px;
  }

  .shop-card {
    gap: 5px;
    padding: 7px 6px 8px;
    border-radius: 12px;
  }

  .shop-stage {
    height: 54px;
  }

  .shop-canvas {
    width: 54px;
    height: 54px;
  }

  .shop-blurb {
    display: none;
  }

  .shop-meta {
    gap: 4px;
  }

  .shop-name {
    font-size: 0.76rem;
  }

  .shop-tag {
    padding: 1px 7px;
    font-size: 0.55rem;
  }

  .shop-state {
    padding: 3px 9px;
    font-size: 0.58rem;
  }

  .modal-foot {
    margin-top: 12px;
    padding-top: 12px;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-phone {
    animation: none;
    transform: rotate(-90deg);
  }
}
