/* ============================================
   MADNESS — Song Tournament
   Dark dungeon aesthetic, bold typography
   ============================================ */

:root {
  --bg:      #08080e;
  --bg2:     #0f0f18;
  --bg3:     #161620;
  --bg4:     #1e1e2c;
  --gold:    #f0a030;
  --gold2:   #ffc040;
  --gold-dim: rgba(240, 160, 48, 0.25);
  --gold-faint: rgba(240, 160, 48, 0.08);
  --white:   #ffffff;
  --dim:     rgba(255,255,255,0.55);
  --faint:   rgba(255,255,255,0.12);
  --faint2:  rgba(255,255,255,0.06);
  --border:  rgba(255,255,255,0.1);
  --border2: rgba(255,255,255,0.06);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--white);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ============ CANVAS MAP ============ */
#map-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.85;
}

/* ============ APP SHELL ============ */
#app {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  animation: fadeIn 0.4s ease;
}
.screen.active { display: flex; }

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

/* ============ SPLASH ============ */
#screen-splash {
  justify-content: center;
  text-align: center;
}

.splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px;
}

.splash-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.8;
}

.splash-title {
  font-size: clamp(100px, 18vw, 200px);
  font-weight: 900;
  letter-spacing: -0.05em;
  line-height: 0.88;
  color: var(--white);
  text-shadow:
    0 0 60px rgba(240,160,48,0.2),
    0 0 120px rgba(240,160,48,0.1);
  user-select: none;
}

.splash-sub {
  font-size: 16px;
  font-weight: 400;
  color: var(--dim);
  letter-spacing: 0.05em;
  margin-top: -4px;
}

.splash-note {
  font-size: 11px;
  color: rgba(255,255,255,0.25);
  max-width: 300px;
  line-height: 1.6;
  text-align: center;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 36px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-gold {
  background: var(--gold);
  color: #09090e;
}
.btn-gold:hover {
  background: var(--gold2);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(240,160,48,0.3);
}
.btn-gold:disabled {
  opacity: 0.3;
  cursor: default;
  transform: none;
  box-shadow: none;
}

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

/* ============ SETUP ============ */
#screen-setup { justify-content: center; }

.center-panel {
  max-width: 560px;
  padding: 40px;
  text-align: center;
}
.setup-text {
  font-size: 14px;
  color: var(--dim);
  line-height: 1.7;
  margin-bottom: 32px;
}
.setup-text code {
  background: var(--bg3);
  padding: 2px 6px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  color: var(--gold);
}
.setup-text a { color: var(--gold); }
.setup-text strong { color: var(--white); word-break: break-all; }

/* ============ FLOW SCREENS (genres/artists) ============ */
.flow-header {
  text-align: center;
  padding: 52px 40px 36px;
  flex-shrink: 0;
}

.flow-step {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 12px;
}

.flow-title {
  font-size: clamp(32px, 5vw, 56px);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.05;
  margin-bottom: 12px;
}

.flow-sub {
  font-size: 15px;
  color: var(--dim);
  line-height: 1.5;
}

.flow-footer {
  padding: 32px 40px 48px;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-shrink: 0;
}

/* ============ GENRES ============ */
.genre-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding: 0 40px;
  max-width: 840px;
  width: 100%;
}

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

.genre-tile {
  padding: 28px 16px 24px;
  border: 1px solid var(--border2);
  background: var(--bg2);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  user-select: none;
}
.genre-tile:hover {
  border-color: var(--border);
  background: var(--bg3);
}
.genre-tile.selected {
  border-color: var(--gold);
  background: var(--gold-faint);
}
.genre-tile.selected .genre-label { color: var(--gold); }

.genre-icon { font-size: 30px; margin-bottom: 10px; line-height: 1; }
.genre-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--dim);
  transition: color 0.2s;
}

/* ============ ARTISTS ============ */
.artist-search-row {
  width: 100%;
  max-width: 560px;
  padding: 0 40px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  padding: 14px 20px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: inherit;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--gold); }
.search-input::placeholder { color: rgba(255,255,255,0.25); }

.artist-results {
  width: 100%;
  max-width: 560px;
  padding: 0 40px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  min-height: 80px;
}

.artist-result-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  cursor: pointer;
  transition: all 0.15s;
}
.artist-result-row:hover { border-color: var(--gold-dim); background: var(--bg3); }
.artist-result-row.already-added { opacity: 0.4; cursor: default; }

.artist-thumb {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg4);
  object-fit: cover;
  flex-shrink: 0;
}
.artist-result-name { font-size: 14px; font-weight: 600; }
.artist-result-meta { font-size: 11px; color: var(--dim); }

.add-btn {
  margin-left: auto;
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--dim);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  font-family: inherit;
}
.add-btn:hover { border-color: var(--gold); color: var(--gold); }

.artist-selected-label {
  width: 100%;
  max-width: 560px;
  padding: 20px 40px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--dim);
  flex-shrink: 0;
}

.artist-selected-list {
  width: 100%;
  max-width: 560px;
  padding: 0 40px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 8px;
  background: var(--gold-dim);
  border: 1px solid var(--gold-dim);
  font-size: 12px;
  font-weight: 600;
}
.chip-img {
  width: 24px; height: 24px;
  border-radius: 50%;
  object-fit: cover;
}
.chip-remove {
  width: 18px; height: 18px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
  padding: 0;
  line-height: 1;
}
.chip-remove:hover { color: var(--white); }

/* ============ BUILDING ============ */
#screen-building { justify-content: center; }

.building-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px;
  text-align: center;
}

.building-icon {
  font-size: 48px;
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.92); }
}

.building-title {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.building-progress-bar {
  width: 280px;
  height: 2px;
  background: var(--bg4);
  position: relative;
  overflow: hidden;
}
.building-fill {
  height: 100%;
  background: var(--gold);
  width: 0%;
  transition: width 0.4s ease;
}

.building-status {
  font-size: 12px;
  color: var(--dim);
  letter-spacing: 0.1em;
}

/* ============ BATTLE ARENA ============ */
#screen-battle {
  flex-direction: column;
  overflow: hidden;
}

.battle-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  padding: 20px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
  background: linear-gradient(to bottom, rgba(8,8,14,0.9) 0%, transparent 100%);
  pointer-events: none;
}

.battle-round-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--gold);
}

.battle-counter {
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.battle-dots {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.battle-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--faint2);
  transition: background 0.3s;
}
.battle-dot.done { background: var(--gold); }
.battle-dot.active { background: var(--white); box-shadow: 0 0 6px rgba(255,255,255,0.5); }

.battle-arena {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

.battle-side {
  flex: 1;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  transition: flex 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.battle-side:hover .battle-album-bg { opacity: 0.65; filter: grayscale(10%); }
.battle-side:hover .battle-overlay { opacity: 0.7; }

.battle-album-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0.35;
  filter: grayscale(40%);
  transition: opacity 0.4s, filter 0.4s;
  transform: scale(1.02);
}

.battle-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(8,8,14,0.6) 0%, rgba(8,8,14,0.2) 100%);
  transition: opacity 0.3s;
}

/* Left side */
#battle-side-a .battle-overlay {
  background: linear-gradient(to right, rgba(8,8,14,0.85) 0%, rgba(8,8,14,0.4) 50%, rgba(8,8,14,0.6) 100%);
}

/* Right side */
#battle-side-b .battle-overlay {
  background: linear-gradient(to left, rgba(8,8,14,0.85) 0%, rgba(8,8,14,0.4) 50%, rgba(8,8,14,0.6) 100%);
}

.battle-content {
  position: absolute;
  bottom: 80px;
  left: 48px;
  right: 48px;
  z-index: 2;
}
.battle-content-right {
  left: 48px;
  right: 48px;
  text-align: right;
}

.battle-tag {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  padding: 3px 8px;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  margin-bottom: 12px;
}

.battle-song {
  font-size: clamp(24px, 3.5vw, 56px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.08;
  margin-bottom: 10px;
  text-shadow: 0 2px 20px rgba(0,0,0,0.8);
}

.battle-artist {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 20px;
}

.battle-preview {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(8px);
}
.battle-preview:hover { background: rgba(255,255,255,0.15); }
.battle-preview.playing { background: rgba(240,160,48,0.15); border-color: var(--gold-dim); color: var(--gold); }
.battle-preview:disabled { opacity: 0.3; cursor: default; }

.preview-icon { font-size: 12px; }

.battle-divider {
  position: absolute;
  left: 50%;
  top: 0; bottom: 0;
  width: 1px;
  background: rgba(255,255,255,0.06);
  z-index: 10;
  pointer-events: none;
}

.battle-vs {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.35em;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(240,160,48,0.6);
  background: var(--bg);
  padding: 10px 14px;
  border: 1px solid var(--gold-dim);
}

.battle-hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.2);
  z-index: 20;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.5s;
}

/* ─── Winner animation ─── */
.battle-side.choosing-winner {
  flex: 1.8;
}
.battle-side.choosing-winner .battle-album-bg {
  opacity: 0.7;
  filter: grayscale(0%);
}
.battle-side.choosing-loser {
  flex: 0.2;
}
.battle-side.choosing-loser .battle-overlay {
  background: rgba(8,8,14,0.88) !important;
}
.battle-side.choosing-loser .battle-album-bg {
  opacity: 0.1;
  filter: grayscale(100%);
}

.winner-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  animation: winFlash 0.6s ease-out forwards;
}
@keyframes winFlash {
  0% { box-shadow: inset 0 0 0 0px rgba(240,160,48,0); }
  30% { box-shadow: inset 0 0 0 4px rgba(240,160,48,0.8); }
  100% { box-shadow: inset 0 0 0 2px rgba(240,160,48,0.2); }
}

/* ============ CHECKPOINT ============ */
#screen-checkpoint {
  justify-content: center;
  overflow-y: auto;
}

.checkpoint-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 60px 40px;
  text-align: center;
  max-width: 700px;
}

.checkpoint-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--gold);
}

.checkpoint-title {
  font-size: clamp(36px, 6vw, 64px);
  font-weight: 900;
  letter-spacing: -0.03em;
}

.checkpoint-stat {
  font-size: 14px;
  color: var(--dim);
}

.survivor-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 8px 0;
}

.survivor-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  font-size: 12px;
  font-weight: 600;
  max-width: 220px;
}
.survivor-chip img {
  width: 28px; height: 28px;
  object-fit: cover;
}
.survivor-chip-info { text-align: left; overflow: hidden; }
.survivor-chip-song { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.survivor-chip-artist { font-size: 10px; color: var(--dim); letter-spacing: 0.05em; }

/* ============ WINNER SCREEN ============ */
#screen-winner { justify-content: center; overflow-y: auto; }

.winner-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 40px;
  text-align: center;
  max-width: 600px;
}

.winner-crown { font-size: 52px; animation: float 3s ease-in-out infinite; }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.winner-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--gold);
}

.winner-art {
  width: 180px; height: 180px;
  background-size: cover;
  background-position: center;
  background-color: var(--bg3);
  box-shadow: 0 0 60px rgba(240,160,48,0.25), 0 0 120px rgba(240,160,48,0.1);
}

.winner-song {
  font-size: clamp(28px, 5vw, 52px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.1;
  max-width: 480px;
  text-shadow: 0 0 40px rgba(240,160,48,0.2);
}

.winner-artist {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
}

.winner-stats {
  display: flex;
  gap: 32px;
  justify-content: center;
  margin-top: 8px;
}
.winner-stat { text-align: center; }
.winner-stat-val {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--gold);
}
.winner-stat-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--dim);
  margin-top: 4px;
}

/* ============ SCREEN EYEBROW / TITLE ============ */
.screen-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 12px;
}

.screen-title {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 20px;
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }
