/* ============================================
   TypeBlocks - Components
   Menu/stage, game UI, panels, modals, stats, achievements,
   animations. Tokens/base load before; responsive/themes after.
   ============================================ */

/* ============================================
   MENU SCREEN
   ============================================ */

#menu-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(18px, 3vh, 32px);
  width: 100%;
  position: relative;
  padding-block: clamp(8px, 2vh, 24px);
}

.menu-header {
  text-align: center;
  margin-bottom: 8px;
}

/* Wordmark: mono is the subject material (keyboards). TYPE plain,
   BLOCKS in the theme's two-note gradient, block cursor blinking after. */
.menu-header h1 {
  font-family: var(--font-display);
  font-size: 46px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--color-text);
  text-shadow: 0 0 40px var(--color-primary-glow);
  margin-bottom: 4px;
  white-space: nowrap;
}

.menu-header h1 span {
  font-weight: 700;
  background: linear-gradient(120deg, var(--color-primary) 20%, var(--color-accent-2) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 0 16px var(--color-primary-glow));
}

.menu-header h1::after {
  content: '▌';
  color: var(--color-primary);
  text-shadow: none;
  margin-left: 0.08em;
  animation: caretBlink 1.1s steps(1) infinite;
}

/* Ends visible: keyframes return to base so reduced-motion's
   single 0.01ms run leaves the cursor solid */
@keyframes caretBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Signature: CSS-only equalizer under the wordmark. Each bar rests at
   its --h waveform height and dances toward --l; under reduced motion
   the animation resolves instantly back to the static waveform. */
.menu-eq {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 6px;
  height: 24px;
  margin: 10px auto 12px;
}

.menu-eq span {
  width: 6px;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--color-accent-2), var(--color-primary));
  box-shadow: 0 0 6px var(--color-primary-glow);
  opacity: 0.85;
  transform: scaleY(var(--h, 0.5));
  transform-origin: bottom;
  animation: eqDance var(--t, 0.9s) ease-in-out var(--d, 0s) infinite alternate;
}

@keyframes eqDance {
  from { transform: scaleY(var(--h, 0.5)); }
  to { transform: scaleY(var(--l, 0.15)); }
}

/* Static waveform arc + off-grid phases so it reads as a live band, not a metronome */
.menu-eq span:nth-child(1)  { --h: 0.30; --l: 0.18; --t: 1.05s; --d: -0.10s; }
.menu-eq span:nth-child(2)  { --h: 0.50; --l: 0.30; --t: 0.85s; --d: -0.42s; }
.menu-eq span:nth-child(3)  { --h: 0.70; --l: 0.42; --t: 0.95s; --d: -0.21s; }
.menu-eq span:nth-child(4)  { --h: 0.95; --l: 0.55; --t: 0.75s; --d: -0.65s; }
.menu-eq span:nth-child(5)  { --h: 0.60; --l: 0.34; --t: 1.10s; --d: -0.33s; }
.menu-eq span:nth-child(6)  { --h: 1.00; --l: 0.60; --t: 0.80s; --d: -0.05s; }
.menu-eq span:nth-child(7)  { --h: 0.80; --l: 0.48; --t: 0.90s; --d: -0.52s; }
.menu-eq span:nth-child(8)  { --h: 0.55; --l: 0.30; --t: 1.00s; --d: -0.27s; }
.menu-eq span:nth-child(9)  { --h: 0.85; --l: 0.52; --t: 0.78s; --d: -0.60s; }
.menu-eq span:nth-child(10) { --h: 0.50; --l: 0.28; --t: 1.08s; --d: -0.15s; }
.menu-eq span:nth-child(11) { --h: 0.38; --l: 0.22; --t: 0.88s; --d: -0.47s; }
.menu-eq span:nth-child(12) { --h: 0.25; --l: 0.14; --t: 1.02s; --d: -0.30s; }

.tagline {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.mode-selection {
  width: 100%;
  max-width: 620px;
  padding-right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mode-selection h2 {
  align-self: stretch;
}

.mode-selection h2 {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 20px;
}

.mode-selection h2::before,
.mode-selection h2::after {
  content: '';
  height: 1px;
  flex: 1;
  background: linear-gradient(90deg, transparent, var(--border-default));
}

.mode-selection h2::after {
  background: linear-gradient(90deg, var(--border-default), transparent);
}

/* The Stage: modes are keycaps on a keyboard — press the letter to play.
   The second row is offset like a real keyboard row. */
.key-row {
  display: flex;
  gap: 14px;
  justify-content: center;
  margin-bottom: 14px;
}

.key-row-lower {
  margin-bottom: 0;
}

.mode-key {
  position: relative;
  width: 96px;
  height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: linear-gradient(180deg, var(--color-surface-elevated), var(--color-surface));
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.45), var(--shadow-md);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    transform var(--transition-fast), box-shadow var(--transition-fast);
}

.mode-key .key-letter {
  position: absolute;
  top: 7px;
  left: 8px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  color: var(--color-text);
  background: var(--color-surface-hover);
  border: 1px solid var(--border-default);
  border-bottom-width: 3px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: color var(--transition-fast), background var(--transition-fast),
    border-color var(--transition-fast), transform var(--transition-fast);
}

/* Icon slot: monoline SVG (js/ui/icons.js) inherits the label colour via
   currentColor, so it warms with .key-name on hover — one visual voice, no
   per-icon hue. Fixed box keeps the cap layout stable while the svg fills. */
.mode-key .key-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--color-text-secondary);
  transition: color var(--transition-fast);
}

.mode-key .key-icon .tb-icon {
  width: 26px;
  height: 26px;
}

.mode-key:hover .key-icon,
.mode-key:focus-visible .key-icon {
  color: var(--color-primary);
}

/* Inline label glyph (word-pack picker, variant sub-labels) — sized in em so it
   tracks the label text, inherits colour so it warms with the label on hover /
   check. vertical-align covers plain-inline parents (sub-label); flex parents
   (.opt-label) centre via align-items and ignore it. */
.opt-label {
  display: inline-flex;
  align-items: center;
}

.opt-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1em;
  height: 1.1em;
  margin-right: 7px;
  flex: none;
  color: inherit;
  vertical-align: -0.2em;
}

.opt-icon .tb-icon {
  width: 100%;
  height: 100%;
}

/* Base size for a bare, JS-injected .tb-icon (reward/status marks in badges &
   labels): tracks the text it sits in. The explicit .key-icon/.opt-icon rules
   above are more specific and still win in those slots. */
.tb-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
}

/* Reward marks keep their warmth (streak = hot, PB = celebration) as a
   gold monoline glyph rather than a full-colour emoji. */
.icon-warm {
  color: var(--color-warning);
}

.mode-key .key-name {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--color-text-secondary);
}

.mode-key:hover,
.mode-key:focus-visible {
  border-color: var(--border-accent);
  transform: translateY(-3px);
  box-shadow: 0 9px 0 rgba(0, 0, 0, 0.45), var(--shadow-md), 0 0 22px var(--color-primary-glow);
}

.mode-key:hover .key-name,
.mode-key:focus-visible .key-name {
  color: var(--color-text);
}

.mode-key:hover .key-letter,
.mode-key:focus-visible .key-letter {
  color: var(--color-primary);
  background: color-mix(in srgb, var(--color-primary) 10%, var(--color-surface-hover));
  border-color: var(--border-accent);
  transform: translateY(-1px);
}

.mode-key[aria-disabled="true"],
.mode-key:disabled,
.mode-key-disabled {
  cursor: not-allowed;
  opacity: 0.48;
  filter: grayscale(0.55);
  transform: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45), var(--shadow-md);
}

.mode-key[aria-disabled="true"]:hover,
.mode-key[aria-disabled="true"]:focus-visible,
.mode-key:disabled:hover,
.mode-key:disabled:focus-visible,
.mode-key-disabled:hover,
.mode-key-disabled:focus-visible {
  border-color: var(--border-default);
  transform: none;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45), var(--shadow-md);
}

.mode-key[aria-disabled="true"] .key-name,
.mode-key:disabled .key-name,
.mode-key-disabled .key-name {
  color: var(--color-text-muted);
}

/* Bottoming out: the letter-key press and the click share this state */
.mode-key:active,
.mode-key.pressed {
  transform: translateY(4px);
  border-color: var(--color-primary);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.45), 0 0 30px var(--color-primary-glow);
}

.mode-key[aria-disabled="true"]:active,
.mode-key[aria-disabled="true"].pressed,
.mode-key-disabled:active,
.mode-key-disabled.pressed {
  transform: none;
  border-color: var(--border-default);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.45), var(--shadow-md);
}

/* Ghost/Daily blurbs are data for the detail line, not visible on the cap */
.key-blurb {
  display: none;
}

/* Variant chooser: pressing C or K splits the key into its two variants */
.variant-bar {
  width: 100%;
  max-width: 480px;
  margin-top: 16px;
}

.variant-bar.hidden {
  display: none;
}

.variant-set {
  display: flex;
  gap: 10px;
}

.variant-set.hidden {
  display: none;
}

.variant-btn {
  flex: 1;
  min-height: 56px;
  padding: 10px 12px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-normal), border-color var(--transition-normal),
    transform var(--transition-normal), box-shadow var(--transition-normal);
  text-align: center;
  position: relative;
}

.variant-btn kbd {
  position: absolute;
  top: 6px;
  left: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-text-muted);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  padding: 1px 5px;
}

.variant-btn .sub-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 2px;
}

.variant-btn .sub-desc {
  display: block;
  font-size: 11px;
  color: var(--color-text-secondary);
}

.variant-btn:hover,
.variant-btn:focus-visible {
  background: var(--color-surface-hover);
  transform: translateY(-1px);
  box-shadow: 0 0 12px var(--color-primary-glow);
}

.variant-btn.penalty:hover,
.variant-btn.penalty:focus-visible {
  border-color: var(--color-error);
  box-shadow: 0 0 12px var(--color-error-glow);
}

.variant-btn:active {
  transform: translateY(0);
}

/* One quiet line under the keys: hovered mode's description + best */
.stage-detail {
  min-height: 20px;
  margin-top: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: center;
}

.stage-detail b {
  color: var(--color-text-secondary);
  font-weight: 600;
}

/* Enter bar: the smart continue action — last mode, its best, your streak */
.stage-continue {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 12px 26px;
  background: var(--color-primary);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  box-shadow: 0 5px 0 color-mix(in srgb, var(--color-primary) 50%, #000);
  cursor: pointer;
  font-family: var(--font-mono);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast),
    border-color var(--transition-fast);
}

.stage-continue .enter-glyph {
  font-size: 16px;
  color: var(--color-bg);
}

.stage-continue #continue-label {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--color-bg);
}

.stage-continue #continue-sub {
  font-size: 11px;
  color: color-mix(in srgb, var(--color-bg) 65%, transparent);
}

.stage-continue:hover,
.stage-continue:focus-visible {
  transform: translateY(-2px);
  background: color-mix(in srgb, var(--color-primary) 88%, #fff);
  box-shadow: 0 7px 0 color-mix(in srgb, var(--color-primary) 50%, #000);
}

.stage-continue:active,
.stage-continue.pressed {
  transform: translateY(3px);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--color-primary) 50%, #000);
}

#settings-btn {
  position: absolute;
  top: 0;
  right: 0;
}

.icon-btn {
  background: var(--color-surface);
  border: 1px solid var(--border-default);
  color: var(--color-text-secondary);
  padding: 10px;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-normal), border-color var(--transition-normal),
    color var(--transition-normal), box-shadow var(--transition-normal);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--color-surface-elevated);
  border-color: var(--border-accent);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.icon-btn:active {
  transform: scale(0.95);
}

.menu-footer-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

/* ============================================
   GAME UI
   ============================================ */

#game-ui {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(6px, 1.5vh, 12px);
  width: 100%;
}

#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 600px;
  padding: 0 4px;
  margin-bottom: 4px;
}

#game-header #mode-name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  white-space: nowrap;
}

#playfield-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
  background: var(--color-surface);
  border: 0;
  border-radius: var(--radius-md);
  outline: 1px solid var(--border-accent);
  outline-offset: -1px;
  box-shadow: var(--shadow-md);
  transition: background var(--transition-normal), outline-color var(--transition-normal),
    box-shadow var(--transition-normal);
}

/* Mode name + now-playing chip share the header's center slot */
.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

/* Now-playing chip: soundtrack name + BPM with a live music meter.
   Theme tokens only — body[data-theme] restyles it for free. */
#now-playing {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 10px;
  background: var(--color-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
}

/* Beat-synced dot: --np-pulse (0..1) is set from the game loop */
.np-beat {
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-primary);
  box-shadow: 0 0 calc(4px + var(--np-pulse, 0) * 8px) var(--color-primary-glow);
  transform: scale(calc(1 + var(--np-pulse, 0) * 0.45));
}

.np-track {
  font-size: calc(11px * var(--text-scale, 1));
  font-weight: 600;
  color: var(--color-text-secondary);
  letter-spacing: 0.4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.np-meter {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.np-layers {
  display: flex;
  gap: 2px;
}

.np-layer-seg {
  width: 3px;
  height: 9px;
  border-radius: 1px;
  background: var(--color-surface-hover);
}

.np-layer-seg.on {
  background: var(--color-primary);
  box-shadow: 0 0 4px var(--color-primary-glow);
}

.np-intensity {
  width: 42px;
  height: 4px;
  border-radius: 2px;
  background: var(--color-surface-hover);
  overflow: hidden;
}

.np-intensity-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent-2));
}

#stats {
  display: flex;
  gap: 16px;
  padding: 12px 24px;
  background: var(--color-surface);
  border: 0;
  border-bottom: 1px solid var(--border-default);
  border-radius: 0;
  box-shadow: none;
  box-sizing: border-box;
  width: 100%;
  max-width: none;
  transition: background var(--transition-normal), border-color var(--transition-normal);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 65px;
}

.mode-status-stat {
  flex: 0 0 65px;
  min-width: 65px;
  max-width: 65px;
}

.stat-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.mode-status-stat .stat-label,
.mode-status-stat .stat-value {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-status-stat .stat-value {
  font-family: var(--font-mono);
  font-size: 15px;
}

/* Canvas */
#game-canvas {
  display: block;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transition: none;
}

/* Beat-exact glow. The color follows the chord-reactive accent
   (--music-accent, set each frame from the musical state) so the frame
   itself shifts with the harmony; falls back to the theme's primary glow
   before a game starts. --beat-glow carries the downbeat emphasis. */
#playfield-shell:has(#game-canvas.beat-pulse) {
  box-shadow: var(--shadow-md),
    0 0 calc(28px + var(--beat-glow, 0.1) * 24px)
      var(--music-accent, var(--color-primary-glow));
}

/* Input */
#input-area {
  width: 100%;
  max-width: 500px;
  position: relative;
}

/* Caps Lock warning pill above the input */
#capslock-warning {
  position: absolute;
  top: -34px;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 4px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #0a0a14;
  background: var(--color-warning);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
  z-index: 10;
}

#capslock-warning.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#word-input {
  width: 100%;
  padding: 16px 24px;
  font-size: calc(24px * var(--text-scale, 1));
  font-family: var(--font-mono);
  font-weight: 500;
  text-align: center;
  background: var(--color-surface);
  border: 2px solid var(--color-primary);
  border-radius: var(--radius-md);
  color: var(--color-text);
  outline: none;
  transition: all var(--transition-normal);
  box-shadow: 0 0 20px var(--color-primary-glow);
}

#word-input:focus {
  border-color: var(--color-success);
  box-shadow: 0 0 25px var(--color-success-glow);
}

#word-input::placeholder {
  color: var(--color-text-muted);
  font-weight: 400;
}

#word-input.correct {
  border-color: var(--color-success);
  background: linear-gradient(180deg, rgba(0, 255, 136, 0.08) 0%, var(--color-surface) 100%);
  box-shadow: 0 0 25px var(--color-success-glow);
}

#word-input.wrong {
  border-color: var(--color-error);
  background: linear-gradient(180deg, rgba(255, 107, 107, 0.08) 0%, var(--color-surface) 100%);
  box-shadow: 0 0 25px var(--color-error-glow);
}

#word-input.shake {
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

#game-ui[data-chrome="quiet"] #playfield-shell {
  background: transparent;
  outline-color: var(--border-default);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

#game-ui[data-chrome="quiet"] #playfield-shell:has(#game-canvas.beat-pulse) {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

#game-ui[data-chrome="quiet"] #stats {
  background: color-mix(in srgb, var(--color-surface) 72%, transparent);
  border-bottom-color: color-mix(in srgb, var(--border-default) 70%, transparent);
}

#game-ui[data-chrome="quiet"] #word-input:not(.correct):not(.wrong) {
  background: color-mix(in srgb, var(--color-bg) 76%, transparent);
  border-color: var(--border-default);
  box-shadow: none;
}

#game-ui[data-chrome="quiet"] .icon-btn,
#game-ui[data-chrome="quiet"] #now-playing,
#game-ui[data-chrome="quiet"] .rail-card {
  background: transparent;
  border-color: color-mix(in srgb, var(--border-default) 72%, transparent);
  box-shadow: none;
}

#game-ui[data-chrome="quiet"] .icon-btn:hover,
#game-ui[data-chrome="quiet"] .icon-btn:focus-visible {
  background: var(--color-surface);
  border-color: var(--border-accent);
}

#game-ui[data-chrome="quiet"] .np-beat,
#game-ui[data-chrome="quiet"] .rail-card.is-live {
  box-shadow: none;
}

#game-ui[data-chrome="quiet"] .rail-eq {
  opacity: 0.55;
}

/* ============================================
   SETTINGS PANEL
   ============================================ */

#settings-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 5, 10, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(12px);
}

.panel-content {
  background: var(--color-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 28px 32px;
  min-width: 380px;
  width: min(500px, calc(100vw - 32px));
  max-width: 90vw;
  max-height: min(82vh, calc(100dvh - 32px));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  box-shadow: var(--shadow-lg);
}

.panel-content::-webkit-scrollbar,
.stats-content::-webkit-scrollbar,
.game-over-content::-webkit-scrollbar {
  width: 8px;
}

.panel-content::-webkit-scrollbar-track,
.stats-content::-webkit-scrollbar-track,
.game-over-content::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
}

.panel-content::-webkit-scrollbar-thumb,
.stats-content::-webkit-scrollbar-thumb,
.game-over-content::-webkit-scrollbar-thumb {
  background: rgba(0, 217, 255, 0.35);
  background: color-mix(in srgb, var(--color-primary) 35%, transparent);
  border-radius: 999px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: -28px;
  z-index: 2;
  background: var(--color-surface);
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.panel-header h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: 1px;
}

/* Rail tick: panels carry the channel-strip mark too */
.panel-header h2::before {
  content: '';
  width: 4px;
  height: 20px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--color-primary), var(--color-accent-2));
  box-shadow: 0 0 8px var(--color-primary-glow);
}

.panel-close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  transition: color var(--transition-fast), background var(--transition-fast);
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.panel-close:hover {
  color: var(--color-error);
  background: rgba(255, 107, 107, 0.1);
}

.stats-back-control {
  width: auto;
  padding: 0 10px;
  gap: 6px;
  color: var(--color-text);
  font-size: 12px;
  font-weight: 600;
}

.stats-back-control:hover {
  color: var(--color-primary);
  background: var(--color-surface-hover);
}

.setting-group {
  margin-bottom: 22px;
}

.setting-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 1.5px;
  margin-bottom: 12px;
  text-transform: uppercase;
}

.setting-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 8px;
}

.sync-data-card {
  padding: 16px;
  background: color-mix(in srgb, var(--color-primary) 5%, var(--color-surface-elevated));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.sync-data-copy strong {
  display: block;
  margin-bottom: 5px;
  color: var(--color-text);
  font-size: 14px;
}

.sync-data-copy p {
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1.5;
}

.sync-data-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.sync-data-actions .secondary-btn {
  width: 100%;
  padding: 11px 12px;
  font-size: 12px;
}

.sync-data-status {
  min-height: 18px;
}

.sync-data-status[data-kind="success"] {
  color: var(--color-success);
}

.sync-data-status[data-kind="error"] {
  color: var(--color-error);
}

/* Radio Group */
.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.radio-option {
  flex: 1 1 calc(33.333% - 8px);
  min-width: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 12px 14px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-normal);
}

.radio-group-even .radio-option {
  flex-basis: calc(50% - 8px);
}

.radio-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.radio-option span {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: color var(--transition-fast);
}

.radio-option:hover {
  border-color: var(--border-accent);
  background: var(--color-surface-hover);
}

.radio-option:has(input:focus-visible) {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.radio-option:has(input:checked) {
  background: rgba(0, 217, 255, 0.1);
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  border-color: var(--color-primary);
}

.radio-option:has(input:checked) span {
  color: var(--color-primary);
  font-weight: 600;
}

/* Slider */
.slider-container {
  display: flex;
  align-items: center;
  gap: 16px;
}

.slider-container input[type="range"] {
  flex: 1;
  height: 6px;
  background: var(--color-surface-elevated);
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
}

.slider-container input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--color-primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--color-primary-glow);
  transition: transform var(--transition-fast);
}

.slider-container input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
}

.slider-value {
  font-family: var(--font-display);
  min-width: 48px;
  text-align: right;
  color: var(--color-primary);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Toggle */
.toggle-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
  cursor: pointer;
  padding: 8px 0;
  border-radius: var(--radius-sm);
}

.toggle-option > span:first-of-type {
  color: var(--color-text-secondary);
  font-size: 15px;
  font-weight: 500;
}

.toggle-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.toggle-slider {
  width: 48px;
  height: 26px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 13px;
  position: relative;
  transition: all var(--transition-normal);
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: var(--color-text-muted);
  border-radius: 50%;
  transition: all var(--transition-normal);
}

.toggle-option input:checked + .toggle-slider {
  background: rgba(0, 217, 255, 0.2);
  background: color-mix(in srgb, var(--color-primary) 22%, transparent);
  border-color: var(--color-primary);
}

.toggle-option input:checked + .toggle-slider::after {
  left: 25px;
  background: var(--color-primary);
  box-shadow: 0 0 10px var(--color-primary-glow);
}

.toggle-option:has(input:focus-visible) {
  outline: 2px solid var(--color-primary);
  outline-offset: 4px;
}

/* ============================================
   PAUSE MENU
   ============================================ */

#pause-menu {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 5, 10, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 175;
  backdrop-filter: blur(12px);
}

.pause-content {
  background: var(--color-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: 40px 50px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.pause-content h2 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 32px;
  letter-spacing: 0.14em;
  text-shadow: 0 0 30px var(--color-primary-glow);
}

.pause-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.primary-btn, .secondary-btn {
  padding: 16px 40px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-sans);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  letter-spacing: 1px;
  transition: all var(--transition-normal);
}

.primary-btn {
  background: var(--color-primary);
  color: var(--color-bg);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--color-primary) 50%, #000);
}

.primary-btn:hover {
  transform: translateY(-2px);
  background: color-mix(in srgb, var(--color-primary) 88%, #fff);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--color-primary) 50%, #000);
}

.primary-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--color-primary) 50%, #000);
}

.secondary-btn {
  background: var(--color-surface-elevated);
  color: var(--color-text-secondary);
  border: 1px solid var(--border-default);
}

.secondary-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  border-color: var(--border-accent);
}

/* ============================================
   GAME OVER SCREEN
   ============================================ */

#game-over {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 5, 10, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
  z-index: 150;
  backdrop-filter: blur(12px);
}

.game-over-content {
  background: var(--color-surface);
  --result-accent: var(--color-error);
  --result-glow: var(--color-error-glow);
  border: 1px solid var(--result-accent);
  border-radius: var(--radius-xl);
  padding: 24px 28px;
  text-align: center;
  box-shadow: var(--shadow-lg), 0 0 60px var(--result-glow);
  width: min(760px, calc(100vw - 32px));
  max-height: min(86vh, calc(100dvh - 32px));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.game-over-content h2 {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  color: var(--result-accent);
  margin-bottom: 12px;
  letter-spacing: 0.16em;
  text-shadow: 0 0 30px var(--result-glow);
}

.game-over-content.result-mood-complete {
  --result-accent: var(--color-primary);
  --result-glow: var(--color-primary-glow);
}

.game-over-content.result-mood-practice {
  --result-accent: var(--color-warning);
  --result-glow: var(--color-warning-glow);
}

.game-over-content.result-mood-best {
  --result-accent: var(--color-success);
  --result-glow: var(--color-success-glow);
}

.game-over-content.result-mood-defeat {
  --result-accent: var(--color-error);
  --result-glow: var(--color-error-glow);
}

/* Personal best banner */
.pb-badge {
  display: inline-block;
  margin: -2px auto 12px;
  padding: 6px 18px;
  font-size: 14px;
  font-weight: 600;
  color: #0a0a14;
  background: var(--color-warning);
  border-radius: 999px;
  animation: pbPop 0.4s ease-out;
}

/* The badge's own gold IS the celebration; its icon rides in the dark text
   colour (not warm-gold, which would vanish on the gold pill). */
.pb-badge .tb-icon {
  vertical-align: -0.18em;
  margin-right: 3px;
}

.pb-badge.hidden {
  display: none;
}

@keyframes pbPop {
  0% { transform: scale(0.6); opacity: 0; }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

/* Daily Challenge result line (streak / practice notice) */
.daily-result-note {
  margin: -4px auto 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.daily-result-note .tb-icon {
  vertical-align: -0.18em;
}

.daily-result-note.practice {
  color: var(--color-warning);
}

.daily-result-note.hidden {
  display: none;
}

/* WPM-over-time results chart */
#result-chart-wrap {
  margin: 0;
  padding: 12px 12px 8px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  max-width: none;
}

#result-chart-wrap.hidden {
  display: none;
}

#result-chart {
  display: block;
  margin: 0 auto;
  max-width: 100%;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--color-text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-swatch {
  width: 10px;
  height: 3px;
  border-radius: 2px;
}

.legend-consistency strong {
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

/* Skill summary: a compact TETR.IO-style run card that turns the result
   into a training readout without moving the player to another screen. */
.skill-summary {
  margin: -12px auto 24px;
  padding: 12px 14px 14px;
  max-width: 360px;
  background: color-mix(in srgb, var(--color-surface-elevated) 82%, transparent);
  border: 1px solid color-mix(in srgb, var(--result-accent) 42%, var(--border-subtle));
  border-radius: var(--radius-md);
  text-align: left;
}

.skill-summary.hidden {
  display: none;
}

.skill-summary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.skill-summary-kicker {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.skill-grade {
  min-width: 38px;
  text-align: right;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  color: var(--result-accent);
  text-shadow: 0 0 20px color-mix(in srgb, var(--result-accent) 45%, transparent);
}

.skill-grade-strip {
  display: flex;
  gap: 3px;
  height: 7px;
  margin-bottom: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.skill-grade-segment {
  min-width: 8px;
  border-radius: 999px;
}

.skill-grade-segment.empty {
  flex-grow: 0 !important;
  min-width: 0;
}

.skill-grade.skill-grade-a { color: #8be9fd; }
.skill-grade.skill-grade-b { color: #66e6a3; }
.skill-grade.skill-grade-c { color: #ffcc66; }
.skill-grade.skill-grade-d { color: #ff9966; }
.skill-grade.skill-grade-e { color: #ff5f7a; }

.skill-grade-segment.skill-grade-a { background: #8be9fd; }
.skill-grade-segment.skill-grade-b { background: #66e6a3; }
.skill-grade-segment.skill-grade-c { background: #ffcc66; }
.skill-grade-segment.skill-grade-d { background: #ff9966; }
.skill-grade-segment.skill-grade-e { background: #ff5f7a; }

.skill-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.skill-summary-item {
  min-width: 0;
}

.skill-summary-label,
.skill-summary-value {
  display: block;
}

.skill-summary-label {
  margin-bottom: 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.skill-summary-value {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text);
  overflow-wrap: anywhere;
}

/* Run context: "vs your average" + session position — two quiet lines
   between the stat tiles and the chart, in the mono game voice */
.run-context {
  margin: -6px auto 14px;
}

.run-context-line {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.6;
}

.run-context-line strong {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.run-context-line .delta-up {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--color-success);
  font-variant-numeric: tabular-nums;
}

.run-context-line .delta-down {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--color-error);
  font-variant-numeric: tabular-nums;
}

.run-context-line .delta-even {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--color-text-muted);
}

.run-context-line.session-position {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

/* Run insights: this run's key patterns and missed words — a quiet nudge
   toward the practice diagnostics in the menu stats panel */
.run-insights {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
}

.insight-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}

.insight-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-right: 4px;
}

.insight-list {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.run-insights .key-cap {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  font-size: 11px;
}

.key-insight-list {
  width: 100%;
  min-width: 100%;
  max-width: 420px;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 6px;
}

.key-insight-row {
  display: grid;
  grid-template-columns: 1fr;
  align-items: stretch;
  justify-items: stretch;
  gap: 8px;
  width: 100%;
}

.key-insight-row .insight-label {
  justify-self: start;
  width: min(100%, 420px);
  margin-right: 0;
  padding-top: 0;
  white-space: nowrap;
}

.key-insight {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  flex: 1 1 132px;
  min-height: 40px;
  padding: 7px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--color-surface-elevated) 72%, transparent);
  text-align: left;
}

.key-insight-metrics {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 1px;
  color: var(--color-text-muted);
  font-size: 10px;
  line-height: 1.35;
}

.key-insight-metrics strong {
  color: var(--color-text-secondary);
  font-size: 12px;
  font-weight: 600;
}

.key-pattern-badge {
  grid-column: 2;
  color: var(--color-warning);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.key-analytics-link {
  grid-column: 2;
  justify-self: start;
  padding: 4px 0;
  border: 0;
  color: var(--color-accent-secondary);
  background: transparent;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}

.result-lower-grid .run-insights {
  width: 100%;
}

.result-lower-grid .run-insights .insight-row {
  width: 100%;
}

.result-lower-grid .key-insight-list {
  justify-self: stretch;
}

.key-analytics-link:hover,
.key-analytics-link:focus-visible {
  color: var(--color-accent-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.run-insights .word-tag {
  padding: 3px 10px;
  font-size: 12px;
}

.next-action {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  margin: 4px auto 12px;
  padding: 12px 0;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.next-action.hidden {
  display: none;
}

.next-action.next-action-copy-only {
  grid-template-columns: 1fr;
  text-align: center;
}

.next-action-kicker {
  margin: 0 0 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--result-accent);
}

.next-action-copy {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--color-text-secondary);
}

.next-action-btn {
  min-width: 150px;
  min-height: 44px;
  padding: 11px 18px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid var(--result-accent);
  background: color-mix(in srgb, var(--result-accent) 16%, transparent);
  color: var(--color-text);
  box-shadow: 0 0 18px color-mix(in srgb, var(--result-accent) 18%, transparent);
  transition: transform var(--transition-normal), background var(--transition-normal), box-shadow var(--transition-normal);
}

.next-action-btn:hover {
  background: color-mix(in srgb, var(--result-accent) 26%, transparent);
  box-shadow: 0 0 26px color-mix(in srgb, var(--result-accent) 28%, transparent);
  transform: translateY(-1px);
}

.next-action-btn.hidden {
  display: none;
}

.game-over-content.coach-action-priority .next-action-btn {
  border-color: transparent;
  background: var(--result-accent);
  color: var(--color-bg);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--result-accent) 50%, #000);
}

.game-over-content.coach-action-priority .next-action-btn:hover {
  background: color-mix(in srgb, var(--result-accent) 90%, #fff);
  box-shadow: 0 8px 0 color-mix(in srgb, var(--result-accent) 50%, #000);
}

.game-over-content.coach-action-priority #restart-btn {
  background: var(--color-surface-elevated);
  color: var(--color-text-secondary);
  border: 1px solid var(--border-default);
  box-shadow: none;
}

.game-over-content.coach-action-priority #restart-btn.result-replay-secondary {
  padding: 10px 18px;
  font-size: 12px;
  opacity: 0.86;
}

.game-over-content.coach-action-priority #restart-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  box-shadow: none;
  opacity: 1;
}

@media (max-width: 520px) {
  .insight-row {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .insight-label {
    margin-right: 0;
  }

  .key-insight-list {
    width: min(100%, 300px);
    grid-template-columns: 1fr;
  }

  .key-insight-row {
    grid-template-columns: 1fr;
  }

  .key-insight-row .insight-label {
    padding-top: 0;
  }

  .key-analytics-link {
    grid-column: 1;
    justify-self: center;
  }

  .next-action {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .next-action-btn {
    width: 100%;
  }
}

/* Track feedback: one subtle, ignorable row — "did you like the track?" */
.track-feedback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}

.track-feedback button {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 13px;
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.15s, transform 0.1s;
}

.track-feedback .btn-icon {
  display: inline-flex;
  width: 15px;
  height: 15px;
  color: var(--color-text-secondary);
}

.track-feedback .btn-icon .tb-icon {
  width: 15px;
  height: 15px;
}

.feedback-count {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.feedback-count .tb-icon {
  width: 11px;
  height: 11px;
}

.track-feedback button.chosen .btn-icon {
  color: var(--color-primary);
}

.track-feedback button:hover:not(:disabled) {
  opacity: 1;
  transform: scale(1.1);
}

.track-feedback button:disabled {
  cursor: default;
  opacity: 0.3;
}

.track-feedback button.chosen {
  opacity: 1;
  border-color: var(--color-accent, #21a2c7);
}

.track-feedback-tally {
  font-size: 11px;
  color: var(--color-text-muted);
}

/* M2: the .mid export rides in the feedback row, one size quieter */
.midi-export-btn {
  font-size: 11px !important;
  font-family: var(--font-mono);
  margin-left: 6px;
}

.midi-export-btn.hidden {
  display: none;
}

.game-over-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin: 0 0 10px;
}

.game-over-hint kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--border-default);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--color-text-secondary);
}

.final-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.final-stat {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  padding: 10px 9px;
  background: var(--color-surface-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  transition: background var(--transition-normal), border-color var(--transition-normal);
}

.final-stat.is-headline {
  background: color-mix(in srgb, var(--color-primary) 10%, var(--color-surface-elevated));
  border-color: var(--border-accent);
}

.final-stat.is-headline::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--color-primary);
  box-shadow: 0 0 12px var(--color-primary-glow);
}

.final-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 1px;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.final-value {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.final-stat.is-headline .final-value {
  font-size: 26px;
  color: var(--color-success);
  text-shadow: 0 0 16px var(--color-success-glow);
}

.final-value-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.final-value-icon .tb-icon {
  width: 19px;
  height: 19px;
}

.final-value-small {
  font-size: 20px;
}

.game-over-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 16px;
}

#restart-btn,
#menu-btn,
#share-performance-btn {
  padding: 14px 32px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-sans);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  letter-spacing: 1px;
  transition: all var(--transition-normal);
}

#restart-btn {
  background: var(--color-primary);
  color: var(--color-bg);
  box-shadow: 0 4px 0 color-mix(in srgb, var(--color-primary) 50%, #000);
}

#restart-btn:hover {
  transform: translateY(-2px);
  background: color-mix(in srgb, var(--color-primary) 88%, #fff);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--color-primary) 50%, #000);
}

#restart-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--color-primary) 50%, #000);
}

#menu-btn {
  background: var(--color-surface-elevated);
  color: var(--color-text-secondary);
  border: 1px solid var(--border-default);
}

#share-performance-btn {
  border: 1px solid var(--border-accent);
  background: color-mix(in srgb, var(--color-primary) 8%, var(--color-surface-elevated));
  color: var(--color-primary);
}

#menu-btn:hover,
#share-performance-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
}

#share-performance-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.result-lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 340px);
  align-items: stretch;
  gap: 12px;
  margin: 10px 0 0;
  text-align: left;
}

#performance-share-dialog {
  position: fixed;
  inset: 0;
  z-index: 260;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(5, 5, 10, 0.92);
  backdrop-filter: blur(14px);
}

.share-dialog-content {
  position: relative;
  width: min(520px, calc(100vw - 32px));
  min-width: 0;
  max-height: min(88vh, calc(100dvh - 32px));
  border-color: var(--border-accent);
}

.share-dialog-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
}

.share-dialog-heading {
  padding-right: 42px;
}

.share-dialog-eyebrow,
.shared-performance-score-label,
.shared-performance-stats small,
.shared-performance-grade-wrap span,
.share-link-field-wrap > span {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.share-dialog-heading h2 {
  margin: 5px 0 0;
  font-family: var(--font-display);
  font-size: 25px;
  letter-spacing: 0.06em;
}

.share-dialog-status {
  min-height: 18px;
  margin: 7px 0 12px;
  color: var(--color-text-secondary);
  font-size: 12px;
}

.share-dialog-trust-copy {
  margin: 7px 0 0;
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1.45;
}

.share-dialog-status[data-kind="success"] {
  color: var(--color-success);
}

.share-dialog-status[data-kind="error"] {
  color: var(--color-error);
}

.shared-performance-card {
  position: relative;
  overflow: hidden;
  padding: 20px;
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 100% 0%, var(--color-primary-glow), transparent 44%),
    linear-gradient(145deg, var(--color-surface-elevated), var(--color-surface));
  box-shadow: inset 0 1px 0 var(--border-subtle), var(--shadow-md);
}

.shared-performance-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent-2));
}

.shared-performance-identity,
.shared-performance-context,
.shared-performance-grade-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.shared-performance-mode {
  color: var(--color-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.shared-performance-badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.shared-performance-badges span {
  padding: 3px 7px;
  border: 1px solid var(--border-default);
  border-radius: 999px;
  color: var(--color-text-secondary);
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.shared-performance-score {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 18px 0 14px;
}

.shared-performance-score-value {
  color: var(--color-text);
  font-family: var(--font-display);
  font-size: clamp(38px, 11vw, 58px);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.shared-performance-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
}

.shared-performance-stats div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.shared-performance-stats span {
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
}

.shared-performance-context {
  align-items: flex-start;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--color-text-secondary);
  font-size: 11px;
}

.shared-performance-context > span {
  display: inline-flex;
  flex-direction: column;
  gap: 3px;
}

.shared-performance-context small {
  color: var(--color-text-muted);
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.1em;
}

.shared-performance-context strong {
  color: var(--color-text-secondary);
  font-weight: 600;
}

.shared-performance-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 13px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  color: var(--color-text-muted);
  font-size: 11px;
}

.share-performance-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.share-performance-actions[hidden],
.share-link-field-wrap[hidden],
.share-privacy-note[hidden] {
  display: none !important;
}

.share-performance-actions button {
  min-height: 44px;
}

.share-link-field-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 13px;
}

#performance-share-link {
  width: 100%;
  min-height: 72px;
  resize: none;
  padding: 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text-secondary);
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.45;
}

#performance-share-link:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.share-privacy-note {
  margin: 12px 0 0;
  color: var(--color-text-muted);
  font-size: 11px;
  line-height: 1.45;
}

.performance-share-invalid {
  padding: 24px 18px;
  border: 1px solid color-mix(in srgb, var(--color-error) 45%, transparent);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--color-error) 8%, var(--color-surface-elevated));
  text-align: center;
}

.performance-share-invalid strong {
  color: var(--color-error);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.06em;
}

.performance-share-invalid p {
  margin: 8px 0 0;
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 1.5;
}

.result-lower-grid > .track-feedback {
  grid-column: 1 / -1;
  justify-self: center;
}

/* ============================================
   STATS PANEL
   ============================================ */

#stats-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 5, 10, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.stats-content {
  min-width: 440px;
  max-width: 500px;
}

.stats-overview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
}

.stat-card-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  color: var(--color-primary);
  font-variant-numeric: tabular-nums;
}

.stat-card-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}

/* Day streak: full-width summary card (days played, any mode —
   distinct from the Daily Challenge's scored streak) */
.streak-card {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: baseline;
  justify-content: flex-start;
  gap: 10px;
  padding: 12px 16px;
  text-align: left;
}

.streak-card .stat-card-value {
  font-size: 22px;
}

.streak-card .stat-card-label {
  margin-top: 0;
}

.streak-flame {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  align-self: center;
  color: var(--color-warning);
}

.streak-flame .tb-icon {
  width: 18px;
  height: 18px;
}

.streak-best {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* Net-WPM trend sparkline (same chart surface as the results chart) */
.wpm-trend-wrap {
  padding: 12px 12px 10px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

#wpm-trend-chart {
  display: block;
  margin: 0 auto;
  max-width: 100%;
}

.wpm-trend-summary {
  margin-top: 8px;
  text-align: center;
  font-size: 11px;
  color: var(--color-text-secondary);
}

.wpm-trend-summary strong {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.wpm-trend-empty {
  padding: 18px 8px;
  text-align: center;
  font-size: 13px;
  font-style: italic;
  color: var(--color-text-muted);
}

.stats-section {
  margin-bottom: 20px;
}

.stats-section h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--color-surface-elevated);
  border-radius: var(--radius-sm);
}

.stat-row-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--color-text-secondary);
  font-size: 14px;
  font-weight: 500;
}

.stat-row-label .tb-icon {
  width: 16px;
  height: 16px;
  color: var(--color-primary);
}

.stat-row-value {
  font-family: var(--font-display);
  color: var(--color-primary);
  font-weight: 600;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* Mastery path (stats panel): goal rows with a thin progress track. The
   percentage TEXT is the canonical readout (rule 1 non-colour twin); the
   bar only echoes it. */
.mastery-goal {
  padding: 12px 14px;
  background: var(--color-surface-elevated);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mastery-goal-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.mastery-detail {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 12px;
}

.mastery-track {
  height: 4px;
  border-radius: 2px;
  background: var(--color-surface);
  overflow: hidden;
}

.mastery-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--color-primary);
}

/* Daily Challenge: streak badge pinned to the Daily keycap's corner */
.daily-streak {
  position: absolute;
  top: -9px;
  right: -9px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  color: var(--color-warning);
  background: var(--color-bg);
  border: 1px solid rgba(255, 204, 0, 0.35);
  border-radius: 999px;
  box-shadow: inset 0 0 12px rgba(255, 204, 0, 0.12);
}

.daily-streak .tb-icon {
  width: 11px;
  height: 11px;
  vertical-align: -2px;
}

.daily-streak.hidden {
  display: none;
}

/* Daily Challenge: last-14-days strip in the stats panel */
.daily-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.daily-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-surface-elevated);
  border: 1px solid var(--border-default);
}

.daily-dot.played {
  background: var(--color-primary);
  border-color: transparent;
}

.daily-dot.today {
  border-color: var(--color-primary);
}

.word-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.word-tag {
  padding: 6px 14px;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.2);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-error);
}

.word-tag.mastered {
  background: rgba(0, 255, 136, 0.1);
  border-color: rgba(0, 255, 136, 0.2);
  color: var(--color-success);
}

.word-tag.empty {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--color-text-muted);
  font-style: italic;
}

.danger-btn {
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.2);
  border-radius: var(--radius-sm);
  color: var(--color-error);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all var(--transition-normal);
}

.danger-btn:hover {
  background: rgba(255, 107, 107, 0.15);
  border-color: var(--color-error);
}

#reset-stats-dialog {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 135;
  background: rgba(5, 5, 10, 0.72);
  backdrop-filter: blur(10px);
}

#sync-import-dialog {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 240;
  background: rgba(5, 5, 10, 0.78);
  backdrop-filter: blur(12px);
}

.sync-import-content {
  width: min(440px, calc(100vw - 32px));
  padding: 24px;
  background: var(--color-surface);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 42px var(--color-primary-glow);
}

.sync-import-content h2 {
  margin: 6px 0 10px;
  color: var(--color-text);
  font-family: var(--font-display);
  font-size: 24px;
}

.sync-import-content > p {
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 1.5;
}

.sync-import-details {
  margin-top: 8px;
  color: var(--color-text-muted) !important;
  font-size: 11px !important;
}

.sync-import-warning {
  margin-top: 14px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--color-primary) 7%, transparent);
  border-left: 2px solid var(--color-primary);
}

.sync-import-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.sync-import-actions .primary-btn,
.sync-import-actions .secondary-btn {
  width: 100%;
  padding: 12px 14px;
}

.reset-confirm-content {
  width: min(360px, calc(100vw - 32px));
  padding: 22px;
  background: rgba(255, 107, 107, 0.08);
  border: 1px solid rgba(255, 107, 107, 0.4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg), 0 0 42px rgba(255, 107, 107, 0.18);
}

.reset-confirm-content h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-error);
  margin-bottom: 8px;
}

.reset-confirm-content p {
  font-size: 13px;
  line-height: 1.4;
  color: var(--color-text-secondary);
  margin-bottom: 18px;
}

.reset-confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.reset-confirm-actions .secondary-btn,
.reset-confirm-actions .danger-btn {
  width: 100%;
  margin-top: 0;
  padding: 12px 14px;
}

/* Waiting service-worker affordance, only shown outside active play. */
.sw-update-prompt {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 3000;
  padding: 10px 14px;
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  background: var(--color-surface-elevated);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: calc(13px * var(--text-scale, 1));
  font-weight: 700;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

/* ============================================
   ACHIEVEMENTS
   ============================================ */

#achievements-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 5, 10, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.achievements-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.achievement-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--color-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  opacity: 0.45;
  filter: grayscale(1);
  transition: all var(--transition-normal);
}

.achievement-card.unlocked {
  opacity: 1;
  filter: none;
  border-color: rgba(255, 204, 0, 0.3);
  background: linear-gradient(135deg, var(--color-surface-elevated) 0%, rgba(255, 204, 0, 0.06) 100%);
}

.achievement-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.achievement-icon .tb-icon {
  width: 28px;
  height: 28px;
}

.achievement-icon.locked {
  color: var(--color-text-muted);
  width: 40px;
  text-align: center;
}

.achievement-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.achievement-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.achievement-card.unlocked .achievement-name {
  color: var(--color-warning);
}

.achievement-desc {
  font-size: 12px;
  color: var(--color-text-muted);
}

/* Tiered achievements: bronze/silver/gold pips + next-target readout */
.achievement-tiers {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.tier-pips {
  display: inline-flex;
  gap: 5px;
}

.tier-pip {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--color-surface);
  border: 1px solid var(--border-default);
}

/* Medal colors are semantic (bronze/silver/gold), not theme hues */
.tier-pip.t1.earned {
  background: #cd7f32;
  border-color: transparent;
}

.tier-pip.t2.earned {
  background: #b8c0cc;
  border-color: transparent;
}

.tier-pip.t3.earned {
  background: var(--color-warning);
  border-color: transparent;
}

.achievement-next {
  font-size: 11px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.achievement-next strong {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--color-text-secondary);
}

.achievement-next.maxed {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--color-warning);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Locked family cards keep their pips readable through the grayscale */
.achievement-card.achievement-family:not(.unlocked) .achievement-tiers {
  opacity: 0.9;
}

/* ============================================
   ANIMATIONS & SCREEN TRANSITIONS
   Screens/modals toggle display via .hidden, so entrance
   keyframes restart automatically when a screen appears.
   Transform is translate/opacity only: resizeCanvas measures
   getBoundingClientRect heights, which translation never skews.
   ============================================ */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheetIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

#menu-screen {
  animation: screenIn 0.22s ease-out;
}

#game-ui {
  animation: screenIn 0.18s ease-out;
}

#settings-panel,
#stats-panel,
#achievements-panel,
#pause-menu,
#game-over,
#performance-share-dialog,
#reset-stats-dialog,
#focus-overlay {
  animation: overlayIn 0.15s ease-out;
}

#settings-panel .panel-content,
#stats-panel .panel-content,
#achievements-panel .panel-content,
.pause-content,
.game-over-content,
.share-dialog-content,
.reset-confirm-content,
.focus-overlay-content {
  animation: sheetIn 0.2s ease-out;
}

/* The stage lights come up in sequence: header, key rows, detail
   line, then the Enter bar (h2 is child 1) */
.mode-selection > * {
  animation: fadeIn 0.3s ease-out;
  animation-fill-mode: both;
}

.mode-selection > *:nth-child(2) { animation-delay: 0.04s; }
.mode-selection > *:nth-child(3) { animation-delay: 0.08s; }
.mode-selection > *:nth-child(4) { animation-delay: 0.12s; }
.mode-selection > *:nth-child(5) { animation-delay: 0.16s; }
.mode-selection > *:nth-child(6) { animation-delay: 0.20s; }

/* ============================================
   AD PLACEHOLDERS (Test Mode)
   Replace with real ad code when approved
   ============================================ */

.ad-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 16px 0;
}

.ad-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: repeating-linear-gradient(
    45deg,
    rgba(0, 217, 255, 0.05),
    rgba(0, 217, 255, 0.05) 10px,
    rgba(0, 217, 255, 0.1) 10px,
    rgba(0, 217, 255, 0.1) 20px
  );
  border: 2px dashed var(--color-primary);
  border-radius: var(--radius-md);
  color: var(--color-primary);
  font-family: var(--font-mono);
  text-align: center;
  opacity: 0.8;
}

.ad-banner .ad-placeholder {
  width: 320px;
  height: 100px;
}

.ad-rectangle .ad-placeholder {
  width: 300px;
  height: 250px;
}

.ad-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  opacity: 0.7;
}

.ad-size {
  font-size: 14px;
  font-weight: 500;
}

.ad-note {
  font-size: 10px;
  opacity: 0.6;
  max-width: 200px;
}

/* Hide ads when data-ads="false" on body */
body[data-ads="false"] .ad-container {
  display: none;
}

@media (max-width: 400px) {
  /* Tight header: keep the chip's track name + intensity bar, drop the
     layer segments so the mode name never gets crowded out */
  .np-layers {
    display: none;
  }

  .ad-banner .ad-placeholder {
    width: 280px;
    height: 90px;
  }

  .ad-rectangle .ad-placeholder {
    width: 250px;
    height: 200px;
  }
}

/* Hide ad slots until a real ad network is configured (set via JS `hidden` attribute) */
.ad-container[hidden] {
  display: none;
}

/* ============================================
   FOCUS-LOST OVERLAY
   ============================================ */

#focus-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 10, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 180;
  cursor: pointer;
}

#focus-overlay.hidden {
  display: none;
}
