/* ============================================================
   TAPOTRON — Design tokens
   ============================================================ */

:root {
  --frame: #f05a28;
  --frame-dark: #c4421a;
  --frame-light: #ff7a4a;
  --frame-shadow: #a83512;

  --lcd-bg: #0a0a0a;
  --lcd-text: #ff6b35;
  --lcd-text-dim: #cc5528;
  --lcd-text-muted: #666666;
  --lcd-green: #4ade80;
  --lcd-red: #ef4444;

  --btn-bg: #1a1a1a;
  --btn-border: #000;
  --btn-active: #2d2d2d;
  --btn-glow: rgba(255, 107, 53, 0.4);

  --knob-bg: #2a2a2a;

  --radius-device: 28px;
  --radius-lcd: 6px;
  --radius-btn: 5px;

  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --font-brand: 'Space Grotesk', 'Helvetica Neue', sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  font-family: var(--font-mono);
  padding: 20px;
  overflow: hidden;
}

/* ==================== DEVICE ==================== */

.device {
  width: 340px;
  max-width: 100%;
  background: var(--frame);
  border-radius: var(--radius-device);
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow:
    0 0 0 2px var(--frame-dark),
    0 0 0 4px var(--frame-shadow),
    0 20px 60px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 var(--frame-light);
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}

/* ==================== TOP: LCD ==================== */

.bezel-top {
  background: #0a0a0a;
  border-radius: var(--radius-lcd);
  padding: 10px;
  border: 2px solid #1a1a1a;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.8);
  position: relative;
}

.lcd {
  position: relative;
  overflow: hidden;
  border-radius: 3px;
}

.lcd-inner {
  position: relative;
  z-index: 2;
  padding: 8px 10px;
  min-height: 172px;
  display: flex;
  flex-direction: column;
}

.lcd-scanlines {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 2px,
    rgba(0, 0, 0, 0.15) 2px, rgba(0, 0, 0, 0.15) 3px
  );
  border-radius: 3px;
}

.lcd-terminal {
  font-size: 10px;
  line-height: 1.5;
  color: var(--lcd-text);
  margin-bottom: 10px;
  min-height: 30px;
}

.lcd-terminal .prompt {
  color: var(--lcd-text-dim);
  margin-right: 4px;
}

.lcd-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  opacity: 1;
  transition: opacity 0.25s ease;
}

.lcd-view.hidden { display: none; }

/* --- Readouts --- */

.lcd-readouts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.readout-label {
  font-size: 7px;
  letter-spacing: 0.08em;
  color: var(--lcd-text-muted);
  text-transform: uppercase;
  display: block;
  margin-bottom: 2px;
}

.score-mult { color: var(--lcd-text-dim); }

.readout-value {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--lcd-text);
}

/* --- TPM row with vertical bar and PR overlay --- */

.tpm-group { position: relative; }

.tpm-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
}

.tpm-content {
  display: flex;
  align-items: center;
  gap: 4px;
  transition: opacity 0.25s ease;
}

.tpm-content.hidden { opacity: 0; }

.tpm-display {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  font-size: 14px;
  font-weight: 700;
  color: var(--lcd-text);
  min-width: 32px;
}

.tpm-unit {
  font-size: 7px;
  color: var(--lcd-text-muted);
  font-weight: 400;
  margin-left: 1px;
}

/* Vertical bar — short and fat, orange, fades out with PR */

.tpm-bar-v {
  width: 10px;
  height: 22px;
  background: rgba(255, 107, 53, 0.14);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
  flex-shrink: 0;
  transition: opacity 0.25s ease;
}

.tpm-bar-v.hidden { opacity: 0; }

.tpm-bar-v-fill {
  width: 100%;
  height: 0%;
  background: var(--lcd-text);
  border-radius: 2px;
  transition: height 0.12s linear;
}

/* PR notification sits in the row, aligned with the orange text baseline */

.pr-notification {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(calc(-50% + 4px));
  display: flex;
  align-items: center;
  height: 22px;
  font-size: 13px;
  font-weight: 700;
  color: var(--lcd-green);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: 0.02em;
  z-index: 2;
}

.pr-notification.visible {
  opacity: 1;
  transform: translateY(-50%);
}

.pr-notification.negative { color: var(--lcd-red); }

/* --- Stats row --- */

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

.stat-label {
  font-size: 7px;
  letter-spacing: 0.06em;
  color: var(--lcd-text-muted);
  text-transform: uppercase;
  display: block;
  margin-bottom: 2px;
}

.stat-pct { color: var(--lcd-text-dim); }

.stat-value {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--lcd-text);
  font-variant-numeric: tabular-nums;
}

.dot {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--lcd-text-dim);
  flex-shrink: 0;
}

/* ==================== LCD Snake stage ==================== */

.lcd-view-game {
  align-items: center;
  justify-content: center;
  padding: 4px 0;
}

.snake-stage {
  position: relative;
  width: 100%;
  max-width: 200px;
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 4px;
  background-color: rgba(255, 107, 53, 0.03);
  background-image:
    repeating-linear-gradient(to right,  rgba(255,107,53,0.12) 0 1px, transparent 1px calc(100%/6)),
    repeating-linear-gradient(to bottom, rgba(255,107,53,0.12) 0 1px, transparent 1px calc(100%/6));
  box-shadow:
    inset 0 0 0 1px var(--lcd-text-dim),
    inset 0 0 10px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.snake-fg {
  position: absolute;
  inset: 0;
}

/* Snake segments — absolutely positioned squares, small with gaps */

.snake-seg {
  position: absolute;
  width: calc(100% / 6);
  height: calc(100% / 6);
  pointer-events: none;
}

.snake-seg::before {
  content: '';
  position: absolute;
  inset: 24%;
  background: #ffffff;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(255, 255, 255, 0.45);
}

.snake-seg-head::before {
  inset: 20%;
  box-shadow: 0 0 7px rgba(255, 255, 255, 0.9);
}

/* Apple — smaller than snake body */

.snake-apple {
  position: absolute;
  width: calc(100% / 6);
  height: calc(100% / 6);
  pointer-events: none;
}

.snake-apple::before {
  content: '';
  position: absolute;
  inset: 34%;
  background: #dc2626;
  border-radius: 2px;
  box-shadow:
    0 0 4px rgba(220, 38, 38, 0.7),
    inset 0 0 0 1px rgba(255, 200, 200, 0.4);
}

/* ==================== MID BEZEL ==================== */

.bezel-mid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-tabs { display: flex; gap: 2px; }

.mode-tab {
  flex: 1;
  padding: 6px 4px;
  font-family: var(--font-mono);
  font-size: 7px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: #1a1a1a;
  color: var(--lcd-text-muted);
  border: 1px solid #000;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.mode-tab:first-child { border-radius: 3px 0 0 3px; }
.mode-tab:last-child  { border-radius: 0 3px 3px 0; }

.mode-tab.active {
  background: var(--frame);
  color: #0a0a0a;
  font-weight: 700;
}

.mode-tab:hover:not(.active) {
  background: #222;
  color: var(--lcd-text-dim);
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
}

.mode-icons {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mode-icon {
  width: 26px; height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.mode-icon.active {
  color: #0a0a0a;
  background: rgba(0, 0, 0, 0.12);
  border-color: rgba(0, 0, 0, 0.35);
}

.mode-icon:hover:not(.active) { color: rgba(0, 0, 0, 0.6); }

.knob {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #3a3a3a, var(--knob-bg));
  border: 2px solid #000;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4), inset 0 1px 2px rgba(255,255,255,0.1);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s ease;
}

.knob:active { transform: scale(0.96); }

.knob-line {
  position: absolute;
  width: 2px; height: 16px;
  background: #666;
  border-radius: 1px;
  top: 6px; left: 50%;
  transform: translateX(-50%) rotate(0deg);
  transform-origin: bottom center;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.tap-dial {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.dial-ticks {
  display: flex;
  gap: 8px;
  margin-bottom: 2px;
}

.tick {
  width: 1px; height: 4px;
  background: var(--frame-shadow);
}

.dial {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #3a3a3a, #1e1e1e);
  border: 2px solid #000;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 2px rgba(255,255,255,0.08);
  position: relative;
  cursor: pointer;
  transition: transform 0.1s ease;
}

.dial:active { transform: scale(0.94); }

.dial-indicator {
  position: absolute;
  width: 2px; height: 10px;
  background: #ccc;
  border-radius: 1px;
  top: 4px; left: 50%;
  transform: translateX(-50%) rotate(0deg);
  transform-origin: bottom center;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.dial-label {
  font-size: 6px;
  letter-spacing: 0.1em;
  color: var(--frame-shadow);
  text-transform: uppercase;
}

.side-buttons {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.side-btn {
  font-family: var(--font-mono);
  font-size: 7px;
  font-weight: 500;
  letter-spacing: 0.06em;
  padding: 5px 8px;
  background: #1a1a1a;
  color: var(--lcd-text-muted);
  border: 1px solid #000;
  border-radius: 3px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.15s, color 0.15s;
}

.side-btn:hover { background: #222; color: var(--lcd-text-dim); }
.side-btn:active { background: #0a0a0a; }

/* ==================== BOTTOM: GRID ==================== */

.bezel-bottom { padding: 4px 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

/* --- Tap buttons --- */

.grid-btn {
  aspect-ratio: 1;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-btn);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: background 0.08s, border-color 0.08s, transform 0.06s, box-shadow 0.12s;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 1px 2px rgba(0,0,0,0.35);
}

.grid-btn:hover { background: #222; }

.grid-btn.active,
.grid-btn:active {
  background: var(--btn-active);
  border-color: #000;
  transform: scale(0.97);
}

.grid-btn.active::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--btn-glow);
  border-radius: inherit;
  animation: tapFlash 0.3s ease-out forwards;
}

@keyframes tapFlash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

.grid-btn.filled {
  background: rgba(255, 107, 53, 0.18);
  border-color: rgba(255, 107, 53, 0.6);
}

/* Flash needs to pop against the orange frame — black border + strong glow */

.grid-btn.flash {
  background: var(--lcd-text);
  border-color: #000;
  box-shadow:
    0 0 12px rgba(255, 107, 53, 0.95),
    inset 0 0 6px rgba(255, 255, 255, 0.45);
  z-index: 2;
}

/* --- Game controls (D-pad) --- */

.grid.game-controls {
  grid-template-columns: 0.8fr 1.35fr 1.35fr 0.8fr;
  grid-template-rows:    0.8fr 1.35fr 1.35fr 0.8fr;
  gap: 4px;
}

.grid.game-controls .grid-btn {
  aspect-ratio: auto;
}

.grid.game-controls .filler-btn {
  background: #141414;
  border-color: #000;
  cursor: default;
  opacity: 0.55;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
  pointer-events: none;
}

.grid.game-controls .dir-btn {
  background: #1f1f1f;
  border: 1px solid #000;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--lcd-text);
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.06),
    0 2px 4px rgba(0,0,0,0.4);
  transition: background 0.08s, border-color 0.08s, transform 0.06s;
}

.grid.game-controls .dir-btn:hover {
  background: #262626;
  border-color: #000;
}

.grid.game-controls .dir-btn.pressed,
.grid.game-controls .dir-btn:active {
  background: var(--lcd-text);
  border-color: #000;
  color: #0a0a0a;
  transform: scale(0.94);
}

.grid.game-controls .dir-btn svg {
  width: 55%;
  height: 55%;
  display: block;
}

/* ==================== BRAND ==================== */

.brand-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 6px 0 2px;
}

.brand {
  font-family: var(--font-brand);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #0a0a0a;
  text-transform: lowercase;
}

.speaker {
  width: 22px; height: 16px;
  background:
    repeating-linear-gradient(90deg, #0a0a0a 0px, #0a0a0a 1px, transparent 1px, transparent 3px),
    repeating-linear-gradient(0deg,  #0a0a0a 0px, #0a0a0a 1px, transparent 1px, transparent 3px);
  opacity: 0.5;
  border-radius: 2px;
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 400px) {
  .device { width: 100%; border-radius: 20px; }
  .lcd-inner { min-height: 140px; }
  .knob { width: 44px; height: 44px; }
  .dial { width: 28px; height: 28px; }
  .brand { font-size: 13px; }
  .tpm-bar-v { width: 8px; height: 18px; }
  .snake-stage { max-width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}