:root {
  --chrome-blue-1: #2b57b7;
  --chrome-blue-2: #4f80e0;
  --chrome-deep: #123679;
  --chrome-gray-0: #f5f2e4;
  --chrome-gray-1: #ece9d8;
  --chrome-gray-2: #c9c9c9;
  --chrome-gray-3: #8c8c8c;
  --chrome-light: #fff;
  --chrome-dark: #666;
  --ink: #111;
  --success: #45e388;
  --danger: #f26565;
  --bg-start: #7698d7;
  --bg-mid: #486aa5;
  --bg-end: #355086;
  --ring-rgb: 255, 231, 140;
  --spring-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  --spring-settle: cubic-bezier(0.22, 0.68, 0.36, 1.02);
  --ease-exit: cubic-bezier(0.55, 0, 1, 0.45);
}

* {
  box-sizing: border-box;
}

/* XP drew a 1px dotted focus rectangle; keep it, plus the gold glow
   so the indicator survives both light chrome and dark surfaces. */
*:focus-visible {
  outline: 1px dotted #111;
  outline-offset: 1px;
  box-shadow: 0 0 0 3px rgba(255, 231, 140, 0.7);
  border-radius: 2px;
}

button:focus-visible {
  box-shadow: 0 0 0 3px rgba(255, 231, 140, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

.nums {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
  letter-spacing: 0.02em;
}

body {
  font-family: 'Tahoma', 'Segoe UI', Geneva, sans-serif;
  color: var(--ink);
  background: radial-gradient(
    circle at 10% 10%,
    var(--bg-start) 0%,
    var(--bg-mid) 45%,
    var(--bg-end) 100%
  );
}

#desktop {
  position: relative;
  min-height: 100vh;
  overflow: hidden;
  isolation: isolate;
}

#desktop::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 36px 36px;
}

/* Crisp XP title-bar blue: bright highlight band, saturated body,
   dark seat line. No translucent wash. */
.top-bar {
  position: relative;
  /* Sits above the overlay scrim: the title screen no longer dims and
     blurs the taskbar, so the chrome stays crisp pre-run. */
  z-index: 20;
  height: 52px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 8px 14px;
  color: #fff;
  background: linear-gradient(
    180deg,
    #5c8bea 0%,
    #3667cd 10%,
    #2b57b7 55%,
    #1e429c 100%
  );
  border-bottom: 2px solid var(--chrome-deep);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65), inset 0 -1px 0 rgba(0, 0, 0, 0.3);
}

.brand {
  font-family: 'Comic Sans MS', 'Comic Sans', cursive;
  letter-spacing: 0.2px;
  line-height: 1.25;
}

.brand-name {
  display: inline-block;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.55);
}

.brand-sub {
  display: inline-block;
  white-space: nowrap;
  font-size: 12px;
  color: #cddcfa;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

.hud {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

/* HUD chips: raised XP bevel, dark labels, larger tabular values. */
.hud-item {
  font-size: 11px;
  font-weight: 700;
  color: #1a1a1a;
  padding: 4px 8px;
  background: linear-gradient(180deg, #fdfcf6, #e3dfcd);
  border-top: 1px solid var(--chrome-light);
  border-left: 1px solid var(--chrome-light);
  border-right: 1px solid #58585a;
  border-bottom: 1px solid #58585a;
  border-radius: 0;
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
}

.hud-item span {
  color: #0a246a;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  font-weight: 700;
  margin-left: 5px;
  font-variant-numeric: tabular-nums;
}

/* The pause chip is just a button: no double chrome around it. */
.hud-item:has(.mini-btn) {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

/* Pre-run (pause disabled = no run active): classic XP disabled text,
   gray with a 1px white emboss, on a flatter chip. Reads as
   intentionally inactive instead of washed out. */
.hud:has(#pauseButton:disabled) .hud-item:not(:has(.mini-btn)) {
  color: #55544c;
  background: linear-gradient(180deg, #f0ede1, #e0dcc9);
}

.hud:has(#pauseButton:disabled) .hud-item:not(:has(.mini-btn)) span {
  color: #7c7b74;
  text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.85);
}

#playfield {
  position: absolute;
  inset: 52px 0 0;
  overflow: hidden;
}

.popup {
  position: absolute;
  height: 160px;
  min-width: 220px;
  max-width: 320px;
  font-family: 'Tahoma', 'Segoe UI', Geneva, sans-serif;
  border-top: 2px solid var(--chrome-light);
  border-left: 2px solid var(--chrome-light);
  border-right: 2px solid var(--chrome-dark);
  border-bottom: 2px solid var(--chrome-dark);
  background: var(--chrome-gray-1);
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: scale(0.7) translateY(24px);
  filter: blur(4px);
  transition: transform 280ms var(--spring-pop), opacity 200ms ease, filter 280ms var(--spring-pop);
}

.popup.active {
  opacity: 1;
  transform: scale(1) translateY(0);
  filter: blur(0);
}

.title-bar {
  height: 30px;
  padding: 4px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-family: 'Tahoma', 'Segoe UI', Geneva, sans-serif;
  font-size: 12px;
  background: linear-gradient(90deg, var(--chrome-blue-1), var(--chrome-blue-2));
  border-bottom: 1px solid var(--chrome-deep);
  user-select: none;
}

.window-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 6px;
}

.close-hitbox {
  appearance: none;
  -webkit-appearance: none;
  width: 36px;
  height: 36px;
  padding: 6px;
  margin: -6px -6px -6px 4px;
  border: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 2px;
}

.close-hitbox:focus-visible {
  outline: 1px dotted #fff;
  outline-offset: 1px;
}

.close-btn {
  width: 19px;
  height: 19px;
  border: 1px solid #4c4c4c;
  border-radius: 1px;
  background: linear-gradient(180deg, #fffbff, #d9d9d9);
  color: #111;
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  pointer-events: none;
}

.close-hitbox:active .close-btn {
  transform: translateY(1px);
}

.popup-body {
  position: relative;
  height: calc(100% - 30px);
  padding: 12px 12px 8px;
  color: #1d1d1d;
  background: var(--chrome-gray-0);
  border-top: 1px solid var(--chrome-light);
  overflow: hidden;
}

.popup-body p {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.3;
}

.popup-body small {
  font-size: 11px;
  color: #1a1a1a;
}

.approach-ring {
  position: absolute;
  left: calc(100% - 15px);
  top: 15px;
  width: 20px;
  height: 20px;
  border: 2px solid rgb(var(--ring-rgb));
  border-radius: 50%;
  box-shadow:
    0 0 0 3px rgba(var(--ring-rgb), 0.25),
    0 0 16px rgba(var(--ring-rgb), 0.55);
  transform: translate(-50%, -50%) scale(6.4);
  opacity: 0;
  pointer-events: none;
}

.popup.active .approach-ring {
  animation: approach var(--beat-duration, 560ms) linear var(--ring-delay, 0ms) both;
}

.popup.hit {
  border-right-color: #2d7f4e;
  border-bottom-color: #2d7f4e;
  box-shadow: 0 0 0 2px rgba(69, 227, 136, 0.5), 2px 2px 0 rgba(0, 0, 0, 0.35);
  animation: hit-fade 240ms linear forwards;
}

.popup.hit.hit-perfect {
  border-right-color: #8f7912;
  border-bottom-color: #8f7912;
  box-shadow: 0 0 0 2px rgba(255, 226, 95, 0.85), 0 0 20px rgba(255, 214, 70, 0.68);
}

.popup.hit.hit-great {
  border-right-color: #2d7f4e;
  border-bottom-color: #2d7f4e;
  box-shadow: 0 0 0 2px rgba(116, 241, 169, 0.64), 0 0 14px rgba(77, 198, 136, 0.48);
}

.popup.hit.hit-good {
  box-shadow: 0 0 0 2px rgba(69, 227, 136, 0.45), 2px 2px 0 rgba(0, 0, 0, 0.35);
}

.popup.miss {
  border-right-color: #8b3030;
  border-bottom-color: #8b3030;
  animation: miss-shake 220ms linear, miss-fade 280ms linear forwards;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 21, 33, 0.55);
  backdrop-filter: blur(2px);
  opacity: 1;
  visibility: visible;
  transition: opacity 200ms ease, visibility 0ms 0ms;
  overflow-y: auto;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 200ms ease, visibility 0ms 200ms;
}

.dialog {
  width: min(580px, 100%);
  border-top: 2px solid var(--chrome-light);
  border-left: 2px solid var(--chrome-light);
  border-right: 2px solid var(--chrome-dark);
  border-bottom: 2px solid var(--chrome-dark);
  background: var(--chrome-gray-1);
  padding: 32px 28px;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.35);
  transform: scale(0.96) translateY(12px);
  filter: blur(4px);
  transition: transform 320ms var(--spring-pop), filter 320ms var(--spring-pop);
}

.overlay:not(.hidden) .dialog {
  transform: scale(1) translateY(0);
  filter: blur(0);
}

.dialog-wide {
  width: min(900px, 100%);
}

.dialog h1,
.dialog h2 {
  margin: 0 0 10px;
  font-weight: 700;
}

.dialog h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.dialog p {
  margin: 0 0 12px;
  line-height: 1.4;
}

.dialog ul {
  margin: 0 0 14px;
  padding-left: 18px;
  font-size: 14px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.controls-tight {
  margin-bottom: 0;
  margin-top: 8px;
}

.controls label {
  font-size: 13px;
  color: #111111;
}

.leaderboard-layout {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  align-items: stretch;
  gap: 10px;
  margin-top: 16px;
}

/* Both title-screen columns run to the same baseline: panels are
   flex columns, the board pads itself with ghost rows, the stats
   grid stretches its cells to fill the shared height. */
.leaderboard-layout .panel {
  display: flex;
  flex-direction: column;
}

.leaderboard-layout .stats-grid {
  flex: 1;
  grid-auto-rows: 1fr;
  align-content: stretch;
}

.leaderboard-layout .controls-tight {
  margin-top: auto;
  padding-top: 10px;
}

/* Ghost slots: an empty board still reads as a full 10-row board.
   Rank numbers are real slot positions; every value cell is a dash. */
.ghost-row td {
  color: #9a9583;
}

.progression-layout {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 10px;
  margin-top: 10px;
}

/* XP etched groupbox: 1px dark #808080 border with a 1px #ffffff
   highlight offset down-right (inside on top/left, outside on
   bottom/right), caption notched into the top border line. */
.panel {
  position: relative;
  border: 1px solid #808080;
  border-radius: 0;
  box-shadow: inset 1px 1px 0 var(--chrome-light), 1px 1px 0 var(--chrome-light);
  background: var(--chrome-gray-0);
  padding: 15px 10px 10px;
}

.panel > h3 {
  width: fit-content;
  margin: -23px 0 8px 4px;
  padding: 0 6px;
  font-size: 12px;
  line-height: 1.3;
  background: var(--chrome-gray-0);
  color: #1a1a1a;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.score-table th,
.score-table td {
  border: 1px solid #9a9a9a;
  padding: 4px 6px;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.score-table th {
  background: #ded9c5;
}

.empty-row {
  color: #1a1a1a;
  font-style: italic;
}

/* Empty-state note lives above the table so all 10 ghost ranks stay
   visible instead of the message eating slot #1. */
.board-empty-note {
  margin: 0 0 6px;
  font-size: 12px;
  font-style: italic;
  color: #1a1a1a;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

/* 9 cells balance as 3 rows of 2 plus a deliberate 3-up bottom row
   (the per-mode bests), so no cell reads as a stretched orphan. */
.stats-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.stats-grid .stat-card {
  grid-column: span 3;
}

.stats-grid .stat-card:nth-last-child(-n + 3) {
  grid-column: span 2;
}

/* Classic sunken field: dark top/left, light bottom/right, inset dip. */
.stat-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-top: 1px solid #808080;
  border-left: 1px solid #808080;
  border-right: 1px solid var(--chrome-light);
  border-bottom: 1px solid var(--chrome-light);
  background: #eeebdb;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.16);
  padding: 6px 8px;
}

.stat-label {
  display: block;
  font-size: 11px;
  color: #2a2a2a;
}

.stat-value {
  display: block;
  margin-top: 2px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #131313;
}

/* Result hero: grade tile + punchy numbers own the top third. */
.result-hero {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 16px;
  border-top: 2px solid var(--chrome-light);
  border-left: 2px solid var(--chrome-light);
  border-right: 2px solid var(--chrome-dark);
  border-bottom: 2px solid var(--chrome-dark);
  background: linear-gradient(180deg, #fbf9ef, #e7e3d1);
  padding: 16px;
  margin: 0 0 12px;
}

.result-grade {
  flex: 0 0 200px;
  align-self: stretch;
  min-height: 200px;
  display: grid;
  place-items: center;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 120px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.02em;
  /* Tier fill + text color are set per grade below. Defaults (D). */
  color: #f4f4f2;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
  background: linear-gradient(180deg, #b7b4ac, #7d7a72);
  border-top: 3px solid rgba(255, 255, 255, 0.6);
  border-left: 3px solid rgba(255, 255, 255, 0.55);
  border-right: 3px solid rgba(0, 0, 0, 0.45);
  border-bottom: 3px solid rgba(0, 0, 0, 0.5);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35);
}

/* Tier ramp tuned to the XP palette: SS/S gold, A green, B blue,
   C orange, D muted gray. Real fills, not just text color. */
.result-grade.grade-ss {
  color: #4d3800;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
  background: linear-gradient(180deg, #fff4b0, #f5c542 55%, #e0a91f);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.6), 0 0 22px rgba(245, 197, 66, 0.7);
}

.result-grade.grade-s {
  color: #4d3800;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
  background: linear-gradient(180deg, #fff6cf, #ffdd74 55%, #e9bf49);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.55), 0 0 18px rgba(255, 221, 116, 0.6);
}

.result-grade.grade-a {
  color: #f2fff6;
  background: linear-gradient(180deg, #58c877, #2f9d54 55%, #1f7a3f);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 0 16px rgba(47, 157, 84, 0.5);
}

.result-grade.grade-b {
  color: #f2f7ff;
  background: linear-gradient(180deg, #6fa4f0, #3f74d6 55%, #295aad);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.35), 0 0 16px rgba(63, 116, 214, 0.5);
}

.result-grade.grade-c {
  color: #fff6ec;
  background: linear-gradient(180deg, #f5a94f, #e2812a 55%, #c26514);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.32), 0 0 16px rgba(226, 129, 42, 0.5);
}

.result-grade.grade-d {
  color: #f4f4f2;
  background: linear-gradient(180deg, #b7b4ac, #8a8780 55%, #6d6a63);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

/* Pop-in reveal each time the card is shown. */
.result-grade.grade-reveal {
  animation: grade-reveal 460ms var(--spring-pop) both;
}

@keyframes grade-reveal {
  0% {
    opacity: 0;
    transform: scale(0.55);
    filter: brightness(1.6);
  }

  62% {
    opacity: 1;
    transform: scale(1.07);
  }

  100% {
    opacity: 1;
    transform: scale(1);
    filter: brightness(1);
  }
}

/* Personal-best promotion. The .is-pb gold chrome is static, so it
   survives prefers-reduced-motion. The .celebrate flash and pops are
   one-shot animations that the reduced-motion block collapses. */
.result-hero.is-pb {
  border-top-color: #f5df8a;
  border-left-color: #f5df8a;
  border-right-color: #a58110;
  border-bottom-color: #a58110;
  background: linear-gradient(180deg, #fff9e2, #f2e5b6);
  box-shadow: 0 0 0 1px #a58110, 0 0 16px rgba(245, 197, 66, 0.45);
}

.result-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 32% 42%, rgba(255, 244, 176, 0.95), rgba(255, 216, 109, 0) 72%);
}

.result-hero.celebrate::after {
  animation: pb-flash 920ms ease-out both;
}

.result-hero.celebrate .result-grade,
.result-hero.celebrate .hero-score {
  animation: pb-pop 620ms var(--spring-pop);
}

@keyframes pb-flash {
  0% { opacity: 0; }
  16% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes pb-pop {
  0% { transform: scale(0.88); }
  55% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.result-hero-numbers {
  flex: 1 1 260px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

/* Right half of the hero: run context + judgment ribbon fill the
   space a GIF would otherwise show as empty beige. Wraps to its own
   full-width row when the dialog gets narrow. */
.result-hero {
  flex-wrap: wrap;
}

.result-hero-detail {
  flex: 1 1 260px;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  text-align: right;
}

.result-hero-detail .result-context {
  margin: 0;
}

.result-hero-detail .result-breakdown {
  margin: 0;
}

.result-hero-detail .hit-counts {
  text-align: right;
}

.hero-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #4a5566;
}

.hero-score {
  display: block;
  margin-top: 2px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 84px;
  line-height: 0.92;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: #10233d;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}

.hero-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 34px;
  margin-top: 4px;
}

.hero-sub {
  display: block;
  margin-top: 1px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 30px;
  line-height: 1;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  color: #1b3a5f;
}

.result-context {
  margin: 6px 0 0;
  font-size: 12px;
  font-weight: 700;
  color: #4a5566;
}

.result-breakdown {
  margin: 0 0 6px;
}

.hit-bar {
  display: flex;
  height: 14px;
  border: 1px solid #7c7c7c;
  background: #d5d1c0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  overflow: hidden;
}

.hit-seg {
  height: 100%;
  width: 0%;
  transition: width 400ms var(--spring-settle);
}

.seg-perfect {
  background: linear-gradient(180deg, #fff4b0, #ffd86d);
}

.seg-great {
  background: #9ff2c2;
}

.seg-good {
  background: #c9f4d8;
}

.seg-miss {
  background: #f7a4a4;
}

.hit-counts {
  margin-top: 5px;
  font-size: 11px;
  font-weight: 700;
  color: #2a2a2a;
}

.hit-counts b {
  font-family: 'Consolas', 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
  color: #131313;
}

.result-rank {
  margin-top: -6px;
  font-size: 13px;
  font-weight: 700;
  color: #1e4f98;
}

/* Enlarged New Personal Best headline. The pop is animation-gated so
   prefers-reduced-motion keeps the promoted gold banner without motion. */
.result-rank.new-best {
  display: block;
  margin-top: -2px;
  padding: 8px 12px;
  font-size: 21px;
  line-height: 1.15;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  color: #4d3800;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
  background: linear-gradient(180deg, #fff4b0, #ffd86d);
  border-top: 2px solid #fff6cf;
  border-left: 2px solid #fff6cf;
  border-right: 2px solid #a58110;
  border-bottom: 2px solid #a58110;
  box-shadow: 0 0 0 1px #a58110, 0 0 14px rgba(255, 225, 120, 0.65);
  animation: pb-headline 700ms var(--spring-pop) both;
}

@keyframes pb-headline {
  0% {
    opacity: 0;
    transform: scale(0.82);
  }

  60% {
    opacity: 1;
    transform: scale(1.05);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.result-progress {
  margin-top: -8px;
  font-size: 12px;
  color: #284460;
  font-weight: 700;
}

.result-recap {
  margin-top: 14px;
  background:
    linear-gradient(180deg, #f7f4e8, #e9e5d4);
}

/* Caption fill matches the top stop of the recap gradient so the
   notch gap reads as one surface. */
.result-recap > h3 {
  background: #f7f4e8;
}

.reward-strip {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 10px;
}

.reward-pill {
  border-top: 1px solid #808080;
  border-left: 1px solid #808080;
  border-right: 1px solid var(--chrome-light);
  border-bottom: 1px solid var(--chrome-light);
  background: #eeebdb;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.16);
  padding: 8px;
}

.reward-pill span {
  display: block;
  font-size: 11px;
  color: #2a2a2a;
}

.reward-pill strong {
  display: block;
  margin-top: 3px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: #112748;
}

.meter-block {
  margin-top: 8px;
}

.meter-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
  color: #223f67;
}

.meter-head span {
  font-variant-numeric: tabular-nums;
}

.xp-track-large {
  height: 16px;
}

.unlock-banner {
  margin-top: 10px;
  margin-bottom: 0;
  padding: 6px 8px;
  border: 1px solid #7a5a03;
  color: #4e3800;
  background: linear-gradient(180deg, #ffef9e, #f7cf5a);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(255, 228, 136, 0.55);
}

.unlock-banner.hidden {
  display: none;
}

.result-recap.celebrate .reward-pill strong {
  animation: reward-pop 540ms ease;
}

.result-recap.celebrate .xp-fill {
  box-shadow: 0 0 12px rgba(141, 231, 255, 0.8);
}

.xp-headline {
  font-size: 13px;
  margin-bottom: 8px;
}

.xp-headline span {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* Sunken XP bevel: dark top/left, light bottom/right, inset shadow. */
.xp-track {
  height: 14px;
  border-top: 1px solid #82826f;
  border-left: 1px solid #82826f;
  border-right: 1px solid #fdfcf6;
  border-bottom: 1px solid #fdfcf6;
  background: linear-gradient(180deg, #cdc9b8, #ddd9c8);
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.xp-fill {
  width: 0%;
  /* Always-visible nub so an empty track reads as a progress control. */
  min-width: 6px;
  height: 100%;
  background: linear-gradient(90deg, #5f97ff, #8de7ff);
  transition: width 400ms var(--spring-settle);
}

.xp-meta {
  margin-top: 6px;
  font-size: 12px;
  color: #1a1a2a;
}

.battlepass-list {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.battle-tier {
  border: 1px solid #8e8e8e;
  background: #e9e5d4;
  padding: 6px;
  font-size: 12px;
}

.battle-tier strong {
  font-size: 12px;
}

.battle-tier.unlocked {
  border-color: #3f7f53;
  background: #d8f0df;
}

.battle-tier.locked {
  border-color: #8a8a8a;
  background: #eeebdd;
  color: #4a4a4a;
}

.battle-tier.active-tier {
  border-color: #315a98;
  box-shadow: 0 0 0 1px rgba(49, 90, 152, 0.35);
}

/* The Volume label and its slider travel as one unit: if the row
   wraps, they wrap together instead of orphaning the label. */
.control-pair {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

/* XP-chrome range input: sunken beveled trough (same recipe as
   .xp-track) with a square silver beveled thumb. Radius 0 everywhere. */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 180px;
  height: 22px;
  margin: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 10px;
  border-top: 1px solid #82826f;
  border-left: 1px solid #82826f;
  border-right: 1px solid #fdfcf6;
  border-bottom: 1px solid #fdfcf6;
  border-radius: 0;
  background: linear-gradient(180deg, #cdc9b8, #ddd9c8);
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.22);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 20px;
  margin-top: -6px;
  border-top: 1px solid var(--chrome-light);
  border-left: 1px solid var(--chrome-light);
  border-right: 1px solid #4c4c4c;
  border-bottom: 1px solid #4c4c4c;
  border-radius: 0;
  background: linear-gradient(180deg, #fdfcf6, #d9d9d9);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
}

input[type="range"]::-moz-range-track {
  height: 10px;
  border-top: 1px solid #82826f;
  border-left: 1px solid #82826f;
  border-right: 1px solid #fdfcf6;
  border-bottom: 1px solid #fdfcf6;
  border-radius: 0;
  background: linear-gradient(180deg, #cdc9b8, #ddd9c8);
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.22);
}

input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 20px;
  border-top: 1px solid var(--chrome-light);
  border-left: 1px solid var(--chrome-light);
  border-right: 1px solid #4c4c4c;
  border-bottom: 1px solid #4c4c4c;
  border-radius: 0;
  background: linear-gradient(180deg, #fdfcf6, #d9d9d9);
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.3);
}

select {
  font-family: inherit;
  font-size: 13px;
  padding: 4px 6px;
  border-top: 2px solid var(--chrome-light);
  border-left: 2px solid var(--chrome-light);
  border-right: 2px solid var(--chrome-dark);
  border-bottom: 2px solid var(--chrome-dark);
  background: linear-gradient(180deg, #fdfcf6, #e3dfcd);
  color: #151515;
}

.tag-input {
  width: 52px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  padding: 4px 6px;
  border-top: 2px solid var(--chrome-light);
  border-left: 2px solid var(--chrome-light);
  border-right: 2px solid var(--chrome-dark);
  border-bottom: 2px solid var(--chrome-dark);
  background: linear-gradient(180deg, #fdfcf6, #e3dfcd);
  color: #151515;
}

button {
  font-family: inherit;
  border-top: 2px solid var(--chrome-light);
  border-left: 2px solid var(--chrome-light);
  border-right: 2px solid var(--chrome-dark);
  border-bottom: 2px solid var(--chrome-dark);
  background: linear-gradient(180deg, #fdfcf6, #e3dfcd);
  color: #161616;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 12px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.65;
  cursor: default;
}

button:active {
  border-top-color: var(--chrome-dark);
  border-left-color: var(--chrome-dark);
  border-right-color: var(--chrome-light);
  border-bottom-color: var(--chrome-light);
}

.btn-primary {
  padding: 10px 24px;
  box-shadow: 0 0 0 1px #0a246a;
}

.start-controls {
  margin-bottom: 12px;
}

.mini-btn {
  padding: 3px 8px;
  font-size: 11px;
  min-width: 58px;
}

.tip {
  font-size: 12px;
  color: #1a1a1a;
  margin-bottom: 0;
}

.judgement {
  position: fixed;
  transform: translate(-50%, -50%);
  padding: 6px 12px;
  font-size: 16px;
  font-weight: 700;
  border-radius: 2px;
  z-index: 50;
  pointer-events: none;
  animation: judgement-float 800ms ease forwards;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.judgement.perfect {
  color: #4d3800;
  background: linear-gradient(180deg, #fff4b0, #ffd86d);
  border: 1px solid #a58110;
  font-size: 24px;
  letter-spacing: 0.12em;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  box-shadow: 0 0 0 3px rgba(255, 225, 120, 0.85), 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: perfect-float 920ms cubic-bezier(0.18, 0.8, 0.25, 1) forwards;
}

.judgement.perfect::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 4px;
  background: radial-gradient(circle, rgba(255, 225, 120, 0.6), transparent 70%);
  animation: perfect-burst 400ms ease-out forwards;
  pointer-events: none;
}

.judgement.great {
  color: #0f361b;
  background: #9ff2c2;
  border: 1px solid #2d7f4e;
  font-size: 18px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.judgement.good {
  color: #0f361b;
  background: #c9f4d8;
  border: 1px solid #4f976a;
}

.judgement.miss {
  color: #430909;
  background: #f7a4a4;
  border: 1px solid #8b3030;
  font-size: 18px;
  animation: miss-badge-shake 200ms ease, judgement-float 800ms ease forwards;
}

@keyframes miss-badge-shake {
  0%, 100% { transform: translate(-50%, -50%) rotate(0); }
  25% { transform: translate(-50%, -50%) rotate(-3deg); }
  75% { transform: translate(-50%, -50%) rotate(3deg); }
}

.toast {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  min-width: 220px;
  max-width: 90%;
  padding: 8px 12px;
  font-size: 12px;
  text-align: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 180ms ease;
}

.toast.show {
  opacity: 1;
}

/* Scale is linear from first frame to last: only 0% and 100% carry
   a transform, so the closing rate never lies about the beat. */
@keyframes approach {
  0% {
    transform: translate(-50%, -50%) scale(6.4);
    opacity: 0;
  }

  12% {
    opacity: 0.9;
  }

  100% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.95;
  }
}

@keyframes hit-fade {
  0% {
    filter: brightness(1.15);
  }

  100% {
    opacity: 0;
  }
}

@keyframes miss-fade {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes miss-shake {
  0% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-5px);
  }

  40% {
    transform: translateX(5px);
  }

  60% {
    transform: translateX(-4px);
  }

  80% {
    transform: translateX(4px);
  }

  100% {
    transform: translateX(0);
  }
}

/* Badges are fully opaque on frame 1: the click and the verdict share a frame. */
@keyframes judgement-float {
  0% {
    opacity: 1;
    transform: translate(-50%, -44%) scale(0.72);
  }

  18% {
    transform: translate(-50%, -52%) scale(1.12);
  }

  32% {
    transform: translate(-50%, -58%) scale(1);
  }

  78% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -94%) scale(1);
  }
}

@keyframes perfect-float {
  0% {
    opacity: 1;
    transform: translate(-50%, -42%) scale(0.6);
  }

  22% {
    transform: translate(-50%, -54%) scale(1.25);
  }

  40% {
    transform: translate(-50%, -62%) scale(1);
  }

  80% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -102%) scale(1);
  }
}

@keyframes perfect-burst {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 0.6;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.5);
    opacity: 0;
  }
}

@keyframes reward-pop {
  0% {
    transform: scale(0.86);
    filter: brightness(1.25);
  }

  55% {
    transform: scale(1.08);
  }

  100% {
    transform: scale(1);
    filter: brightness(1);
  }
}

@media (max-width: 700px) {
  .top-bar {
    height: auto;
    padding: 8px 10px;
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-name {
    font-size: 13px;
  }

  .brand-sub {
    font-size: 11px;
  }

  .hud {
    width: 100%;
    justify-content: flex-start;
  }

  #playfield {
    inset: 88px 0 0;
    padding: 10px 8px 14px;
  }

  .dialog {
    padding: 20px 16px;
  }

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

  .result-hero {
    flex-direction: column;
    gap: 12px;
  }

  .result-grade {
    flex-basis: auto;
    width: 100%;
    min-height: 132px;
    font-size: 80px;
  }

  .hero-score {
    font-size: 54px;
  }

  .leaderboard-layout {
    grid-template-columns: 1fr;
  }

  .progression-layout {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid .stat-card,
  .stats-grid .stat-card:nth-last-child(-n + 3) {
    grid-column: auto;
  }

  .result-hero-detail {
    min-width: 0;
    text-align: left;
  }

  .result-hero-detail .hit-counts {
    text-align: left;
  }

  .reward-strip {
    grid-template-columns: 1fr;
  }
}

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

  /* The float animation ends at opacity 0, so collapsing it would erase
     the verdict. Hold the badge static; JS removes it after 820ms. */
  .judgement {
    animation: none !important;
    opacity: 1;
    transform: translate(-50%, -60%);
  }

  .judgement.perfect::after {
    display: none;
  }
}

.share-x-btn {
  background: linear-gradient(180deg, #1a1a1a, #000);
  color: #fff;
  border-top: 2px solid #444;
  border-left: 2px solid #444;
  border-right: 2px solid #000;
  border-bottom: 2px solid #000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.copy-result-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

.share-x-btn:active {
  border-top-color: #000;
  border-left-color: #000;
  border-right-color: #444;
  border-bottom-color: #444;
}
