:root {
  /* --bg-color and --accent-rgb are overridden by JS each game from the rolled
     palette, so the HUD/overlays harmonise with the field. Defaults below match
     the original look for the first paint. */
  --accent-rgb: 124, 77, 255;
  --bg-color: #0d0e12;
  --panel-bg: rgba(26, 29, 38, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  --accent-color: rgb(var(--accent-rgb));
  --accent-glow: rgba(var(--accent-rgb), 0.4);
  --text-primary: #f0f2f5;
  --text-secondary: #9099a8;
  --shadow-color: rgba(0, 0, 0, 0.5);
  --card-border: 1px solid rgba(255, 255, 255, 0.05);
}

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

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(var(--accent-rgb), 0.05) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(var(--accent-rgb), 0.05) 0%, transparent 40%);
  transition: background-color 0.6s ease;
}

/* The frame must fit the viewport: the page never scrolls (body is
   overflow:hidden), so anything that doesn't fit is simply unreachable. Before
   this, a 1280×720 laptop lost the footer buttons, 84px of the field, and the
   third mode button entirely. dvh keeps mobile browser chrome out of it. */
.game-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  padding: 16px;
}

.game-header {
  width: 100%;
  margin-bottom: 12px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: var(--card-border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 32px var(--shadow-color);
}

.logo {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-align: center;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.logo .highlight {
  color: var(--accent-color);
  text-shadow: 0 0 10px var(--accent-glow);
}

/* Which mode the run belongs to — Classic scores and Zen scores are ranked
   separately, so the badge sits right next to the HIGH SCORE readout. */
.mode-badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

body.zen-mode .mode-badge {
  color: var(--accent-color);
  background: rgba(var(--accent-rgb), 0.15);
  border-color: rgba(var(--accent-rgb), 0.35);
  box-shadow: 0 0 12px var(--accent-glow);
}

/* Time Attack runs hot — the badge matches the sinking ceiling's warning tone. */
body.time-mode .mode-badge {
  color: #ff8a5c;
  background: rgba(255, 122, 74, 0.15);
  border-color: rgba(255, 122, 74, 0.4);
  box-shadow: 0 0 12px rgba(255, 122, 74, 0.35);
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr 80px;
  gap: 8px;
}

.stat-box {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.stat-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 1px;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: #fff;
}

/* A new personal best lands live in the HUD — mostly for Zen, where the tier
   readout is the whole scoreboard and there's no game-over screen to report it. */
.stat-box.record-flash {
  animation: record-pop 0.7s ease-out;
}

@keyframes record-pop {
  0%   { background: rgba(var(--accent-rgb), 0.45); transform: scale(1.06); }
  100% { background: rgba(0, 0, 0, 0.25); transform: scale(1); }
}

/* The clock only exists in Time Attack, and only then does the header make
   room for a fourth box. */
.clock-box {
  display: none;
}

body.timed-mode .clock-box {
  display: flex;
}

body.timed-mode .stats-row {
  grid-template-columns: 1fr 1fr 1fr 68px;
}

/* The last ten seconds. Colour and weight only — no movement, so it survives
   reduced motion, where the pulse below is switched off. */
.clock-box.urgent {
  background: rgba(255, 92, 60, 0.22);
  border-color: rgba(255, 122, 74, 0.5);
}

.clock-box.urgent .stat-value {
  color: #ff8a5c;
  animation: clock-urgent 1s ease-in-out infinite alternate;
}

@keyframes clock-urgent {
  from { opacity: 0.65; }
  to { opacity: 1; }
}

.preview-box {
  padding: 4px;
}

.next-preview-container {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-color);
  box-shadow: 0 0 12px var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}

.next-bubble-val {
  font-size: 0.9rem;
  font-weight: 800;
  color: white;
}

.canvas-wrapper {
  position: relative;
  width: 100%;
  /* Width-limited on tall screens (unchanged), height-limited on short ones,
     so the field always lands whole. The subtrahend is the header + footer +
     padding around it; erring large just leaves a little breathing room. */
  max-width: min(100%, calc((100dvh - 215px) * 450 / 650));
  aspect-ratio: 450 / 650;
  flex: 0 0 auto;
  background: var(--panel-bg);
  border: var(--card-border);
  border-radius: 20px;
  box-shadow: 0 12px 40px var(--shadow-color);
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Overlays */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(13, 14, 18, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10;
  transition: opacity 0.3s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-content {
  width: 85%;
  /* Three mode buttons plus the how-to-play list can outgrow a short field.
     Scrolling inside the card keeps every button reachable rather than pushing
     the last one past the bottom edge. */
  max-height: calc(100% - 8px);
  overflow-y: auto;
  text-align: center;
  padding: 30px 20px;
  background: rgba(26, 29, 38, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.6);
  transform: translateY(0);
  transition: transform 0.3s ease;
}

.overlay.hidden .overlay-content {
  transform: translateY(20px);
}

.overlay-content h2 {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #fff 0%, var(--accent-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.overlay-content p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.final-score-container {
  background: rgba(0, 0, 0, 0.3);
  padding: 12px 20px;
  border-radius: 12px;
  margin-bottom: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.final-score-container span:first-child {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.final-score-container span:last-child {
  font-size: 1.6rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

/* Game-over summary rows (best tier reached, the record that now stands). */
.result-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 18px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.result-row span:first-child {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-secondary);
}

.result-row span:last-child {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
}

.new-record {
  margin-bottom: 18px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #fff;
  background: rgba(var(--accent-rgb), 0.9);
  box-shadow: 0 0 18px var(--accent-glow);
  animation: record-banner 1.6s ease-in-out infinite alternate;
}

.new-record.hidden {
  display: none;
}

@keyframes record-banner {
  from { box-shadow: 0 0 10px var(--accent-glow); }
  to   { box-shadow: 0 0 26px rgba(var(--accent-rgb), 0.85); }
}

.how-to-play {
  text-align: left;
  margin-bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.02);
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.02);
}

.step .icon {
  font-size: 1.2rem;
}

.step .desc {
  font-size: 0.85rem;
  color: var(--text-primary);
}

.glow-button {
  width: 100%;
  background: var(--accent-color);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 14px 24px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--accent-glow);
  transition: all 0.2s ease;
}

.glow-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(var(--accent-rgb), 0.6);
}

.glow-button:active {
  transform: translateY(1px);
}

/* Secondary button (e.g. NEW GAME shown under CONTINUE) */
.glow-button.secondary {
  background: var(--panel-bg);
  color: var(--text-primary);
  border: var(--card-border);
  box-shadow: none;
  margin-top: 12px;
}

.glow-button.secondary:hover {
  background: rgba(var(--accent-rgb), 0.12);
  box-shadow: 0 0 10px var(--accent-glow);
}

.glow-button.hidden {
  display: none;
}

.game-footer {
  width: 100%;
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 8px;
}

.footer-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  background: var(--panel-bg);
  border: var(--card-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 1.1rem;
  transition: all 0.2s ease;
}

.icon-button:hover {
  background: rgba(var(--accent-rgb), 0.12);
  transform: scale(1.05);
  box-shadow: 0 0 10px var(--accent-glow);
}

.controls-info {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* Short viewports: tighten the overlay so the menu mostly fits without
   scrolling. It still scrolls when it has to — this only reduces how often. */
@media (max-height: 800px) {
  .overlay-content {
    padding: 20px 16px;
  }
  .overlay-content h2 {
    font-size: 1.5rem;
  }
  .overlay-content p {
    margin-bottom: 16px;
  }
  .how-to-play {
    gap: 7px;
    margin-bottom: 18px;
  }
  .step {
    padding: 7px 12px;
  }
  .step .desc {
    font-size: 0.8rem;
  }
  .glow-button {
    padding: 11px 20px;
  }
  .glow-button.secondary {
    margin-top: 9px;
  }
  /* The mode explainers are the first thing worth cutting when space is tight —
     the buttons below them carry the same names. */
  .step.mode-hint {
    display: none;
  }
}

/* Honour the OS "reduce motion" setting. Movement goes; colour, contrast and
   every piece of information stay — the record flash still flashes, it just
   doesn't jump, and the splash still fades rather than pulsing. The canvas-side
   camera shake is suppressed in game.js. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .stat-box.record-flash {
    /* Keep the highlight, drop the pulse. */
    animation: none !important;
    background: rgba(var(--accent-rgb), 0.45);
    transition: background 0.6s ease-out !important;
  }

  .glow-button:hover,
  .icon-button:hover {
    transform: none;
  }

  .dev-logo-skip {
    animation: none !important;
    opacity: 0.7;
  }
}

/* ── SlothByte studio splash (DevLogoScreen parity) ── */
.dev-logo-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #171b24;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  transition: opacity 0.8s ease-out;
  cursor: pointer;
}

.dev-logo-splash.fade-out {
  opacity: 0;
  pointer-events: none;
}

.dev-logo-splash.hidden {
  display: none;
}

.dev-logo-img {
  max-width: min(300px, 70vw);
  max-height: min(300px, 70vh);
  width: auto;
  height: auto;
  opacity: 0;
  transition: opacity 0.8s ease-out;
  filter: drop-shadow(0 0 30px rgba(224, 214, 185, 0.30));
  pointer-events: none;
}

.dev-logo-splash.logo-visible .dev-logo-img {
  opacity: 1;
}

.dev-logo-skip {
  position: absolute;
  bottom: 24px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 9px;
  font-weight: 400;
  color: rgb(56, 56, 56); /* white @ 0.22 */
  letter-spacing: 0.08em;
  animation: skip-hint-pulse 0.9s ease-in-out infinite alternate;
  pointer-events: none;
}

@keyframes skip-hint-pulse {
  from { opacity: 0.35; }
  to { opacity: 0.9; }
}
