:root {
  --bg: #0e0b1a;
  --panel: #1a1530;
  --panel-2: #241d42;
  --line: #37305c;
  --text: #e8e3f4;
  --muted: #9a92b8;
  --gold: #e8b64c;
  --gold-dark: #b8862b;
  --red: #e05563;
  --green: #5fd08a;
  --blue: #6ea8e8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #221a45 0%, var(--bg) 60%);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#app { width: 100%; max-width: 640px; padding: 24px 16px 8px; }
.screen { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.8rem;
  margin: 24px 0 0;
  letter-spacing: 0.04em;
}
.title span { color: var(--gold); }
.tagline { color: var(--muted); margin: 0; text-align: center; font-size: 0.85rem; max-width: 440px; }
.subtitle { font-family: Georgia, serif; font-weight: normal; margin: 12px 0 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel label { font-size: 0.85rem; color: var(--muted); text-align: left; }
.checkbox-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem; color: var(--muted); cursor: pointer;
}
.checkbox-row input { width: auto; accent-color: var(--gold); }

input, select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 1rem;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--gold-dark); border-color: transparent; }
#code-input { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 16px;
  font-size: 1rem;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}
.btn:hover:not(:disabled) { filter: brightness(1.2); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-gold { background: linear-gradient(180deg, var(--gold), var(--gold-dark)); color: #241a05; font-weight: 700; border: none; }
.btn-small { padding: 5px 10px; font-size: 0.8rem; }

.divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 0.8rem; margin: 4px 0;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; }

.rules { max-width: 440px; color: var(--muted); font-size: 0.9rem; }
.rules summary { cursor: pointer; color: var(--text); }
.rules ul { text-align: left; line-height: 1.6; }

/* Lobby */
.room-code-box {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px 32px;
}
.room-code-box span { font-size: 0.8rem; color: var(--muted); }
.room-code-box strong { font-size: 2.2rem; letter-spacing: 0.35em; color: var(--gold); }

.roster { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; width: 100%; }
.pchip {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 14px; min-width: 88px;
  transition: opacity 0.3s;
}
.pchip.me { border-color: var(--gold-dark); }
.pchip.me .pname { color: var(--gold); }
.pchip.out { opacity: 0.35; }
.pchip.disconnected { border-style: dashed; opacity: 0.55; }
.pchip .pname { font-size: 0.85rem; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ready-dot { font-size: 0.7rem; color: var(--muted); }
.ready-dot.in { color: var(--green); }

.hint { color: var(--muted); font-size: 0.9rem; margin: 0; min-height: 1.2em; text-align: center; }

.customize {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.customize label { font-size: 0.8rem; color: var(--muted); text-align: left; }

/* Question screen */
.game-header {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  font-family: Georgia, serif; font-size: 1.05rem;
}
.tier-badge {
  background: var(--panel-2); border: 1px solid var(--gold-dark); color: var(--gold);
  border-radius: 999px; padding: 4px 12px; font-size: 0.85rem; font-weight: 600;
}
.tier-badge.line { border-color: var(--red); color: #ffb4bd; }

.timer-bar {
  width: 100%; height: 22px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; position: relative; overflow: hidden;
}
.timer-bar .timer-fill {
  --pct: 100%;
  height: 100%; width: var(--pct);
  background: linear-gradient(90deg, var(--green), var(--gold), var(--red));
  transition: width 1s linear;
}
.timer-bar #timer-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 600; text-shadow: 0 1px 2px rgba(0,0,0,0.6);
}

.question-text {
  font-family: Georgia, serif; font-size: 1.3rem; line-height: 1.4; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px; width: 100%;
}
.question-image {
  display: block;
  width: 100%;
  max-height: min(38vh, 360px);
  object-fit: contain;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.question-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.choice-btn { padding: 16px 10px; text-align: center; font-size: 0.95rem; }
.choice-btn.selected { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
@media (max-width: 420px) {
  .question-choices { grid-template-columns: 1fr; }
}

.banner {
  width: 100%; text-align: center; padding: 12px;
  border-radius: 12px; font-size: 0.95rem;
  background: var(--panel-2); border: 1px solid var(--gold-dark); color: var(--gold);
}
.banner.grim { border-color: var(--red); color: #ffb4bd; }

/* Reveal */
.answer-box {
  background: var(--panel-2); border: 1px solid var(--green); border-radius: 12px;
  padding: 12px 18px; font-size: 1rem;
}
.answer-box strong { color: var(--green); }
.explain { max-width: 480px; font-style: italic; }
.reveal-results { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.result-row {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font-size: 0.9rem; text-align: left;
}
.result-row.correct { border-color: var(--green); }
.result-row.wrong { border-color: var(--red); opacity: 0.8; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #3a1620; color: #ffb4bd; border: 1px solid var(--red);
  padding: 10px 18px; border-radius: 10px; font-size: 0.9rem;
  transition: opacity 0.3s; z-index: 10;
}

.credits { color: #5b5478; font-size: 0.72rem; padding: 18px 0 14px; text-align: center; max-width: 440px; }
