:root {
  /* Muted pastel block colors (screenshot palette) */
  --c-red: #d96a5d;
  --c-green: #93cd68;
  --c-blue: #7295d6;
  --c-yellow: #e8ab44;

  /* Near-black base */
  --bg: #0c0c10;
  --panel: #16161c;
  --panel-2: #1e1e26;
  --line: #26262e;

  --text: #f2f2f4;
  --muted: #9a9aa6;
  --faint: #5c5c66;

  --danger: #d96a5d;
  --success: #93cd68;

  /* Repeated non-palette literals, tokenized for consistency */
  --ink: #101014;         /* dark text on light-fill buttons; also panel/nav bg */
  --shadow-slab: #060608; /* "3D press" shadow-slab color on dark panels */
  --shadow-light: #6b6b74; /* "3D press" shadow-slab color on light-fill buttons */

  --radius: 22px;
  --radius-sm: 14px;
  --header-h: 64px;
  --nav-h: 76px;

  /* Retro pixel fonts — reserved for "67 speaking" moments (brand wordmark,
     result-modal dialogue) and small game-UI labels. Never used for the main
     game copy (buttons, counters, status line), which stays on the normal
     system font per design direction. */
  --font-pixel: 'Press Start 2P', ui-monospace, monospace;
  --font-retro-body: 'VT323', ui-monospace, monospace;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

button:focus-visible {
  outline: 2px solid var(--c-blue);
  outline-offset: 2px;
}

/* Mono utility for retro labels */
.mono, .run-label, .puzzle-no, .status-line, .lifeline-label, .nav-btn span:last-child, .panel-section h3 {
  font-family: ui-monospace, 'Cascadia Mono', 'Segoe UI Mono', Consolas, monospace;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

/* Faint CRT scanlines over near-black */
.app {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 3px),
    radial-gradient(120% 90% at 50% 0%, #131318 0%, var(--bg) 60%);
  overflow: hidden;
}

/* Full-screen tint that pulses green/red when a round's pattern resolves */
.screen-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  opacity: 0;
}

.screen-flash--good {
  background: radial-gradient(circle at 50% 42%, rgba(147, 205, 104, 0.32), transparent 72%);
  animation: screenFlash 600ms ease-out;
}

.screen-flash--bad {
  background: radial-gradient(circle at 50% 42%, rgba(217, 106, 93, 0.34), transparent 72%);
  animation: screenFlash 600ms ease-out;
}

@keyframes screenFlash {
  0% { opacity: 0; }
  15% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- Header ---------- */

.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

.icon-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 20px;
  flex-shrink: 0;
}

.icon-btn:active { background: var(--panel); }

.bars, .bars::before, .bars::after {
  content: '';
  display: block;
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}
.bars { position: relative; }
.bars::before { position: absolute; top: -7px; }
.bars::after { position: absolute; top: 7px; }

.logo-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.logo {
  height: 34px;
  width: auto;
  image-rendering: pixelated;
}

.logo-says {
  font-family: var(--font-pixel);
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--text);
  text-shadow: 0 0 14px rgba(242, 242, 244, 0.35);
}

.puzzle-no {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: var(--faint);
}

/* ---------- Game area ---------- */

.game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 4px 20px 14px;
}

.start-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 16px;
  padding: 10px 0 20px;
}

.start-sub {
  color: var(--muted);
  margin: 0;
  font-size: 16px;
  font-weight: 500;
}

/* Static preview bars on home screen (mirrors the real grid) */
.preview-bars {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 200px;
  margin: 6px 0 10px;
}

.preview-bar {
  flex: 1;
  min-height: 44px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, color-mix(in srgb, var(--bar) 86%, white) 0%, var(--bar) 55%);
  box-shadow: 0 6px 0 0 color-mix(in srgb, var(--bar) 55%, black);
}

.daily-warning {
  margin: -4px 0 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-yellow);
  letter-spacing: 0.01em;
}

.start-btn {
  width: 100%;
  max-width: 340px;
  padding: 17px 16px;
  font-weight: 700;
  font-size: 17px;
  border-radius: 999px;
  transition: transform 90ms ease, box-shadow 90ms ease, opacity 90ms ease;
}

.start-btn--daily {
  background: var(--text);
  color: var(--ink);
  box-shadow: 0 5px 0 0 var(--shadow-light);
}

.start-btn--daily:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 0 var(--shadow-light);
}

.start-btn--practice {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.start-btn--practice:active { background: var(--panel); }

.already-played-note {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin: 0;
  max-width: 320px;
}

.already-played-tag {
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.already-played-note span:last-child {
  font-family: var(--font-retro-body);
  font-size: 18px;
  color: var(--text);
  text-align: center;
  line-height: 1.3;
}

.play-area {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 14px;
  transition: filter 300ms ease;
}

/* Held-breath pause before a high-stakes reveal (round 67, or a late loss). */
.play-area.suspense-hold {
  filter: brightness(0.5) saturate(0.6);
}

/* ---------- Progress rails ---------- */

.progress-rail {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  z-index: 1;
}

.progress-rail--left { left: -13px; }
.progress-rail--right { right: -13px; }

.rail-segment {
  width: 6px;
  height: 16px;
  border-radius: 3px;
  background: var(--panel-2);
  transition: background 150ms ease, box-shadow 150ms ease;
}

.rail-segment.filled {
  background: var(--c-yellow);
  box-shadow: 0 0 7px 1px color-mix(in srgb, var(--c-yellow) 65%, transparent);
}

/* ---------- Live "67 says" milestone overlay ---------- */

.live-quip {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 8px);
  max-width: 320px;
  text-align: center;
  padding: 8px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 2;
}

.live-quip-tag {
  display: block;
  font-family: var(--font-pixel);
  font-size: 8px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}

.live-quip-text {
  font-family: var(--font-retro-body);
  font-size: 17px;
  color: var(--c-yellow);
  line-height: 1.25;
}

/* ---------- Button grid ---------- */

.button-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(4, 1fr);
  gap: 13px;
  min-height: 260px;
  padding-top: 4px;
}

.color-btn {
  width: 100%;
  background: linear-gradient(180deg, color-mix(in srgb, var(--btn-color) 86%, white) 0%, var(--btn-color) 55%);
  border-radius: var(--radius);
  box-shadow:
    0 7px 0 0 color-mix(in srgb, var(--btn-color) 55%, black),
    0 0 0 0 var(--btn-color);
  opacity: 0.92;
  transition: opacity 90ms ease, transform 70ms ease;
  min-height: 56px;
}

.color-btn:active {
  transform: translateY(6px);
  box-shadow:
    0 1px 0 0 color-mix(in srgb, var(--btn-color) 55%, black),
    0 0 28px 4px color-mix(in srgb, var(--btn-color) 70%, transparent);
}

.color-btn.lit {
  opacity: 1;
  background: linear-gradient(180deg, color-mix(in srgb, var(--btn-color) 70%, white) 0%, var(--btn-color) 70%);
  box-shadow:
    0 7px 0 0 color-mix(in srgb, var(--btn-color) 55%, black),
    0 0 34px 8px color-mix(in srgb, var(--btn-color) 75%, transparent);
}

.color-btn.locked { pointer-events: none; }

/* ---------- Step track + run row ---------- */

.step-track {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-start;
  align-content: flex-start;
  min-height: 18px;
  padding: 2px 2px 0;
}

.step-square {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  background: var(--panel-2);
  transition: background 120ms ease, box-shadow 120ms ease;
}

.step-square.filled {
  background: var(--text);
  box-shadow: 0 0 8px 1px rgba(242, 242, 244, 0.55);
}

.step-square.pending { animation: pulse 700ms ease-in-out infinite; }

.step-square.good {
  background: var(--success);
  box-shadow: 0 0 9px 1px rgba(147, 205, 104, 0.6);
}

.step-square.bad {
  background: var(--danger);
  box-shadow: 0 0 9px 1px rgba(217, 106, 93, 0.6);
}

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

.run-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 2px;
}

.run-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--faint);
}

.counter {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

.counter b {
  font-size: 30px;
  font-weight: 800;
  color: var(--text);
  margin-right: 2px;
}

.status-line {
  min-height: 18px;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.status-line.good { color: var(--success); }
.status-line.bad { color: var(--danger); }

/* ---------- Lifeline bar ---------- */

.lifeline-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.lifeline-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 11px 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 0 0 var(--shadow-slab);
  color: var(--text);
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.lifeline-icon { font-size: 17px; }

.lifeline-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}

.lifeline-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 0 var(--shadow-slab);
}

.lifeline-btn--passive {
  cursor: default;
  border-color: rgba(147, 205, 104, 0.35);
}

.lifeline-btn--used {
  opacity: 0.3;
  filter: grayscale(1);
  pointer-events: none;
}

.lifeline-btn--saved {
  animation: saveFlash 900ms ease;
}

@keyframes saveFlash {
  0%, 100% { box-shadow: 0 4px 0 0 var(--shadow-slab); }
  30% { box-shadow: 0 4px 0 0 var(--shadow-slab), 0 0 24px 4px color-mix(in srgb, var(--success) 60%, transparent); }
}

/* ---------- Bottom nav ---------- */

.bottom-nav {
  height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom, 0);
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--ink);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
  position: relative;
}

.bottom-nav::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0) + 16px);
  width: 1px;
  background: var(--line);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--faint);
}

.nav-icon { font-size: 19px; opacity: 0.85; }

.nav-btn span:last-child {
  font-size: 10px;
  font-weight: 600;
}

.nav-btn--active { color: var(--text); }

/* ---------- Menu panel ---------- */

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 20;
}

.menu-panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 84vw);
  background: var(--ink);
  border-right: 1px solid var(--line);
  z-index: 21;
  transform: translateX(-100%);
  transition: transform 220ms ease;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0) 0 0;
}

.menu-panel.open { transform: translateX(0); }

.menu-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
}

.menu-content {
  padding: 16px;
  overflow-y: auto;
}

.panel-section { margin-bottom: 26px; }
.panel-section h3 {
  font-size: 11px;
  color: var(--faint);
  margin: 0 0 10px;
}

.retro-tag {
  font-family: var(--font-pixel);
  text-transform: none;
  letter-spacing: normal;
  font-size: 8px;
  color: var(--danger);
  vertical-align: middle;
}

.stat-row { display: flex; gap: 10px; }

.stat {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
}

.stat-label {
  display: block;
  font-size: 10px;
  color: var(--faint);
  margin-top: 3px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.speed-toggle { display: flex; gap: 8px; }

.speed-btn {
  flex: 1;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.speed-btn--active {
  background: var(--text);
  color: var(--ink);
  border-color: var(--text);
}

.dev-tools { display: flex; flex-direction: column; gap: 8px; }

.dev-btn {
  padding: 12px;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}

.dev-btn:active { background: var(--panel-2); }

.history-list { list-style: none; margin: 0; padding: 0; }

.history-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  color: var(--muted);
}

.history-date { color: var(--muted); font-weight: 500; }
.history-score.won { color: var(--success); font-weight: 700; }
.history-empty { color: var(--faint); font-size: 13px; padding: 8px 4px; }

/* ---------- Result modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 20px;
}

.modal {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 0 0 var(--shadow-slab);
  padding: 30px 22px 24px;
  text-align: center;
}

.result-score {
  font-size: 52px;
  font-weight: 800;
  color: var(--text);
}

.result-streak {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin-top: 6px;
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.result-near-miss {
  color: var(--c-yellow);
  font-size: 13px;
  font-weight: 700;
  margin-top: 8px;
}

.result-message {
  margin-top: 18px;
  text-align: left;
}

.result-speaker {
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
  min-height: 12px;
}

.result-roast {
  font-family: var(--font-retro-body);
  font-size: 22px;
  color: var(--text);
  line-height: 1.35;
  min-height: 1.35em;
  letter-spacing: 0.01em;
}

.result-speaker span,
.result-roast span {
  display: inline-block;
  opacity: 0;
  animation: charPop 200ms ease forwards;
}

@keyframes charPop {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 2px 0;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.3;
  animation: dotPulse 900ms ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 150ms; }
.typing-dots span:nth-child(3) { animation-delay: 300ms; }

@keyframes dotPulse {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1); }
}

.result-roast--rare {
  color: var(--c-yellow);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(232, 171, 68, 0.4);
  background: rgba(232, 171, 68, 0.08);
  box-shadow: 0 0 18px rgba(232, 171, 68, 0.25);
  animation: rareGlow 1.8s ease-in-out infinite;
}

.result-roast--rare::before {
  content: '★ GOLD ROAST ★';
  display: block;
  font-style: normal;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  margin-bottom: 6px;
  color: var(--c-yellow);
}

@keyframes rareGlow {
  0%, 100% { box-shadow: 0 0 12px rgba(232, 171, 68, 0.2); }
  50% { box-shadow: 0 0 26px rgba(232, 171, 68, 0.45); }
}

.result-canvas-preview {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.result-canvas-preview img { width: 100%; display: block; }

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

.modal-btn {
  padding: 15px;
  font-weight: 700;
  font-size: 15px;
  background: var(--panel-2);
  color: var(--text);
  border-radius: 999px;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.modal-btn--primary {
  background: var(--text);
  color: var(--ink);
  box-shadow: 0 4px 0 0 var(--shadow-light);
}

.modal-btn--primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 0 var(--shadow-light);
}

/* ---------- Intro modal (first-run "how to play") ---------- */

.intro-modal {
  text-align: left;
  max-height: 85vh;
  overflow-y: auto;
}

.intro-title {
  font-family: var(--font-pixel);
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--text);
  margin: 0 0 18px;
  text-align: center;
}

.intro-rule {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.intro-rule-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.intro-rule-text {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.45;
}

.intro-quip {
  font-family: var(--font-retro-body);
  font-size: 19px;
  color: var(--c-yellow);
  line-height: 1.3;
  margin: -6px 0 16px;
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.intro-quip-tag {
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  margin-right: 6px;
  vertical-align: middle;
}

/* ---------- Small screens ---------- */

@media (max-width: 340px) {
  .counter b { font-size: 24px; }
}
