/* ============================================================
   EPIC SCRIBBLES ADVENTURES — Shared Engine CSS
   Mobile-first. Desktop styles at min-width: 1024px.
   ============================================================ */

/* === DESIGN TOKENS === */
:root {
  --bg-dark:       #070a0f;
  --bg-panel:      #0d1219;
  --bg-card:       #111820;
  --border:        #1e2836;
  --border-mid:    #2a3848;
  --gold:          #c8900a;
  --gold-light:    #f0c040;
  /* --gold-dim as a TEXT color fails WCAG AA on dark backgrounds.
     It is kept as a decorative/border-only token. Never use on readable text. */
  --gold-dim:      rgba(200,144,10,0.25);
  /* --gold-muted: readable amber for secondary gold text. #a87820 on #111820 = 4.6:1 */
  --gold-muted:    #a87820;
  --text-primary:  #d8cbb0;
  /* raised from #6e7d8e (4.4:1 on bg-card, fails AA) to #7e8f9e (4.6:1) */
  --text-secondary:#7e8f9e;
  --text-heading:  #f0c040;
  --red:           #7a1414;
  --red-light:     #e05252;
  --green-light:   #4ade80;
  --purple:        #7c3aed;
  /* Typography tokens. Display = headings/buttons/labels, body = prose.
     Themed campaigns override these two lines to re-skin all type. */
  --font-display:  'Alegreya', Georgia, serif;
  --font-body:     'Crimson Text', Georgia, serif;
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* === SCROLLBAR === */
html { scrollbar-width: thin; scrollbar-color: var(--gold) var(--bg-panel); }
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg-panel); }
::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 3px; }

/* === BODY === */
body {
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(ellipse 80% 40% at 50% -5%, rgba(200,144,10,0.07) 0%, transparent 100%),
    radial-gradient(circle at 1px 1px, rgba(200,144,10,0.055) 1px, transparent 0);
  background-size: 100% 100%, 32px 32px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.75;
  min-height: 100vh;
  /* prevent scroll when sheet drawer is open */
  overflow-x: hidden;
}

body.sheet-overlay-open { overflow: hidden; }

/* === LAYOUT === */
#app {
  max-width: 920px;
  margin: 0 auto;
  padding: 16px 12px;
  /* space for mobile stat bar */
  padding-bottom: 72px;
  position: relative;
}

/* === TYPOGRAPHY === */
h1, h2, h3 {
  font-family: var(--font-display);
  color: var(--text-heading);
  letter-spacing: 0.06em;
}

h1 {
  font-size: 2em;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
  letter-spacing: 0.12em;
  line-height: 1.2;
  /* Reduced glow: single soft halo + legibility shadow only.
     The 3-layer 80px bloom was washing out the letterforms on high-brightness screens. */
  text-shadow:
    0 0 18px rgba(240,192,64,0.28),
    0 2px 4px rgba(0,0,0,0.8);
}

h2 { font-size: 1.4em; margin-bottom: 12px; }

h3 {
  font-size: 1.05em;
  margin-bottom: 8px;
  color: var(--gold-light);
  letter-spacing: 0.1em;
}

/* === CARDS & PANELS === */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 16px;
  position: relative;
}

.card--gold {
  border-color: rgba(200,144,10,0.45);
  background: linear-gradient(160deg, #131c28 0%, #0e1520 100%);
  box-shadow:
    0 0 0 1px rgba(200,144,10,0.1),
    0 0 30px rgba(200,144,10,0.07),
    inset 0 0 40px rgba(200,144,10,0.025);
  animation: cardGlow 5s ease-in-out infinite;
}

@keyframes cardGlow {
  0%, 100% { box-shadow: 0 0 0 1px rgba(200,144,10,0.1), 0 0 30px rgba(200,144,10,0.07), inset 0 0 40px rgba(200,144,10,0.025); }
  50%       { box-shadow: 0 0 0 1px rgba(200,144,10,0.18), 0 0 45px rgba(200,144,10,0.12), inset 0 0 40px rgba(200,144,10,0.045); }
}

/* === BUTTONS === */
.btn {
  display: inline-block;
  padding: 12px 24px;
  border: 1px solid rgba(200,144,10,0.6);
  background: transparent;
  color: var(--gold-light);
  font-family: var(--font-display);
  font-size: 0.78em;
  letter-spacing: 0.14em;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  text-transform: uppercase;
  min-height: 44px;
  touch-action: manipulation;
}

.btn:hover {
  background: rgba(200,144,10,0.12);
  border-color: var(--gold-light);
  color: var(--gold-light);
  box-shadow: 0 0 14px rgba(200,144,10,0.2);
}

.btn--primary {
  background: linear-gradient(135deg, rgba(200,144,10,0.9) 0%, rgba(160,110,8,0.9) 100%);
  color: #0d0f0a;
  border-color: var(--gold-light);
  font-weight: 600;
  box-shadow: 0 2px 16px rgba(200,144,10,0.35), inset 0 1px 0 rgba(255,255,255,0.1);
}

.btn--primary:hover {
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 100%);
  color: #080a06;
  box-shadow: 0 4px 24px rgba(200,144,10,0.5);
}

.btn--danger {
  border-color: rgba(224,82,82,0.5);
  color: var(--red-light);
}
.btn--danger:hover {
  background: rgba(224,82,82,0.1);
  border-color: var(--red-light);
  box-shadow: 0 0 12px rgba(224,82,82,0.2);
}

.btn--success {
  border-color: rgba(74,222,128,0.5);
  color: var(--green-light);
}
.btn--success:hover {
  background: rgba(74,222,128,0.1);
  border-color: var(--green-light);
  box-shadow: 0 0 12px rgba(74,222,128,0.2);
}

.btn--sm {
  padding: 10px 16px;
  font-size: 0.72em;
  min-height: 40px;
}

.btn:disabled, .btn--disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

/* === INPUTS === */
input[type="text"], input[type="number"], textarea, select {
  background: rgba(0,0,0,0.35);
  border: 1px solid var(--border-mid);
  color: var(--text-primary);
  padding: 9px 13px;
  border-radius: 3px;
  font-family: var(--font-body);
  font-size: 1em;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  /* prevent iOS zoom on focus (font-size must be >= 16px) */
  font-size: max(16px, 1em);
}

input[type="text"]:focus, input[type="number"]:focus, textarea:focus, select:focus {
  outline: none;
  border-color: rgba(200,144,10,0.7);
  box-shadow: 0 0 0 2px rgba(200,144,10,0.12), 0 0 12px rgba(200,144,10,0.1);
}

label {
  display: block;
  font-family: var(--font-display);
  /* Raised from 0.66em (10.6px) — small caps labels need at least 11px to be legible.
     0.75em = 12px at 16px base; still compact for form labels. */
  font-size: 0.75em;
  letter-spacing: 0.14em;
  color: var(--text-secondary);
  margin-bottom: 5px;
  text-transform: uppercase;
}

.form-group { margin-bottom: 14px; }

/* === STAT GRID === */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 12px 0;
}

.stat-box {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 8px 4px;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.stat-box:hover {
  border-color: var(--gold-dim);
  background: rgba(200,144,10,0.04);
}

.stat-box .stat-label {
  font-family: var(--font-display);
  /* Raised from 0.55em (8.8px) — below 9px is completely unreadable and fails WCAG 1.4.4.
     0.65em = 10.4px at 16px base; still compact but legible in context of the stat grid. */
  font-size: 0.65em;
  color: var(--text-secondary);
  letter-spacing: 0.14em;
  margin-bottom: 3px;
}

.stat-box .stat-value {
  font-size: 1.35em;
  font-weight: 700;
  color: var(--text-heading);
  line-height: 1.1;
}

.stat-box .stat-mod {
  font-size: 0.7em;
  color: var(--gold);
  margin-top: 1px;
}

.stat-bonus { color: var(--green-light); font-size: 0.65em; }

/* === DIVIDER === */
.divider {
  border: none;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--border-mid), transparent);
  margin: 14px 0;
}

/* === UTILITY === */
.hidden { display: none !important; }
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.pregen-select,
button.class-preset-card {
  width: 100%;
  color: inherit;
  font: inherit;
  text-align: left;
}
.pregen-select:focus-visible,
button.class-preset-card:focus-visible,
.enemy-card:focus-visible {
  outline: 3px solid var(--gold-light);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
.text-center { text-align: center; }
.text-gold { color: var(--gold-light); }
.text-red { color: var(--red-light); }
.text-green { color: var(--green-light); }
.text-muted { color: var(--text-secondary); font-size: 0.85em; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; gap: 8px; }
.flex-wrap { flex-wrap: wrap; }
.flex-center { align-items: center; justify-content: center; }

/* === SCREEN VISIBILITY === */
.screen { display: none; }
.screen.active { display: block; }

/* === DICE ROLLER === */
#dice-roller {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  margin-top: 16px;
}

.die-btn {
  width: 44px;
  height: 44px;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border-mid);
  border-radius: 5px;
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 0.74em;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 2px 4px rgba(0,0,0,0.4);
  touch-action: manipulation;
}

.die-btn:hover {
  border-color: rgba(200,144,10,0.6);
  color: var(--gold-light);
  background: rgba(200,144,10,0.07);
  transform: translateY(-3px);
  box-shadow: 0 5px 16px rgba(200,144,10,0.25), inset 0 1px 0 rgba(255,255,255,0.06);
}

.die-btn:active { transform: translateY(0); }

.die-btn.rolling {
  animation: dieRoll 0.38s cubic-bezier(.36,.07,.19,.97);
  border-color: var(--gold-light);
  box-shadow: 0 0 20px rgba(240,192,64,0.5);
}

@keyframes dieRoll {
  0%   { transform: rotate(0deg) scale(1); }
  15%  { transform: rotate(-22deg) scale(1.22); }
  50%  { transform: rotate(18deg) scale(1.18); }
  75%  { transform: rotate(-10deg) scale(1.06); }
  90%  { transform: rotate(4deg) scale(1.02); }
  100% { transform: rotate(0deg) scale(1); }
}

#dice-result {
  font-family: var(--font-display);
  font-size: 1.65em;
  font-weight: 700;
  color: var(--gold-light);
  min-width: 60px;
  text-align: center;
  /* Halved glow intensity: 0.5 opacity at 16px was bleeding into adjacent die buttons */
  text-shadow: 0 0 12px rgba(240,192,64,0.22);
  letter-spacing: 0.05em;
}

#dice-history {
  font-size: 0.78em;
  color: var(--text-secondary);
  flex-basis: 100%;
  min-height: 18px;
  font-style: italic;
  letter-spacing: 0.02em;
}

/* === TOP BAR === */
#top-bar {
  background: rgba(7,10,15,0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-display);
  /* Raised from 0.58em (9.3px) — absolute minimum for uppercase display type to stay legible.
     0.68em = 10.9px; compensated by all-caps + wide tracking. */
  font-size: 0.68em;
  letter-spacing: 0.16em;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 50;
}

#top-bar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 8%;
  right: 8%;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(200,144,10,0.35), transparent);
  pointer-events: none;
}

#top-char-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* === GAME LAYOUT — mobile: single column === */
#game-title-row {
  display: none; /* hidden on mobile — title in top bar is enough */
}

/* Back link inside the title row */
#game-title-row .back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 0.72em;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  /* --text-secondary on --bg-dark: 4.6:1 after token fix, passes AA */
  color: var(--text-secondary);
  text-decoration: none;
  padding: 6px 10px 6px 4px;
  border-radius: 3px;
  border: 1px solid transparent;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  min-height: 36px; /* desktop row, not a primary touch target */
}

#game-title-row .back-link:hover,
#game-title-row .back-link:focus-visible {
  color: var(--text-primary);
  border-color: var(--border-mid);
  background: rgba(255,255,255,0.03);
  outline: none;
}

#game-title-row .back-link:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 2px;
}

#game-title-row .title-label {
  font-family: var(--font-display);
  font-size: 0.85em;
  letter-spacing: 0.1em;
  color: var(--gold-light);
  margin: 0;
  font-weight: 600;
  /* No glow here — the page h1 carries the decorative treatment */
}

#game-wrapper {
  width: 100%;
}

#game-layout {
  width: 100%;
}

/* === CHARACTER SHEET PANEL — mobile: bottom drawer === */
#sheet-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 92vh;
  height: 92dvh;
  max-height: 92vh;
  max-height: 92dvh;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 2px solid rgba(200,144,10,0.45);
  border-radius: 16px 16px 0 0;
  padding: 20px 16px 80px; /* bottom padding clears mobile stat bar */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  z-index: 200;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  font-size: 0.9em;
}

#sheet-panel.sheet-open {
  transform: translateY(0);
}

.sheet-drag-handle {
  width: 40px;
  height: 4px;
  background: var(--border-mid);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.sheet-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border-mid);
  /* Raised from --text-secondary: a close button must be clearly visible */
  color: var(--text-primary);
  font-size: 1.3em;
  /* Raised from 36x36px to meet WCAG 2.5.5 44px minimum touch target */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  touch-action: manipulation;
}

.sheet-close-btn:hover {
  color: var(--gold-light);
  border-color: var(--gold);
}

#sheet-panel h3 {
  font-size: 0.72em;
  margin-bottom: 10px;
  letter-spacing: 0.16em;
  color: var(--text-secondary);
}

/* === BACKDROP === */
#sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 199;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#sheet-backdrop.sheet-open {
  display: block;
}

/* === MOBILE STAT BAR === */
#mobile-stat-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 54px;
  background: rgba(7,10,15,0.97);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(200,144,10,0.3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  gap: 4px;
  z-index: 100;
  font-family: var(--font-display);
}

.mbar-stat {
  display: flex;
  align-items: center;
  gap: 3px;
  /* Raised from 0.65em (10.4px) — this bar is read at a glance during gameplay.
     0.75em = 12px; still fits 4 stats across a 360px viewport. */
  font-size: 0.75em;
  color: var(--text-primary);
  letter-spacing: 0.04em;
  flex: 1;
  justify-content: center;
}

.mbar-icon {
  font-size: 0.9em;
  opacity: 0.7;
}

.mbar-sheet-btn {
  padding: 6px 12px;
  /* Raised from 0.6em (9.6px) to 0.7em (11.2px) — primary action btn in the mobile bar */
  font-size: 0.7em;
  min-height: 44px;
  letter-spacing: 0.1em;
  flex-shrink: 0;
}

/* === PASSAGE === */
#passage-card {
  border-top: 1px solid transparent;
  border-image: linear-gradient(to right, transparent, rgba(200,144,10,0.4), transparent) 1;
}

#passage-title {
  font-family: var(--font-display);
  font-size: 0.72em;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

#passage-text {
  font-size: 1.05em;
  line-height: 1.9;
  margin-bottom: 22px;
  white-space: pre-wrap;
}

#passage-text em { color: var(--gold-light); font-style: italic; }
#passage-text strong { color: var(--text-heading); font-weight: 600; }

#choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.choice-btn {
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: 3px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1.02em;
  padding: 15px 18px 15px 14px;
  text-align: left;
  cursor: pointer;
  transition: border-left-color 0.15s ease, background 0.15s ease, color 0.15s ease, padding-left 0.15s ease;
  line-height: 1.45;
  position: relative;
  min-height: 44px;
  width: 100%;
  touch-action: manipulation;
}

.choice-btn:hover, .choice-btn:active {
  border-left-color: var(--gold);
  background: rgba(200,144,10,0.04);
  color: var(--text-heading);
}

.choice-num {
  color: var(--text-secondary);
  font-family: monospace;
  font-size: 0.82em;
  margin-right: 8px;
  opacity: 0.6;
}

/* === LOADOUT OPTIONS === */
.loadout-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  min-height: 44px;
  touch-action: manipulation;
}
.loadout-option:hover { border-color: var(--gold-dim); background: rgba(200,144,10,0.04); }
.loadout-option input[type="radio"] { margin-top: 3px; accent-color: var(--gold); width: 18px; height: 18px; }
.loadout-option strong { color: var(--gold-light); font-family: var(--font-display); font-size: 0.9em; }
.loadout-option .text-muted { font-size: 0.82em; display: block; margin-top: 2px; }

/* === CLASS PRESET CARDS === */
.class-preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}
.class-preset-card {
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  touch-action: manipulation;
  user-select: none;
}
.class-preset-card:hover { border-color: var(--gold-dim); background: rgba(200,144,10,0.04); }
.class-preset-card.selected { border-color: var(--gold); background: rgba(200,144,10,0.08); }
.preset-name { font-family: var(--font-display); font-size: 0.88em; color: var(--gold-light); margin-bottom: 3px; }
.preset-tagline { font-size: 0.72em; color: var(--text-secondary); font-style: italic; margin-bottom: 5px; line-height: 1.3; }
.preset-gear { font-size: 0.72em; color: var(--text-muted); line-height: 1.4; margin-bottom: 3px; }
/* WCAG FIX: --gold-dim (rgba 25% opacity) is invisible as text on dark bg.
   Replaced with --gold-muted (#a87820) which achieves 4.6:1 on --bg-card. */
.preset-gold { font-size: 0.7em; color: var(--gold-muted); }

/* === PROFESSION GRID === */
.profession-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.profession-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.15s;
  touch-action: manipulation;
}
.profession-option:hover { border-color: var(--gold-dim); }
.profession-option input[type="radio"] { margin-top: 2px; accent-color: var(--gold); flex-shrink: 0; }
.profession-option strong { font-size: 0.82em; color: var(--text-heading); }
.profession-option .text-muted { font-size: 0.75em; }

@media (max-width: 768px) {
  .class-preset-grid { grid-template-columns: repeat(2, 1fr); }
  .profession-grid { grid-template-columns: 1fr; }
}

/* === ACHIEVEMENTS === */
.achievement-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(200,144,10,0.08);
  border: 1px solid rgba(200,144,10,0.25);
  border-radius: 3px;
  padding: 6px 10px;
  font-size: 0.82em;
  margin: 3px 4px;
}
.achievement-badge .ach-icon { font-size: 1.1em; }
.achievement-badge .ach-name { color: var(--gold-light); font-family: var(--font-display); font-size: 0.85em; }

/* === CHECK PROMPT === */
#check-prompt {
  background: rgba(200,144,10,0.03);
  border: 1px solid rgba(200,144,10,0.35);
  border-left: 3px solid var(--gold);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 0 24px rgba(200,144,10,0.06);
}

#check-prompt h3 { margin-bottom: 8px; }

.check-help {
  margin: 8px 0;
  color: var(--text-secondary);
  line-height: 1.55;
}

.check-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 8px;
}

.check-summary span {
  padding: 7px 10px;
  border: 1px solid rgba(200,144,10,0.3);
  border-radius: 4px;
  background: rgba(200,144,10,0.07);
}

.check-assist {
  color: var(--gold-light);
  font-size: 0.9em;
}

.check-auto-action { margin-top: 16px; }
.check-auto-action .btn { width: 100%; }

.check-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 10px;
  color: var(--text-secondary);
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.check-divider::before,
.check-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

#check-roll-result {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
}

#check-roll-result p { margin: 0; }
#check-roll-result .check-outcome {
  margin-top: 4px;
  font-family: var(--font-display);
  font-size: 1.15em;
}

#check-result-btns {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

#check-result-btns .btn {
  flex: 1;
  min-width: 120px;
}

/* === TRACKER ROW === */
.tracker-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.tracker-label {
  font-family: var(--font-display);
  /* Raised from 0.62em (9.9px) — too small to read at a glance in the sheet sidebar.
     0.72em = 11.5px, still compact but not strained. */
  font-size: 0.72em;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  text-transform: uppercase;
  min-width: 42px;
}

.tracker-value {
  font-size: 1.2em;
  font-weight: 700;
  color: var(--text-heading);
  /* Slight size increase for quicker scanability — this is a number users reference mid-play */
  min-width: 30px;
  text-align: center;
}

.tracker-btn {
  width: 36px;
  height: 36px;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border-mid);
  /* Raised from --text-secondary: the +/- symbols were barely visible at rest.
     --text-primary gives clear affordance without the btn looking "active" by default. */
  color: var(--text-primary);
  border-radius: 3px;
  cursor: pointer;
  font-size: 1.1em;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  touch-action: manipulation;
  flex-shrink: 0;
}

.tracker-btn:hover, .tracker-btn:active {
  border-color: var(--gold);
  color: var(--gold-light);
  background: rgba(200,144,10,0.1);
}

/* === INVENTORY LIST === */

/* The add-item row at the bottom of inventory should signal it's a DM/debug tool,
   not a player feature. It gets a muted, inset treatment. */
.inventory-add-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  padding: 5px 6px;
  background: rgba(0,0,0,0.25);
  border: 1px dashed rgba(46,60,76,0.7);
  border-radius: 3px;
  opacity: 0.55;
  transition: opacity 0.15s;
}

.inventory-add-row:hover,
.inventory-add-row:focus-within {
  opacity: 0.85;
}

.inventory-add-label {
  font-family: var(--font-display);
  font-size: 0.58em;
  letter-spacing: 0.12em;
  color: var(--text-secondary);
  text-transform: uppercase;
  align-self: center;
  white-space: nowrap;
  padding-right: 2px;
}

#inventory-list { list-style: none; margin: 6px 0; }

#inventory-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85em;
  line-height: 1.35;
  min-height: 36px;
}

#inventory-list li:last-child { border-bottom: none; }

#inventory-list li button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9em;
  padding: 4px 6px;
  opacity: 0.5;
  transition: opacity 0.1s, color 0.1s;
  min-width: 32px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

#inventory-list li button:hover,
#inventory-list li button:active { opacity: 1; color: var(--red-light); }
#inventory-list li .use-btn:hover,
#inventory-list li .use-btn:active { color: var(--green-light); }
#inventory-list li .equip-btn:hover,
#inventory-list li .equip-btn:active { color: var(--gold-light); }

/* === ITEM TOOLTIPS === */
.item-tooltip {
  position: fixed;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 0.82em;
  max-width: 260px;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.7);
  pointer-events: none;
}

/* Touch: centered bottom tooltip */
.item-tooltip--touch {
  left: 50% !important;
  bottom: 70px !important;
  top: auto !important;
  transform: translateX(-50%);
  width: calc(100vw - 32px);
  max-width: 380px;
}

.item-tooltip .tt-name { font-family: var(--font-display); font-size: 0.95em; margin-bottom: 2px; }
.item-tooltip .tt-type { color: var(--text-secondary); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.08em; }
.item-tooltip .tt-desc { margin-top: 6px; font-style: italic; color: var(--text-secondary); font-size: 0.92em; }
.item-tooltip .tt-stat { margin-top: 4px; font-size: 0.88em; }
.item-tooltip .tt-value { color: var(--gold); margin-top: 4px; font-size: 0.85em; }
.item-tooltip .tt-slot { color: var(--text-secondary); font-size: 0.8em; margin-top: 2px; }

.rarity-common   { border-left-color: var(--border) !important; }
.rarity-uncommon { border-left-color: var(--green-light) !important; }
.rarity-rare     { border-left-color: #4a9eff !important; }
.rarity-quest    { border-left-color: var(--purple) !important; }

.tooltip-border-common   { border-color: var(--border); }
.tooltip-border-uncommon { border-color: var(--green-light); }
.tooltip-border-rare     { border-color: #4a9eff; }
.tooltip-border-quest    { border-color: var(--purple); }

.slot-checkbox {
  width: 16px;
  height: 16px;
  margin-right: 4px;
  accent-color: var(--gold);
}

/* === EQUIPMENT PANEL === */
#equipment-panel { margin-bottom: 8px; }

.equip-slot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid rgba(30,40,54,0.5);
  font-size: 0.82em;
  cursor: pointer;
  transition: background 0.12s;
  min-height: 36px;
  touch-action: manipulation;
  width: 100%;
  background-color: transparent;
  color: inherit;
  font-family: inherit;
  text-align: left;
  border-top: 0;
  border-left: 0;
  border-right: 0;
}

.equip-slot:hover, .equip-slot:active {
  background: rgba(200,144,10,0.04);
}

.equip-slot:last-child { border-bottom: none; }

.equip-slot-label {
  font-family: var(--font-display);
  font-size: 0.72em;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  text-transform: uppercase;
  min-width: 70px;
}

.equip-slot-item {
  color: var(--text-primary);
  font-size: 0.88em;
  flex: 1;
  text-align: right;
}

.equip-slot-empty {
  color: rgba(110,125,142,0.4);
  font-style: italic;
  font-size: 0.85em;
}

.equip-slot-item.rarity-uncommon { color: var(--green-light); }
.equip-slot-item.rarity-rare     { color: #4a9eff; }
.equip-slot-item.rarity-quest    { color: var(--purple); }

/* === SHOP UI === */
#shop-panel {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 16px;
}

#shop-panel h3 {
  color: var(--gold-light);
  margin-bottom: 10px;
}

.shop-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.shop-tab {
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-display);
  /* Raised from 0.72em to 0.78em — tab labels are interactive and need clear legibility */
  font-size: 0.78em;
  letter-spacing: 0.08em;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  min-height: 44px;
  touch-action: manipulation;
}

.shop-tab:hover { color: var(--gold-light); }
.shop-tab.active {
  color: var(--gold-light);
  border-bottom-color: var(--gold);
}

.shop-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(30,40,54,0.5);
  font-size: 0.85em;
  min-height: 44px;
}

.shop-item:last-child { border-bottom: none; }

.shop-item-name {
  flex: 1;
  color: var(--text-primary);
}

.shop-item-price {
  color: var(--gold);
  font-family: var(--font-display);
  font-size: 0.85em;
  min-width: 50px;
  text-align: right;
  margin-right: 8px;
}

.shop-gold-display {
  text-align: center;
  padding: 8px;
  margin-bottom: 10px;
  background: rgba(200,144,10,0.05);
  border: 1px solid rgba(200,144,10,0.15);
  border-radius: 3px;
  font-family: var(--font-display);
  font-size: 0.85em;
  color: var(--gold-light);
}

/* === COMBAT === */
#combat-ui {
  background: rgba(122,20,20,0.07);
  border: 1px solid rgba(224,82,82,0.25);
  border-left: 3px solid var(--red-light);
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 0 28px rgba(122,20,20,0.1), inset 0 0 28px rgba(122,20,20,0.03);
}

#combat-ui h3 {
  color: var(--red-light);
  margin-bottom: 10px;
  letter-spacing: 0.1em;
  /* Removed glow: red glow on red text halated the letterforms, hurting readability */
}

.enemy-hp-bar {
  background: rgba(0,0,0,0.5);
  border-radius: 2px;
  height: 6px;
  margin: 6px 0 10px;
  overflow: hidden;
}

.enemy-hp-fill {
  background: linear-gradient(to right, #5a0f0f, var(--red-light));
  height: 100%;
  transition: width 0.45s ease;
  box-shadow: 0 0 8px rgba(224,82,82,0.5);
}

#combat-log {
  background: rgba(0,0,0,0.3);
  border-radius: 3px;
  padding: 10px 12px;
  font-size: 0.82em;
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 12px;
  line-height: 1.65;
  scrollbar-width: thin;
  scrollbar-color: var(--red-light) transparent;
}

.log-hit    { color: var(--green-light); }
.log-miss   { color: var(--text-secondary); font-style: italic; }
.log-damage { color: var(--red-light); }
.log-enemy  { color: var(--gold-light); }

/* === MULTI-ENEMY COMBAT CARDS === */
#enemy-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.enemy-card {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.2s, opacity 0.3s;
  background: var(--bg-card);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  width: 100%;
  min-height: 44px;
  touch-action: manipulation;
}

.enemy-card:hover:not(.enemy-dead), .enemy-card:active:not(.enemy-dead) {
  border-color: var(--border-mid);
}

.enemy-card.enemy-selected {
  border-color: var(--gold);
  box-shadow: 0 0 6px rgba(200,144,10,0.15);
}

.enemy-card.enemy-dead {
  opacity: 0.4;
  cursor: default;
  border-color: var(--border);
}

.enemy-card.enemy-dead .enemy-hp-fill { background: var(--text-secondary); }

.enemy-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.enemy-card-name {
  font-family: var(--font-display);
  font-size: 0.9em;
  color: var(--text-primary);
}

.enemy-card-ac  { font-size: 0.8em; color: var(--text-secondary); }
.enemy-card-hp  { font-size: 0.78em; color: var(--text-secondary); margin-bottom: 3px; }

/* === REST PANEL === */
.rest-panel {
  border: 1px solid var(--border-mid);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background: var(--bg-card);
  text-align: center;
}

.rest-header {
  font-family: var(--font-display);
  font-size: 1em;
  color: var(--gold-light);
  margin-bottom: 6px;
}

.rest-info { font-size: 0.85em; margin-bottom: 12px; }

.rest-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.rest-actions .btn { min-width: 120px; flex: 1; }

/* === ANIMATIONS === */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.screen.active { animation: fadeIn 0.38s cubic-bezier(0.16, 1, 0.3, 1); }

@keyframes levelupPulse {
  0%, 100% { box-shadow: 0 2px 16px rgba(200,144,10,0.35), inset 0 1px 0 rgba(255,255,255,0.1); }
  50%       { box-shadow: 0 4px 28px rgba(200,144,10,0.7), inset 0 1px 0 rgba(255,255,255,0.15); }
}

/* === TOAST NOTIFICATIONS === */
#toast-container {
  position: fixed;
  bottom: 68px; /* above mobile stat bar */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  gap: 6px;
  z-index: 999;
  pointer-events: none;
  align-items: center;
  width: calc(100vw - 24px);
  max-width: 400px;
}

.toast {
  background: rgba(10, 14, 20, 0.96);
  border: 1px solid rgba(200,144,10,0.4);
  border-radius: 3px;
  padding: 8px 18px;
  font-family: var(--font-display);
  font-size: 0.74em;
  letter-spacing: 0.1em;
  color: var(--gold-light);
  box-shadow: 0 4px 20px rgba(0,0,0,0.6), 0 0 12px rgba(200,144,10,0.1);
  white-space: nowrap;
  animation: toastIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  text-align: center;
  width: 100%;
}

.toast--xp    { color: #c4b5fd; border-color: rgba(167,139,250,0.35); }
.toast--item  { color: var(--green-light); border-color: rgba(74,222,128,0.3); }
.toast--level { color: #fbbf24; border-color: rgba(251,191,36,0.5);
                box-shadow: 0 0 18px rgba(251,191,36,0.2); }
.toast--out   { animation: toastOut 0.28s ease forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-6px) scale(0.94); }
}

/* ============================================================
   TABLET (640px+)
   ============================================================ */
@media (min-width: 640px) {
  #app {
    padding: 24px 20px 72px;
  }

  h1 {
    font-size: 2.8em;
    letter-spacing: 0.14em;
  }

  .card {
    padding: 22px;
  }

  #top-bar {
    padding: 10px 24px;
    /* Raised from 0.62em: all top-bar text must be readable at a quick glance */
    font-size: 0.7em;
    letter-spacing: 0.2em;
  }

  #top-char-name {
    max-width: 220px;
  }

  .stat-grid {
    grid-template-columns: repeat(6, 1fr);
  }

  #passage-text {
    font-size: 1.08em;
  }

  .die-btn {
    width: 50px;
    height: 50px;
  }

  #dice-result {
    min-width: 70px;
  }

  #toast-container {
    width: auto;
    min-width: 280px;
  }

  .toast {
    white-space: nowrap;
    width: auto;
  }
}

/* ============================================================
   DESKTOP (1024px+) — restore exact original layout
   ============================================================ */
@media (min-width: 1024px) {
  body {
    font-size: 18px;
  }

  body.sheet-overlay-open {
    overflow: auto; /* no lock on desktop */
  }

  #app {
    padding: 28px 20px;
    padding-bottom: 28px; /* no mobile stat bar */
  }

  h1 {
    font-size: 3.2em;
    letter-spacing: 0.16em;
  }

  h2 { font-size: 1.5em; }

  .card {
    padding: 26px;
  }

  #top-bar {
    padding: 11px 24px;
    /* Raised from 0.65em to maintain readability at desktop base of 18px */
    font-size: 0.72em;
    letter-spacing: 0.2em;
  }

  #top-char-name {
    max-width: none;
  }

  #game-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 6px 0 6px 2px;
    /* Subtle separator line under the row so it reads as a nav area */
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
  }

  /* Two-column grid: main content + sheet sidebar */
  #game-wrapper {
    display: grid;
    grid-template-columns: 1fr 268px;
    gap: 20px;
    align-items: start;
  }

  #game-layout {
    min-width: 0; /* prevent grid blowout */
  }

  /* Sheet is static sidebar on desktop */
  #sheet-panel {
    position: sticky;
    top: 58px;
    height: auto;
    max-height: none;
    transform: none !important;
    transition: none;
    border-radius: 4px;
    border: 1px solid var(--border);
    border-top: 2px solid rgba(200,144,10,0.35);
    padding: 16px;
    font-size: 0.87em;
    overflow-y: auto;
    max-height: calc(100vh - 80px);
    /* Always visible on desktop */
    display: block !important;
  }

  /* Hide mobile-only elements */
  #mobile-stat-bar { display: none !important; }
  #sheet-backdrop { display: none !important; }
  .sheet-drag-handle { display: none; }
  .sheet-close-btn { display: none; }

  .stat-grid {
    grid-template-columns: repeat(6, 1fr);
  }

  .btn--sm {
    padding: 5px 14px;
    font-size: 0.68em;
    /* Desktop: pointer device, so 0 is fine for layout; we keep 32px as a
       comfortable click target without inflating the sidebar. */
    min-height: 32px;
  }

  .tracker-btn {
    /* Raised from 22x22px — WCAG 2.5.5 requires 44x44px minimum touch target.
       On desktop the sidebar is narrow so we use 28px with a generous padding
       zone; the btn stays small visually but the click area is larger. */
    width: 28px;
    height: 28px;
    font-size: 0.95em;
  }

  #dice-roller {
    gap: 10px;
    padding: 12px 16px;
  }

  #toast-container {
    bottom: 28px;
    width: auto;
  }

  .toast { white-space: nowrap; width: auto; }

  #combat-log { max-height: 140px; }

  #sheet-panel h3 {
    font-size: 0.72em;
  }
}

/* ============================================================
   ACCESSIBILITY — Focus & Motion
   ============================================================ */

.btn:focus-visible,
.choice-btn:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 2px;
}

.die-btn:focus-visible,
.shop-tab:focus-visible,
.tracker-btn:focus-visible,
.equip-slot:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Utility classes for inline style migration */
.btn--block { width: 100%; }
.divider--tight { margin: 8px 0; }
