*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #000000;
  --accent: #5566dd;
  --accent2: #aa44ff;
  --text: #e8e8ff;
  --text-dim: #8888aa;
}

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, monospace, sans-serif;
  overflow: hidden;
}

/* ── Game wrapper ── */
#game-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  position: relative;
  z-index: 0;
}

#game-wrapper.board-hidden {
  visibility: hidden;
}

/* Shrink-wraps canvas so countdown overlay matches the board (not the full viewport). */
#game-stage {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 96vw;
}

/* Canvas + line-clear toasts — hidden during countdown; slide in from the right when play starts */
#game-playfield {
  position: relative;
  display: inline-block;
  line-height: 0;
  transition: none;
  /* Same end pose as .playfield-enter-active so removing animation classes does not snap (transform: none vs translate3d(0,0,0)). */
  transform: translate3d(0, 0, 0);
  backface-visibility: hidden;
}

/* Fixed px only — vw in transform can jitter when the countdown overlay / layout shifts */
#game-playfield.playfield-prestart {
  opacity: 0;
  transform: translate3d(64px, 0, 0);
  transition: none;
  pointer-events: none;
}

#game-playfield.playfield-enter {
  opacity: 0;
  transform: translate3d(64px, 0, 0);
  pointer-events: none;
}

/* One duration for both properties avoids one finishing early and repainting the layer */
#game-playfield.playfield-enter.playfield-enter-active {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  pointer-events: none;
  transition:
    opacity 0.56s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.56s cubic-bezier(0.22, 1, 0.36, 1);
}

/* After reveal: no transition property (avoids end-of-transition compositor flicker) */
#game-playfield.playfield-reveal-done {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  #game-playfield {
    transform: none;
  }

  #game-playfield.playfield-prestart {
    transform: none;
  }

  #game-playfield.playfield-enter {
    transform: none;
  }

  #game-playfield.playfield-enter.playfield-enter-active {
    transition: opacity 0.24s ease-out;
  }
}

#gameCanvas {
  display: block;
  /* Intrinsic ratio from width/height attributes (kept in sync with constants in main.js) */
  width: auto;
  height: min(1020px, 96vh);
  max-width: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  /* Keyboard-only game: don't capture clicks — lets menu/buttons stay clickable */
  pointer-events: none;
}

/* Line clear / combo toasts — left of playfield; width set from JS (PLAYFIELD_X / canvas) */
#line-clear-feed {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  box-sizing: border-box;
  padding: 0 10px 0 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
  z-index: 4;
  overflow: visible;
}

.line-clear-toast {
  max-width: 100%;
  font-family: 'Press Start 2P', ui-monospace, monospace;
  font-size: clamp(10px, 1.45vw, 15px);
  font-weight: 400;
  letter-spacing: 0.06em;
  line-height: 1.15;
  text-align: right;
  color: #e9d5ff;
  opacity: 0;
  transform: translate3d(0, 18px, 0);
  transition:
    opacity 0.42s cubic-bezier(0.25, 0.9, 0.35, 1),
    transform 0.42s cubic-bezier(0.25, 0.9, 0.35, 1);
}

.line-clear-toast.line-clear-toast--visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.line-clear-toast.line-clear-toast--out {
  opacity: 0;
  transform: translate3d(0, -14px, 0);
  transition:
    opacity 0.48s ease-out,
    transform 0.48s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .line-clear-toast {
    transition-duration: 0.12s;
  }

  .line-clear-toast.line-clear-toast--out {
    transition-duration: 0.16s;
    transform: translate3d(0, 0, 0);
  }
}

/* ── Pre-start countdown (dims playfield) ── */
#countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.78);
  z-index: 5;
  pointer-events: auto;
  opacity: 1;
  transition: none;
}

#countdown-overlay.hidden {
  display: none;
  pointer-events: none;
}

/* Fade in when Start is pressed (dimmer appears) */
#countdown-overlay.countdown-enter {
  opacity: 0;
}

#countdown-overlay.countdown-enter.countdown-enter-active {
  opacity: 1;
  transition: opacity 0.34s ease-out;
}

#countdown-overlay.countdown-fade-out {
  opacity: 0;
  transition: opacity 0.4s ease-out;
  pointer-events: none;
}

#countdown-text {
  font-family: 'Press Start 2P', ui-monospace, monospace;
  font-size: clamp(28px, 9vw, 56px);
  font-weight: 400;
  letter-spacing: 0.14em;
  line-height: 1.35;
  text-align: center;
  text-transform: uppercase;
  color: #ffffff;
}

#countdown-text.countdown-tick {
  animation: countdownPop 0.42s cubic-bezier(0.25, 0.9, 0.35, 1) both;
}

@keyframes countdownPop {
  0% {
    transform: translateY(14px);
    opacity: 0;
  }
  55% {
    opacity: 1;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  #countdown-overlay.countdown-enter.countdown-enter-active {
    transition-duration: 0.14s;
  }

  #countdown-overlay.countdown-fade-out {
    transition: opacity 0.16s ease-out;
  }

  #countdown-text.countdown-tick {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* ── Splash overlay ── */
#splash-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #0c0c1a 0%, #000000 100%);
  z-index: 500;
  cursor: pointer;
  user-select: none;
}

#splash-overlay.splash-leaving {
  pointer-events: none;
}

/* After letters finish: whole overlay fades so the main menu shows through */
#splash-overlay.splash-fade-out {
  opacity: 0;
  transition: opacity 0.55s ease;
}

#splash-overlay.splash-gone {
  display: none;
}

#splash-text {
  font-family: 'Press Start 2P', ui-monospace, monospace;
  font-size: clamp(14px, 3.2vw, 24px);
  letter-spacing: 0.18em;
  display: flex;
  align-items: center;
  perspective: 600px;
}

.splash-char {
  display: inline-block;
  color: #ffffff;
  transition: none;
}

/* Inner span keeps the wave; outer gets fly transform so float doesn’t stop on click */
.splash-char-float {
  display: inline-block;
  animation: splashCharFloat 2.8s ease-in-out infinite;
  animation-delay: calc(var(--ci) * 0.12s);
}

.splash-space {
  width: 0.7em;
}

@keyframes splashCharFloat {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}

/* On click: each letter flies away one by one (stagger via --fly-delay set in JS) */
.splash-char.splash-char--fly {
  transition: transform 0.8s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.6s ease-out;
  transition-delay: var(--fly-delay, 0s);
}

@media (prefers-reduced-motion: reduce) {
  .splash-char-float {
    animation: none;
  }
  .splash-char.splash-char--fly {
    transition-duration: 0.2s;
  }
  #splash-overlay.splash-fade-out {
    transition-duration: 0.2s;
  }
}

/* ── Menu overlay ── */
#menu-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 4, 10, 0.42);
  z-index: 200;
  pointer-events: auto;
  opacity: 1;
  /* Opacity only here — transform on the full overlay shrinks getBoundingClientRect() and broke backdrop sizing. */
  animation: menuOverlayFadeIn 0.35s ease;
  transition: opacity 0.38s ease-out;
}

/* Fades out under #settings-overlay / #stats-overlay instead of display:none */
#menu-overlay.menu-fade-for-settings,
#menu-overlay.menu-fade-for-stats {
  opacity: 0;
  pointer-events: none;
  /* Kill menuOverlayFadeIn or it restarts and fights opacity / transition */
  animation: none;
}

/* While overlay is closing; menu fades in */
#menu-overlay.menu-restoring-from-settings,
#menu-overlay.menu-restoring-from-stats {
  pointer-events: none;
  /* Same as .menu-fade-for-settings: don’t restart menuOverlayFadeIn or it overrides opacity */
  animation: none;
  transition: opacity 0.38s ease-out;
}

/* Avoid menuCardEnter replaying while the overlay opacity is animating up */
#menu-overlay.menu-restoring-from-settings:not(.menu-fade-for-settings) #menu-card,
#menu-overlay.menu-restoring-from-stats:not(.menu-fade-for-stats) #menu-card {
  animation: none;
  opacity: 1;
  transform: none;
}

/*
 * After closing overlay, done() must not leave #menu-overlay without this — otherwise
 * menuOverlayFadeIn + menuCardEnter restart from opacity 0 and flash the whole menu.
 */
#menu-overlay.menu-back-from-settings,
#menu-overlay.menu-back-from-stats {
  animation: none;
}

#menu-overlay.menu-back-from-settings #menu-card,
#menu-overlay.menu-back-from-stats #menu-card {
  animation: none;
  opacity: 1;
  transform: none;
}

#menu-backdrop-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  background: transparent;
}

#menu-fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  background: transparent;
}

#menu-overlay.hidden {
  display: none;
}

@keyframes menuOverlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Menu card (layout only — no visible panel) ── */
#menu-card {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  min-width: 0;
  animation: menuCardEnter 0.35s ease;
}

@keyframes menuCardEnter {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ── Logo (same face as countdown) ── */
#menu-logo {
  font-family: 'Press Start 2P', ui-monospace, monospace;
  font-size: clamp(22px, 5.2vw, 38px);
  font-weight: 400;
  letter-spacing: 0.14em;
  line-height: 1.35;
  margin-bottom: 4px;
}

.logo-char {
  display: inline-block;
  --d: calc(var(--i) * 0.11s);
  background: linear-gradient(
    105deg,
    #e9d5ff 0%,
    #c084fc 18%,
    #a855f7 38%,
    #7c3aed 55%,
    #9333ea 72%,
    #c4b5fd 88%,
    #a78bfa 100%
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(168, 85, 247, 0.45))
    drop-shadow(0 0 28px rgba(124, 58, 237, 0.35));
  animation: logoShimmer 3.2s ease-in-out infinite,
    logoFloat 2.4s ease-in-out infinite;
  animation-delay: var(--d), var(--d);
}

@media (prefers-reduced-motion: reduce) {
  #menu-overlay {
    animation: none;
    opacity: 1;
    transition-duration: 0.14s;
  }

  #menu-overlay.menu-restoring-from-settings,
  #menu-overlay.menu-restoring-from-stats {
    transition-duration: 0.14s;
  }

  #menu-card {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .logo-char {
    animation: none;
    filter: drop-shadow(0 0 10px rgba(168, 85, 247, 0.35));
  }
}

@keyframes logoShimmer {
  0%,
  100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

@keyframes logoFloat {
  0%,
  100% {
    transform: translateY(0) rotate(-1.4deg);
  }
  50% {
    transform: translateY(-7px) rotate(1.4deg);
  }
}

/* ── Buttons (invisible chrome: text only until hover) ── */
.menu-btn {
  position: relative;
  display: inline-block;
  cursor: pointer;
  isolation: isolate;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 11px 28px;
  background: transparent;
  user-select: none;
  text-align: center;
  text-decoration: none;
  transition: color 0.45s cubic-bezier(0.4, 0, 0.2, 1),
    border-color 0.45s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.1s ease;
}

.menu-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  z-index: -1;
  pointer-events: none;
  transition: opacity 0.5s cubic-bezier(0.33, 1, 0.68, 1);
}

.menu-btn:hover::before {
  opacity: 1;
}

.menu-btn:active {
  transform: scale(0.97);
}

.menu-btn-letter {
  display: inline-block;
  vertical-align: baseline;
}

.menu-btn-letter--space {
  width: 0.3em;
}

.menu-btn-letter--bounce {
  animation: menuBtnLetterBounce 0.2s cubic-bezier(0.34, 1.08, 0.55, 1);
}

@keyframes menuBtnLetterBounce {
  0%,
  100% {
    transform: translateY(0);
  }
  38% {
    transform: translateY(-5px);
  }
  62% {
    transform: translateY(-1.5px);
  }
  82% {
    transform: translateY(-0.5px);
  }
}

.menu-btn.primary {
  color: rgba(237, 238, 255, 0.82);
  min-width: 200px;
  animation: menuPrimaryText 4.2s ease-in-out infinite;
}

.menu-btn.primary::before {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
}

.menu-btn.primary:hover::before {
  opacity: 0.14;
}

.menu-btn.primary:hover {
  animation: none;
  color: rgba(255, 255, 255, 0.98);
  border-color: rgba(120, 130, 255, 0.2);
}

.menu-btn.secondary {
  color: rgba(158, 158, 195, 0.82);
  font-size: 13px;
  padding: 9px 20px;
  animation: menuSecondaryText 4.6s ease-in-out infinite;
}

.menu-btn.secondary::before {
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.menu-btn.secondary:hover::before {
  opacity: 0.12;
}

.menu-btn.secondary:hover {
  animation: none;
  color: rgba(230, 230, 250, 0.94);
  border-color: rgba(255, 255, 255, 0.12);
}

.menu-btn:focus-visible {
  outline: 1px solid rgba(168, 85, 247, 0.45);
  outline-offset: 3px;
}

.menu-btn:focus-visible::before {
  opacity: 0.1;
}

@keyframes menuPrimaryText {
  0%,
  100% {
    color: rgba(233, 234, 255, 0.78);
  }
  50% {
    color: rgba(244, 245, 255, 0.94);
  }
}

@keyframes menuSecondaryText {
  0%,
  100% {
    color: rgba(145, 145, 185, 0.72);
  }
  50% {
    color: rgba(175, 175, 210, 0.9);
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu-btn.primary,
  .menu-btn.secondary {
    animation: none;
  }
  .menu-btn::before {
    transition: opacity 0.25s ease;
  }
  .menu-btn-letter--bounce {
    animation: none;
  }
}

/* ── Skin upload area (settings Skin tab) ── */
#skin-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#settings-panel-skin #skin-label {
  text-align: center;
}

.skin-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 12px 10px;
  margin-bottom: 14px;
  width: 100%;
  justify-items: center;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

.skin-preview-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: transparent;
}

#skin-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#skin-name {
  color: var(--text-dim);
  font-size: 11px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  min-height: 16px;
}

/* ── Full-screen settings ── */
#settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: flex;
  /* Top-align so tab row stays a fixed distance from the viewport when panels change height */
  align-items: flex-start;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  padding-top: max(
    20px,
    env(safe-area-inset-top),
    clamp(28px, 10dvh, 88px)
  );
  box-sizing: border-box;
  background: rgba(4, 4, 10, 0.93);
  opacity: 1;
  transition: none;
}

#settings-overlay[hidden] {
  display: none !important;
}

#settings-overlay.settings-enter {
  opacity: 0;
}

#settings-overlay.settings-enter.settings-enter-active {
  opacity: 1;
  transition: opacity 0.38s ease-out;
}

#settings-overlay.settings-fade-out {
  opacity: 0;
  transition: opacity 0.38s ease-out;
  pointer-events: none;
}

/* ── Full-screen statistics (above settings if stacked) ── */
#stats-overlay {
  position: fixed;
  inset: 0;
  z-index: 255;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  padding-top: max(20px, env(safe-area-inset-top), clamp(28px, 10dvh, 88px));
  box-sizing: border-box;
  background: rgba(4, 4, 10, 0.93);
  opacity: 1;
  transition: none;
}

#stats-overlay[hidden] {
  display: none !important;
}

#stats-overlay.stats-enter {
  opacity: 0;
}

#stats-overlay.stats-enter.stats-enter-active {
  opacity: 1;
  transition: opacity 0.38s ease-out;
}

#stats-overlay.stats-fade-out {
  opacity: 0;
  transition: opacity 0.38s ease-out;
  pointer-events: none;
}

.stats-shell {
  width: min(520px, 100%);
  max-height: min(680px, calc(100dvh - 112px));
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow: hidden;
}

.stats-heading {
  font-family: 'Press Start 2P', ui-monospace, monospace;
  font-size: clamp(14px, 3.2vw, 20px);
  font-weight: 400;
  letter-spacing: 0.14em;
  line-height: 1.35;
  text-transform: uppercase;
  color: rgba(233, 234, 255, 0.88);
  text-align: center;
  margin: 0;
}

.stats-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 2px 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.stats-section {
  margin: 0;
}

.stats-section-title {
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(168, 160, 220, 0.95);
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(136, 120, 255, 0.28);
}

.stats-lifetime-sub {
  font-size: 12px;
  color: rgba(180, 182, 215, 0.82);
  letter-spacing: 0.03em;
  margin: -4px 0 12px;
}

.stats-lifetime-sub strong {
  color: rgba(210, 200, 255, 0.98);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stats-grid--wide {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.stats-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(
    165deg,
    rgba(60, 50, 95, 0.35) 0%,
    rgba(28, 26, 48, 0.55) 100%
  );
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.stats-card--compact {
  padding: 10px 12px;
}

.stats-card-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(145, 145, 185, 0.85);
}

.stats-card-value {
  font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
  font-size: 18px;
  font-weight: 700;
  color: rgba(210, 200, 255, 0.98);
  text-shadow: 0 0 18px rgba(136, 120, 255, 0.25);
}

.stats-loading,
.stats-error {
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 24px 12px;
}

.stats-error {
  color: rgba(255, 140, 160, 0.9);
}

.stats-empty {
  text-align: center;
  padding: 20px 12px 8px;
}

.stats-empty-title {
  font-size: 13px;
  font-weight: 700;
  color: rgba(220, 220, 245, 0.92);
  letter-spacing: 0.04em;
  margin: 0 0 12px;
}

.stats-empty-hint {
  font-size: 12px;
  line-height: 1.55;
  color: rgba(160, 162, 195, 0.88);
  margin: 0;
  max-width: 340px;
  margin-left: auto;
  margin-right: auto;
}

.stats-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding-top: 4px;
}

.stats-actions .menu-btn.secondary {
  min-width: 120px;
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}

.settings-shell {
  width: min(420px, 100%);
  max-height: min(640px, calc(100dvh - 112px));
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
}

.settings-heading {
  font-family: 'Press Start 2P', ui-monospace, monospace;
  font-size: clamp(14px, 3.2vw, 20px);
  font-weight: 400;
  letter-spacing: 0.14em;
  line-height: 1.35;
  text-transform: uppercase;
  color: rgba(233, 234, 255, 0.88);
  text-align: center;
}

.settings-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.settings-tab {
  flex: 1;
  min-width: 0;
  padding: 10px 6px;
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(145, 145, 185, 0.65);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.settings-tab:hover {
  color: rgba(200, 200, 230, 0.9);
}

.settings-tab:focus-visible {
  outline: 1px solid rgba(168, 85, 247, 0.45);
  outline-offset: 2px;
}

.settings-tab[aria-selected='true'] {
  color: rgba(233, 213, 255, 0.95);
  border-bottom-color: rgba(136, 120, 255, 0.65);
}

.settings-tab-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 2px 8px;
}

.settings-panel-intro {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  margin-bottom: 14px;
}

.settings-controls-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-control-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.settings-control-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-control-label {
  font-size: 13px;
  color: rgba(220, 220, 245, 0.88);
  letter-spacing: 0.02em;
}

.settings-control-key {
  font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: rgba(196, 181, 253, 0.95);
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.04);
  white-space: nowrap;
}

.settings-audio-block {
  margin-bottom: 22px;
}

.settings-audio-block:last-child {
  margin-bottom: 0;
}

.settings-audio-block .settings-volume-label {
  margin-bottom: 10px;
}

.settings-volume-label {
  display: block;
  font-size: 13px;
  color: rgba(220, 220, 245, 0.88);
  letter-spacing: 0.04em;
}

.settings-volume-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.settings-volume-slider {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  appearance: none;
  background: rgba(255, 255, 255, 0.1);
  accent-color: var(--accent);
}

.settings-volume-slider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  cursor: pointer;
  box-shadow: 0 0 12px rgba(85, 102, 221, 0.45);
}

.settings-volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  cursor: pointer;
}

.settings-volume-value {
  font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  color: rgba(196, 181, 253, 0.9);
  min-width: 3ch;
  text-align: right;
}

/* ── Account tab (sign up / log in) ── */
.settings-account-signed-in {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid rgba(136, 120, 255, 0.35);
  background: rgba(255, 255, 255, 0.04);
}

.settings-account-signed-in[hidden] {
  display: none !important;
}

.settings-account-signed-text {
  font-size: 12px;
  color: rgba(220, 220, 245, 0.92);
  letter-spacing: 0.03em;
}

#settings-account-username {
  color: rgba(196, 181, 253, 0.98);
  font-weight: 700;
  font-style: normal;
}

.settings-account-logout {
  flex-shrink: 0;
  min-width: 100px;
  padding: 8px 14px;
  font-size: 10px;
}

/* Two-column layout: Create account | divider | Log in */
.settings-account-forms-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 0 16px;
  align-items: start;
}

/* `display: grid` would otherwise override the [hidden] attribute */
.settings-account-forms-grid[hidden] {
  display: none !important;
}

.settings-account-divider {
  width: 1px;
  align-self: stretch;
  background: rgba(255, 255, 255, 0.08);
  margin-top: 36px;
}

.settings-account-block {
  margin-bottom: 0;
}

.settings-account-heading {
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(200, 200, 230, 0.85);
  margin: 0 0 12px;
}

.settings-account-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-account-label {
  font-size: 12px;
  color: rgba(220, 220, 245, 0.88);
  letter-spacing: 0.03em;
}

.settings-account-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
  font-size: 13px;
  color: rgba(233, 234, 255, 0.95);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.settings-account-input::placeholder {
  color: rgba(145, 145, 185, 0.45);
}

.settings-account-input:focus {
  border-color: rgba(136, 120, 255, 0.55);
  box-shadow: 0 0 0 2px rgba(136, 120, 255, 0.2);
}

.settings-account-submit {
  align-self: flex-start;
  margin-top: 4px;
}

.settings-account-status {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  min-height: 1.2em;
  margin: 8px 0 0;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.settings-account-status.fading {
  opacity: 0;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding-top: 8px;
}

.settings-actions .menu-btn.secondary {
  min-width: 120px;
}

@media (prefers-reduced-motion: reduce) {
  #settings-overlay.settings-enter.settings-enter-active {
    transition-duration: 0.14s;
  }

  #settings-overlay.settings-fade-out {
    transition-duration: 0.14s;
  }

  #stats-overlay.stats-enter.stats-enter-active {
    transition-duration: 0.14s;
  }

  #stats-overlay.stats-fade-out {
    transition-duration: 0.14s;
  }
}
