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

:root {
  --bg: #0a0a0f;
  --surface: #151520;
  --surface2: #1e1e2e;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --accent: #e63946;
  --accent-glow: #e6394640;
  --gold: #f0c040;
  --green: #2ecc71;
  --purple: #a855f7;
  --blue: #3b82f6;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app { height: 100%; position: relative; }

/* Screens */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; flex-direction: column; }

/* ── MENU ── */
.menu-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  gap: 2.5rem;
}
.logo { text-align: center; }
.logo-icon { font-size: 4rem; margin-bottom: 0.5rem; filter: drop-shadow(0 0 20px var(--accent-glow)); }
.logo h1 {
  font-family: 'Creepster', cursive;
  font-size: 3rem;
  line-height: 1.1;
  color: var(--text);
  letter-spacing: 2px;
}
.logo h1 span { color: var(--accent); font-size: 4rem; display: block; }
.tagline { color: var(--text-dim); margin-top: 0.75rem; font-size: 1.1rem; letter-spacing: 3px; text-transform: uppercase; }

.menu-buttons { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; max-width: 320px; }

/* ── BUTTONS ── */
.btn {
  padding: 0.9rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-primary:hover { background: #d32f3f; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }
.btn-icon { background: none; border: none; font-size: 1.3rem; cursor: pointer; padding: 0.3rem; }

.back-btn {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.5rem;
}
.back-btn:hover { color: var(--text); }

/* ── PANELS ── */
.panel {
  position: relative;
  max-width: 420px;
  width: 100%;
  margin: auto;
  padding: 2rem;
}
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-dim); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 1px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--accent); }
.code-input { text-align: center; font-size: 1.8rem; letter-spacing: 0.5rem; text-transform: uppercase; font-weight: 700; }

.stepper { display: flex; align-items: center; gap: 1rem; }
.stepper-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
}
.stepper-btn:hover { background: var(--border); }
#rounds-val { font-size: 1.5rem; font-weight: 700; min-width: 2rem; text-align: center; }

.error-msg { color: var(--accent); font-size: 0.9rem; margin-top: 0.75rem; text-align: center; min-height: 1.4rem; }

/* Category grid */
.category-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.cat-chip {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}
.cat-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Custom category */
.custom-cat-row { display: flex; gap: 0.5rem; }
.custom-cat-row input { flex: 1; }
.btn-sm { padding: 0.6rem 1rem; font-size: 0.85rem; white-space: nowrap; }
.custom-cat-status { font-size: 0.8rem; margin-top: 0.4rem; min-height: 1.2rem; }
.custom-cat-status.success { color: var(--green); }
.custom-cat-status.error { color: var(--accent); }
.custom-cat-status.loading { color: var(--gold); }

/* ── LOBBY ── */
.lobby-panel { text-align: center; }
.room-code-display {
  margin: 1.5rem 0;
  padding: 1.25rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.room-code-display .label { display: block; font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 2px; margin-bottom: 0.5rem; }
.room-code-display .code { font-size: 3rem; font-weight: 800; letter-spacing: 0.75rem; color: var(--gold); font-family: 'Creepster', cursive; }

.player-list { display: flex; flex-direction: column; gap: 0.5rem; margin: 1rem 0; }
.player-tag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.player-tag .name { font-weight: 600; }
.player-tag .badge { font-size: 0.7rem; padding: 0.15rem 0.5rem; border-radius: 100px; background: var(--accent); color: #fff; }
.player-tag .badge.host { background: var(--gold); color: #000; }
.player-tag .kick-btn {
  background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 0.8rem; padding: 0.2rem 0.5rem;
}
.player-tag .kick-btn:hover { color: var(--accent); }
.lobby-info { color: var(--text-dim); font-size: 0.85rem; margin: 0.5rem 0 1rem; }

/* ── GAME HEADER ── */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.round-info { font-weight: 700; font-size: 0.95rem; }
.room-code-sm { font-size: 0.8rem; color: var(--text-dim); letter-spacing: 2px; }

/* ── SCENARIO ── */
.scenario-banner {
  background: linear-gradient(135deg, #1a0a0e, #0f0a1a);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  margin: 1rem;
  padding: 1.25rem;
  text-align: center;
  box-shadow: 0 0 30px var(--accent-glow);
  flex-shrink: 0;
}
.scenario-label {
  font-size: 0.7rem;
  letter-spacing: 3px;
  color: var(--accent);
  margin-bottom: 0.5rem;
  font-weight: 600;
}
#scenario-text { font-size: 1.05rem; line-height: 1.5; }

/* ── JUDGE BANNER ── */
.judge-banner {
  text-align: center;
  padding: 2rem 1.5rem;
  margin: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--gold);
}
.judge-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.judge-banner p { color: var(--text-dim); line-height: 1.6; }
#judge-progress { margin-top: 1rem; color: var(--text-dim); font-size: 0.9rem; }

/* ── PLAYER HAND ── */
.player-hand {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.player-hand h3 { font-size: 0.95rem; margin-bottom: 0.75rem; }
.player-hand .hint { color: var(--text-dim); font-weight: 400; font-size: 0.8rem; }

.hand-cards {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.item-card {
  padding: 0.65rem 0.4rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.item-card .card-category { font-size: 0.6rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 0.4rem; }
.item-card .card-name { font-size: 0.85rem; font-weight: 600; line-height: 1.3; }
.item-card.selected { border-color: var(--green); background: #2ecc7115; box-shadow: 0 0 12px #2ecc7130; }
.item-card.selected::after {
  content: '\2713';
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.75rem;
  color: var(--green);
  font-weight: 700;
}
.item-card.used { opacity: 0.4; border-style: dashed; cursor: not-allowed; }

/* Plan area */
.plan-area { flex: 1; display: flex; flex-direction: column; }
.plan-area textarea {
  flex: 1;
  min-height: 100px;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  outline: none;
  line-height: 1.5;
}
.plan-area textarea:focus { border-color: var(--accent); }
.plan-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 0.5rem; }
#char-count { font-size: 0.8rem; color: var(--text-dim); }

/* ── WAITING ── */
.waiting-msg { text-align: center; padding: 3rem 1.5rem; }
.pulse-icon { font-size: 3rem; animation: pulse 2s infinite; }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.95); }
}
.waiting-msg p { color: var(--text-dim); margin-top: 1rem; font-size: 1rem; }

/* ── PRESENTATIONS ── */
.presentation-card {
  margin: 1rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.presentation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.pres-name { font-weight: 700; font-size: 1.1rem; }
.pres-counter { font-size: 0.8rem; color: var(--text-dim); }
.pres-items {
  display: flex;
  gap: 0.5rem;
  padding: 1rem;
  flex-wrap: wrap;
}
.pres-item {
  padding: 0.4rem 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 0.8rem;
  color: var(--gold);
}
.pres-plan { padding: 0 1rem 1rem; font-size: 0.95rem; line-height: 1.6; color: var(--text); white-space: pre-wrap; }

#btn-next-pres { margin: 0 1rem 1rem; }

/* ── JUDGING ── */
.judging-title { text-align: center; padding: 1rem; color: var(--gold); }
.judging-cards { display: flex; flex-direction: column; gap: 0.75rem; padding: 0 1rem 1rem; }
.judge-pick {
  padding: 1rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}
.judge-pick:hover { border-color: var(--gold); background: var(--surface2); }
.judge-pick .jp-name { font-weight: 700; margin-bottom: 0.3rem; }
.judge-pick .jp-items { font-size: 0.8rem; color: var(--gold); margin-bottom: 0.4rem; }
.judge-pick .jp-plan { font-size: 0.9rem; color: var(--text-dim); line-height: 1.4; white-space: pre-wrap; }

/* ── ROUND END ── */
.winner-announce { text-align: center; padding: 3rem 1.5rem; }
.winner-icon { font-size: 4rem; margin-bottom: 0.5rem; }
.winner-announce h2 { font-size: 2rem; color: var(--gold); font-family: 'Creepster', cursive; }
.winner-announce p { color: var(--text-dim); margin-top: 0.25rem; }
#btn-next-round { margin: 0 auto; display: block; min-width: 200px; }

/* ── GAME OVER ── */
.game-over-content { text-align: center; padding: 2rem 1.5rem; }
.game-over-content h2 { font-size: 2.5rem; font-family: 'Creepster', cursive; margin-bottom: 1.5rem; color: var(--accent); }
.final-scores { margin-bottom: 1.5rem; }
.final-score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  margin-bottom: 0.4rem;
}
.final-score-row.winner { border: 1px solid var(--gold); background: #f0c04010; }
.final-score-row .fs-rank { font-size: 1.2rem; margin-right: 0.75rem; }
.final-score-row .fs-name { flex: 1; font-weight: 600; text-align: left; }
.final-score-row .fs-score { font-weight: 700; color: var(--gold); }
.game-over-content .btn { margin-top: 0.5rem; min-width: 200px; }

/* ── OVERLAYS ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}
.overlay-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 480px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}
.close-btn {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
}
.close-btn:hover { color: var(--text); }

.overlay-content h2 { margin-bottom: 1rem; text-align: center; }

/* Rules */
.rules-body { display: flex; flex-direction: column; gap: 1rem; }
.rule-step { display: flex; gap: 1rem; align-items: flex-start; }
.step-num {
  min-width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.rule-step strong { display: block; margin-bottom: 0.2rem; }
.rule-step p { color: var(--text-dim); font-size: 0.9rem; line-height: 1.4; }

/* Scoreboard */
.scoreboard-list { display: flex; flex-direction: column; gap: 0.4rem; }
.sb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  background: var(--surface2);
  border-radius: var(--radius-sm);
}
.sb-row .sb-name { flex: 1; font-weight: 500; }
.sb-row .sb-score { font-weight: 700; color: var(--gold); min-width: 2rem; text-align: right; }
.sb-row .sb-badge { margin-left: 0.5rem; font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: 100px; }
.sb-row .sb-badge.judge { background: var(--gold); color: #000; }

/* Mobile tweaks */
@media (max-width: 600px) {
  .hand-cards { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  .logo h1 { font-size: 2.2rem; }
  .logo h1 span { font-size: 3rem; }
  .hand-cards { grid-template-columns: repeat(2, 1fr); }
  .item-card .card-name { font-size: 0.78rem; }
  .room-code-display .code { font-size: 2.5rem; }
}
