/* ── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --gold:    #d4af37;
  --gold-dk: #a0822a;
  --bg:      #0f0a04;
  --bg2:     #1c130a;
  --bg3:     #2a1e10;
  --parch:   #f2e4c4;
  --parch2:  #e8d5a8;
  --text:    #f0e6d0;
  --red:     #c0392b;
  --green:   #27ae60;
  --radius:  12px;
}

body {
  font-family: 'Lato', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Screens ────────────────────────────────────────────────────────────────── */
.screen { display: none; min-height: 100vh; padding: 24px 16px; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ── HOME ───────────────────────────────────────────────────────────────────── */
.home-bg {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 30%, #3a2200 0%, #0f0a04 70%);
  z-index: 0;
}
.home-content { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 420px; padding-top: 60px; }

.logo-wrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.logo-deco {
  color: var(--gold-dk);
  font-size: .9rem;
  letter-spacing: .2em;
  opacity: .7;
}

.title {
  font-family: 'Uncial Antiqua', serif;
  font-size: clamp(3rem, 10vw, 5.5rem);
  font-weight: 400;
  color: var(--gold);
  text-shadow: 0 0 50px rgba(212,175,55,.6), 0 2px 4px rgba(0,0,0,.8);
  line-height: 1;
  letter-spacing: .06em;
}

.title-sub {
  font-family: 'Cinzel Decorative', serif;
  font-size: clamp(.9rem, 2.5vw, 1.2rem);
  font-weight: 700;
  letter-spacing: .45em;
  color: var(--parch2);
  opacity: .85;
}

.subtitle { margin-top: 12px; color: var(--parch2); font-size: .95rem; opacity: .7; }

.citation-stats {
  margin-top: 4px;
  font-size: .78rem;
  color: var(--gold-dk);
  letter-spacing: .05em;
  opacity: .8;
}

.card {
  margin-top: 36px;
  background: var(--bg2);
  border: 1px solid var(--gold-dk);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  display: flex; flex-direction: column; gap: 12px;
}

input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid var(--gold-dk);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  font-family: 'Lato', sans-serif;
  transition: border-color .2s;
}
input[type="text"]:focus { outline: none; border-color: var(--gold); }

.btn {
  padding: 12px 20px;
  border: none; border-radius: 8px;
  font-family: 'Cinzel', serif;
  font-size: .9rem;
  font-weight: 700;
  letter-spacing: .06em;
  cursor: pointer;
  transition: transform .1s, filter .2s;
}
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--gold); color: #1a0e00; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-secondary { background: var(--bg3); color: var(--gold); border: 1px solid var(--gold-dk); }
.btn-secondary:hover { border-color: var(--gold); }

.btn-ghost {
  background: none; border: none;
  color: var(--parch2); opacity: .5;
  cursor: pointer; font-size: .85rem;
  transition: opacity .2s;
}
.btn-ghost:hover { opacity: 1; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--gold-dk); font-size: .8rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--gold-dk); }

.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .15em; font-size: 1.1rem; }

.admin-btn { margin-top: 24px; font-size: .8rem; }

.error { color: #e74c3c; font-size: .85rem; padding: 8px 0; }
.hidden { display: none !important; }

/* ── LOBBY ──────────────────────────────────────────────────────────────────── */
#screen-lobby { gap: 16px; max-width: 480px; margin: 0 auto; }

.lobby-header { text-align: center; margin-bottom: 8px; }
.code-display {
  font-family: 'Cinzel', serif;
  font-size: 1.8rem;
  color: var(--parch2);
}
.code-display span {
  color: var(--gold);
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: .2em;
  text-shadow: 0 0 20px rgba(212,175,55,.4);
}
.waiting-msg { color: var(--parch2); opacity: .6; font-size: .9rem; margin-top: 6px; }
.section-title { font-family: 'Cinzel', serif; color: var(--gold-dk); font-size: 1rem; letter-spacing: .1em; }

.player-list { list-style: none; width: 100%; display: flex; flex-direction: column; gap: 8px; }
.player-list li {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 8px;
  padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.player-list li .crown { color: var(--gold); margin-left: 6px; }
#screen-lobby .btn-primary { width: 100%; margin-top: 8px; }

.update-btn { margin-top: auto; padding-top: 16px; font-size: .8rem; }

/* ── GAME ───────────────────────────────────────────────────────────────────── */
#screen-game {
  flex-direction: column;
  align-items: center;
  padding: 16px;
  max-width: 580px;
  margin: 0 auto;
  position: relative;
}

.game-header {
  width: 100%;
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.session-info { font-family: 'Cinzel', serif; font-size: .85rem; color: var(--gold-dk); }
.my-score { font-family: 'Cinzel', serif; font-size: 1.1rem; color: var(--gold); font-weight: 700; }

/* Timer */
.timer-wrap { position: relative; width: 90px; height: 90px; margin: 4px 0 12px; }
.timer-ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--bg3); stroke-width: 8; }
.ring-progress {
  fill: none; stroke: var(--gold); stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 327;
  stroke-dashoffset: 0;
  transition: stroke 0.5s;
}
.timer-count {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Cinzel', serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
}

/* Citation */
.citation-card {
  background: var(--parch);
  color: #2a1a00;
  border-radius: var(--radius);
  padding: 24px 28px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
}
.citation-label {
  font-family: 'Cinzel', serif;
  font-size: .75rem;
  letter-spacing: .1em;
  color: var(--gold-dk);
  margin-bottom: 12px;
}
.citation-text {
  font-size: clamp(1rem, 3vw, 1.2rem);
  line-height: 1.6;
  font-style: italic;
  color: #1a0e00;
}

/* Answer */
.answer-form { width: 100%; display: flex; gap: 8px; margin-top: 16px; }
.answer-form input { flex: 1; }
.answered-msg { color: var(--gold); font-size: .9rem; margin-top: 8px; }

/* Sidebar */
.sidebar {
  position: fixed; right: 12px; top: 50%; transform: translateY(-50%);
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  padding: 12px;
  min-width: 130px;
  display: none;
}
@media (min-width: 900px) { .sidebar { display: block; } }
.sidebar-title { font-family: 'Cinzel', serif; font-size: .75rem; color: var(--gold-dk); margin-bottom: 8px; }
.sidebar-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.sidebar-list li { font-size: .85rem; display: flex; justify-content: space-between; gap: 12px; }
.sidebar-list li .sname { opacity: .8; }
.sidebar-list li .sscore { color: var(--gold); font-weight: 700; }

/* ── OVERLAYS ───────────────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 6, 2, .92);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px;
  z-index: 100;
  padding: 24px;
  animation: fadeIn .3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: scale(.95); } to { opacity: 1; transform: scale(1); } }

.reveal-icon { font-size: 4rem; }
.reveal-verdict { font-family: 'Cinzel', serif; font-size: 2rem; font-weight: 900; }
.reveal-verdict.correct { color: var(--green); }
.reveal-verdict.wrong { color: var(--red); }
.reveal-character { font-size: 1.4rem; color: var(--parch2); }
.reveal-points { font-family: 'Cinzel', serif; font-size: 1.6rem; color: var(--gold); font-weight: 700; }

.reveal-scores { list-style: none; margin-top: 16px; display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: 320px; }
.reveal-scores li { display: flex; justify-content: space-between; background: var(--bg2); border-radius: 6px; padding: 8px 14px; }
.reveal-scores li .rsname { opacity: .9; }
.reveal-scores li .rsscore { color: var(--gold); font-weight: 700; }

.overlay-title { font-family: 'Cinzel', serif; font-size: 1.8rem; color: var(--gold); }
.overlay-countdown { color: var(--parch2); opacity: .7; font-size: .9rem; }

.leaderboard { list-style: none; width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.leaderboard li {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg2); border-radius: 8px; padding: 12px 16px;
}
.leaderboard li .rank { font-family: 'Cinzel', serif; font-size: 1.1rem; color: var(--gold-dk); min-width: 28px; }
.leaderboard li .lname { flex: 1; }
.leaderboard li .lscore { font-family: 'Cinzel', serif; font-weight: 700; color: var(--gold); }
.leaderboard li:first-child { border: 1px solid var(--gold); }
.leaderboard li:first-child .rank { color: var(--gold); font-size: 1.3rem; }

/* ── END ────────────────────────────────────────────────────────────────────── */
#screen-end { gap: 20px; }
.end-title { font-family: 'Cinzel', serif; font-size: 2.2rem; color: var(--gold); text-align: center; }
.leaderboard-final { max-width: 460px; }

/* ── ADMIN MODAL ────────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--gold-dk);
  border-radius: var(--radius);
  padding: 28px 24px;
  max-width: 400px;
  width: 90%;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-box h3 { font-family: 'Cinzel', serif; color: var(--gold); }
.modal-box p { font-size: .9rem; line-height: 1.6; opacity: .8; }
.modal-box code { background: var(--bg3); padding: 1px 5px; border-radius: 4px; font-size: .85rem; }
.update-result { font-size: .9rem; padding: 10px; border-radius: 6px; }
.update-result.ok { background: rgba(39,174,96,.15); color: #2ecc71; }
.update-result.err { background: rgba(192,57,43,.15); color: #e74c3c; }
