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

:root {
  /* Warm-tinted neutrals — never pure black or white */
  --bg: oklch(97.5% 0.005 70);
  --bg-surface: oklch(99% 0.003 70);
  --bg-inset: oklch(95% 0.008 70);
  --text: oklch(20% 0.01 70);
  --text-secondary: oklch(45% 0.01 70);
  --text-dim: oklch(60% 0.008 70);
  --border: oklch(88% 0.01 70);
  --border-light: oklch(92% 0.005 70);

  /* Accent — warm terracotta/rust (intentional, not AI-purple) */
  --accent: oklch(62% 0.14 35);
  --accent-hover: oklch(55% 0.14 35);
  --accent-subtle: oklch(93% 0.04 35);

  /* Character colors — muted, sophisticated */
  --agent1: oklch(55% 0.14 25);   /* warm rust */
  --agent2: oklch(50% 0.1 165);   /* sage green */
  --agent3: oklch(52% 0.1 250);   /* slate blue */
  --agent4: oklch(50% 0.12 310);  /* dusty plum */

  /* Semantic */
  --green: oklch(48% 0.14 155);
  --gold: oklch(55% 0.14 75);
  --red: oklch(52% 0.17 25);
  --xp: var(--xp);

  /* Derived — computed from semantic tokens */
  --btn-text: var(--btn-text);
  --overlay-bg: var(--overlay-bg);
  --shadow-sm: var(--shadow-sm);
  --shadow-md: var(--shadow-md);
  --red-subtle: var(--red-subtle);
  --green-subtle: var(--green-subtle);
  --gold-subtle: var(--gold-subtle);
  --accent-condition: var(--accent-condition);
  --accent-condition-text: var(--accent-condition-text);

  /* Type */
  --font: 'DM Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', monospace;
  --font-display: 'Playfair Display', 'Georgia', serif;

  /* Spacing scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 40px;
  --space-2xl: 64px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

/* Fonts loaded via <link> in HTML for performance */

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 2s ease, color 2s ease;
}

.hidden { display: none !important; }

/* Screen reader only — visually hidden but accessible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Welcome hint — shown once at game start */
.chat-welcome {
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
  color: var(--text-dim);
  animation: fadeIn 0.5s ease;
  margin: auto 0;
}
.welcome-title {
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}
.welcome-party {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--space-lg);
}
.welcome-body {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-secondary);
  max-width: 400px;
  margin: 0 auto var(--space-md);
}
.welcome-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.welcome-hint strong {
  color: var(--accent);
}

/* Save toast */
.save-toast {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  color: white;
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  z-index: 50;
  animation: fadeIn 0.2s ease;
}

/* Error toast */
.error-toast {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--red);
  color: white;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  z-index: 50;
  animation: fadeIn 0.2s ease;
  max-width: 90%;
  text-align: center;
}

.screen {
  height: 100vh;
  width: 100vw;
  overflow-y: auto;
}

/* ── Setup Screen ────────────────────────────────────── */
.setup-container {
  max-width: 520px;
  margin: 0 auto;
  padding: clamp(48px, 8vh, 100px) 24px 40px;
}

.setup-container.wide {
  max-width: 1200px;
}

.logo {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(2rem, 5vw, 3rem);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: var(--space-sm);
  text-align: center;
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
  font-size: 1.05rem;
  line-height: 1.6;
  text-align: center;
}

.setup-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.setup-form textarea {
  margin-top: var(--space-xs);
}

.setup-form button {
  margin-top: var(--space-sm);
}

.setup-form input,
.setup-form textarea {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  resize: vertical;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.setup-form input:focus,
.setup-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.setup-form input::placeholder,
.setup-form textarea::placeholder {
  color: var(--text-dim);
}

button {
  background: var(--accent);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 22px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

button:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

button.btn-secondary {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
}

button.btn-secondary:hover {
  background: var(--bg-inset);
}

.status-text {
  color: var(--text-dim);
  font-size: 0.85rem;
  min-height: 1.4em;
  text-align: center;
}

/* ── Saved Games ─────────────────────────────────────── */
.saved-games {
  margin-top: var(--space-xl);
  text-align: left;
}

.story-counter {
  margin-top: var(--space-xs);
  margin-bottom: var(--space-md);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}
.story-count-number {
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
}

.saved-games h3 {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  margin-bottom: var(--space-md);
}

.saved-game-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.saved-game-item:hover {
  border-color: var(--accent);
}

.saved-game-item .name { font-weight: 600; font-size: 0.9rem; }
.saved-game-item .meta { color: var(--text-dim); font-size: 0.8rem; }

/* ── Character Design Screen ─────────────────────────── */
.char-grid {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  justify-content: center;
}

.char-grid > .char-card {
  flex: 0 0 260px;
  min-width: 260px;
}

.char-grid > .char-card.card-new {
  animation: cardSlideIn 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.char-grid > .char-card-add {
  flex: 0 0 260px;
  min-width: 260px;
}

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

.char-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  position: relative;
  overflow: hidden;
  text-align: left;
}

.char-card-color {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
}

.char-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.char-card h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 10px;
  margin-top: 6px;
}

button.char-remove {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 1rem;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1;
}

button.char-remove:hover {
  color: var(--red);
  border-color: var(--red);
  background: var(--red-subtle);
}

.char-card input,
.char-card select,
.char-card textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.88rem;
  margin-bottom: var(--space-sm);
  resize: none;
  transition: border-color 0.15s ease;
}

.char-card input:focus,
.char-card select:focus,
.char-card textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.char-card input::placeholder,
.char-card textarea::placeholder {
  color: var(--text-dim);
}

.char-card select {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' fill='none' stroke='%23999' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.char-hp {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--green);
  text-align: center;
  padding: var(--space-xs) 0;
  margin-top: var(--space-xs);
}

.char-card-add {
  background: transparent;
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.char-card-add:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.char-add-icon {
  font-size: 2rem;
  color: var(--text-dim);
  line-height: 1;
  margin-bottom: var(--space-sm);
  transition: color 0.2s ease;
  font-weight: 300;
}

.char-card-add:hover .char-add-icon {
  color: var(--accent);
}

.char-add-label {
  color: var(--text-dim);
  font-size: 0.82rem;
}

.char-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
  margin-bottom: var(--space-md);
}

/* ── Game Screen ─────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
}

.logo-small {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.world-title {
  color: var(--text-secondary);
  font-size: 0.85rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.top-actions button {
  padding: 6px 14px;
  font-size: 0.8rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.top-actions button:hover {
  background: var(--bg-inset);
}

.turn-counter {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 500;
}

.token-stats {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.model-badge {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-inset);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 2px 8px;
  letter-spacing: 0.02em;
}

.game-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#game-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Entity Bar (heroes + enemies) ───────────────────── */
.entity-bar {
  display: flex; justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-surface); border-bottom: 1px solid var(--border-light);
  gap: var(--space-lg);
}
.char-bar { display: flex; gap: var(--space-sm); overflow-x: auto; flex: 1; }
.enemy-bar, .npc-bar { display: flex; gap: var(--space-sm); overflow-x: auto; justify-content: flex-end; }
.enemy-bar:not(:empty) { padding-left: var(--space-md); border-left: 1px solid var(--border-light); }
.npc-bar:not(:empty) { padding-left: var(--space-md); border-left: 1px solid var(--border-light); }

.char-bar-item {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: 5px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-light); background: var(--bg-surface);
  cursor: pointer; transition: border-color 0.15s ease; white-space: nowrap; flex-shrink: 0;
}
.char-bar-item:hover { border-color: var(--accent); }
.char-bar-item.dead { opacity: 0.4; filter: grayscale(0.5); }
.char-bar-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.char-bar-name { font-weight: 600; font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.char-bar-class { font-size: 0.72rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; }
.char-bar-hp { font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500; color: var(--green); }
.char-bar-hp.low { color: var(--gold); }
.char-bar-hp.critical { color: var(--red); }
.char-bar-level { font-size: 0.68rem; color: var(--text-dim); font-family: var(--font-mono); }

.enemy-bar-item {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: 5px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--red); background: var(--red-subtle);
  cursor: pointer; transition: border-color 0.15s ease; white-space: nowrap; flex-shrink: 0;
}
.enemy-bar-item:hover { background: var(--bg-inset); }
.enemy-bar-item.dead { opacity: 0.3; text-decoration: line-through; }
.enemy-bar-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex-shrink: 0; }
.enemy-bar-item.dead .enemy-bar-dot { background: var(--text-dim); }
.enemy-bar-name { font-weight: 600; font-size: 0.82rem; color: var(--red); overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.enemy-bar-item.dead .enemy-bar-name { color: var(--text-dim); }
.enemy-hp-bar { width: 50px; height: 5px; background: var(--bg-inset); border-radius: 3px; overflow: hidden; }
.enemy-hp-fill { height: 100%; background: var(--red); border-radius: 3px; transition: width 0.3s ease; }
.enemy-bar-hp { font-family: var(--font-mono); font-size: 0.68rem; color: var(--red); }

/* ── Enemy Detection Card ──────────────────────────── */
.enemy-detect-card { border-left: 3px solid var(--red); }
.enemy-detect-fields { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--space-sm); }
.edet-row { display: flex; align-items: center; gap: var(--space-sm); }
.edet-label { font-size: 0.72rem; font-weight: 600; color: var(--text-dim); width: 36px; flex-shrink: 0; }
.edet-actions { display: flex; align-items: center; gap: var(--space-md); }
.edet-actions .roll-inline-btn { background: var(--red) !important; width: auto; flex: 1; }
.edet-actions .roll-skip-link { font-size: 0.75rem; color: var(--text-dim); cursor: pointer; text-decoration: underline; }
.edet-confirmed { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--red); font-weight: 500; }

/* ── NPC Bar ───────────────────────────────────────────── */
.npc-bar-item {
  display: flex; align-items: center; gap: var(--space-sm);
  padding: 5px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--green); background: var(--green-subtle);
  cursor: pointer; transition: border-color 0.15s ease; white-space: nowrap; flex-shrink: 0;
}
.npc-bar-item:hover { background: var(--bg-inset); }
.npc-bar-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.npc-bar-name { font-weight: 600; font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.npc-bar-disposition { font-size: 0.68rem; font-style: italic; }

/* ── NPC Detection Card ────────────────────────────────── */
.npc-detect-card { border-left: 3px solid var(--green); }
.npc-detect-card .edet-actions .roll-inline-btn { background: var(--green) !important; }
.npc-detect-card .edet-confirmed { color: var(--green); }

/* ── Entity Update Card ────────────────────────────────── */
.entity-update-card { border-left: 3px solid var(--accent); }
.eupd-reason { font-size: 0.75rem; color: var(--text-dim); font-style: italic; margin-bottom: var(--space-sm); }

/* ── Inline Roll Card ────────────────────────────────── */
.chat-roll-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm); padding: var(--space-md); margin: var(--space-sm) 0;
  animation: fadeIn 0.3s ease; transition: all 0.3s ease;
}
.chat-roll-card.roll-resolved {
  background: transparent; border-color: var(--border-light); border-left-color: var(--gold);
  padding: var(--space-sm) var(--space-md);
}
.roll-header { display: flex; align-items: center; gap: 6px; margin-bottom: var(--space-sm); flex-wrap: wrap; }
.roll-resolved .roll-header { margin-bottom: 4px; }
.roll-char-name { font-weight: 700; font-size: 0.82rem; }
.roll-check-type { font-size: 0.8rem; color: var(--text-secondary); font-weight: 500; }
.roll-dice-info { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-dim); }

.roll-tiers { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-md); }
.roll-tier { display: flex; align-items: center; gap: var(--space-sm); position: relative; }
.tier-label { font-size: 0.68rem; font-weight: 700; font-family: var(--font-mono); width: 40px; text-align: right; flex-shrink: 0; }
.tier-crit { color: var(--gold); }
.tier-high { color: var(--green); }
.tier-mid  { color: var(--text-secondary); }
.tier-low  { color: var(--gold); }
.tier-fail { color: var(--red); }

.tier-input { flex: 1; background: var(--bg); border: 1px solid var(--border-light); border-radius: 4px; padding: 5px 8px; color: var(--text); font-family: var(--font); font-size: 0.8rem; }
.tier-input::placeholder { color: var(--border); }
.tier-loading .tier-input { display: none; }
.tier-input:focus { outline: none; border-color: var(--accent); }
.tier-input.suggestion-updated { animation: suggestionFlash 0.6s ease; }
@keyframes suggestionFlash { 0% { background: var(--gold-subtle); } 100% { background: var(--bg); } }

.tier-dots { display: flex; gap: 3px; align-items: center; padding: 0 6px; }
.tier-dots span { width: 4px; height: 4px; border-radius: 50%; background: var(--text-dim); animation: typingBounce 1.4s ease-in-out infinite; }
.tier-dots span:nth-child(2) { animation-delay: 0.2s; }
.tier-dots span:nth-child(3) { animation-delay: 0.4s; }

.roll-inline-btn { background: var(--accent); color: var(--btn-text); border: none; padding: 8px 20px; font-size: 0.9rem; font-weight: 700; border-radius: var(--radius-sm); cursor: pointer; width: 100%; margin-top: var(--space-xs); }
.roll-inline-btn:hover { opacity: 0.9; }
.roll-inline-btn:disabled { opacity: 0.5; cursor: wait; }

.roll-result-line { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; padding-top: 2px; }
.result-score { font-family: var(--font-mono); font-size: 1.1rem; font-weight: 800; color: var(--accent); }
.result-breakdown { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-dim); }
.result-dash { color: var(--text-dim); }
.result-outcome { font-size: 0.85rem; color: var(--text); font-style: italic; }
.result-hp { font-family: var(--font-mono); font-size: 0.8rem; font-weight: 700; margin-left: 6px; padding: 1px 6px; border-radius: 3px; }
.result-hp.hp-damage { color: var(--red); background: var(--red-subtle); }
.result-hp.hp-heal { color: var(--green); background: var(--green-subtle); }

/* ── Timeline ────────────────────────────────────────── */
.timeline-panel {
  width: 220px;
  min-width: 220px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-light);
  padding: var(--space-lg) var(--space-md);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  contain: layout style;
}

.timeline-panel h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: var(--space-lg);
}

.timeline {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.timeline-entry {
  position: relative;
  padding: var(--space-sm) 0 var(--space-lg) 22px;
  animation: fadeIn 0.4s ease;
}

.timeline-entry::before {
  content: '';
  position: absolute;
  left: 5px;
  top: 0;
  bottom: 0;
  width: 1.5px;
  background: var(--border);
}

.timeline-entry:last-child::before { bottom: 50%; }

.timeline-entry::after {
  content: '';
  position: absolute;
  left: 1px;
  top: 11px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--bg-surface);
}

.timeline-entry.major::after {
  width: 12px; height: 12px; left: 0;
  background: var(--gold);
}

.timeline-entry.critical::after {
  width: 12px; height: 12px; left: 0;
  background: var(--red);
}

.timeline-title {
  font-weight: 600;
  font-size: 0.82rem;
  margin-bottom: 2px;
  color: var(--text);
}

.timeline-summary {
  font-size: 0.76rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.timeline-location {
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ── Logbook ────────────────────────────────────────── */
.logbook-toggle {
  width: 100%;
  margin-top: var(--space-md);
  padding: 6px 0;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  background: var(--bg-inset);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
}
.logbook-toggle:hover { background: var(--bg-surface); color: var(--text); border-color: var(--accent); }

.logbook-panel {
  margin-top: var(--space-sm);
  border-top: 1px solid var(--border-light);
  padding-top: var(--space-sm);
  max-height: 300px;
  overflow-y: auto;
}

.logbook-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: var(--space-sm);
  flex-wrap: wrap;
}
.logbook-tab {
  padding: 3px 6px;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--bg-inset);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s ease;
}
.logbook-tab:hover { color: var(--text); }
.logbook-tab.active { background: var(--accent); color: white; border-color: var(--accent); }

.logbook-entry {
  display: flex;
  gap: var(--space-sm);
  padding: 4px 0;
  border-bottom: 1px solid var(--border-light);
  animation: fadeIn 0.3s ease;
}
.logbook-entry:last-child { border-bottom: none; }
.logbook-icon { font-size: 0.82rem; flex-shrink: 0; padding-top: 1px; }
.logbook-entry-body { flex: 1; min-width: 0; }
.logbook-entry-title { font-size: 0.75rem; font-weight: 600; color: var(--text); }
.logbook-entry-desc { font-size: 0.68rem; color: var(--text-dim); margin-top: 1px; }
.logbook-entry-turn { font-size: 0.6rem; color: var(--text-dim); font-family: var(--font-mono); margin-top: 1px; }
.logbook-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0 4px;
  margin-left: 4px;
  border-radius: 3px;
  background: var(--bg-inset);
  color: var(--text-dim);
  vertical-align: middle;
}
.logbook-badge.defeated { color: var(--red); }
.logbook-empty { font-size: 0.72rem; color: var(--text-dim); text-align: center; padding: var(--space-md); }

/* ── Agents Grid ─────────────────────────────────────── */
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  contain: layout style;
}

/* ── Single Chat Log ──────────────────────────────────── */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-msg {
  padding: var(--space-sm) 0;
  animation: fadeIn 0.3s ease;
  line-height: 1.55;
  content-visibility: auto;
  contain-intrinsic-size: auto 3em;
}

.chat-msg + .chat-msg {
  border-top: 1px solid var(--border-light);
}

/* GM narration gets more visual weight — generous spacing above */
.chat-msg.gm-msg {
  padding-top: var(--space-md);
  padding-bottom: var(--space-sm);
}
.chat-msg.gm-msg + .chat-msg {
  border-top: none;
}

.chat-sender {
  font-weight: 700;
  font-size: 0.78rem;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-sender-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.chat-content {
  font-size: 0.88rem;
  color: var(--text);
}

.chat-msg.gm-msg .chat-sender {
  color: var(--accent);
}

.chat-msg.gm-msg .chat-content {
  font-style: italic;
  color: var(--text-secondary);
}

.chat-msg.system-msg .chat-content {
  color: var(--text-dim);
  font-size: 0.82rem;
}

.chat-msg.system-msg .chat-sender {
  color: var(--text-dim);
}

.chat-typing {
  padding: var(--space-sm) 0;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: fadeIn 0.2s ease;
}

.chat-typing-name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-dim);
}

.chat-typing-dots {
  display: flex;
  gap: 3px;
}

.chat-typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: typingBounce 1.4s ease-in-out infinite;
}

.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ── GM Bar ──────────────────────────────────────── */
.gm-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px var(--space-md);
  background: var(--bg-surface);
  position: relative;
  border-top: 1px solid var(--border-light);
}

.gm-label {
  background: var(--accent);
  color: var(--btn-text);
  font-weight: 700;
  font-size: 0.7rem;
  padding: 5px 10px;
  border-radius: 4px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.gm-bar input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  transition: border-color 0.15s ease;
}

.gm-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

.gm-bar input::placeholder { color: var(--text-dim); }

.gm-bar > button {
  padding: 10px 20px;
  font-size: 0.88rem;
}

/* ── Help / Command Reference ────────────────────── */
.help-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-inset); border: 1px solid var(--border-light);
  color: var(--text-dim); font-weight: 700; font-size: 0.9rem;
  cursor: pointer; transition: all 0.15s ease; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 0; line-height: 1;
}
.help-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

.command-ref {
  position: fixed; top: 50px; right: var(--space-md);
  width: 420px; max-width: 90vw;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--space-md);
  box-shadow: 0 4px 16px var(--shadow-md);
  animation: fadeIn 0.2s ease; z-index: 100;
}
.command-ref-title {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-dim); margin-bottom: var(--space-sm);
}
.command-ref-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.cmd-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 6px 8px; background: var(--bg); border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}
.cmd-item code {
  font-size: 0.72rem; font-family: var(--font-mono); font-weight: 600;
  color: var(--accent); word-break: break-all;
}
.cmd-item span {
  font-size: 0.68rem; color: var(--text-dim);
}
.command-ref-note {
  margin-top: var(--space-sm); font-size: 0.65rem; color: var(--text-dim);
  font-style: italic;
}

/* ── Animations ──────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}


/* ── Stat Preview (Class Selection) ──────────────── */
.stat-bar-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: var(--space-xs);
}

.stat-bar-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
}

.stat-bar-row .stat-label {
  width: 28px;
  font-weight: 600;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.stat-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-inset);
  border-radius: 3px;
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.stat-bar-row .stat-val {
  width: 20px;
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.72rem;
  color: var(--text);
}

/* Custom stat adjustment (within bar rows) */
button.stat-adj {
  width: 18px; height: 18px;
  padding: 0; font-size: 0.75rem; line-height: 1;
  background: var(--bg-inset);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

button.stat-adj:hover {
  color: var(--text);
  border-color: var(--accent);
}

.stat-bar-clickable { cursor: pointer; }
.stat-bar-clickable:hover { opacity: 0.8; }

.stat-points-left {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  text-align: center;
  margin-top: var(--space-xs);
  color: var(--text-dim);
}

/* ── Character Card Popup ────────────────────────── */
.overlay-bottom {
  align-items: flex-end;
  padding-bottom: 100px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.char-card-popup {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  max-width: 440px;
  width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 40px var(--shadow-md);
  animation: slideUp 0.25s ease;
}

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

.card-close {
  position: absolute;
  top: 12px; right: 14px;
  background: transparent !important;
  border: none !important;
  font-size: 1.3rem;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 8px !important;
}

.card-close:hover { color: var(--text); }

/* ── Card Edit Fields ──────────────────────────────── */
.card-edit-name {
  font-size: 1.1rem; font-weight: 700; background: var(--bg-inset);
  border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  padding: 4px 8px; width: 100%; margin-bottom: 4px;
}
.card-edit-name:focus { border-color: var(--accent); outline: none; }
.card-edit-desc {
  width: 100%; background: var(--bg-inset); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 6px 8px; font-size: 0.8rem;
  font-family: var(--font); resize: vertical; color: var(--text);
}
.card-edit-desc:focus { border-color: var(--accent); outline: none; }
.card-edit-select {
  background: var(--bg-inset); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 3px 6px; font-size: 0.75rem;
  color: var(--text);
}
.card-edit-hp {
  width: 60px; background: var(--bg-inset); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); padding: 2px 6px; font-family: var(--font-mono);
  font-size: 0.82rem; color: var(--red); text-align: center;
}
.card-save-btn {
  width: 100%; padding: 8px; margin-top: var(--space-sm);
  background: var(--accent); color: white; border: none;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 0.8rem;
  cursor: pointer; transition: opacity 0.15s ease;
}
.card-save-btn:hover { opacity: 0.85; }

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-lg);
}

.card-name {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.card-subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.card-xp { text-align: right; }

.card-xp-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-bottom: 4px;
}

.xp-bar {
  width: 100px;
  height: 5px;
  background: var(--bg-inset);
  border-radius: 3px;
  overflow: hidden;
}

.xp-bar-fill {
  height: 100%;
  background: var(--xp);
  border-radius: 3px;
}

.card-hp-section { margin-bottom: var(--space-md); }

.card-hp-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.hp-bar {
  height: 8px;
  background: var(--bg-inset);
  border-radius: 4px;
  overflow: hidden;
}

.hp-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.card-stats-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.card-stat {
  text-align: center;
  padding: var(--space-sm);
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.card-stat-val {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.card-stat-mod {
  font-size: 0.72rem;
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 500;
}

.card-stat-name {
  font-size: 0.62rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-top: 2px;
}

.card-section {
  margin-bottom: var(--space-md);
}

.card-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.card-section-body {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.5;
}

.card-item {
  padding: 3px 0;
  font-size: 0.82rem;
}

.card-condition {
  display: inline-block;
  background: var(--accent-condition);
  color: var(--accent-condition-text);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 500;
  margin-right: 4px;
}

.dim { color: var(--text-dim); }

/* World popup story beats */
.world-story { display: flex; flex-direction: column; gap: var(--space-sm); }
.story-beat { font-size: 0.82rem; line-height: 1.5; padding-left: var(--space-sm); border-left: 2px solid var(--border); }
.story-beat.story-major { border-left-color: var(--gold); }
.story-beat.story-critical { border-left-color: var(--red); }
.story-location { font-size: 0.72rem; color: var(--text-dim); }

/* Clickable world title */
.world-title:hover { color: var(--accent); }

/* ── Dice Roll Popup ─────────────────────────────── */
/* ── Roll Popup (loot cards at bottom) ────────────── */
.roll-popup {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
  justify-content: center;
  max-width: 90vw;
}

.roll-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
  min-width: 140px;
  box-shadow: 0 4px 20px var(--shadow-sm);
  animation: slideUp 0.3s ease;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.roll-card.roll-fade {
  opacity: 0;
  transform: translateY(-8px);
}

.roll-character {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--text);
}

.roll-purpose {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.roll-notation {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Inline Roll Card (in chat) ───────────────────── */
.chat-roll-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin: var(--space-sm) 0;
  animation: fadeIn 0.3s ease;
  transition: all 0.3s ease;
}

.chat-roll-card.roll-resolved {
  background: transparent;
  border-color: var(--border-light);
  padding: var(--space-sm) var(--space-md);
}

.roll-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: var(--space-sm);
  flex-wrap: wrap;
}

.roll-resolved .roll-header {
  margin-bottom: 4px;
}

.roll-char-name {
  font-weight: 700;
  font-size: 0.82rem;
}

.roll-check-type {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.roll-dice-info {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
}

.roll-tiers {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: var(--space-sm);
}

.roll-tier {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.tier-label {
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--font-mono);
  width: 40px;
  text-align: right;
  flex-shrink: 0;
}

.tier-crit { color: var(--gold); }
.tier-high { color: var(--green); }
.tier-mid  { color: var(--text-secondary); }
.tier-low  { color: var(--gold); }
.tier-fail { color: var(--red); }

.tier-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 5px 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
}

.tier-input::placeholder { color: var(--border); }

.tier-loading .tier-input {
  opacity: 0.5;
}

.tier-input:focus {
  outline: none;
  border-color: var(--accent);
}

.tier-input.suggestion-updated {
  animation: suggestionFlash 0.6s ease;
}

@keyframes suggestionFlash {
  0% { background: var(--gold-subtle); }
  100% { background: var(--bg); }
}

.roll-inline-btn {
  background: var(--accent) !important;
  color: var(--btn-text) !important;
  border: none !important;
  padding: 8px 20px !important;
  font-size: 0.9rem !important;
  font-weight: 700 !important;
  border-radius: var(--radius-sm) !important;
  cursor: pointer;
  width: 100%;
  margin-top: var(--space-xs);
}

.roll-inline-btn:hover { opacity: 0.9; }
.roll-inline-btn:disabled { opacity: 0.5; cursor: wait; }

.roll-result-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 2px;
}

.result-score {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--accent);
}

.result-breakdown {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.result-dash {
  color: var(--text-dim);
}

.result-outcome {
  font-size: 0.85rem;
  color: var(--text);
  font-style: italic;
}

.roll-outcomes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-md);
}

.roll-skip-link {
  font-size: 0.75rem;
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: underline;
}

.roll-skip-link:hover { color: var(--text-secondary); }

.roll-btn {
  background: var(--accent) !important;
  color: var(--btn-text) !important;
  border: none !important;
  padding: 10px 24px !important;
  font-size: 1rem !important;
  font-weight: 700 !important;
  border-radius: var(--radius-sm) !important;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

.roll-btn:hover { transform: scale(1.05); }
.roll-btn:active { transform: scale(0.98); }

.roll-btn.rolling {
  animation: rollSpin 0.4s ease-in-out;
}

.roll-btn.rolled {
  background: var(--green) !important;
  cursor: default;
  pointer-events: none;
}

.roll-result-number {
  font-size: 1.4rem;
  font-family: var(--font-mono);
  font-weight: 800;
}

.roll-btn-dice {
  font-size: 1.1rem;
}

/* ── Loot Popup ──────────────────────────────────── */
.loot-roll-result {
  margin: var(--space-sm) 0;
  text-align: center;
}

.loot-roll-number {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.loot-roll-mod {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.loot-rarity {
  display: inline-block;
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 12px;
  border: 2px solid;
  border-radius: 4px;
  margin-top: var(--space-xs);
}

.loot-customize {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: var(--space-sm);
}

.loot-customize input,
.loot-customize select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.82rem;
}

.loot-customize input:focus,
.loot-customize select:focus {
  outline: none;
  border-color: var(--accent);
}

.loot-customize input::placeholder { color: var(--text-dim); }

.loot-card { min-width: 200px; }

.item-rarity {
  font-size: 0.7rem;
  font-weight: 600;
}

@keyframes rollSpin {
  0% { transform: rotate(0deg); }
  25% { transform: rotate(10deg) scale(1.1); }
  50% { transform: rotate(-10deg); }
  75% { transform: rotate(5deg); }
  100% { transform: rotate(0deg); }
}

/* ── Reduced Motion ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Scrollbar ───────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
/* Firefox */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ── Tablet (768px and below) ───────────────────── */
@media (max-width: 768px) {
  /* Setup screens */
  .setup-container { padding: clamp(32px, 5vh, 60px) 16px 24px; }
  .setup-container.wide { max-width: 100%; padding: 24px 16px; }

  .char-grid {
    flex-wrap: wrap;
    justify-content: center;
  }
  .char-grid > .char-card,
  .char-grid > .char-card-add {
    flex: 0 0 220px;
    min-width: 220px;
  }

  /* Game layout — collapse sidebar */
  .game-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 49px - 48px);
  }

  .timeline-panel {
    width: 100%;
    min-width: 0;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--border-light);
    padding: var(--space-sm) var(--space-md);
    flex-shrink: 0;
  }
  .timeline-panel h2 { margin-bottom: var(--space-sm); }

  .game-main {
    flex: 1;
    min-height: 0;
  }
  .chat-log { padding: var(--space-sm) var(--space-md); }

  /* Hide logbook on tablet — not enough space */
  .logbook-toggle, .logbook-panel { display: none !important; }

  /* Entity bar scrolls horizontally */
  .entity-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-sm);
  }
  .char-bar, .enemy-bar, .npc-bar { gap: var(--space-xs); flex: none; overflow: visible; }

  /* Top bar compact */
  .top-bar { gap: var(--space-sm); padding: var(--space-xs) var(--space-sm); }
  .token-stats, .model-badge { display: none; }
  .top-actions { gap: 4px; }
  .top-actions button { padding: 5px 10px; font-size: 0.72rem; }

  /* Command ref */
  .command-ref { width: calc(100vw - 32px); right: 16px; top: 44px; }
  .command-ref-grid { grid-template-columns: 1fr; }

  /* Character card popup */
  .char-card-popup { max-width: 95vw; padding: var(--space-md); }
  .card-stats-grid { grid-template-columns: repeat(4, 1fr); gap: var(--space-xs); }

  /* Roll popup */
  .roll-popup { bottom: 60px; max-width: 95vw; }

  /* Logbook tabs — larger touch targets */
  .logbook-tab { padding: 6px 10px; font-size: 0.68rem; }
}

/* ── Mobile (480px and below) ───────────────────── */
@media (max-width: 480px) {
  .logo { font-size: 1.8rem; }
  .subtitle { font-size: 0.92rem; margin-bottom: var(--space-lg); }

  /* Setup */
  .setup-container { padding: 24px 12px 16px; }
  .char-grid > .char-card,
  .char-grid > .char-card-add {
    flex: 1 1 100%;
    min-width: 0;
  }
  .char-actions { flex-direction: column; gap: var(--space-sm); }
  .char-actions button { width: 100%; }

  /* Game layout — full screen chat, timeline hidden by default */
  .timeline-panel {
    max-height: 140px;
  }

  /* Entity bar — single scrollable row */
  .entity-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    gap: var(--space-sm);
    padding: var(--space-sm);
  }
  .char-bar, .enemy-bar, .npc-bar {
    flex: none;
    overflow: visible;
  }
  .enemy-bar:not(:empty), .npc-bar:not(:empty) {
    border-left: none;
    padding-left: 0;
  }

  /* Top bar — minimal */
  .logo-small { font-size: 0.85rem; }
  .world-title { font-size: 0.75rem; }
  .turn-counter { font-size: 0.72rem; }

  /* GM bar — stack on very small */
  .gm-bar {
    flex-wrap: wrap;
    padding: var(--space-sm);
  }
  .gm-bar input {
    order: 1;
    flex: 1 1 100%;
    font-size: 16px; /* prevent iOS zoom */
  }
  .gm-label { order: 0; }
  .gm-bar > button {
    order: 2;
    flex: 1;
    padding: 10px;
  }

  /* Chat — tighter */
  .chat-log { padding: var(--space-xs) var(--space-sm); }
  .chat-content { font-size: 0.84rem; }
  .chat-sender { font-size: 0.72rem; }

  /* Character popup */
  .card-stats-grid { grid-template-columns: repeat(3, 1fr); }
  .card-name { font-size: 1.1rem; }

  /* Roll cards */
  .roll-tiers { gap: 6px; }
  .tier-input { font-size: 0.75rem; padding: 6px; }
  .roll-inline-btn { padding: 10px !important; font-size: 0.85rem !important; }

  /* Overlay */
  .char-card-popup {
    max-width: 100vw;
    width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    padding: var(--space-md) var(--space-sm);
  }

  /* Help button — larger touch target */
  .help-btn { width: 36px; height: 36px; }
}

/* ── Mood Themes ────────────────────────────────── */
/* Transitions applied to all themed elements */
.top-bar, .gm-bar, .game-main, .timeline-panel, .entity-bar,
.chat-log, .char-card-popup, .chat-roll-card {
  transition: background-color 2s ease, border-color 2s ease, color 2s ease;
}

/* Tense — dark amber, danger lurking */
[data-mood="tense"] { --bg: oklch(15% 0.02 50); --bg-surface: oklch(18% 0.02 50); --bg-inset: oklch(12% 0.03 50);
  --text: oklch(85% 0.01 70); --text-secondary: oklch(65% 0.01 70); --text-dim: oklch(50% 0.01 70);
  --border: oklch(25% 0.02 50); --border-light: oklch(22% 0.015 50);
  --accent: oklch(60% 0.18 55); --accent-hover: oklch(55% 0.18 55); --accent-subtle: oklch(20% 0.06 55);
  --red-subtle: oklch(18% 0.06 25); --green-subtle: oklch(18% 0.04 155); --gold-subtle: oklch(18% 0.05 75); }

/* Whimsical — warm golden, lighthearted */
[data-mood="whimsical"] { --bg: oklch(96% 0.02 85); --bg-surface: oklch(98% 0.015 85); --bg-inset: oklch(93% 0.025 85);
  --text: oklch(25% 0.02 85); --text-secondary: oklch(45% 0.02 85); --text-dim: oklch(55% 0.015 85);
  --border: oklch(87% 0.02 85); --border-light: oklch(91% 0.01 85);
  --accent: oklch(60% 0.16 85); --accent-hover: oklch(55% 0.16 85); --accent-subtle: oklch(93% 0.04 85); }

/* Gothic — deep purple darkness */
[data-mood="gothic"] { --bg: oklch(10% 0.02 300); --bg-surface: oklch(13% 0.025 300); --bg-inset: oklch(8% 0.03 300);
  --text: oklch(80% 0.01 300); --text-secondary: oklch(60% 0.02 300); --text-dim: oklch(45% 0.02 300);
  --border: oklch(20% 0.03 300); --border-light: oklch(18% 0.02 300);
  --accent: oklch(55% 0.18 310); --accent-hover: oklch(50% 0.18 310); --accent-subtle: oklch(15% 0.06 310);
  --red-subtle: oklch(15% 0.06 25); --green-subtle: oklch(15% 0.04 155); --gold-subtle: oklch(15% 0.05 75); }

/* Peaceful — soft sage green */
[data-mood="peaceful"] { --bg: oklch(96% 0.01 150); --bg-surface: oklch(98% 0.008 150); --bg-inset: oklch(93% 0.015 150);
  --text: oklch(25% 0.01 150); --text-secondary: oklch(45% 0.01 150); --text-dim: oklch(55% 0.01 150);
  --border: oklch(88% 0.01 150); --border-light: oklch(92% 0.008 150);
  --accent: oklch(50% 0.12 155); --accent-hover: oklch(45% 0.12 155); --accent-subtle: oklch(93% 0.03 155); }

/* Battle — aggressive crimson */
[data-mood="battle"] { --bg: oklch(12% 0.03 25); --bg-surface: oklch(15% 0.035 25); --bg-inset: oklch(10% 0.04 25);
  --text: oklch(88% 0.01 25); --text-secondary: oklch(65% 0.02 25); --text-dim: oklch(50% 0.02 25);
  --border: oklch(22% 0.04 25); --border-light: oklch(20% 0.03 25);
  --accent: oklch(55% 0.2 25); --accent-hover: oklch(50% 0.2 25); --accent-subtle: oklch(18% 0.08 25);
  --red-subtle: oklch(18% 0.08 25); --green-subtle: oklch(18% 0.04 155); --gold-subtle: oklch(18% 0.06 75); }

/* Mysterious — deep ocean blue */
[data-mood="mysterious"] { --bg: oklch(14% 0.02 240); --bg-surface: oklch(17% 0.025 240); --bg-inset: oklch(11% 0.03 240);
  --text: oklch(82% 0.01 240); --text-secondary: oklch(62% 0.015 240); --text-dim: oklch(48% 0.015 240);
  --border: oklch(22% 0.025 240); --border-light: oklch(20% 0.02 240);
  --accent: oklch(55% 0.14 220); --accent-hover: oklch(50% 0.14 220); --accent-subtle: oklch(18% 0.05 220);
  --red-subtle: oklch(17% 0.06 25); --green-subtle: oklch(17% 0.04 155); --gold-subtle: oklch(17% 0.05 75); }

/* Somber — muted grey with cool undertones */
[data-mood="somber"] { --bg: oklch(18% 0.005 250); --bg-surface: oklch(21% 0.005 250); --bg-inset: oklch(15% 0.008 250);
  --text: oklch(70% 0.005 250); --text-secondary: oklch(55% 0.005 250); --text-dim: oklch(42% 0.005 250);
  --border: oklch(25% 0.008 250); --border-light: oklch(23% 0.005 250);
  --accent: oklch(50% 0.05 250); --accent-hover: oklch(45% 0.05 250); --accent-subtle: oklch(20% 0.02 250);
  --red-subtle: oklch(20% 0.04 25); --green-subtle: oklch(20% 0.03 155); --gold-subtle: oklch(20% 0.03 75); }

/* Triumphant — bright gold on warm white */
[data-mood="triumphant"] { --bg: oklch(95% 0.02 75); --bg-surface: oklch(97% 0.015 75); --bg-inset: oklch(92% 0.025 75);
  --text: oklch(20% 0.02 75); --text-secondary: oklch(40% 0.02 75); --text-dim: oklch(50% 0.015 75);
  --border: oklch(85% 0.025 75); --border-light: oklch(90% 0.015 75);
  --accent: oklch(62% 0.18 75); --accent-hover: oklch(57% 0.18 75); --accent-subtle: oklch(92% 0.05 75); }
