/* ============================================================
   DUNGEON QUEST — Global Styles
   Mobile-first dark dungeon theme
   ============================================================ */

:root {
  --gold: #d4a017;
  --gold-light: #f0c040;
  --bg-dark: #0e0e18;
  --bg-card: #1a1a2e;
  --bg-card2: #16213e;
  --border: rgba(212, 160, 23, 0.25);
  --text: #e8e0d0;
  --text-dim: #a09880;
  --red: #c0392b;
  --red-light: #e74c3c;
  --green: #27ae60;
  --blue: #2980b9;
  --purple: #8e44ad;
  --font-title: 'Cinzel', serif;
  --font-body: 'Crimson Text', serif;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --glow-gold: 0 0 0 1px rgba(212,160,23,0.2), 0 12px 40px rgba(212,160,23,0.14);
}

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

html, body {
  height: 100%;
  background: var(--bg-dark);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: none;
}

/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, .game-title { font-family: var(--font-title); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 12px 24px; border: none; border-radius: var(--radius);
  font-family: var(--font-title); font-size: 14px; font-weight: 700;
  letter-spacing: 0.5px; cursor: pointer; transition: all 0.2s;
  text-decoration: none;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, #8b6914, var(--gold));
  color: #0e0e18; box-shadow: 0 2px 12px rgba(212,160,23,0.3);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--gold), var(--gold-light)); }

.btn-secondary {
  background: transparent; border: 2px solid var(--gold);
  color: var(--gold);
}
.btn-secondary:hover { background: rgba(212,160,23,0.1); }

.btn-ghost {
  background: rgba(255,255,255,0.07); color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.1);
}
.btn-ghost:hover { background: rgba(255,255,255,0.12); }

.btn-xl { padding: 16px 32px; font-size: 17px; }
.btn-full { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-icon { font-size: 20px; }

/* ── Forms ───────────────────────────────────────────────────── */
.form-input {
  width: 100%; padding: 12px 16px; background: rgba(255,255,255,0.06);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-family: var(--font-body); font-size: 16px;
  transition: border-color 0.2s;
}
.form-input:focus { outline: none; border-color: var(--gold); }
.form-input::placeholder { color: var(--text-dim); }
.form-textarea { min-height: 80px; resize: vertical; }
.form-label { display: block; margin-bottom: 8px; font-weight: 600; color: var(--gold); }
.form-group { margin-bottom: 20px; }
.label-hint { font-size: 13px; color: var(--text-dim); font-weight: 400; }
.char-counter { text-align: right; font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.hint-text { font-size: 13px; color: var(--text-dim); margin-top: 6px; }
.hint-text.center { text-align: center; }

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.card-title {
  font-family: var(--font-title); color: var(--gold);
  font-size: 16px; margin-bottom: 16px;
}

/* ── Toasts / errors ─────────────────────────────────────────── */
.error-toast {
  background: rgba(192,57,43,0.2); border: 1px solid var(--red);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
  color: #ff7675; font-size: 15px;
}
.status-message {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card2); border: 1px solid var(--gold);
  border-radius: 20px; padding: 10px 20px; font-size: 14px;
  opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 999;
}
.status-message.visible { opacity: 1; }

/* ── Main screen ─────────────────────────────────────────────── */
.main-screen {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px 20px;
  background:
    radial-gradient(1200px 680px at 18% 22%, rgba(56,33,106,0.34), transparent 62%),
    radial-gradient(900px 540px at 88% 72%, rgba(14,80,140,0.18), transparent 64%),
    radial-gradient(ellipse at 50% 30%, #1a1030 0%, var(--bg-dark) 70%);
}

.landing-shell {
  width: 100%;
  max-width: 1290px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 34px;
  align-items: start;
}

.landing-hero,
.landing-actions {
  width: 100%;
}

.landing-back {
  display: inline-flex;
  align-items: center;
  margin-bottom: 24px;
}

.hero-section { text-align: center; margin-bottom: 30px; }

.landing-kicker {
  font-family: var(--font-title);
  color: rgba(240,192,64,0.85);
  font-size: 12px;
  letter-spacing: 2.8px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.landing-copy {
  max-width: 660px;
  margin: 0 auto;
  text-align: center;
}

.landing-lead {
  font-size: 23px;
  line-height: 1.5;
  color: rgba(232,224,208,0.95);
  margin-bottom: 22px;
  text-wrap: balance;
}

.landing-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.landing-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02));
  border: 1px solid rgba(212,160,23,0.2);
  border-radius: 14px;
  color: rgba(232,224,208,0.88);
  font-size: 16px;
  transition: transform .2s ease, border-color .2s ease, background .2s ease;
}

.landing-step:hover {
  transform: translateY(-1px);
  border-color: rgba(212,160,23,0.36);
  background: linear-gradient(180deg, rgba(212,160,23,0.08), rgba(255,255,255,0.03));
}

.landing-step span {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(212,160,23,0.14);
  color: var(--gold-light);
  font-family: var(--font-title);
  font-size: 14px;
  font-weight: 700;
}

.dungeon-gate {
  font-size: 80px; filter: drop-shadow(0 0 30px rgba(212,160,23,0.5));
  animation: float 3s ease-in-out infinite; margin-bottom: 16px;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.game-title {
  font-size: clamp(34px, 8.2vw, 66px); color: var(--gold);
  text-shadow: 0 0 34px rgba(212,160,23,0.35); line-height: 0.95;
  letter-spacing: 3px; margin-bottom: 14px;
}
.title-quest { color: #f2ce70; font-size: 0.66em; letter-spacing: 6px; }
.game-subtitle {
  color: rgba(232,224,208,0.82);
  font-size: 18px;
  line-height: 1.45;
}

.main-buttons { width: 100%; max-width: 400px; }

.landing-actions {
  max-width: 456px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.action-card {
  background: linear-gradient(180deg, rgba(26,26,50,0.84) 0%, rgba(18,18,35,0.9) 100%);
  border: 1px solid rgba(212,160,23,0.17);
  border-radius: 20px;
  padding: 20px;
  backdrop-filter: blur(6px);
  box-shadow: 0 14px 36px rgba(0,0,0,0.32);
  transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}

.action-card:hover {
  transform: translateY(-2px);
  border-color: rgba(212,160,23,0.3);
  box-shadow: 0 18px 44px rgba(0,0,0,0.42);
}

.action-card-primary {
  border-color: rgba(212,160,23,0.45);
  background: linear-gradient(180deg, rgba(45,31,6,0.86) 0%, rgba(28,20,8,0.92) 100%);
  box-shadow: var(--glow-gold);
}

.action-card-label {
  font-family: var(--font-title);
  color: rgba(240,192,64,0.88);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.landing-create-btn {
  width: 100%;
  min-height: 82px;
}

.btn-hint {
  display: block; font-size: 11px; font-family: var(--font-body);
  font-weight: 400; color: rgba(14,14,24,0.7); margin-top: 2px;
}

.join-section { margin-top: 8px; }
.join-label {
  text-align: center; color: rgba(232,224,208,0.92); font-size: 14px;
  margin-bottom: 14px; font-family: var(--font-title); letter-spacing: .5px;
}
.join-form { display: flex; gap: 8px; align-items: stretch; }
.input-code {
  flex: 1; padding: 12px 16px; background: rgba(255,255,255,0.05);
  border: 1px solid rgba(212,160,23,0.24); border-radius: 14px;
  color: var(--text); font-size: 17px; font-family: var(--font-title);
  letter-spacing: 3px; text-align: center;
}
.input-code:focus { outline: none; border-color: var(--gold); }

.qr-card {
  text-align: center;
}

.qr-hint {
  max-width: 340px;
  margin: 0 auto 12px;
  line-height: 1.45;
}

.qr-preview {
  width: min(200px, 50vw);
  border-radius: 18px;
  background: #fff;
  padding: 12px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.3);
}

.qr-link {
  margin-top: 10px;
  word-break: break-word;
  font-size: 11px;
  opacity: .72;
  max-width: 280px;
  margin-left: auto;
  margin-right: auto;
}

.qr-room-badge {
  display: inline-block;
  margin: 8px auto;
}

.game-features {
  display: flex; gap: 12px; flex-wrap: wrap; justify-content: center;
  margin-top: 32px;
}
.feature {
  padding: 6px 12px; background: rgba(212,160,23,0.08);
  border: 1px solid rgba(212,160,23,0.25); border-radius: 999px;
  font-size: 13px; color: var(--text-dim);
}

/* ── Page container (shared) ──────────────────────────────────── */
.page-container {
  max-width: 600px; margin: 0 auto; padding: 16px;
  min-height: 100vh;
}
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.back-link { color: var(--text-dim); text-decoration: none; font-size: 14px; }
.back-link:hover { color: var(--gold); }
.room-badge {
  background: rgba(212,160,23,0.1); border: 1px solid var(--border);
  border-radius: 20px; padding: 6px 14px; font-size: 14px; color: var(--gold);
}
.room-badge-large {
  font-family: var(--font-title); font-size: 20px; color: var(--gold);
  letter-spacing: 2px;
}
.section-title {
  font-family: var(--font-title); color: var(--gold);
  font-size: 22px; margin-bottom: 8px;
}

/* ── Character select ─────────────────────────────────────────── */
.character-form { margin-top: 16px; }
.classes-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 20px;
}
.class-card {
  position: relative; background: var(--bg-card);
  border: 2px solid var(--border); border-radius: var(--radius);
  padding: 16px 12px; text-align: center; cursor: pointer;
  transition: all 0.2s;
}
.class-card input[type=radio] { display: none; }
.class-card.selected {
  border-color: var(--gold);
  background: rgba(212,160,23,0.08);
  box-shadow: 0 0 16px rgba(212,160,23,0.2);
}
.class-emoji { font-size: 32px; margin-bottom: 6px; }
.class-name { font-family: var(--font-title); color: var(--gold); font-size: 14px; }
.class-stats { font-size: 12px; color: #e74c3c; margin: 4px 0; }
.class-desc { font-size: 11px; color: var(--text-dim); line-height: 1.3; }

/* ── Lobby ───────────────────────────────────────────────────── */
.share-hint {
  background: rgba(212,160,23,0.08); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; text-align: center;
  font-size: 14px; color: var(--text-dim); margin-bottom: 16px;
}
.lobby-grid { display: flex; flex-direction: column; gap: 16px; }

.players-lobby-list { display: flex; flex-direction: column; gap: 10px; }
.player-lobby-item {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.04); border-radius: 8px; padding: 10px 12px;
}
.player-emoji { font-size: 24px; }
.player-lobby-info { flex: 1; }
.player-lobby-info strong { display: block; font-size: 15px; }
.player-class-badge {
  font-size: 12px; color: var(--text-dim);
  background: rgba(255,255,255,0.07); border-radius: 10px; padding: 2px 8px;
}
.admin-badge {
  font-size: 12px; color: var(--gold);
  background: rgba(212,160,23,0.1); border-radius: 10px; padding: 2px 8px;
}
.player-prompt-preview { font-size: 12px; color: var(--text-dim); margin-top: 4px; font-style: italic; }

.admin-card { border-color: rgba(212,160,23,0.4); }
.waiting-card { text-align: center; padding: 40px; }
.waiting-animation { font-size: 48px; animation: float 2s ease-in-out infinite; margin-bottom: 12px; }

/* ── GAME SCREEN ─────────────────────────────────────────────── */
body:has(.game-topbar) {
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}

.game-topbar {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  padding: 10px 14px; flex-shrink: 0; z-index: 10;
}
.topbar-room { font-family: var(--font-title); color: var(--gold); font-size: 13px; }
.topbar-act { font-size: 13px; color: var(--text-dim); white-space: nowrap; }
.topbar-act #stepNum, .topbar-act #stepTotal { color: var(--text-dim); opacity: 0.7; }
.topbar-doom { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: flex-end; }
.doom-label { font-size: 12px; color: var(--text-dim); }
.doom-bar-wrap {
  width: 80px; height: 8px; background: rgba(255,255,255,0.1);
  border-radius: 4px; overflow: hidden;
}
.doom-bar-fill {
  height: 100%; border-radius: 4px;
  background: var(--green); transition: width 0.5s, background 0.5s;
}
.doom-bar-fill.warn { background: orange; }
.doom-bar-fill.danger { background: var(--red-light); animation: pulse-doom 0.8s ease-in-out infinite; }
@keyframes pulse-doom { 0%,100% { opacity:1; } 50% { opacity:0.6; } }
.doom-value { font-size: 12px; color: var(--text-dim); }

.players-bar {
  display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto;
  background: var(--bg-card2); border-bottom: 1px solid var(--border);
  flex-shrink: 0; scrollbar-width: none;
}
.players-bar::-webkit-scrollbar { display: none; }

.player-chip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 10px 4px 6px; white-space: nowrap; flex-shrink: 0;
  transition: all 0.3s;
}
.player-chip.dead { opacity: 0.4; filter: grayscale(1); }
.chip-info { display: flex; flex-direction: column; gap: 2px; }
.chip-name { font-size: 12px; font-weight: 600; }
.chip-hp-bar {
  width: 50px; height: 4px; background: rgba(255,255,255,0.1);
  border-radius: 2px; overflow: hidden;
}
.chip-hp-fill {
  height: 100%; border-radius: 2px;
  background: var(--green); transition: width 0.5s;
}
.chip-hp-text { font-size: 11px; color: var(--text-dim); }

.game-main {
  flex: 1; overflow-y: auto; display: flex;
  flex-direction: column; padding: 12px;
}

.game-layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 100%;
}

.story-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.story-feed {
  flex: 1; overflow-y: auto; display: flex;
  flex-direction: column; gap: 12px; padding-bottom: 8px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

.game-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.sidebar-title {
  font-family: var(--font-title);
  color: var(--gold);
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 14px 16px 0;
}

.story-block {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  animation: fadeIn 0.4s ease;
  font-size: 16px; line-height: 1.7;
}
.story-block.active { border-color: rgba(212,160,23,0.5); }
.story-block.outcome-block { background: rgba(39,174,96,0.08); border-color: rgba(39,174,96,0.3); }
.story-block.mood-epic { border-color: rgba(142,68,173,0.5); }
.story-block.mood-tense { border-color: rgba(192,57,43,0.4); }
.waiting-text { color: var(--text-dim); text-align: center; font-style: italic; }
.loot-line { margin-top: 10px; font-family: var(--font-title); font-size: 13px; color: var(--gold); }
.boss-alert {
  text-align: center; padding: 10px;
  font-family: var(--font-title); color: var(--red-light);
  font-size: 14px; letter-spacing: 2px;
  animation: pulse-doom 1s ease-in-out infinite;
}

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

.choice-panel { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.sidebar-card .choice-panel { margin-top: 0; padding: 14px 16px 16px; }
.choice-btn {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
  color: var(--text); font-family: var(--font-body); font-size: 15px;
  text-align: left; cursor: pointer; transition: all 0.2s;
}
.choice-btn:hover:not(:disabled) {
  border-color: var(--gold); background: rgba(212,160,23,0.08);
}
.choice-btn:disabled { opacity: 0.5; cursor: default; }
.choice-btn.selected {
  border-color: var(--gold); background: rgba(212,160,23,0.15);
  box-shadow: 0 0 12px rgba(212,160,23,0.2);
}
.choice-num {
  font-family: var(--font-title); color: var(--gold); font-size: 16px;
  min-width: 24px; padding-top: 1px;
}
.choice-text { flex: 1; line-height: 1.4; }

.choices-tracker {
  background: rgba(39,174,96,0.06); border: 1px solid rgba(39,174,96,0.3);
  border-radius: var(--radius); padding: 12px; margin-top: 12px;
}
.game-sidebar .choices-tracker {
  margin-top: 0;
  padding: 14px 16px 16px;
}
.tracker-label { font-size: 13px; color: var(--text-dim); margin-bottom: 8px; }
.tracker-entry { font-size: 14px; margin-bottom: 4px; color: var(--text); }

.ai-thinking {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; margin-top: 12px;
  background: rgba(212,160,23,0.06); border-radius: var(--radius);
  border: 1px solid var(--border);
}
.game-sidebar .ai-thinking {
  margin-top: 0;
  padding: 14px 16px;
}
.thinking-dots { display: flex; gap: 4px; }
.thinking-dots span {
  width: 8px; height: 8px; background: var(--gold);
  border-radius: 50%; animation: bounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100% { transform:translateY(0); } 30% { transform:translateY(-8px); } }
#thinkingText { font-size: 13px; color: var(--text-dim); font-style: italic; }

/* ── Bottom Panel ─────────────────────────────────────────────── */
.bottom-panel {
  background: var(--bg-card); border-top: 1px solid var(--border);
  flex-shrink: 0; display: flex; flex-direction: column; max-height: 240px;
}
.my-status {
  padding: 8px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.my-status-inner { display: flex; align-items: center; gap: 10px; }
.my-emoji { font-size: 22px; }
.my-stats { flex: 1; }
.my-name { font-size: 13px; font-weight: 700; color: var(--gold); }
.my-hp-bar {
  width: 100%; height: 6px; background: rgba(255,255,255,0.1);
  border-radius: 3px; overflow: hidden; margin: 4px 0;
}
.my-hp-fill { height: 100%; background: var(--green); border-radius: 3px; transition: width 0.5s, background 0.3s; }
.my-hp-fill.hp-warn { background: orange; }
.my-hp-fill.hp-critical { background: var(--red-light); animation: pulse-doom 0.8s ease-in-out infinite; }
.my-hp-text { font-size: 11px; color: var(--text-dim); }
.my-hp-delta {
  font-size: 14px; font-weight: 700; min-width: 40px; text-align: center;
  transition: opacity 0.5s; opacity: 0;
}

.bottom-tabs {
  display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.tab-btn {
  flex: 1; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--text-dim); padding: 8px; font-size: 13px;
  cursor: pointer; font-family: var(--font-body); transition: all 0.2s;
}
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }

.tab-content { display: none; padding: 8px; flex: 1; overflow-y: auto; min-height: 0; }
.tab-content.active { display: flex; flex-direction: column; }

.log-feed { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }
.log-entry { display: flex; gap: 8px; font-size: 12px; line-height: 1.4; }
.log-type { color: var(--gold); white-space: nowrap; font-size: 11px; }
.log-text { color: var(--text-dim); }
.log-story .log-type { color: var(--gold); }
.log-outcome .log-type { color: var(--green); }
.log-system .log-type { color: var(--purple); }

/* ── Chat ──── */
.chat-feed { flex: 1; overflow-y: auto; margin-bottom: 6px; min-height: 0; scrollbar-width: thin; }
.chat-msg { font-size: 13px; margin-bottom: 4px; line-height: 1.4; }
.chat-input-wrap {
  display: flex; gap: 6px; flex-shrink: 0; padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.chat-input {
  flex: 1; background: rgba(255,255,255,0.06); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; color: var(--text);
  font-family: var(--font-body); font-size: 14px;
}
.chat-input:focus { outline: none; border-color: var(--gold); }
.chat-input::placeholder { color: var(--text-dim); }

/* ── HP change indicators ──── */
.hp-delta-neg { color: var(--red-light); }
.hp-delta-pos { color: var(--green); }

.chip-hp-fill.hp-warn { background: orange; }
.chip-hp-fill.hp-critical { background: var(--red-light); animation: pulse-doom 0.8s ease-in-out infinite; }

.chip-hp-delta {
  font-size: 11px; font-weight: 700; margin-left: 2px;
  animation: hpDeltaFade 2.5s ease-out forwards;
}
@keyframes hpDeltaFade {
  0%   { opacity: 1; transform: translateY(0); }
  70%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}

.chip-shake {
  animation: chipShake 0.4s ease-out;
}
@keyframes chipShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

/* ── Modal ───────────────────────────────────────────────────── */
/* ── Game over banner (in-flow, sits between game-main and bottom-panel) ── */
#gameOverBanner {
  flex-shrink: 0;
  animation: bannerIn 0.4s ease-out;
}
@keyframes bannerIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.gameover-banner-inner {
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(135deg, #110e22 0%, #1a1a2e 100%);
  border-top: 2px solid var(--gold);
  border-bottom: 1px solid rgba(212,160,23,0.15);
  box-shadow: 0 -4px 24px rgba(212,160,23,0.25);
  padding: 12px 16px;
}
#gameOverIcon { font-size: 26px; flex-shrink: 0; line-height: 1; }
.gameover-banner-text {
  flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0;
}
.gameover-banner-text strong {
  font-family: var(--font-title); color: var(--gold);
  font-size: 15px; letter-spacing: 0.5px; line-height: 1.3;
}
.gameover-banner-text span {
  color: var(--text-dim); font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#gameOverBanner .btn {
  flex-shrink: 0; white-space: nowrap;
  padding: 8px 14px; font-size: 13px;
}

/* ── Acts selector ───────────────────────────────────────────── */
.acts-selector {
  display: flex; gap: 8px; margin-bottom: 8px;
}
.act-btn {
  flex: 1; text-align: center; padding: 10px 4px;
  background: var(--bg-card2); border: 2px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  font-family: var(--font-title); font-size: 18px; color: var(--text-dim);
  transition: all 0.2s;
}
.act-btn input { display: none; }
.act-btn.selected {
  border-color: var(--gold); color: var(--gold);
  background: rgba(212,160,23,0.1);
  box-shadow: 0 0 12px rgba(212,160,23,0.2);
}
.act-btn:hover:not(.selected) { border-color: rgba(212,160,23,0.4); }

/* ── Theme preview ───────────────────────────────────────────── */
.theme-preview {
  margin-top: 6px; font-size: 13px; color: var(--text-dim);
  min-height: 18px; transition: all 0.3s;
}

/* ── Theme transitions ───────────────────────────────────────── */
body, .game-topbar, .players-bar, .bottom-panel,
.story-block, .choice-btn, .card, .player-chip,
.tab-btn, .chat-input-wrap, .tts-panel,
.story-feed, .log-feed, .chat-feed {
  transition: background-color 1s ease, border-color 0.8s ease, color 0.8s ease, box-shadow 0.8s ease;
}

/* ── TTS Control Panel ──────────────────────────────────────── */
.tts-panel {
  position: fixed;
  bottom: 80px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  z-index: 200;
}

.tts-toggle-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--gold);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px rgba(0,0,0,0.5);
  transition: all 0.2s;
  color: white;
}
.tts-toggle-btn:hover { transform: scale(1.1); background: rgba(212,160,23,0.15); }

.tts-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

.tts-ctrl-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.15s;
  color: white;
}
.tts-ctrl-btn:hover { background: rgba(255,255,255,0.1); }

.tts-status {
  font-size: 11px;
  color: var(--text-dim);
  min-width: 70px;
  text-align: center;
}

/* ── Home button in topbar ────────────────────────────────────── */
.topbar-home {
  font-size: 18px;
  text-decoration: none;
  opacity: 0.7;
  padding: 4px 6px;
  border-radius: 6px;
  transition: opacity 0.2s, background 0.2s;
  flex-shrink: 0;
}
.topbar-home:hover { opacity: 1; background: rgba(255,255,255,0.1); }

/* ── Mobile Responsive ───────────────────────────────────────── */
@media (max-width: 480px) {

  /* Main screen */
  .main-screen {
    padding: 24px 16px;
    min-height: 100vh;
  }
  .dungeon-gate { font-size: 64px; }
  .game-title { font-size: 36px; }
  .game-subtitle { font-size: 13px; }
  .hero-section { margin-bottom: 24px; }
  .landing-lead { font-size: 16px; }
  .landing-step { font-size: 14px; padding: 10px 12px; }
  .landing-actions { max-width: 100%; gap: 12px; }
  .action-card { padding: 16px; border-radius: 18px; }

  .main-buttons { max-width: 100%; }
  .btn-xl { padding: 14px 20px; font-size: 15px; width: 100%; }
  .btn-primary, .btn-secondary { width: 100%; justify-content: center; }

  .join-form { flex-direction: column; gap: 8px; }
  .input-code { width: 100%; box-sizing: border-box; font-size: 20px; text-align: center; }
  .join-section .btn-secondary { width: 100%; }

  .game-features {
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
  }
  .feature { font-size: 12px; padding: 4px 10px; }

  /* Lobby */
  .lobby-grid { grid-template-columns: 1fr; gap: 12px; }
  .page-container { padding: 12px; }
  .narrator-presets { grid-template-columns: 1fr 1fr; }

  /* Game topbar */
  .game-topbar { padding: 6px 10px; gap: 8px; }
  .topbar-room { font-size: 12px; }
  .topbar-act { font-size: 11px; }
  .doom-label { display: none; }
  .doom-bar-wrap { width: 60px; }

  /* Players bar */
  .players-bar { gap: 6px; padding: 6px 10px; }
  .player-chip { padding: 4px 8px; gap: 4px; }
  .chip-name { font-size: 11px; }
  .chip-hp-text { font-size: 10px; }

  /* Story feed */
  .story-feed { font-size: 14px; }
  .story-block p { font-size: 14px; line-height: 1.5; }

  /* Choice buttons */
  .choice-btn { padding: 10px 12px; font-size: 13px; }
  .choice-num { width: 22px; height: 22px; font-size: 12px; }

  /* Bottom panel */
  .bottom-panel { max-height: 240px; }
  .my-hp-text { font-size: 11px; }

  /* TTS panel */
  .tts-panel { bottom: 230px; right: 10px; }

  /* Character select */
  .class-grid { grid-template-columns: 1fr 1fr; }

  /* Modals */
}

@media (min-width: 980px) {
  .main-screen {
    padding: 42px 34px 34px;
  }

  .landing-shell {
    grid-template-columns: minmax(0, 1.2fr) minmax(370px, 448px);
    gap: 60px;
  }

  .landing-hero {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 680px;
    padding-top: 10px;
  }

  .landing-back {
    margin-bottom: 18px;
  }

  .hero-section,
  .landing-copy {
    margin-left: 0;
    text-align: left;
  }

  .hero-section {
    margin-bottom: 18px;
  }

  .game-title {
    font-size: clamp(56px, 5.8vw, 86px);
    line-height: 0.92;
    margin-bottom: 16px;
  }

  .title-quest {
    font-size: 0.6em;
    letter-spacing: 4px;
  }

  .game-subtitle {
    font-size: 19px;
    max-width: 600px;
  }

  .dungeon-gate-logo {
    width: 164px;
    height: 164px;
    margin-bottom: 14px;
    border-radius: 20px;
    border: 1px solid rgba(212,160,23,0.32);
    box-shadow: 0 14px 36px rgba(0,0,0,0.42), 0 0 28px rgba(212,160,23,0.22);
  }

  .game-features {
    justify-content: flex-start;
    margin-top: 22px;
  }

  .landing-steps {
    max-width: 560px;
  }

  .landing-actions {
    max-width: none;
    margin: 0;
    position: sticky;
    top: 26px;
  }

  .action-card {
    padding: 18px 20px;
  }

  .action-card.qr-card {
    padding-top: 16px;
  }
}

@media (min-width: 1024px) {
  .game-main {
    overflow: hidden;
    padding: 16px;
  }

  .game-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
    gap: 16px;
    height: 100%;
  }

  .story-column,
  .story-feed {
    height: 100%;
    min-height: 0;
  }

  .game-sidebar {
    position: sticky;
    top: 0;
    max-height: 100%;
    overflow-y: auto;
    padding-right: 2px;
  }

  .sidebar-card {
    background: linear-gradient(180deg, rgba(26,26,46,.98) 0%, rgba(22,33,62,.96) 100%);
  }

  .choice-btn {
    min-height: 68px;
  }
}

@media (max-width: 360px) {
  .game-title { font-size: 30px; }
  .dungeon-gate { font-size: 52px; }
  .narrator-presets { grid-template-columns: 1fr; }
}

/* ── TTS in topbar ───────────────────────────────────────────── */
.topbar-tts {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
}
.tts-topbar-btn {
  background: none;
  border: none;
  font-size: 15px;
  cursor: pointer;
  padding: 3px 5px;
  border-radius: 5px;
  opacity: 0.7;
  transition: opacity 0.15s, background 0.15s;
  line-height: 1;
}
.tts-topbar-btn:hover { opacity: 1; background: rgba(255,255,255,0.12); }
.tts-topbar-btn.muted { opacity: 0.35; }

/* ── Choice buttons with icon ────────────────────────────────── */
.choice-btn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  text-align: left;
}
.choice-icon {
  font-size: 20px;
  line-height: 1.2;
  flex-shrink: 0;
  min-width: 26px;
  text-align: center;
}
.choice-text {
  flex: 1;
  font-size: 13px;
  line-height: 1.4;
}
/* Remove old .choice-num if present */
.choice-num { display: none; }

/* ── Logo ────────────────────────────────────────────────────── */
.dungeon-gate-logo {
  width: 160px;
  height: 160px;
  object-fit: contain;
  filter: drop-shadow(0 0 24px rgba(212,160,23,0.45));
  animation: float 3s ease-in-out infinite;
  margin-bottom: 8px;
}
.topbar-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  vertical-align: middle;
  filter: drop-shadow(0 0 6px rgba(212,160,23,0.4));
  transition: filter 0.2s;
}
.topbar-logo:hover { filter: drop-shadow(0 0 10px rgba(212,160,23,0.7)); }

/* ── TTS selector (lobby) ─────────────────────────────────────── */
.tts-selector {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}
.tts-btn {
  flex: 1; min-width: 120px; text-align: center;
  padding: 10px 12px;
  background: var(--bg-card2); border: 2px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  font-size: 14px; color: var(--text-dim);
  transition: all 0.2s;
}
.tts-btn input { display: none; }
.tts-btn.selected {
  border-color: var(--gold); color: var(--gold);
  background: rgba(212,160,23,0.1);
  box-shadow: 0 0 12px rgba(212,160,23,0.2);
}
.tts-btn:hover:not(.selected) { border-color: rgba(212,160,23,0.4); }
