/* ============================================
   BOOK RACE — Retro Arcade Aesthetic
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

:root {
  --bg-dark: #0a0a1a;
  --bg-mid: #1a1a2e;
  --accent: #FFD700;
  --red: #DC143C;
  --cyan: #00FFFF;
  --pink: #FF1493;
  --text: #fff;
  --text-dim: #888;
  --font-pixel: 'Press Start 2P', monospace;
}

body {
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--font-pixel);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ============================================
   SCANLINES OVERLAY
   ============================================ */

.scanlines {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.08) 0px,
    rgba(0, 0, 0, 0.08) 1px,
    transparent 1px,
    transparent 3px
  );
}

/* ============================================
   SCREEN MANAGEMENT
   ============================================ */

.screen {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   SCREEN SHAKE
   ============================================ */

@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-8px, 4px); }
  20% { transform: translate(6px, -6px); }
  30% { transform: translate(-4px, 8px); }
  40% { transform: translate(8px, -2px); }
  50% { transform: translate(-6px, -4px); }
  60% { transform: translate(4px, 6px); }
  70% { transform: translate(-2px, -8px); }
  80% { transform: translate(6px, 2px); }
  90% { transform: translate(-4px, 4px); }
}

body.shake {
  animation: screenShake 0.2s ease-out;
}

/* ============================================
   LANDING SCREEN
   ============================================ */

.landing-content {
  text-align: center;
  padding: 20px;
}

.title-main {
  font-size: clamp(48px, 12vw, 96px);
  line-height: 1.1;
  color: var(--accent);
  text-shadow:
    4px 4px 0 var(--red),
    -2px -2px 0 var(--cyan);
  margin-bottom: 20px;
  letter-spacing: 8px;
  animation: heartbeat 1.8s ease-in-out infinite;
}

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14% { transform: scale(1.04); }
  22% { transform: scale(1); }
  32% { transform: scale(1.06); }
  44% { transform: scale(1); }
}

.title-sub {
  font-size: clamp(8px, 1.5vw, 12px);
  color: var(--text-dim);
  letter-spacing: 2px;
  margin-bottom: 50px;
  line-height: 1.8;
}

.landing-runner-canvas {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 54px;
  pointer-events: none;
  image-rendering: pixelated;
  opacity: 0.4;
}

.landing-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.join-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ============================================
   BUTTONS & INPUTS
   ============================================ */

.btn {
  font-family: var(--font-pixel);
  font-size: 12px;
  padding: 14px 28px;
  border: none;
  cursor: pointer;
  letter-spacing: 2px;
  transition: all 0.1s;
  text-transform: uppercase;
}

.btn:active {
  transform: scale(0.95);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg-dark);
  box-shadow: 0 4px 0 #B8860B;
}

.btn-primary:hover {
  background: #ffe44d;
}

.btn-primary:active {
  box-shadow: 0 1px 0 #B8860B;
  transform: translateY(3px);
}

.btn-secondary {
  background: var(--bg-mid);
  color: var(--text);
  border: 2px solid var(--text-dim);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--text-dim);
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text);
}

.btn-start {
  background: var(--red);
  color: var(--text);
  font-size: 14px;
  padding: 18px 36px;
  box-shadow: 0 4px 0 #8B0000;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.btn-start:hover {
  background: #FF1744;
}

.input-code {
  font-family: var(--font-pixel);
  font-size: 18px;
  width: 140px;
  padding: 12px 16px;
  background: var(--bg-mid);
  border: 2px solid var(--text-dim);
  color: var(--text);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 6px;
}

.input-code:focus {
  outline: none;
  border-color: var(--accent);
}

.input-field {
  font-family: var(--font-pixel);
  font-size: 11px;
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-dark);
  border: 2px solid var(--text-dim);
  color: var(--text);
  margin-bottom: 12px;
}

.input-field:focus {
  outline: none;
  border-color: var(--accent);
}

.input-field::placeholder {
  color: #555;
}

@keyframes shakeInput {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.shake-input {
  animation: shakeInput 0.4s ease-out;
  border-color: var(--red) !important;
}

/* ============================================
   LOBBY SCREEN
   ============================================ */

.lobby-content {
  text-align: center;
  padding: 20px;
}

.room-code-box {
  background: var(--bg-mid);
  border: 3px solid var(--accent);
  padding: 30px 50px;
  margin: 30px auto;
  display: inline-block;
}

.room-code {
  font-size: clamp(36px, 8vw, 64px);
  color: var(--accent);
  letter-spacing: 16px;
}

.lobby-text {
  font-size: 10px;
  color: var(--text-dim);
  line-height: 2;
  margin-bottom: 10px;
}

.lobby-text.small {
  font-size: 8px;
}

.section-title {
  font-size: clamp(14px, 3vw, 24px);
  color: var(--accent);
  letter-spacing: 4px;
  margin-bottom: 10px;
}

/* ============================================
   CHARACTER SELECT
   ============================================ */

#select-screen {
  flex-direction: column;
  padding: 20px;
}

.select-header {
  text-align: center;
  margin-bottom: 20px;
}

.player-count {
  font-size: 10px;
  color: var(--cyan);
  margin-top: 8px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  max-width: 800px;
  width: 100%;
  padding: 0 10px;
}

@media (max-width: 600px) {
  .character-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

.char-card {
  background: linear-gradient(180deg, var(--char-bg, var(--bg-mid)) 0%, var(--bg-mid) 70%);
  border: 2px solid var(--char-color, #333);
  border-top-width: 3px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.char-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.char-card.taken {
  cursor: default;
  opacity: 0.7;
  border-color: #555;
}

.char-card.taken:hover {
  transform: none;
  border-color: #555;
}

.char-card.mine {
  border-color: var(--cyan);
  opacity: 1;
  box-shadow: 0 0 15px rgba(0, 255, 255, 0.3);
}

.char-preview {
  width: 100%;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  position: relative;
}

.char-canvas {
  width: 100px;
  height: 120px;
  image-rendering: pixelated;
}


.char-name {
  font-size: 9px;
  color: var(--char-color, var(--accent));
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.char-subtitle {
  font-size: 7px;
  color: var(--text-dim);
}

.char-taken-info {
  margin-top: 8px;
}

.taken-name {
  font-size: 8px;
  color: var(--cyan);
}

.taken-book {
  font-size: 7px;
  color: var(--pink);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-footer {
  margin-top: 20px;
  text-align: center;
}

.waiting-msg {
  font-size: 9px;
  color: var(--text-dim);
  animation: blink 1.5s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================
   MODAL
   ============================================ */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-mid);
  border: 2px solid var(--accent);
  padding: 30px;
  max-width: 400px;
  width: 90%;
}

.modal-title {
  font-size: 16px;
  color: var(--accent);
  text-align: center;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.modal-actions .btn {
  flex: 1;
  font-size: 10px;
}

/* ============================================
   INTRO SCREEN
   ============================================ */

#intro-screen {
  background: var(--bg-dark);
}

.intro-container {
  text-align: center;
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.intro-text {
  font-size: clamp(48px, 15vw, 120px);
  color: var(--text);
  font-family: var(--font-pixel);
  position: relative;
  z-index: 2;
}

@keyframes slamFromLeft {
  0% { transform: translateX(-120vw) scale(1.5); opacity: 0; }
  60% { transform: translateX(10px) scale(1.1); opacity: 1; }
  80% { transform: translateX(-5px) scale(1); }
  100% { transform: translateX(0) scale(1); opacity: 1; }
}

@keyframes slamFromRight {
  0% { transform: translateX(120vw) scale(1.5); opacity: 0; }
  60% { transform: translateX(-10px) scale(1.1); opacity: 1; }
  80% { transform: translateX(5px) scale(1); }
  100% { transform: translateX(0) scale(1); opacity: 1; }
}

.slam-left {
  animation: slamFromLeft 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
  color: var(--accent);
  text-shadow: 4px 4px 0 var(--red);
}

.slam-right {
  animation: slamFromRight 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
  color: var(--red);
  text-shadow: 4px 4px 0 var(--accent);
}

@keyframes finalFlash {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.3); opacity: 1; }
  70% { transform: scale(0.9); }
  100% { transform: scale(1); opacity: 1; }
}

.final-flash {
  animation: finalFlash 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
  color: var(--cyan);
  text-shadow: 0 0 40px var(--cyan), 0 0 80px var(--cyan);
  font-size: clamp(32px, 10vw, 80px);
}

/* Crack overlay */
.crack-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.1s;
  background:
    radial-gradient(circle at 50% 50%, transparent 30%, rgba(255,255,255,0.05) 31%, transparent 32%),
    linear-gradient(45deg, transparent 40%, rgba(255,255,255,0.1) 40.5%, transparent 41%),
    linear-gradient(-45deg, transparent 35%, rgba(255,255,255,0.1) 35.5%, transparent 36%),
    linear-gradient(30deg, transparent 45%, rgba(255,255,255,0.08) 45.5%, transparent 46%),
    linear-gradient(-60deg, transparent 30%, rgba(255,255,255,0.08) 30.5%, transparent 31%),
    linear-gradient(80deg, transparent 50%, rgba(255,255,255,0.06) 50.5%, transparent 51%),
    linear-gradient(-20deg, transparent 42%, rgba(255,255,255,0.06) 42.5%, transparent 43%);
}

.crack-overlay.active {
  opacity: 1;
}

/* Flash overlay */
.flash-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: white;
  pointer-events: none;
  z-index: 60;
  opacity: 0;
  transition: opacity 0.05s;
}

.flash-overlay.active {
  opacity: 1;
}

/* Intro roster */
.intro-roster {
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.roster-entry {
  font-size: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}

.roster-name {
  font-size: 12px;
}

.roster-as {
  color: var(--text-dim);
  font-size: 8px;
}

.roster-char {
  color: var(--text-dim);
  font-size: 10px;
}

/* ============================================
   RACE SCREEN
   ============================================ */

#race-screen {
  background: var(--bg-dark);
  position: relative;
}

.race-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* Countdown overlay */
.countdown-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  z-index: 10;
  font-family: var(--font-pixel);
  font-size: clamp(60px, 15vw, 140px);
  color: var(--text);
  text-shadow:
    4px 4px 0 var(--red),
    0 0 40px rgba(255, 255, 255, 0.3);
  pointer-events: none;
}

@keyframes countdownPop {
  0% { transform: scale(2.5); opacity: 0; }
  30% { transform: scale(0.9); opacity: 1; }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.countdown-pop {
  animation: countdownPop 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.countdown-go {
  color: var(--accent);
  text-shadow:
    4px 4px 0 var(--red),
    0 0 60px rgba(255, 215, 0, 0.5);
}

/* ============================================
   WINNER SCREEN
   ============================================ */

#winner-screen {
  background: var(--bg-dark);
  flex-direction: column;
  overflow-y: auto;
}

.winner-content {
  text-align: center;
  z-index: 2;
  animation: winnerAppear 0.8s ease;
  padding: 30px 20px;
  max-width: 700px;
  width: 100%;
}

@keyframes winnerAppear {
  0% { transform: scale(0) rotate(-10deg); opacity: 0; }
  60% { transform: scale(1.1) rotate(2deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.results-header {
  margin-bottom: 24px;
}

.winner-label {
  font-size: clamp(10px, 2.5vw, 16px);
  color: var(--text-dim);
  letter-spacing: 4px;
  margin-bottom: 16px;
}

.winner-book-title {
  font-size: clamp(20px, 5vw, 36px);
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--red);
  padding: 0 20px;
  line-height: 1.4;
}

/* Podium */
.results-podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.podium-spot {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 140px;
}

.podium-canvas {
  width: 80px;
  height: 90px;
  image-rendering: pixelated;
  margin-bottom: 6px;
  animation: podiumBounce 1.2s ease-in-out infinite;
}

@keyframes podiumBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.podium-info {
  margin-bottom: 6px;
}

.podium-player {
  font-size: 9px;
  margin-bottom: 3px;
}

.podium-time {
  font-size: 8px;
  color: var(--text-dim);
}

.podium-pedestal {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
}

.podium-place {
  font-size: 14px;
  color: var(--bg-dark);
  font-weight: bold;
}

/* Remaining runners */
.results-rest {
  border-top: 2px solid rgba(255, 255, 255, 0.1);
  padding-top: 16px;
}

.results-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.results-place {
  font-size: 10px;
  color: var(--text-dim);
  width: 28px;
  text-align: right;
  flex-shrink: 0;
}

.results-name {
  font-size: 9px;
  flex-shrink: 0;
  width: 120px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.results-book {
  font-size: 8px;
  color: var(--text-dim);
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.results-time {
  font-size: 8px;
  color: var(--text-dim);
  flex-shrink: 0;
  text-align: right;
}

.race-again-btn {
  margin-top: 24px;
}

/* ============================================
   CONFETTI
   ============================================ */

.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

@keyframes confettiFall {
  0% {
    transform: translateY(-20px) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0.3;
  }
}

.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 8px;
  animation: confettiFall linear forwards;
}
