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

:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface2: #1e1e1e;
  --border: #2a2a2a;
  --text: #f0f0f0;
  --muted: #666;
  --accent: #ff3b3b;
  --accent2: #ff8c00;
  --green: #00ff88;
  --yellow: #ffe600;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Mono', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-x: hidden;
}

body.miss-flash {
  animation: damagePulse 0.18s ease;
}

body.best-score-glow {
  animation: bestScoreGlow 0.9s ease;
}

body.final-boss-mode {
  animation: bossBodyPulse 1.15s ease-in-out infinite;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0,0,0,0.08) 2px,
    rgba(0,0,0,0.08) 4px
  );
  pointer-events: none;
  z-index: 999;
}

@keyframes damagePulse {
  0%, 100% { background: var(--bg); }
  45% { background: #1f0808; }
}

@keyframes bestScoreGlow {
  0%, 100% { box-shadow: inset 0 0 0 rgba(255,230,0,0); }
  45% { box-shadow: inset 0 0 46px rgba(255,230,0,0.2); }
}

@keyframes bossBodyPulse {
  0%, 100% { background: #070707; }
  50% { background: #120612; }
}

#header {
  width: 100%;
  max-width: 700px;
  padding: 2rem 1.5rem 1rem;
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  justify-content: space-between;
}

#game-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(36px, 8vw, 64px);
  letter-spacing: 2px;
  color: var(--text);
  line-height: 1;
}

#game-title span { color: var(--accent); }

#tagline {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  padding-bottom: 6px;
}

#stats {
  width: 100%;
  max-width: 700px;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 1rem;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 4px;
  min-width: 0;
}

.stat-box .label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.stat-box .value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  min-height: 27px;
  overflow: hidden;
  text-overflow: ellipsis;
}

#instruction-bar {
  width: 100%;
  max-width: 700px;
  padding: 0 1.5rem;
  margin-bottom: 12px;
}

#instruction {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--yellow);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text);
  border-radius: 4px;
  letter-spacing: 0.5px;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#instruction.panic-flicker {
  border-left-color: #ff00ff;
  animation: instructionPanic 0.42s steps(2, end) infinite;
}

#instruction.fake-gameover-flash::after {
  content: ' GAME OVER?';
  color: var(--accent);
  font-weight: 700;
  margin-left: auto;
  animation: fakeGameOver 0.5s ease;
}

#instruction .target-word {
  color: var(--yellow);
  font-weight: 700;
  font-size: 15px;
  transition: color 0.1s;
}

#arena-wrap {
  width: 100%;
  max-width: 700px;
  padding: 0 1.5rem;
}

#arena {
  position: relative;
  width: 100%;
  
  /* UPDATE THESE TWO LINES */
  height: min(560px, 70vh);  /* Increased from 420px / 58vh */
  min-height: 460px;         /* Increased from 330px */
  
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: background 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
  will-change: transform;
}

.final-boss-mode #arena {
  background: #09070b;
  border-color: rgba(255,0,255,0.46);
  box-shadow: inset 0 0 32px rgba(255,0,255,0.13), 0 0 28px rgba(255,0,255,0.08);
}

#arena.shake-small { animation: arenaShakeSmall 0.15s ease; }
#arena.shake-level { animation: arenaShakeLevel 0.18s ease; }
#arena.shake-big   { animation: arenaShakeBig 0.24s ease; }
#arena.freeze-buttons .btn-target {
  filter: saturate(1.5) drop-shadow(0 0 9px rgba(255,230,0,0.55));
}

#arena::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}

.btn-target {
  position: absolute;
  --btn-scale: 1;
  --btn-rotate: 0deg;
  --jitter-x: 0px;
  --jitter-y: 0px;
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 9px 20px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transform: translate(var(--jitter-x), var(--jitter-y)) rotate(var(--btn-rotate)) scale(var(--btn-scale));
  transform-origin: center;
  transition:
    background 0.1s,
    border-color 0.1s,
    box-shadow 0.15s ease,
    color 0.12s ease,
    left 0.32s cubic-bezier(.4,0,.2,1),
    top 0.32s cubic-bezier(.4,0,.2,1),
    transform 0.22s cubic-bezier(.2,.9,.2,1.25),
    opacity 0.25s ease,
    font-size 0.3s ease;
  z-index: 2;
  will-change: left, top, transform, opacity;
}

.btn-target:hover {
  background: #2a2a2a;
  border-color: var(--yellow);
  color: #fff8b8;
  box-shadow: 0 0 12px rgba(255,230,0,0.16), inset 0 0 12px rgba(255,230,0,0.05);
}

.btn-target.correct-flash {
  border-color: var(--green) !important;
  color: var(--green) !important;
  background: rgba(0,255,136,0.16) !important;
  box-shadow: 0 0 18px rgba(0,255,136,0.34), inset 0 0 12px rgba(0,255,136,0.13);
}

.btn-target.wrong-flash {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
  background: rgba(255,59,59,0.2) !important;
  box-shadow: 0 0 22px rgba(255,59,59,0.38), inset 0 0 14px rgba(255,59,59,0.16);
  animation: buttonWrongShake 0.32s ease;
}

.btn-target.btn-pop {
  animation: buttonPop 0.2s cubic-bezier(.18,.9,.2,1.55);
}

.btn-target.correct-bounce {
  animation: buttonCorrectBounce 0.26s cubic-bezier(.18,.9,.2,1.4);
}

.btn-target.btn-pop.wrong-flash {
  animation: buttonWrongShake 0.32s ease;
}

.btn-target.chaos-rotate {
  box-shadow: 0 0 14px rgba(255,230,0,0.18);
}

.btn-target.runaway {
  border-color: var(--green);
  box-shadow: 0 0 12px rgba(0,255,136,0.24);
}

@keyframes buttonWrongShake {
  0%, 100% { transform: translate(var(--jitter-x), var(--jitter-y)) rotate(var(--btn-rotate)) scale(var(--btn-scale)); }
  20% { transform: translate(calc(var(--jitter-x) - 8px), var(--jitter-y)) rotate(var(--btn-rotate)) scale(var(--btn-scale)); }
  60% { transform: translate(calc(var(--jitter-x) + 8px), var(--jitter-y)) rotate(var(--btn-rotate)) scale(var(--btn-scale)); }
}

@keyframes buttonPop {
  0% { transform: translate(var(--jitter-x), var(--jitter-y)) rotate(var(--btn-rotate)) scale(var(--btn-scale)); }
  45% { transform: translate(var(--jitter-x), var(--jitter-y)) rotate(var(--btn-rotate)) scale(0.9); }
  100% { transform: translate(var(--jitter-x), var(--jitter-y)) rotate(var(--btn-rotate)) scale(var(--btn-scale)); }
}

@keyframes buttonCorrectBounce {
  0% { transform: translate(var(--jitter-x), var(--jitter-y)) rotate(var(--btn-rotate)) scale(var(--btn-scale)); }
  45% { transform: translate(var(--jitter-x), calc(var(--jitter-y) - 3px)) rotate(var(--btn-rotate)) scale(1.13); }
  100% { transform: translate(var(--jitter-x), var(--jitter-y)) rotate(var(--btn-rotate)) scale(var(--btn-scale)); }
}

.particle {
  position: absolute;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  pointer-events: none;
  z-index: 30;
  box-shadow: 0 0 10px currentColor;
  animation: particleBurst 0.48s cubic-bezier(.12,.78,.25,1) forwards;
}

.reward-pop {
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 31;
  pointer-events: none;
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(34px, 9vw, 66px);
  line-height: 1;
  letter-spacing: 2px;
  text-shadow: 0 0 18px currentColor;
  animation: rewardPop 0.82s cubic-bezier(.13,.82,.2,1) forwards;
}

@keyframes particleBurst {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.15);
  }
}

@keyframes rewardPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.72); }
  18% { opacity: 1; transform: translate(-50%, -54%) scale(1.08); }
  100% { opacity: 0; transform: translate(-50%, -78%) scale(0.95); }
}

@keyframes arenaShakeSmall {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  55% { transform: translate(3px, -1px); }
  75% { transform: translate(-2px, 1px); }
}

@keyframes arenaShakeLevel {
  0%, 100% { transform: translate(0, 0); }
  35% { transform: translate(2px, -2px); }
  70% { transform: translate(-2px, 1px); }
}

@keyframes arenaShakeBig {
  0%, 100% { transform: translate(0, 0); }
  18% { transform: translate(-7px, 3px); }
  38% { transform: translate(6px, -3px); }
  62% { transform: translate(-5px, 2px); }
  82% { transform: translate(3px, -1px); }
}

@keyframes instructionPanic {
  0%, 100% { color: var(--text); box-shadow: inset 0 0 0 rgba(255,0,255,0); }
  50% { color: #ffd6ff; box-shadow: inset 0 0 18px rgba(255,0,255,0.1); }
}

@keyframes fakeGameOver {
  0%, 100% { opacity: 0; transform: scale(0.92); }
  30%, 70% { opacity: 1; transform: scale(1); }
}

/* LEVEL BANNER */
#level-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  background: rgba(10,10,10,0.94);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px 28px;
  width: min(82%, 420px);
  text-align: center;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}

#level-banner.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

#banner-name {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 28px;
  letter-spacing: 2px;
  line-height: 1;
}

#banner-desc {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.5px;
  margin-top: 6px;
}

/* TOAST */
#toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  padding: 10px 20px;
  border-radius: 4px;
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  letter-spacing: 0.5px;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* SCREENS */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(10,10,10,0.95);
  flex-direction: column;
  align-items: center;
  z-index: 10;
  gap: 12px;
  text-align: center;
  padding: 2rem;
  
  overflow-y: auto;
}

.screen::before,
.screen::after {
  content: '';
  margin: auto;
}

.screen.active { display: flex; }

.screen h2 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 52px;
  letter-spacing: 2px;
  line-height: 1;
}

.screen p {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 1px;
  max-width: 340px;
  line-height: 1.8;
}

.screen .final-score {
  font-size: 13px;
  color: var(--yellow);
  letter-spacing: 1px;
}

.screen-btn {
  margin-top: 8px;
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 12px 28px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-transform: uppercase;
}

.screen-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.screen-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

.screen-btn.ghost {
  margin-top: 0;
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

.screen-btn.ghost:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: #555;
}

.lb-end-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 300px;
  margin-top: 4px;
}

.lb-name-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  align-self: flex-start;
}

.lb-name-input {
  width: 100%;
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  padding: 10px 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
}

.lb-name-input:focus {
  outline: none;
  border-color: var(--yellow);
}

.lb-end-block .screen-btn {
  margin-top: 0;
  width: 100%;
}

body.lb-modal-open {
  overflow: hidden;
}

.lb-overlay {
  position: fixed;
  inset: 0;
  z-index: 1001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.72);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.lb-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.lb-panel {
  width: min(100%, 440px);
  max-height: min(86vh, 520px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 18px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
}

.lb-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.lb-panel-head h3 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 28px;
  letter-spacing: 2px;
  color: var(--yellow);
  line-height: 1;
}

.lb-close {
  font-family: 'Space Mono', monospace;
  font-size: 22px;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.lb-close:hover {
  color: var(--text);
  border-color: #555;
}

.lb-status {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.5px;
  line-height: 1.5;
  margin-bottom: 10px;
}

.lb-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.lb-table th,
.lb-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.lb-table th {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  background: var(--surface2);
  position: sticky;
  top: 0;
  z-index: 1;
}

.lb-table tbody tr:last-child td {
  border-bottom: none;
}

.lb-table td.lb-empty {
  text-align: center;
  color: var(--muted);
  padding: 20px 12px;
}

.lb-cell-name {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-refresh {
  margin-top: 12px;
  align-self: center;
}

.screen-btn:hover { background: #2a2a2a; border-color: #555; }
.screen-btn.danger  { border-color: var(--accent); color: var(--accent); }
.screen-btn.success { border-color: var(--green);  color: var(--green);  }

/* level map on start screen */
#level-map {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 8px 0 4px;
  max-width: 340px;
}

.lv-dot {
  height: 6px;
  border-radius: 2px;
  background: var(--border);
}

.lv-dot.done  { background: var(--green); }
.lv-dot.cur   { background: var(--yellow); }

#level-badge {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--muted);
  text-transform: uppercase;
}

#combo {
  position: absolute;
  bottom: 10px;
  left: 12px;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 1px;
}

#combo.hot { color: var(--accent2); }

#progress-wrap {
  width: 100%;
  max-width: 700px;
  padding: 8px 1.5rem 0;
}

#progress-bar-bg {
  width: 100%;
  height: 3px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.3s, background 0.3s;
  width: 0%;
}

#footer-hint {
  width: 100%;
  max-width: 700px;
  padding: 8px 1.5rem 2rem;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 1px;
  text-align: right;
  text-transform: uppercase;
}

@media (max-width: 560px) {
  #header {
    padding: 1.25rem 1rem 0.75rem;
  }

  #stats,
  #instruction-bar,
  #arena-wrap,
  #progress-wrap,
  #footer-hint {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  #stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-box {
    padding: 8px 10px;
  }

  .stat-box .value {
    font-size: 18px;
  }

  #instruction {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  #arena {
    height: 52vh;
    min-height: 320px;
  }

  .screen h2 {
    font-size: 42px;
  }

  .screen-btn {
    max-width: 100%;
    white-space: normal;
  }

  .lb-table th,
  .lb-table td {
    padding: 6px 8px;
    font-size: 11px;
  }

  .lb-cell-name {
    max-width: 72px;
  }

  .lb-panel {
    padding: 14px;
  }

  .lb-panel-head h3 {
    font-size: 24px;
  }

  #banner-name {
    font-size: 24px;
  }
}


/* Avatar Selector */
.avatar-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  justify-content: center;
  width: 100%;
}

.avatar-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 20px;
  padding: 4px;
  cursor: pointer;
  transition: all 0.2s;
  filter: grayscale(100%);
  opacity: 0.5;
}

.avatar-btn:hover {
  filter: grayscale(0%);
  opacity: 1;
  transform: scale(1.1);
}

.avatar-btn.selected {
  filter: grayscale(0%);
  opacity: 1;
  border-color: var(--yellow);
  background: rgba(255, 230, 0, 0.1);
  box-shadow: 0 0 10px rgba(255, 230, 0, 0.2);
}

/* Leaderboard Enhancements */
.lb-table tbody tr {
  transition: background 0.2s;
}
.lb-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* Top 3 Highlighting */
.lb-rank-1 td { color: #ffd700; font-weight: bold; text-shadow: 0 0 8px rgba(255,215,0,0.4); }
.lb-rank-2 td { color: #c0c0c0; font-weight: bold; }
.lb-rank-3 td { color: #cd7f32; font-weight: bold; }

.lb-avatar {
  font-size: 16px;
  margin-right: 6px;
}

.lb-title {
  font-size: 10px;
  color: var(--muted);
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
