:root {
  color-scheme: dark;
  --ink: #081615;
  --paper: #f3eddb;
  --soft: #adbfaf;
  --gold: #e9cc91;
  --mint: #a7e8c5;
  --border: rgba(177, 206, 174, .22);
  --gold-border: rgba(231, 201, 139, .34);
  --ui: Inter, 'Microsoft YaHei UI', 'PingFang SC', 'Noto Sans CJK SC', Arial, sans-serif;
  --display: 'Kaiti SC', KaiTi, 'Songti SC', 'Noto Serif CJK SC', SimSun, Georgia, serif;
  --play-width: clamp(362px, calc((100vh - 155px) * .848485), 560px);
}

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

body {
  position: relative;
  isolation: isolate;
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  color: var(--paper);
  background: var(--ink);
  font: 14px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
button:not(:disabled) { cursor: pointer; }
button:disabled { opacity: .5; }
button, canvas { -webkit-tap-highlight-color: transparent; }
button:focus-visible, canvas:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--mint); outline-offset: 4px; }
h1, h2, p { margin: 0; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.scene-art {
  position: absolute;
  z-index: -1;
  inset: 0 0 auto;
  height: clamp(444px, 46vw, 650px);
  background:
    linear-gradient(90deg, rgba(8, 22, 21, .89), rgba(8, 22, 21, .44) 47%, rgba(8, 22, 21, .06) 90%),
    linear-gradient(180deg, rgba(8, 22, 21, .13), rgba(8, 22, 21, .12) 24%, var(--ink) 96%),
    url('assets/hero.jpg') center 36% / cover;
  pointer-events: none;
}

.page-width { width: min(100% - 56px, calc(var(--play-width) + 345px)); margin-inline: auto; }

.topbar {
  min-height: clamp(99px, 14vh, 126px);
  padding-block: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 12px; white-space: nowrap; }

.brand-mark {
  width: 54px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  flex: none;
  border: 1px solid var(--gold-border);
  border-radius: 12px;
  background: rgba(58, 66, 33, .5);
  box-shadow: 0 3px 11px rgba(0, 0, 0, .29), inset 0 0 10px rgba(235, 201, 120, .07);
}

.brand-mark img { width: 93%; height: 93%; object-fit: contain; }

.brand h1 {
  color: #fff2cd;
  font: 700 clamp(40px, 5.1vw, 59px)/.99 var(--display);
  letter-spacing: .04em;
  text-shadow: 0 3px 18px #071814;
}

.brand p {
  margin-top: 8px;
  color: #d9d6bc;
  font-size: 13px;
  letter-spacing: .07em;
  text-shadow: 0 2px 6px #06110c;
}

.top-actions { display: flex; align-items: center; gap: 6px; }

.control-button, .secondary-button {
  position: relative;
  min-height: 41px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: #f2ebd7;
  background: rgba(14, 35, 31, .86);
  font-size: 12px;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.control-button:hover:not(:disabled), .secondary-button:hover {
  background: #21443a;
  border-color: var(--mint);
  color: #fff4d9;
}

.control-button::before { display: block; width: 12px; height: 12px; flex: none; color: var(--gold); content: ''; }
.control-button[data-icon='pause']::before { border-inline: 2px solid currentColor; width: 8px; }
.control-button[data-icon='pause'][data-paused='true']::before { width: 12px; border: 0; background: currentColor; clip-path: polygon(12% 0, 100% 50%, 12% 100%); }
.control-button[data-icon='sound']::before { width: 15px; background: currentColor; clip-path: polygon(0 30%, 22% 30%, 47% 4%, 47% 96%, 22% 70%, 0 70%, 0 30%, 61% 24%, 76% 39%, 91% 24%, 100% 32%, 84% 50%, 100% 68%, 91% 76%, 76% 61%, 61% 76%, 52% 68%, 68% 50%, 52% 32%, 61% 24%); }
.control-button[data-icon='sound'][aria-pressed='true']::before { clip-path: polygon(0 30%, 22% 30%, 47% 4%, 47% 96%, 22% 70%, 0 70%, 0 30%, 64% 35%, 71% 25%, 82% 37%, 87% 50%, 82% 63%, 71% 75%, 64% 65%, 72% 57%, 75% 50%, 72% 43%, 64% 35%, 86% 17%, 94% 10%, 100% 28%, 100% 72%, 94% 90%, 86% 83%, 92% 66%, 92% 34%, 86% 17%); }
.control-button[data-icon='help']::before {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font: 700 10px/1 sans-serif;
  content: '?';
}
.control-button[data-icon='restart']::before { width: 14px; height: 17px; font: 400 18px/.92 Arial, sans-serif; content: '↻'; }
.control-button[data-icon='download']::before { width: 14px; height: 16px; font: 600 18px/.92 Arial, sans-serif; content: '↓'; }
.control-button[data-icon='leaderboard']::before {
  width: 14px;
  height: 13px;
  background:
    linear-gradient(currentColor, currentColor) left bottom / 3px 65% no-repeat,
    linear-gradient(currentColor, currentColor) center bottom / 3px 100% no-repeat,
    linear-gradient(currentColor, currentColor) right bottom / 3px 44% no-repeat;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, var(--play-width)) minmax(220px, 320px);
  align-items: start;
  gap: 25px;
  padding-bottom: max(25px, env(safe-area-inset-bottom));
}

.pond-panel { min-width: 0; }

.stage-frame {
  display: grid;
  position: relative;
  isolation: isolate;
  aspect-ratio: 560 / 660;
  width: 100%;
  overflow: hidden;
  border: 1px solid rgba(200, 211, 157, .49);
  border-radius: 17px;
  background: #193e34 url('assets/pond.jpg') center / cover;
  box-shadow: 0 15px 45px rgba(0, 0, 0, .38), 0 0 22px rgba(162, 215, 168, .07);
}

.stage-frame::after {
  position: absolute;
  z-index: 2;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px rgba(227, 217, 174, .13), inset 0 0 20px rgba(5, 24, 18, .49);
  pointer-events: none;
  content: '';
}

#pond {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 560 / 660;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}

#pond:focus-visible { outline-offset: -5px; }

.trial-hud {
  position: absolute;
  z-index: 3;
  top: 11px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid rgba(243, 200, 137, .69);
  border-radius: 7px;
  color: #fde4b0;
  background: #132923;
  box-shadow: 0 2px 11px rgba(0, 0, 0, .42);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
}

#trial-timer {
  min-width: 3.15em;
  color: #fff6d7;
  font: 750 17px/1 var(--ui);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.stage-overlay {
  position: absolute;
  z-index: 3;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  padding: 12px;
  background: radial-gradient(ellipse at center, rgba(6, 27, 21, .54), rgba(6, 27, 21, .10) 95%);
}

.overlay-content {
  position: relative;
  width: min(100%, 340px);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  padding: 27px 20px 22px;
  border: 1px solid var(--gold-border);
  border-radius: 13px;
  background: linear-gradient(151deg, rgba(20, 47, 37, .94), rgba(7, 28, 23, .96));
  box-shadow: 0 10px 37px rgba(3, 13, 10, .55), inset 0 1px rgba(255, 237, 187, .05);
  text-align: center;
}

.overlay-content::before {
  position: absolute;
  top: 0;
  left: 50%;
  width: 72px;
  height: 1px;
  transform: translateX(-50%);
  background: linear-gradient(90deg, transparent, #e7c988, transparent);
  content: '';
}

.overlay-content h2 {
  color: #fff1cf;
  font: 700 38px/1.06 var(--display);
  letter-spacing: .05em;
  text-wrap: balance;
}

.overlay-art {
  width: 78px;
  height: 78px;
  margin: -7px auto 6px;
  object-fit: contain;
  filter: drop-shadow(0 0 12px rgba(138, 231, 173, .29));
}

.stage-overlay[data-mode='won'] .overlay-art { width: 98px; height: 98px; }

.stage-overlay[data-mode='dead'] { background: radial-gradient(ellipse at center, rgba(55, 23, 21, .49), rgba(12, 12, 13, .21) 93%); }
.stage-overlay[data-mode='dead'] .overlay-content {
  border-color: rgba(234, 152, 132, .52);
  background: linear-gradient(146deg, rgba(58, 35, 31, .97), rgba(32, 21, 21, .97));
}
.stage-overlay[data-mode='dead'] .overlay-content::before { background: linear-gradient(90deg, transparent, #f3a58e, transparent); }
.stage-overlay[data-mode='dead'] .overlay-content h2 { color: #ffe6d9; }
.stage-overlay[data-mode='dead'] .overlay-art {
  padding: 8px;
  border: 1px solid rgba(232, 151, 133, .31);
  border-radius: 50%;
  background: rgba(232, 151, 133, .08);
  filter: drop-shadow(0 0 13px rgba(244, 140, 111, .39));
}

.stage-overlay[data-mode='dead'] .primary-button {
  min-width: min(100%, 167px);
  min-height: 48px;
  border-color: #ffddbb;
  color: #412623;
  background: linear-gradient(110deg, #f8deb3, #f3ae9e);
}

.overlay-content p { margin: 11px 0 17px; color: #e0dfc8; font-size: 14px; text-wrap: balance; }

.run-settings { display: none; gap: 5px; margin: 12px 0; text-align: left; }
.stage-overlay:is([data-mode='ready'], [data-mode='dead'], [data-mode='won']) .run-settings { display: grid; }
.difficulty-options { min-width: 0; margin: 0; padding: 0; border: 0; }
.difficulty-options legend { margin-bottom: 5px; padding: 0; color: var(--soft); font-size: 11px; }
.difficulty-segments { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.difficulty-segments label { position: relative; min-width: 0; cursor: pointer; }
.difficulty-segments input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.difficulty-segments label > span {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid rgba(174, 202, 169, .26);
  border-radius: 6px;
  color: var(--soft);
  background: rgba(4, 22, 17, .4);
  font-weight: 650;
  font-size: 13px;
}
.difficulty-segments input:checked + span {
  border-color: #bbd9a8;
  color: #ecf4d3;
  background: #315744;
  box-shadow: inset 0 0 11px rgba(175, 226, 160, .09);
}
.difficulty-segments input:focus-visible + span { outline: 2px solid var(--mint); outline-offset: 2px; }
.overlay-content #difficulty-note { margin: 0; color: var(--soft); font-size: 11px; line-height: 1.45; text-wrap: pretty; }
.name-field { display: flex; align-items: center; gap: 8px; color: var(--soft); font-size: 11px; }
.name-field input {
  width: 0;
  min-width: 0;
  flex: 1;
  height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--paper);
  background: #0d251e;
  font-size: 16px;
  line-height: 1.3;
}
.name-field input::placeholder { color: #82998a; font-size: 12px; }
.result-summary {
  margin: 10px 0;
  padding-block: 7px;
  border-block: 1px solid var(--gold-border);
  color: var(--gold);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-line;
  font-variant-numeric: tabular-nums;
}
.result-summary dl { display: flex; justify-content: space-around; gap: 8px; margin: 0; }
.result-summary dt { color: var(--soft); font-size: 10px; }
.result-summary dd { margin: 0; color: var(--gold); }
.overlay-actions { display: flex; justify-content: center; align-items: stretch; gap: 7px; }
.overlay-actions .primary-button { min-height: 44px; flex: 1; }
.overlay-actions .secondary-button { min-height: 44px; padding-inline: 10px; font-size: 12px; }

.stage-overlay:is([data-mode='ready'], [data-mode='dead'], [data-mode='won']) .overlay-content { padding: 17px 17px 16px; }
.stage-overlay:is([data-mode='ready'], [data-mode='dead'], [data-mode='won']) .overlay-art { width: 40px; height: 40px; margin: -2px auto 5px; }
.stage-overlay:is([data-mode='ready'], [data-mode='dead'], [data-mode='won']) .overlay-content h2 { font-size: 32px; }
.stage-overlay:is([data-mode='ready'], [data-mode='dead'], [data-mode='won']) .overlay-content > p { margin: 8px 0 9px; font-size: 12px; line-height: 1.55; }

.primary-button {
  min-height: 46px;
  padding: 8px 18px;
  border: 1px solid rgba(238, 244, 196, .78);
  border-radius: 8px;
  color: #132a21;
  background: linear-gradient(110deg, #e0e8aa, #9dd9b1);
  box-shadow: inset 0 1px rgba(255, 255, 255, .33), 0 4px 12px rgba(0, 0, 0, .20);
  font-weight: 750;
  transition: filter 140ms ease, transform 140ms ease;
}

.primary-button:not(:disabled):hover { filter: brightness(1.1); }
.primary-button:not(:disabled):active { transform: translateY(1px); }
.overlay-content .primary-button { min-width: 124px; letter-spacing: .035em; }

.hint-line {
  min-height: 20px;
  margin: 10px 3px 0;
  color: var(--soft);
  font-size: 12px;
  line-height: 1.55;
}

.hint-line[data-kind='evolve'] { color: var(--mint); }
.hint-line[data-kind='hit'] { color: #f5b7a2; }
.hint-line[data-kind='death'] { color: #ffc5b4; font-weight: 650; }

.mobile-controls { display: none; }
.mobile-run-details { display: none; }

.sidebar { display: grid; gap: 13px; }

.panel {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: linear-gradient(156deg, rgba(19, 40, 35, .97), rgba(9, 24, 23, .99));
  box-shadow: 0 9px 23px rgba(0, 0, 0, .21), inset 0 1px rgba(244, 246, 220, .05);
}

.current-tier { display: flex; align-items: center; gap: 12px; }

.tier-portrait {
  width: 62px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  flex: none;
  border: 1px solid rgba(150, 208, 176, .34);
  border-radius: 9px;
  background: radial-gradient(circle at 50% 55%, #264b3e 0, #112f27 85%);
}

.tier-portrait img { width: 96%; height: 96%; object-fit: contain; }
.current-tier-copy h2 { margin-bottom: 3px; color: var(--soft); font-size: 12px; font-weight: 500; }
.current-tier-copy strong { color: #f5eccf; font: 700 29px/1.12 var(--display); }
.next-tier {
  margin-left: auto;
  padding: 4px 6px;
  border: 1px solid var(--gold-border);
  border-radius: 5px;
  color: var(--gold);
  background: rgba(203, 171, 105, .07);
  font-size: 11px;
  white-space: nowrap;
}

.progress-caption {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 5px;
  margin: 12px 0 5px;
  color: var(--soft);
  font-size: 12px;
}

#progress-text { color: var(--gold); font-variant-numeric: tabular-nums; }

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 9px;
  background: rgba(160, 212, 184, .16);
}

#progress-fill, #mobile-progress-fill {
  display: block;
  width: 33.333%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #7cd5b1, #e7da92);
  transition: width 180ms ease;
}

.scoreboard { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.scoreboard > div { display: grid; gap: 2px; min-width: 0; }
.scoreboard > div + div { padding-left: 12px; border-left: 1px solid var(--border); }
.scoreboard span { color: var(--soft); font-size: 11px; }
.scoreboard strong { min-width: 0; overflow-wrap: anywhere; font: 650 21px/1.13 var(--ui); font-variant-numeric: tabular-nums; }

.run-details { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 11px 0 0; padding-top: 9px; border-top: 1px solid var(--border); }
.run-details > div { display: grid; gap: 2px; min-width: 0; }
.run-details dt { color: var(--soft); font-size: 10px; }
.run-details dd { margin: 0; color: var(--gold); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.codex-panel h2 { color: var(--gold); font: 700 24px/1.04 var(--display); }
.tier-list { display: grid; gap: 3px; margin: 10px 0 0; padding: 0; list-style: none; }

.tier-list li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 37px;
  padding-inline: 4px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--soft);
  background: rgba(0, 12, 11, .22);
  font-size: 13px;
}

.tier-list li img { width: 30px; height: 30px; object-fit: contain; }
.tier-list .tier-name { min-width: 0; font-weight: 600; }
.tier-list .tier-level { color: var(--soft); font-size: 11px; white-space: nowrap; }
.tier-list li.locked img { filter: brightness(.68) saturate(.35); opacity: .64; }
.tier-list li.discovered { color: var(--paper); }
.tier-list li.current, .tier-list li[aria-current='step'] {
  color: #f8dfaa;
  border-color: rgba(234, 208, 153, .38);
  background: linear-gradient(90deg, rgba(191, 177, 104, .21), rgba(185, 177, 110, .07));
}
.tier-list li.current .tier-level { color: var(--gold); }

.boss-codex { margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--border); }
.boss-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.boss-heading h3 { margin: 0; color: #f1c2af; font: 700 18px/1.1 var(--display); }
.boss-heading > span { color: #e9aa99; font-size: 10px; white-space: nowrap; }
.boss-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; margin: 7px 0 0; padding: 0; list-style: none; }
.boss-list li {
  display: grid;
  grid-template-columns: 29px minmax(0, 1fr);
  align-items: center;
  gap: 3px;
  padding: 2px 4px;
  border: 1px solid rgba(222, 149, 135, .22);
  border-radius: 6px;
  color: #f1c9b7;
  background: rgba(145, 76, 64, .11);
  font-size: 12px;
  line-height: 1.25;
}
.boss-list img { width: 29px; height: 29px; object-fit: contain; }

.game-dialog {
  width: min(100% - 28px, 440px);
  max-height: calc(100% - 28px);
  padding: 0;
  border: 1px solid var(--gold-border);
  border-radius: 14px;
  color: var(--paper);
  background: linear-gradient(148deg, #1c3a31, #102521);
  box-shadow: 0 14px 75px rgba(0, 0, 0, .65);
}

.game-dialog::backdrop { background: rgba(3, 12, 10, .83); backdrop-filter: blur(4px); }
.dialog-content { padding: 24px; }
.dialog-content h2 { margin-bottom: 10px; color: var(--gold); font: 700 32px/1.05 var(--display); }
.dialog-content p { color: #e0dfcc; }
.dialog-content ol { display: grid; gap: 8px; margin: 0; padding-left: 1.45em; color: #e0dfcc; }
.dialog-content li::marker { color: var(--gold); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.secondary-button { min-height: 46px; padding: 8px 12px; font-size: 14px; }
.secondary-button:is(a) { text-decoration: none; }
.download-option { display: grid; justify-items: start; gap: 8px; padding-top: 15px; }
.download-option + .download-option { margin-top: 17px; border-top: 1px solid var(--border); }
.download-option h3 { margin: 0; color: var(--paper); font-size: 15px; }
.download-option p { color: var(--soft); font-size: 13px; line-height: 1.6; }
.download-option .primary-button, .download-option .secondary-button { width: 100%; }
.leaderboard-dialog { width: min(100% - 24px, 570px); }
.leaderboard-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.leaderboard-heading > span { color: var(--soft); font-size: 11px; }
.filter-segments { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 8px; background: rgba(3, 18, 14, .45); }
.filter-segments button { min-height: 38px; padding: 4px 8px; border: 1px solid transparent; border-radius: 5px; color: var(--soft); background: transparent; font-size: 13px; }
.filter-segments button[aria-pressed='true'] { border-color: rgba(185, 222, 162, .4); color: #edf3d5; background: #30513e; }
.leaderboard-sort { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.leaderboard-sort button { min-height: 36px; padding: 3px 9px; border: 1px solid transparent; border-radius: 5px; color: var(--soft); background: transparent; font-size: 12px; }
.leaderboard-sort button[aria-pressed='true'] { border-color: var(--gold-border); color: var(--gold); background: rgba(220, 189, 119, .07); }
.leaderboard-table-wrap { overflow-x: auto; scrollbar-width: thin; }
.leaderboard-table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; table-layout: fixed; }
.leaderboard-table th, .leaderboard-table td { padding: 9px 6px; border-bottom: 1px solid rgba(177, 206, 174, .15); text-align: right; vertical-align: middle; }
.leaderboard-table th { color: var(--soft); background: rgba(3, 18, 14, .16); font-weight: 500; }
.leaderboard-table :is(th, td):first-child { width: 12%; text-align: left; }
.leaderboard-table :is(th, td):nth-child(2) { width: 26%; text-align: left; overflow-wrap: anywhere; }
.leaderboard-table th:nth-child(3), .leaderboard-table th:nth-child(4) { width: 22%; }
.leaderboard-table th:nth-child(5) { width: 18%; }
.leaderboard-table td:nth-child(n + 3) { white-space: nowrap; }
.leaderboard-table tbody tr:first-child { color: var(--gold); }
.leaderboard-table tr.is-self { background: rgba(168, 216, 179, .09); }
.leaderboard-table .player-rank { margin-right: 7px; color: var(--soft); font-size: 10px; }
.leaderboard-table .leaderboard-empty { height: 84px; color: var(--soft); text-align: center; line-height: 1.65; }
.dialog-content .leaderboard-status { min-height: 18px; margin-top: 10px; color: var(--soft); font-size: 11px; }

@media (max-width: 820px) {
  .game-layout { grid-template-columns: minmax(0, 1.63fr) minmax(210px, 1fr); gap: 14px; }
  .page-width { width: calc(100% - 34px); }
  .topbar { gap: 8px; }
  .brand-mark { width: 36px; }
  .brand h1 { font-size: 38px; }
  .top-actions { gap: 4px; }
  .top-actions .control-button { padding-inline: 7px; }
}

@media (max-width: 640px), (min-width: 821px) {
  .tier-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
  .tier-list li { padding-inline: 2px 4px; gap: 4px; }
}

@media (max-width: 640px) {
  .scene-art {
    height: 335px;
    background:
      linear-gradient(90deg, rgba(8, 22, 21, .85), rgba(8, 22, 21, .46) 44%, rgba(8, 22, 21, .06) 85%),
      linear-gradient(180deg, rgba(8, 22, 21, .23), rgba(8, 22, 21, .12) 33%, var(--ink) 98%),
      url('assets/hero.jpg') 70% 30% / cover;
  }

  .page-width { width: min(100% - 22px, 515px); }
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr); min-height: 105px; padding-block: 8px; gap: 7px; }
  .brand { gap: 7px; }
  .brand-mark { width: 40px; border-radius: 8px; }
  .brand h1 { font-size: clamp(30px, 7.4vw, 39px); }
  .brand p { display: none; }
  .top-actions { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; width: 100%; }
  .top-actions .control-button { min-width: 44px; min-height: 44px; padding: 3px 2px; flex-direction: column; gap: 3px; }
  .top-actions .control-button > span { position: static; width: auto; height: auto; overflow: visible; clip-path: none; white-space: nowrap; font-size: 10px; line-height: 1.2; }
  .game-layout { grid-template-columns: minmax(0, 1fr); gap: 11px; }
  .stage-frame { border-radius: 12px; }
  .stage-overlay { padding: 10px; }
  .overlay-content { padding: 20px 14px 18px; }
  .overlay-content h2 { font-size: 34px; }
  .stage-overlay:is([data-mode='ready'], [data-mode='dead'], [data-mode='won']) .overlay-content { padding: 12px 13px; }
  .stage-overlay:is([data-mode='ready'], [data-mode='dead'], [data-mode='won']) .overlay-art { width: 31px; height: 31px; margin: -2px auto 3px; }
  .stage-overlay:is([data-mode='ready'], [data-mode='dead'], [data-mode='won']) .overlay-content h2 { font-size: 29px; }
  .stage-overlay:is([data-mode='ready'], [data-mode='dead'], [data-mode='won']) .overlay-content > p { margin-block: 5px 7px; }
  .run-settings { margin-block: 8px; gap: 4px; }
  .difficulty-options legend { margin-bottom: 3px; }
  .hint-line { margin-top: 6px; }
  .sidebar { gap: 10px; }
  .leaderboard-dialog .dialog-content { padding: 18px 12px; }
  .leaderboard-table { font-size: 11px; }
  .leaderboard-table th, .leaderboard-table td { padding-inline: 4px; }
}

@media (max-width: 640px) and (orientation: portrait) {
  .mobile-controls {
    --stick-size: clamp(96px, 30vw, 124px);
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--stick-size) minmax(0, 1fr);
    align-items: center;
    gap: clamp(7px, 3vw, 15px);
    row-gap: 6px;
    margin-top: 7px;
    padding: 9px clamp(8px, 3.1vw, 15px) 7px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: radial-gradient(ellipse at 50% 0%, rgba(94, 139, 110, .15), transparent 76%), #102522;
    box-shadow: inset 0 1px rgba(235, 228, 183, .05), 0 5px 16px rgba(0, 0, 0, .16);
  }

  .mobile-run-details { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding-bottom: 5px; border-bottom: 1px solid var(--border); color: var(--soft); font-size: 10px; line-height: 1.2; font-variant-numeric: tabular-nums; }
  .mobile-run-details > span { white-space: nowrap; }
  #mobile-difficulty, #mobile-speed { color: var(--gold); font-weight: 600; }
  #mobile-time { color: var(--paper); }

  .mobile-form, .mobile-metrics { min-width: 0; }
  .mobile-form { display: grid; justify-items: start; gap: 3px; }
  #mobile-tier { color: var(--paper); font: 700 clamp(22px, 6.1vw, 29px)/1.04 var(--display); }
  .mobile-stat-label { color: var(--soft); font-size: 11px; white-space: nowrap; }
  .mobile-next { color: var(--gold); font-size: 11px; }

  .joystick-column { display: grid; justify-items: center; gap: 2px; }
  .joystick-caption { color: var(--soft); font-size: 10px; line-height: 1.3; }

  #joystick {
    position: relative;
    width: var(--stick-size);
    height: var(--stick-size);
    border: 1px solid rgba(182, 224, 186, .42);
    border-radius: 50%;
    background: radial-gradient(circle at 50% 48%, #143c32, #102b25 72%);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, .35), 0 0 0 3px rgba(168, 207, 166, .07);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
  }

  #joystick::before, #joystick::after {
    position: absolute;
    inset: 8%;
    border-radius: inherit;
    pointer-events: none;
    content: '';
  }

  #joystick::before {
    background:
      linear-gradient(var(--gold), var(--gold)) center top / 1px 8% no-repeat,
      linear-gradient(var(--gold), var(--gold)) center bottom / 1px 8% no-repeat,
      linear-gradient(var(--gold), var(--gold)) left center / 8% 1px no-repeat,
      linear-gradient(var(--gold), var(--gold)) right center / 8% 1px no-repeat;
    opacity: .55;
  }

  #joystick::after { inset: 20%; border: 1px dashed rgba(165, 216, 180, .3); }

  #joystick-knob {
    position: absolute;
    z-index: 1;
    top: 50%;
    left: 50%;
    width: 43%;
    aspect-ratio: 1;
    border: 1px solid rgba(222, 245, 184, .72);
    border-radius: 50%;
    background:
      radial-gradient(circle, rgba(25, 65, 45, .6) 0 9%, transparent 10%),
      linear-gradient(145deg, #c3dfa9, #69ae8d);
    box-shadow: inset 0 1px 2px rgba(244, 255, 219, .46), 0 3px 10px rgba(0, 0, 0, .48);
    transform: translate(calc(-50% + var(--stick-x, 0px)), calc(-50% + var(--stick-y, 0px)));
    pointer-events: none;
  }

  #joystick.is-active { border-color: var(--mint); }
  #joystick.is-active #joystick-knob { filter: brightness(1.08); box-shadow: 0 0 12px rgba(167, 232, 197, .52); }

  .mobile-progress-heading, .mobile-score, .mobile-record { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
  #mobile-progress-text { color: var(--gold); font: 600 11px/1 var(--ui); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .mobile-progress { margin-top: 4px; }
  .mobile-score { margin-top: 9px; padding-top: 6px; border-top: 1px solid var(--border); }
  #mobile-score { min-width: 0; color: var(--paper); font: 650 clamp(13px, 4.2vw, 18px)/1.1 var(--ui); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
  .mobile-record { margin-top: 3px; }
  #mobile-record { min-width: 0; color: var(--soft); font: 600 11px/1 var(--ui); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

  .status-panel { display: none; }
}

@media (max-width: 389px) {
  .brand-mark { width: 34px; }
}

@media (max-width: 365px) {
  .topbar { gap: 4px; }
  .brand h1 { font-size: 26px; }
  .brand p { display: none; }
  .top-actions { gap: 3px; }
  .leaderboard-dialog .dialog-content { padding: 18px 14px; }
  .leaderboard-table { font-size: 10px; }
  .leaderboard-table th, .leaderboard-table td { padding-inline: 2px; }
  .leaderboard-table :is(th, td):first-child { width: 8%; }
  .leaderboard-table :is(th, td):nth-child(2) { width: 22%; }
  .leaderboard-table th:nth-child(3), .leaderboard-table th:nth-child(4) { width: 24%; }
  .leaderboard-table th:nth-child(5) { width: 22%; }
}

@media (max-width: 310px) {
  .top-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (min-width: 641px) and (max-height: 625px) {
  :root { --play-width: clamp(216px, calc((100vh - 101px) * .848485), 500px); }
  .page-width { width: min(100% - 34px, calc(var(--play-width) + 345px)); }
  .game-layout { grid-template-columns: minmax(0, var(--play-width)) minmax(220px, 320px); }
  .topbar { min-height: 79px; padding-block: 8px; }
  .brand h1 { font-size: 39px; }
  .brand-mark { width: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
