/**
 * The Maze Game — "Wayfinder" UI.
 * Ink + blueprint-grid backdrop, lime as the dominant accent (paths / GO),
 * coral as the rare sharp punch (the player), cyan for info. Syne display,
 * Sora UI, JetBrains Mono for tabular HUD numerals.
 *
 * @author Son Nguyen <hoangson091104@gmail.com>
 */

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

:root {
  --ink: #0b0e11;
  --ink-2: #0e1318;
  --surface: rgba(255, 255, 255, 0.025);
  --surface-2: rgba(255, 255, 255, 0.05);
  --surface-3: rgba(255, 255, 255, 0.085);
  --line: rgba(255, 255, 255, 0.08);
  --line-lime: rgba(198, 242, 78, 0.22);
  --lime: #c6f24e;
  --lime-deep: #9bd61f;
  --coral: #ff6a4d;
  --cyan: #45e0ff;
  --gold: #ffd24a;
  --text: #eef2ea;
  --muted: #8b978c;
  --muted-2: #69756c;

  --r-card: 14px;
  --r-btn: 11px;
  --shadow: 0 14px 34px -16px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 26px 60px -20px rgba(0, 0, 0, 0.75);
  --glow-lime: 0 0 0 1px rgba(198, 242, 78, 0.35), 0 14px 30px -12px rgba(198, 242, 78, 0.3);

  /* Theme-aware backdrop glows (overridden per body.<theme>-theme) */
  --glow-1: rgba(198, 242, 78, 0.12);
  --glow-2: rgba(69, 224, 255, 0.09);

  --font-display: "Bricolage Grotesque", sans-serif;
  --font-ui: "Sora", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

body {
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Atmosphere: corner glows + a blueprint dot grid that fades toward the edges */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background: radial-gradient(900px 520px at 10% -8%, var(--glow-1), transparent 60%),
    radial-gradient(820px 620px at 102% 112%, var(--glow-2), transparent 55%), var(--ink);
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 26px 26px;
  -webkit-mask-image: radial-gradient(ellipse 85% 80% at 50% 25%, #000 35%, transparent 100%);
  mask-image: radial-gradient(ellipse 85% 80% at 50% 25%, #000 35%, transparent 100%);
}

/* ----- Header ----- */
.game-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 14, 17, 0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0.95rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  color: var(--line-lime);
  background: linear-gradient(160deg, rgba(198, 242, 78, 0.12), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--line-lime);
  box-shadow: inset 0 0 18px rgba(198, 242, 78, 0.08);
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: -0.025em;
  color: var(--text);
}
.brand-name em {
  font-style: normal;
  color: var(--lime);
}
.brand-tag {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.3rem;
}
.header-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}
.header-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 10px var(--lime);
  animation: pulse-dot 2.4s ease-in-out infinite;
}
/* Installable-PWA button (shown only when the browser offers an install prompt) */
.install-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.74rem;
  letter-spacing: 0.01em;
  color: var(--ink);
  cursor: pointer;
  padding: 0.42rem 0.85rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: linear-gradient(95deg, var(--lime-deep), var(--lime));
  box-shadow: var(--glow-lime);
  transition:
    transform 0.15s ease,
    filter 0.15s ease;
}
.install-btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}
.install-btn[hidden] {
  display: none;
}
@keyframes pulse-dot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* ----- Layout ----- */
.main-container {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.75rem;
  max-width: 1500px;
  margin: 2rem auto;
  padding: 0 2rem;
  align-items: start;
}
.stats-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ----- Panels ----- */
.panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 1.25rem 1.3rem;
  box-shadow: var(--shadow);
}
.panel h3 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1rem;
}
.panel h3 .tick {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--lime);
  box-shadow: 0 0 10px rgba(198, 242, 78, 0.6);
}

/* HUD timer */
.hud-timer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.5rem 0 1rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}
.hud-timer-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.hud-timer-value {
  font-family: var(--font-mono);
  font-size: 2.1rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
}
.stat-item:last-child {
  border-bottom: 0;
}
.stat-label {
  color: var(--muted);
  font-size: 0.85rem;
}
.stat-value {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.stat-value.accent {
  color: var(--lime);
}

/* ----- Settings ----- */
.setting-item {
  margin-bottom: 0.95rem;
}
.setting-item:last-child {
  margin-bottom: 0;
}
.setting-item > label {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}
.select-wrap {
  position: relative;
}
.select-wrap::after {
  content: "";
  position: absolute;
  right: 0.9rem;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}
.setting-control {
  width: 100%;
  padding: 0.62rem 0.8rem;
  border-radius: var(--r-btn);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.setting-control:hover {
  border-color: var(--line-lime);
}
.setting-control:focus {
  outline: none;
  border-color: var(--lime);
  box-shadow: 0 0 0 3px rgba(198, 242, 78, 0.18);
}
.setting-control option {
  background: var(--ink-2);
  color: var(--text);
}

.setting-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.setting-inline > label {
  margin-bottom: 0;
}

/* Toggle switch */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 27px;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  transition:
    background 0.22s,
    border-color 0.22s;
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #c7cec2;
  transition:
    transform 0.22s,
    background 0.22s;
}
.switch input:checked + .switch-track {
  background: linear-gradient(90deg, var(--lime-deep), var(--lime));
  border-color: transparent;
}
.switch input:checked + .switch-track .switch-thumb {
  transform: translateX(21px);
  background: var(--ink);
}
.switch input:focus-visible + .switch-track {
  box-shadow: 0 0 0 3px rgba(198, 242, 78, 0.25);
}

/* ----- Action buttons (Explore) ----- */
.action-button {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--r-btn);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition:
    transform 0.18s,
    border-color 0.18s,
    background 0.18s;
}
.action-button::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--lime);
  transform: scaleY(0);
  transform-origin: bottom;
  transition: transform 0.2s;
}
.action-button:last-child {
  margin-bottom: 0;
}
.action-button:hover {
  transform: translateX(4px);
  border-color: var(--line-lime);
  background: color-mix(in srgb, var(--lime) 9%, transparent);
}
.action-button:hover .ab-ico {
  color: var(--lime);
  border-color: var(--line-lime);
  background: color-mix(in srgb, var(--lime) 12%, transparent);
}
.action-button:hover::before {
  transform: scaleY(1);
}
.ab-ico {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition:
    color 0.18s,
    background 0.18s,
    border-color 0.18s;
}
.ab-ico svg {
  width: 17px;
  height: 17px;
  display: block;
}
.ab-label {
  flex: 1;
}

/* ----- Game area ----- */
.game-area {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}
.game-canvas-container {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 1.75rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 360px;
}
.game-canvas-container::before {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 40px;
  background: radial-gradient(circle at 50% 50%, rgba(198, 242, 78, 0.12), transparent 70%);
  filter: blur(38px);
  z-index: 0;
}
#mazeCanvas {
  position: relative;
  z-index: 1;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 18px 40px -16px rgba(0, 0, 0, 0.7);
  max-width: 100%;
  height: auto;
  touch-action: none;
}
.corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-lime);
  z-index: 2;
}
.corner.tl {
  top: 12px;
  left: 12px;
  border-right: 0;
  border-bottom: 0;
  border-top-left-radius: 4px;
}
.corner.tr {
  top: 12px;
  right: 12px;
  border-left: 0;
  border-bottom: 0;
  border-top-right-radius: 4px;
}
.corner.bl {
  bottom: 12px;
  left: 12px;
  border-right: 0;
  border-top: 0;
  border-bottom-left-radius: 4px;
}
.corner.br {
  bottom: 12px;
  right: 12px;
  border-left: 0;
  border-top: 0;
  border-bottom-right-radius: 4px;
}

/* Start gate — see-through overlay + Play button over the frozen maze */
.start-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  border-radius: var(--r-card);
  background: color-mix(in srgb, var(--ink) 42%, transparent);
  backdrop-filter: blur(1px);
  transition:
    opacity 0.3s,
    visibility 0.3s;
}
.start-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.start-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--ink);
  background: linear-gradient(95deg, var(--lime-deep), var(--lime));
  border: none;
  border-radius: 999px;
  padding: 0.8rem 2.2rem;
  cursor: pointer;
  box-shadow:
    0 16px 36px -14px var(--lime),
    0 0 0 6px color-mix(in srgb, var(--lime) 18%, transparent);
  transition:
    transform 0.16s,
    box-shadow 0.2s;
  animation: start-pulse 2.2s ease-in-out infinite;
}
.start-btn svg {
  width: 22px;
  height: 22px;
  display: block;
}
.start-btn:hover {
  transform: scale(1.05);
}
@keyframes start-pulse {
  0%,
  100% {
    box-shadow:
      0 16px 36px -14px var(--lime),
      0 0 0 6px color-mix(in srgb, var(--lime) 18%, transparent);
  }
  50% {
    box-shadow:
      0 16px 36px -14px var(--lime),
      0 0 0 13px color-mix(in srgb, var(--lime) 5%, transparent);
  }
}
.start-hint {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--text);
  background: color-mix(in srgb, var(--ink) 72%, transparent);
  border: 1px solid var(--line);
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  text-align: center;
}

/* ----- Controls ----- */
.game-controls {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.control-group {
  flex: 1;
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 1.3rem;
  box-shadow: var(--shadow);
}
.control-group h4 {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.1rem;
  text-align: center;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-auto-rows: 56px;
  gap: 0.5rem;
  width: max-content;
  margin: 0 auto;
}
#moveUp {
  grid-column: 2;
  grid-row: 1;
}
#moveLeft {
  grid-column: 1;
  grid-row: 2;
}
#moveDown {
  grid-column: 2;
  grid-row: 2;
}
#moveRight {
  grid-column: 3;
  grid-row: 2;
}

.control-btn {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-btn);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition:
    transform 0.12s,
    background 0.18s,
    border-color 0.18s,
    box-shadow 0.18s;
}
.control-btn svg {
  width: 26px;
  height: 26px;
  display: block;
}
.control-btn:hover {
  background: rgba(198, 242, 78, 0.1);
  border-color: var(--line-lime);
  color: var(--lime);
  box-shadow: var(--glow-lime);
}
.control-btn:active {
  transform: scale(0.92);
}

.control-hint {
  text-align: center;
  color: var(--muted-2);
  font-size: 0.78rem;
  margin-top: 1rem;
}
kbd {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.05rem 0.4rem;
  color: var(--text);
}

.action-controls {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.72rem 1.2rem;
  border: 1px solid transparent;
  border-radius: var(--r-btn);
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  --accent: var(--lime);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  border-color: color-mix(in srgb, var(--accent) 34%, transparent);
  transition:
    transform 0.16s,
    box-shadow 0.18s,
    background 0.18s;
}
.action-btn .btn-ico {
  display: grid;
  place-items: center;
}
.action-btn .btn-ico svg {
  width: 18px;
  height: 18px;
  display: block;
}
.pause-btn {
  --accent: var(--cyan);
}
.hint-btn {
  --accent: var(--lime);
}
.regen-btn {
  --accent: var(--coral);
}
.action-btn:hover {
  transform: translateY(-2px);
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  box-shadow: 0 10px 22px -14px var(--accent);
}
.action-btn:active {
  transform: translateY(0);
}
.action-controls.is-pre-run {
  position: relative;
}
.action-controls.is-pre-run::after {
  content: "Press Play to unlock";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border: 1px dashed color-mix(in srgb, var(--line) 90%, transparent);
  border-radius: var(--r-btn);
  pointer-events: none;
}
.action-btn.is-locked,
.action-btn:disabled {
  cursor: not-allowed !important;
  pointer-events: none;
  opacity: 0.28;
  filter: grayscale(1);
  transform: none !important;
  box-shadow: none !important;
  color: var(--muted) !important;
  background: color-mix(in srgb, var(--muted) 6%, var(--surface-2)) !important;
  border-color: color-mix(in srgb, var(--line) 70%, transparent) !important;
}
.action-btn.is-locked .btn-ico svg,
.action-btn:disabled .btn-ico svg {
  opacity: 0.55;
}
.action-btn.is-locked:hover,
.action-btn.is-locked:active,
.action-btn:disabled:hover,
.action-btn:disabled:active {
  transform: none !important;
  box-shadow: none !important;
  background: color-mix(in srgb, var(--muted) 6%, var(--surface-2)) !important;
}
/* Pause/Play icon swap (selectors specific enough to beat .btn-ico svg) */
.action-btn .btn-ico .ico-play {
  display: none;
}
#pauseGame.paused .btn-ico .ico-pause {
  display: none;
}
#pauseGame.paused .btn-ico .ico-play {
  display: block;
}

/* ----- Reveal animation ----- */
@keyframes reveal-up {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.reveal {
  opacity: 0;
  animation: reveal-up 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
  animation-delay: calc(var(--d, 0) * 80ms);
}

/* ----- Win modal ----- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 9, 11, 0.82);
  backdrop-filter: blur(6px);
  justify-content: center;
  align-items: center;
  z-index: 1100;
}
.modal-overlay.show {
  display: flex;
}
.win-fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}
.modal-box {
  position: relative;
  z-index: 2;
  background: linear-gradient(165deg, #11161c, #0a0d11);
  border: 1px solid var(--line-lime);
  border-radius: 20px;
  padding: 2.5rem 2.75rem;
  text-align: center;
  max-width: 92%;
  width: 460px;
  box-shadow:
    var(--shadow-lg),
    0 0 60px -20px rgba(198, 242, 78, 0.4);
  animation: popIn 0.34s cubic-bezier(0.2, 0.8, 0.2, 1.05);
}
@keyframes popIn {
  from {
    transform: scale(0.86) translateY(10px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
.win-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--lime);
  padding: 0.32rem 0.85rem;
  border-radius: 999px;
  margin-bottom: 1.1rem;
}
.modal-box h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.85rem;
  letter-spacing: -0.01em;
  margin-bottom: 1.75rem;
  color: var(--text);
}
.win-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
  margin-bottom: 1.9rem;
}
.win-stats div {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.win-stat-wide {
  grid-column: 1 / -1;
}
.win-stats span {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.win-stats strong {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--lime);
  font-variant-numeric: tabular-nums;
}
.win-stat-wide strong {
  color: var(--text);
  font-size: 1.1rem;
}
.hint-modal-box {
  width: 420px;
}
.hint-modal-text {
  text-align: left;
  margin-bottom: 1.5rem;
  line-height: 1.55;
}
.hint-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.hint-actions .auth-submit,
.hint-actions .ghost-btn {
  width: 100%;
}

#playAgain {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(95deg, var(--lime-deep), var(--lime));
  color: var(--ink);
  border: none;
  padding: 0.85rem 2rem;
  border-radius: var(--r-btn);
  cursor: pointer;
  transition:
    transform 0.16s,
    box-shadow 0.2s;
}
#playAgain:hover {
  transform: translateY(-2px);
  box-shadow: var(--glow-lime);
}

/* ----- Toast (game.js flashMessage) ----- */
#toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(18px);
  background: rgba(14, 19, 24, 0.96);
  color: var(--text);
  padding: 0.75rem 1.4rem;
  border-radius: var(--r-btn);
  border: 1px solid var(--line-lime);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s,
    transform 0.25s;
  z-index: 1200;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ----- Generic modals (leaderboard / achievements / help) ----- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow: auto;
  background: rgba(7, 9, 11, 0.8);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
.modal-content {
  background: linear-gradient(165deg, #11161c, #0a0d11);
  border: 1px solid var(--line);
  margin: 6vh auto;
  padding: 2rem;
  border-radius: var(--r-card);
  width: 90%;
  max-width: 880px;
  max-height: 82vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.3s ease;
}
.close {
  color: var(--muted);
  float: right;
  font-size: 1.9rem;
  line-height: 1;
  cursor: pointer;
  transition: color 0.2s;
}
.close:hover {
  color: var(--coral);
}
.modal-content h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

/* Leaderboard */
.leaderboard-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.tab-btn {
  flex: 1;
  min-width: 90px;
  padding: 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--r-btn);
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
}
.tab-btn:hover {
  color: var(--text);
  border-color: var(--line-lime);
}
.tab-btn.active {
  background: var(--lime);
  color: var(--ink);
  border-color: transparent;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.leaderboard-table thead {
  background: var(--surface-2);
}
.leaderboard-table th {
  padding: 0.85rem 1rem;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.leaderboard-table td {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.leaderboard-table tr:hover {
  background: rgba(255, 255, 255, 0.03);
}
.top-rank {
  background: rgba(198, 242, 78, 0.05);
}
.rank-1 {
  border-left: 3px solid var(--gold);
}
.rank-2 {
  border-left: 3px solid #cfd6cb;
}
.rank-3 {
  border-left: 3px solid var(--coral);
}
.rank-cell {
  font-size: 1.05rem;
  font-weight: 700;
  font-family: var(--font-mono);
}
.player-cell {
  font-weight: 600;
}
.score-cell {
  font-weight: 700;
  color: var(--lime);
  font-family: var(--font-mono);
}
.time-cell {
  font-family: var(--font-mono);
}
.difficulty-badge {
  display: inline-block;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
}
.difficulty-badge.easy {
  background: rgba(198, 242, 78, 0.16);
  color: var(--lime);
}
.difficulty-badge.medium {
  background: rgba(255, 210, 74, 0.16);
  color: var(--gold);
}
.difficulty-badge.hard {
  background: rgba(255, 106, 77, 0.16);
  color: var(--coral);
}
.difficulty-badge.expert {
  background: rgba(69, 224, 255, 0.16);
  color: var(--cyan);
}

/* Achievements */
.achievements-header {
  text-align: center;
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}
.achievements-header h3 {
  color: var(--lime);
  margin-bottom: 0.35rem;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}
.achievements-header p {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
}
.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}
@media (max-width: 480px) {
  .achievements-grid {
    grid-template-columns: 1fr;
  }
}
.achievement-card {
  display: flex;
  gap: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: 1.25rem;
  transition:
    transform 0.18s,
    box-shadow 0.18s;
}
.achievement-card.unlocked {
  border-color: var(--line-lime);
  background: rgba(198, 242, 78, 0.05);
}
.achievement-card.locked {
  opacity: 0.5;
  filter: grayscale(80%);
}
.achievement-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}
.achievement-icon {
  font-size: 2.5rem;
  line-height: 1;
}
.achievement-info h4 {
  margin-bottom: 0.35rem;
  color: var(--text);
  font-size: 1rem;
}
.achievement-info p {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.achievement-points {
  display: inline-block;
  padding: 0.18rem 0.5rem;
  background: var(--lime);
  color: var(--ink);
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
}
.achievement-date {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--lime);
  font-family: var(--font-mono);
}
.achievement-locked {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--muted-2);
}

/* Help */
.help-content {
  line-height: 1.75;
}
.help-content section {
  margin-bottom: 1.75rem;
}
.help-content h3 {
  color: var(--lime);
  margin-bottom: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.help-content ul {
  list-style: none;
}
.help-content li {
  margin-bottom: 0.5rem;
  padding-left: 1.1rem;
  position: relative;
  color: var(--text);
}
.help-content li::before {
  content: "▸";
  position: absolute;
  left: 0;
  color: var(--lime);
}
.help-content strong {
  color: var(--text);
}
.hl-coral {
  color: var(--coral);
  font-weight: 600;
}
.hl-lime {
  color: var(--lime);
  font-weight: 600;
}

/* States */
.loading,
.no-data {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-style: italic;
}
.error {
  text-align: center;
  padding: 2rem;
  color: var(--coral);
}

/* Footer */
.game-footer {
  text-align: center;
  margin-top: 3rem;
  padding: 1.75rem 1rem;
  border-top: 1px solid var(--line);
}
.game-footer p {
  color: var(--muted-2);
  font-size: 0.82rem;
  font-family: var(--font-mono);
}
.game-footer a {
  color: var(--lime);
  text-decoration: none;
}
.game-footer a:hover {
  text-decoration: underline;
}

/* About page (legacy markup) */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 720px;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
  color: var(--text);
}
.game-container h2 {
  font-family: var(--font-display);
  margin: 1.25rem 0 0.5rem;
}
.game-container p {
  color: var(--muted);
  line-height: 1.7;
}
.game-container button {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line-lime);
  padding: 0.6rem 1.4rem;
  border-radius: var(--r-btn);
  cursor: pointer;
  transition:
    transform 0.16s,
    background 0.18s;
}
.game-container button:hover {
  transform: translateY(-2px);
  background: rgba(198, 242, 78, 0.08);
}

/* ----- Auth: header chip + sign-in ----- */
.header-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.signin-btn {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--lime);
  border: none;
  border-radius: 999px;
  padding: 0.45rem 1.1rem;
  cursor: pointer;
  transition:
    transform 0.16s,
    box-shadow 0.18s;
}
.signin-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--glow-lime);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.3rem 0.8rem 0.3rem 0.3rem;
  cursor: pointer;
  transition:
    border-color 0.18s,
    background 0.18s;
}
.user-chip:hover {
  border-color: var(--line-lime);
  background: rgba(198, 242, 78, 0.06);
}
.user-avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--lime-deep), var(--lime));
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.95rem;
}
.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
  text-align: left;
}
.user-name {
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
}
.user-lvl {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
}

/* ----- Auth modal ----- */
.modal-narrow {
  max-width: 420px;
}
.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.auth-tab {
  flex: 1;
  padding: 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--r-btn);
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.18s;
}
.auth-tab.active {
  background: var(--lime);
  color: var(--ink);
  border-color: transparent;
}
.field {
  margin-bottom: 1rem;
}
.field label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.auth-error {
  color: var(--coral);
  font-size: 0.85rem;
  margin: 0 0 1rem;
  padding: 0.6rem 0.8rem;
  background: rgba(255, 106, 77, 0.1);
  border: 1px solid rgba(255, 106, 77, 0.3);
  border-radius: var(--r-btn);
}
.auth-submit {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(95deg, var(--lime-deep), var(--lime));
  border: none;
  border-radius: var(--r-btn);
  padding: 0.8rem;
  cursor: pointer;
  transition:
    transform 0.16s,
    box-shadow 0.2s;
}
.auth-submit:hover {
  transform: translateY(-2px);
  box-shadow: var(--glow-lime);
}
.auth-submit:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Password field with show/hide toggle */
.password-field {
  position: relative;
}
.password-field .setting-control {
  padding-right: 2.8rem;
}
.pw-toggle {
  position: absolute;
  top: 50%;
  right: 0.5rem;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition:
    color 0.18s,
    background 0.18s;
}
.pw-toggle:hover {
  color: var(--lime);
  background: rgba(198, 242, 78, 0.08);
}
.pw-toggle svg {
  display: block;
  pointer-events: none;
}
/* "Hidden" state strikes the eye, so revealed = open eye */
.pw-toggle::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transform: rotate(-45deg);
  transition: opacity 0.15s;
}
.pw-toggle.revealed::after {
  opacity: 0;
}

.auth-links {
  display: flex;
  justify-content: space-between;
  margin-top: 1rem;
  font-size: 0.85rem;
}
.auth-links a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.18s;
}
.auth-links a:hover {
  color: var(--lime);
}

/* ----- Profile ----- */
.profile-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
}
.profile-avatar {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--lime-deep), var(--lime));
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.8rem;
}
.profile-id {
  flex: 1;
  min-width: 220px;
}
.profile-id h3 {
  font-family: var(--font-display);
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
}
.level-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.level-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  color: var(--ink);
  background: var(--lime);
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}
.level-bar {
  flex: 1;
  min-width: 90px;
}
.level-next {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}
.bar {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--cyan);
  transition: width 0.5s ease;
}
.bar-fill.lime {
  background: linear-gradient(90deg, var(--lime-deep), var(--lime));
}
.profile-footer {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
}
.logout-btn {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--coral);
  background: color-mix(in srgb, var(--coral) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--coral) 32%, transparent);
  border-radius: var(--r-btn);
  padding: 0.7rem 1rem;
  cursor: pointer;
  transition:
    background 0.18s,
    transform 0.16s;
}
.logout-btn:hover {
  transform: translateY(-1px);
  background: color-mix(in srgb, var(--coral) 18%, transparent);
}
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.7rem;
  margin-bottom: 1.75rem;
}
.pstat {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.pstat-val {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--lime);
  font-variant-numeric: tabular-nums;
}
.pstat-lbl {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.profile-sub {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 2rem 0 0.9rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}
.profile-sub:first-of-type {
  margin-top: 0;
}
.diff-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.75rem;
  font-size: 0.9rem;
}
.diff-table th {
  text-align: left;
  padding: 0.5rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.diff-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.diff-table .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.diff-table .cap,
.recent-list .cap {
  text-transform: capitalize;
  color: var(--text);
  font-weight: 600;
}
.bar-cell {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 120px;
}
.bar-cell .bar {
  flex: 1;
}
.bar-cell .wr {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}
.recent-list {
  list-style: none;
}
.recent-list li {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.6rem 0.75rem;
  border-radius: var(--r-btn);
  background: var(--surface-2);
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--muted-2);
  font-size: 0.85rem;
}
.recent-list li.win {
  border-left-color: var(--lime);
}
.recent-list li.loss {
  border-left-color: var(--coral);
}
.recent-list .num {
  font-family: var(--font-mono);
  color: var(--muted);
}

/* ----- Guest-name modal + profile editing ----- */
.modal-sub {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 1.25rem;
}
.name-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.5rem;
}
.name-actions .auth-submit {
  flex: 1;
}
.ghost-btn {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-btn);
  padding: 0.8rem;
  cursor: pointer;
  transition:
    border-color 0.18s,
    background 0.18s;
}
.ghost-btn:hover {
  border-color: var(--line-lime);
  background: rgba(198, 242, 78, 0.06);
}
.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.auth-submit.slim {
  width: auto;
  padding: 0.6rem 1.3rem;
  margin-top: 0.25rem;
}
.profile-msg {
  margin-top: 0.9rem;
  font-size: 0.85rem;
  color: var(--lime);
  font-family: var(--font-mono);
}
.profile-msg.error {
  color: var(--coral);
}
@media (max-width: 600px) {
  .edit-grid {
    grid-template-columns: 1fr;
  }
}

/* ----- Themes (page chrome) -----
 * Each theme overrides the accent palette, the ink tint, and the two backdrop
 * glows. The canvas palettes live in src/js/game.js (this.themes). */
body.dark-theme {
  --ink: #050608;
  --ink-2: #0a0c0e;
  --glow-1: rgba(198, 242, 78, 0.08);
  --glow-2: rgba(69, 224, 255, 0.06);
}
body.neon-theme {
  --lime: #00ffd5;
  --lime-deep: #00c8a8;
  --coral: #ff2d9b;
  --cyan: #38f0ff;
  --gold: #ffe14a;
  --ink: #05010f;
  --ink-2: #0c0322;
  --line-lime: rgba(0, 255, 213, 0.3);
  --glow-1: rgba(0, 255, 213, 0.14);
  --glow-2: rgba(255, 45, 155, 0.12);
}
body.forest-theme {
  --lime: #6fe08a;
  --lime-deep: #3fb866;
  --coral: #ffb24a;
  --cyan: #5fd9c0;
  --gold: #ffd24a;
  --ink: #0a140e;
  --ink-2: #0e1c13;
  --line-lime: rgba(111, 224, 138, 0.26);
  --glow-1: rgba(111, 224, 138, 0.12);
  --glow-2: rgba(255, 178, 74, 0.08);
}
body.sunset-theme {
  --lime: #ff9e6d;
  --lime-deep: #ff6f5e;
  --coral: #ff5d8f;
  --cyan: #ffd36e;
  --gold: #ffd36e;
  --ink: #1a0e1c;
  --ink-2: #241326;
  --line-lime: rgba(255, 158, 109, 0.28);
  --glow-1: rgba(255, 158, 109, 0.15);
  --glow-2: rgba(255, 93, 143, 0.12);
}
body.ocean-theme {
  --lime: #3ad0ff;
  --lime-deep: #2a9fd6;
  --coral: #ff7a8a;
  --cyan: #7af0d0;
  --gold: #ffd166;
  --ink: #06121f;
  --ink-2: #0a1c2e;
  --line-lime: rgba(58, 208, 255, 0.26);
  --glow-1: rgba(58, 208, 255, 0.13);
  --glow-2: rgba(122, 240, 208, 0.1);
}
body.dracula-theme {
  --lime: #bd93f9;
  --lime-deep: #9d6ff0;
  --coral: #ff79c6;
  --cyan: #8be9fd;
  --gold: #f1fa8c;
  --ink: #1a1b26;
  --ink-2: #21222c;
  --line-lime: rgba(189, 147, 249, 0.3);
  --glow-1: rgba(189, 147, 249, 0.14);
  --glow-2: rgba(139, 233, 253, 0.1);
}
body.mono-theme {
  --lime: #ffb000;
  --lime-deep: #d98e00;
  --coral: #d9886a;
  --cyan: #b0b0b0;
  --gold: #ffb000;
  --ink: #0a0a0a;
  --ink-2: #121212;
  --text: #f1f1f1;
  --muted: #8c8c8c;
  --line: rgba(255, 255, 255, 0.1);
  --line-lime: rgba(255, 176, 0, 0.26);
  --glow-1: rgba(255, 176, 0, 0.1);
  --glow-2: rgba(255, 255, 255, 0.05);
}
body.candy-theme {
  --lime: #ff8fcf;
  --lime-deep: #ff6fb5;
  --coral: #ff6f91;
  --cyan: #7ce0ff;
  --gold: #ffd24a;
  --ink: #20132a;
  --ink-2: #2a1838;
  --line-lime: rgba(255, 143, 207, 0.28);
  --glow-1: rgba(255, 143, 207, 0.15);
  --glow-2: rgba(124, 224, 255, 0.12);
}
body.volcano-theme {
  --lime: #ff6a3d;
  --lime-deep: #e8431f;
  --coral: #ff3b2f;
  --cyan: #ffb24a;
  --gold: #ffd24a;
  --ink: #160807;
  --ink-2: #1f0c09;
  --line-lime: rgba(255, 106, 61, 0.3);
  --glow-1: rgba(255, 106, 61, 0.16);
  --glow-2: rgba(255, 178, 74, 0.1);
}

/* ----- Responsive ----- */
/* Stack the sidebar under the game on tablets and below. */
@media (max-width: 1080px) {
  .main-container {
    grid-template-columns: 1fr;
  }
  .stats-sidebar {
    order: 2;
  }
  .game-area {
    order: 1;
  }
  .game-canvas-container {
    min-height: 0;
  }
}

/* Phones */
@media (max-width: 600px) {
  .header-inner {
    padding: 0.7rem 1rem;
    gap: 0.5rem;
  }
  .brand {
    gap: 0.6rem;
  }
  .brand-mark {
    width: 40px;
    height: 40px;
  }
  .brand-name {
    font-size: 1.15rem;
  }
  .brand-tag {
    font-size: 0.55rem;
    letter-spacing: 0.12em;
  }
  /* Hide the version chip but KEEP the sign-in / profile control. */
  .header-pill {
    display: none;
  }
  .main-container {
    padding: 0 0.85rem;
    margin: 1rem auto;
    gap: 1rem;
  }
  .panel,
  .control-group {
    padding: 1.1rem;
  }
  .game-canvas-container {
    padding: 0.75rem;
    min-height: 0;
  }
  .game-controls {
    flex-direction: column;
    gap: 1rem;
  }
  .control-group {
    min-width: 100%;
  }
  .hud-timer-value {
    font-size: 1.9rem;
  }
  .modal-content {
    width: 94%;
    padding: 1.25rem;
    margin: 4vh auto;
    max-height: 90vh;
  }
  .modal-box {
    width: auto;
    max-width: 94%;
    padding: 1.6rem 1.3rem;
  }
  .win-stats {
    grid-template-columns: 1fr 1fr;
  }
  .edit-grid {
    grid-template-columns: 1fr;
  }
  .leaderboard-tabs {
    flex-wrap: wrap;
  }
  /* Let wide tables scroll instead of squishing. */
  .leaderboard-list,
  .diff-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .leaderboard-table {
    min-width: 460px;
  }
  .diff-table {
    min-width: 420px;
  }
}

/* Small phones */
@media (max-width: 380px) {
  .brand-name {
    font-size: 1.02rem;
  }
  .control-btn {
    width: 52px;
    height: 52px;
  }
  .dpad {
    grid-template-columns: repeat(3, 52px);
    grid-auto-rows: 52px;
  }
  .win-stats {
    grid-template-columns: 1fr;
  }
  .profile-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ----- Accessibility ----- */
:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 2px;
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}
@media (prefers-contrast: high) {
  :root {
    --text: #ffffff;
    --muted: #c8c8c8;
    --line: rgba(255, 255, 255, 0.25);
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .reveal {
    opacity: 1;
  }
}
