
:root {
  --bg: #080818;
  --panel: #0f0f2a;
  --panel2: #141432;
  --gold: #f0c040;
  --gold2: #c8960a;
  --blue: #2255aa;
  --blue2: #3370cc;
  --green: #1a6b2a;
  --green2: #22883a;
  --red: #8a1a1a;
  --red2: #b82222;
  --purple: #5a1a8a;
  --curse: #300830;
  --text: #e8e0cc;
  --dim: #9090a8;
  --card-back: #1a1a40;
  --card-back2: #22224e;
  --stone: #2a2838;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #080818; --panel: #0f0f2a; --panel2: #141432;
    --text: #e8e0cc; --dim: #9090a8;
    color-scheme: dark;
  }
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Crimson Text', Georgia, serif; overflow: hidden; }
body { display: flex; flex-direction: column; padding-left: max(0px, env(safe-area-inset-left,0px)); padding-right: max(0px, env(safe-area-inset-right,0px)); padding-block: 0; }

/* ── SETUP SCREEN ── */
#screen-setup {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; gap: 24px;
  background: radial-gradient(ellipse at 50% 20%, #1a0a3a 0%, #080818 70%);
}
.setup-title { font-family: 'Cinzel', serif; font-size: 3rem; font-weight: 900; color: var(--gold); text-align: center; text-shadow: 0 0 30px #f0c04080; letter-spacing: 4px; }
.setup-subtitle { font-family: 'Cinzel', serif; font-size: 1rem; color: var(--dim); letter-spacing: 3px; text-transform: uppercase; }
.setup-card { background: var(--panel); border: 1px solid #333366; border-radius: 12px; padding: 32px 40px; width: 560px; max-width: 95vw; }
.setup-card h2 { font-family: 'Cinzel', serif; font-size: 1.1rem; color: var(--gold); margin-bottom: 20px; letter-spacing: 2px; }
.player-rows { display: flex; flex-direction: column; gap: 12px; }
.player-row { display: flex; gap: 10px; align-items: center; }
.player-row span { font-family: 'Cinzel', serif; font-size: 0.85rem; color: var(--dim); width: 72px; flex-shrink: 0; }
.player-row input { flex: 1; background: #1a1a3e; border: 1px solid #334; border-radius: 6px; color: var(--text); padding: 8px 12px; font-family: 'Crimson Text', serif; font-size: 1rem; outline: none; }
.player-row input:focus { border-color: var(--gold2); }
.char-select { display: flex; gap: 6px; }
.char-btn { width: 38px; height: 38px; border-radius: 6px; border: 2px solid #334; background: #1a1a3e; cursor: pointer; font-size: 1.3rem; transition: all 0.2s; display: flex; align-items: center; justify-content: center; }
.char-btn:hover { border-color: var(--gold2); transform: scale(1.1); }
.char-btn.selected { border-color: var(--gold); background: #2a2a4e; box-shadow: 0 0 10px #f0c04060; }
.num-players { display: flex; gap: 10px; margin-bottom: 20px; }
.num-btn { flex: 1; padding: 10px; border: 2px solid #334; border-radius: 8px; background: #1a1a3e; color: var(--text); font-family: 'Cinzel', serif; font-size: 1rem; cursor: pointer; transition: all 0.2s; }
.num-btn:hover, .num-btn.selected { border-color: var(--gold); background: #2a2a4e; color: var(--gold); }
.btn-start { width: 100%; padding: 14px; background: linear-gradient(135deg, #8a6000, #c89010); border: none; border-radius: 8px; color: #fff; font-family: 'Cinzel', serif; font-size: 1.1rem; font-weight: 700; letter-spacing: 3px; cursor: pointer; margin-top: 20px; transition: all 0.2s; text-transform: uppercase; }
.btn-start:hover { background: linear-gradient(135deg, #a07010, #e0a020); box-shadow: 0 4px 20px #f0c04040; }

/* ── GAME BOARD ── */
#screen-game { display: none; height: 100vh; grid-template-columns: 200px 1fr 260px; grid-template-rows: 48px 1fr; gap: 0; }
#screen-game.active { display: grid; }
#hbar { grid-column: 1/-1; background: var(--panel); border-bottom: 1px solid #22224a; display: flex; align-items: center; padding: 0 16px; gap: 16px; }
#hbar .logo { font-family: 'Cinzel', serif; font-weight: 900; font-size: 1rem; color: var(--gold); letter-spacing: 3px; flex-shrink: 0; }
#hbar .turn-info { flex: 1; text-align: center; font-family: 'Cinzel', serif; font-size: 0.9rem; color: var(--text); }
#hbar .turn-info .player-name-tag { color: var(--gold); font-weight: 700; }
#hbar .phase-tag { font-family: 'Cinzel', serif; font-size: 0.75rem; color: var(--dim); letter-spacing: 2px; text-transform: uppercase; }

/* Tower Panel */
#tower-panel { background: var(--panel); border-right: 1px solid #22224a; display: flex; flex-direction: column; overflow: hidden; }
#tower-wrap { flex: 1; position: relative; overflow: hidden; padding: 8px 0; }
#tower-svg { width: 100%; height: 100%; }
.tower-char-token { font-size: 1.2rem; transition: transform 0.5s ease; }

/* Card Area */
#card-area { background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px; gap: 12px; overflow: hidden; }
#diff-selector { display: flex; gap: 10px; align-items: center; }
#diff-selector label { font-family: 'Cinzel', serif; font-size: 0.75rem; color: var(--dim); letter-spacing: 2px; text-transform: uppercase; margin-right: 4px; }
.diff-btn { padding: 8px 16px; border: 2px solid #334; border-radius: 6px; background: #1a1a3e; color: var(--dim); font-family: 'Cinzel', serif; font-size: 0.8rem; cursor: pointer; transition: all 0.2s; white-space: nowrap; }
.diff-btn:hover:not(:disabled) { border-color: var(--gold2); color: var(--text); }
.diff-btn.selected { border-color: var(--gold); color: var(--gold); background: #2a2a4e; }
.diff-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#card-grid { display: grid; grid-template-columns: repeat(12, 1fr); grid-template-rows: repeat(4, 1fr); gap: 6px; width: 100%; max-width: 860px; }
.card { aspect-ratio: 2.5/3.5; border-radius: 7px; cursor: pointer; perspective: 600px; position: relative; transition: transform 0.15s; }
.card:hover:not(.flipped):not(.eliminated) .card-inner { box-shadow: 0 0 14px #f0c04080; transform: scale(1.04); }
.card.eliminated { cursor: default; opacity: 0.3; }
.card-inner { width: 100%; height: 100%; border-radius: 7px; transform-style: preserve-3d; transition: transform 0.5s; position: relative; }
.card.flipped .card-inner { transform: rotateY(180deg); }
.card-front, .card-back-face { position: absolute; inset: 0; border-radius: 7px; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.card-front { background: linear-gradient(160deg, var(--card-back), var(--card-back2)); border: 1.5px solid #2a2a5a; }
.card-front-icon { font-size: 1.4rem; opacity: 0.6; }
.card-front-num { font-family: 'Cinzel', serif; font-size: 0.55rem; color: #44448a; margin-top: 3px; }
.card-back-face { transform: rotateY(180deg); flex-direction: column; gap: 4px; padding: 6px; text-align: center; }
.card-back-face.type-blue { background: linear-gradient(160deg, #142260, #1e3080); border: 1.5px solid #2244aa; }
.card-back-face.type-green { background: linear-gradient(160deg, #0a3a16, #125522); border: 1.5px solid #1a7a2a; }
.card-back-face.type-red { background: linear-gradient(160deg, #4a0e0e, #6a1818); border: 1.5px solid #aa2222; }
.card-back-face.type-curse { background: linear-gradient(160deg, #1e0028, #380048); border: 1.5px solid #881aaa; }
.card-eff-icon { font-size: 1.6rem; }
.card-eff-name { font-family: 'Cinzel', serif; font-size: 0.55rem; color: #fff; line-height: 1.2; }

/* Score Panel */
#score-panel { background: var(--panel); border-left: 1px solid #22224a; display: flex; flex-direction: column; overflow: hidden; }
.score-header { font-family: 'Cinzel', serif; font-size: 0.75rem; letter-spacing: 2px; color: var(--gold); text-transform: uppercase; padding: 10px 14px 6px; border-bottom: 1px solid #22224a; }
#player-scores { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.ps-card { background: var(--panel2); border-radius: 8px; padding: 10px 12px; border: 1.5px solid #22224a; transition: border-color 0.3s; }
.ps-card.active-player { border-color: var(--gold); box-shadow: 0 0 10px #f0c04030; }
.ps-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.ps-avatar { font-size: 1.5rem; }
.ps-name { font-family: 'Cinzel', serif; font-size: 0.85rem; font-weight: 700; color: var(--text); flex: 1; }
.ps-score { font-family: 'Cinzel', serif; font-size: 1.1rem; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.ps-bar-wrap { background: #1a1a3e; border-radius: 4px; height: 8px; overflow: hidden; }
.ps-bar { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.ps-stage { font-size: 0.75rem; color: var(--dim); margin-top: 4px; }
#game-log { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.log-item { font-size: 0.8rem; color: var(--dim); padding: 4px 8px; background: #0f0f28; border-radius: 4px; border-left: 3px solid #334; }
.log-item.log-good { border-left-color: #2a8a3a; color: #80e090; }
.log-item.log-bad { border-left-color: #8a2222; color: #e08080; }
.log-item.log-event { border-left-color: var(--gold2); color: #e0c060; }

/* ── MODALS ── */
.modal-overlay { position: fixed; inset: 0; background: #000000b0; display: flex; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(4px); }
.modal-overlay[hidden] { display: none !important; }
.modal-box { background: var(--panel); border: 1px solid #33336a; border-radius: 16px; padding: 32px; max-width: 540px; width: 90vw; position: relative; }
.modal-box.modal-lg { max-width: 640px; }
.modal-title { font-family: 'Cinzel', serif; font-size: 1.4rem; font-weight: 900; color: var(--gold); text-align: center; margin-bottom: 8px; }
.modal-subtitle { font-family: 'Cinzel', serif; font-size: 0.8rem; color: var(--dim); text-align: center; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 20px; }
.badges { display: flex; gap: 8px; justify-content: center; margin-bottom: 18px; flex-wrap: wrap; }
.badge { padding: 4px 12px; border-radius: 20px; font-family: 'Cinzel', serif; font-size: 0.75rem; letter-spacing: 1px; text-transform: uppercase; }
.badge-blue { background: #1a3070; color: #88aaff; border: 1px solid #3355bb; }
.badge-green { background: #0a3a18; color: #66dd88; border: 1px solid #1a7a2a; }
.badge-red { background: #4a1010; color: #ff8888; border: 1px solid #882222; }
.badge-gold { background: #3a2800; color: var(--gold); border: 1px solid var(--gold2); }
.badge-purple { background: #2a0a4a; color: #cc88ff; border: 1px solid #6622aa; }
.effect-icon { font-size: 4rem; text-align: center; margin: 12px 0; }
.effect-desc { font-size: 1.1rem; text-align: center; color: var(--text); line-height: 1.6; margin-bottom: 20px; }
.q-text { font-size: 1.15rem; line-height: 1.6; text-align: center; margin-bottom: 24px; color: var(--text); }
.q-options { display: flex; flex-direction: column; gap: 10px; }
.q-opt { background: #1a1a40; border: 2px solid #2a2a5a; border-radius: 8px; padding: 12px 16px; cursor: pointer; display: flex; align-items: center; gap: 12px; transition: all 0.2s; font-size: 1rem; color: var(--text); text-align: left; }
.q-opt:hover:not(:disabled) { border-color: var(--gold2); background: #22224a; }
.q-opt.correct { border-color: #2a8a3a; background: #0a3a18; color: #88dd99; }
.q-opt.wrong { border-color: #8a2222; background: #3a0a0a; color: #ff8888; }
.q-opt .opt-letter { font-family: 'Cinzel', serif; font-size: 0.9rem; color: var(--gold); font-weight: 700; width: 24px; flex-shrink: 0; }
.q-explanation { background: #1a2a3a; border: 1px solid #2a4a5a; border-radius: 8px; padding: 12px 16px; margin-top: 14px; font-size: 0.95rem; color: #a0c8e0; line-height: 1.5; }
.btn { padding: 12px 28px; border-radius: 8px; border: none; cursor: pointer; font-family: 'Cinzel', serif; font-size: 0.9rem; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; transition: all 0.2s; }
.btn-gold { background: linear-gradient(135deg, #8a6000, #c89010); color: #fff; }
.btn-gold:hover { background: linear-gradient(135deg, #a07010, #e0a020); box-shadow: 0 4px 16px #f0c04040; }
.btn-row { display: flex; gap: 12px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.steal-options { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.steal-opt { background: #1a1a40; border: 2px solid #2a2a5a; border-radius: 8px; padding: 10px 16px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; transition: all 0.2s; }
.steal-opt:hover { border-color: var(--gold2); }
/* Game over modal */
.winner-banner { font-size: 5rem; text-align: center; margin: 12px 0; }
.winner-name { font-family: 'Cinzel', serif; font-size: 2rem; font-weight: 900; color: var(--gold); text-align: center; }
.final-scores { display: flex; flex-direction: column; gap: 8px; margin: 20px 0; }
.fs-row { display: flex; justify-content: space-between; align-items: center; background: #1a1a3e; border-radius: 8px; padding: 10px 16px; }
.fs-place { font-family: 'Cinzel', serif; font-size: 0.8rem; color: var(--dim); }
.fs-name { font-family: 'Cinzel', serif; font-size: 1rem; color: var(--text); }
.fs-score { font-family: 'Cinzel', serif; font-size: 1.2rem; color: var(--gold); font-weight: 900; }

/* Stage flash animation */
@keyframes stageFlash { 0%,100%{opacity:1} 50%{opacity:0.3} }
.stage-flash { animation: stageFlash 0.4s ease 3; }
@keyframes cardFlipIn { from{opacity:0;transform:scale(0.8)} to{opacity:1;transform:scale(1)} }
.card-reveal { animation: cardFlipIn 0.3s ease; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-6px)} 75%{transform:translateX(6px)} }
.shake { animation: shake 0.4s ease; }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }
.float-anim { animation: float 2s ease infinite; }

