/* ==========================================================================
   AETHERIA: THE CULLING — VISUAL SYSTEM & CORE STYLES
   Dark-Romantasy Interactive RPG Journal PWA
   ========================================================================== */

/* --- Custom Properties / Design Tokens --- */
:root {
  --bg: #0a0a0f;
  --bg-card: rgba(16, 16, 24, 0.90);
  --bg-card-solid: #12121a;
  --bg-overlay: linear-gradient(180deg, rgba(10, 10, 15, 0.45) 0%, rgba(10, 10, 15, 0.88) 100%);
  --gold: #c9a227;
  --gold-light: #e5c358;
  --gold-dim: rgba(201, 162, 39, 0.25);
  --gold-glow: rgba(201, 162, 39, 0.65);
  --blood: #7a1f2b;
  --blood-glow: rgba(122, 31, 43, 0.7);
  --ivory: #e8e2d4;
  --ivory-muted: rgba(232, 226, 212, 0.72);
  --julian: #5c1f2e;
  --julian-glow: rgba(92, 31, 46, 0.7);
  --kaelen: #3a4a5c;
  --kaelen-glow: rgba(58, 74, 92, 0.7);
  --lyra: #8fb3c9;
  --lyra-glow: rgba(143, 179, 201, 0.7);

  --font-display: 'Cinzel', serif;
  --font-body: 'EB Garamond', 'Crimson Text', serif;

  --transition-screen: opacity 400ms ease;
  --transition-meter: width 600ms cubic-bezier(0.4, 0, 0.2, 1);
  --safe-top: env(safe-area-inset-top, 16px);
  --safe-bottom: env(safe-area-inset-bottom, 20px);
}

/* --- Base & Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  min-height: 100%;
  background-color: var(--bg);
  color: var(--ivory);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.6;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
  -webkit-font-smoothing: antialiased;
}

/* --- Ember Particle Canvas --- */
#ember-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 15;
}

/* --- Background Image Layer --- */
.bg-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: opacity 800ms ease-in-out, filter 800ms ease;
  opacity: 0.32;
  filter: brightness(0.68) contrast(1.15);
  pointer-events: none;
}

.bg-academy {
  background-image: var(--bg-overlay), url('assets/img/academy-bg.webp'), radial-gradient(circle at 50% 20%, #1e1b2e 0%, #0a0a0f 80%);
}
.bg-arena {
  background-image: var(--bg-overlay), url('assets/img/arena-bg.webp'), radial-gradient(circle at 50% 40%, #291016 0%, #0a0a0f 85%);
}
.bg-gala {
  background-image: var(--bg-overlay), url('assets/img/gala-bg.webp'), radial-gradient(circle at 50% 30%, #1d162a 0%, #0a0a0f 80%);
}
.bg-labyrinth {
  background-image: var(--bg-overlay), url('assets/img/labyrinth-bg.webp'), radial-gradient(circle at 50% 50%, #101c22 0%, #0a0a0f 85%);
}
.bg-cusp {
  background-image: var(--bg-overlay), url('assets/img/cusp-circle-bg.webp'), radial-gradient(circle at 50% 30%, #2b1d12 0%, #0a0a0f 80%);
}

/* --- Top Utility Bar (Audio & Install) --- */
.top-controls {
  position: fixed;
  top: var(--safe-top);
  right: 16px;
  z-index: 30;
  display: flex;
  gap: 12px;
  align-items: center;
}

.icon-btn {
  background: rgba(16, 16, 24, 0.85);
  border: 1px solid var(--border-gold);
  color: var(--gold);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transition: transform 150ms ease, border-color 200ms ease, box-shadow 200ms ease;
}

.icon-btn:hover, .icon-btn:focus-visible {
  transform: scale(1.05);
  border-color: var(--gold);
  box-shadow: 0 0 10px var(--gold-dim);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* --- Progressive HUD --- */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: linear-gradient(180deg, rgba(10, 10, 15, 0.96) 0%, rgba(10, 10, 15, 0.85) 80%, transparent 100%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 25;
  padding: calc(var(--safe-top) + 4px) 16px 12px;
  border-bottom: 1px solid rgba(201, 162, 39, 0.15);
  display: none;
  flex-direction: column;
  gap: 8px;
}

#hud.active {
  display: flex;
}

.hud-player-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-display);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  color: var(--gold-light);
  text-transform: uppercase;
}

.hud-meters-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 14px;
}

@media (min-width: 600px) {
  .hud-meters-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.meter-wrapper {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.meter-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  font-family: var(--font-display);
  color: var(--ivory-muted);
  letter-spacing: 0.05em;
}

.meter-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.6);
}

.meter-bar {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  transition: var(--transition-meter);
}

.meter-astral .meter-bar {
  background: linear-gradient(90deg, #c9a227, #f7df83);
  box-shadow: 0 0 8px var(--gold-dim);
}
.meter-astral.danger .meter-bar {
  background: linear-gradient(90deg, #7a1f2b, #d93d50);
  box-shadow: 0 0 10px var(--blood-glow);
}
.meter-reputation .meter-bar {
  background: linear-gradient(90deg, #8a7b63, #d9caa7);
}
.meter-julian .meter-bar {
  background: linear-gradient(90deg, var(--julian), #a83654);
  box-shadow: 0 0 8px var(--julian-glow);
}
.meter-kaelen .meter-bar {
  background: linear-gradient(90deg, var(--kaelen), #627e9e);
  box-shadow: 0 0 8px var(--kaelen-glow);
}
.meter-lyra .meter-bar {
  background: linear-gradient(90deg, var(--lyra), #d0e7f7);
  box-shadow: 0 0 8px var(--lyra-glow);
}

/* Unlock Glow Pulse */
.pulse-glow-gold {
  animation: pulseGold 1.2s ease-in-out 3;
}
.pulse-glow-silver {
  animation: pulseSilver 1.2s ease-in-out 3;
}

@keyframes pulseGold {
  0%, 100% {
    box-shadow: 0 0 4px rgba(201, 162, 39, 0.2);
    border-color: rgba(201, 162, 39, 0.4);
  }
  50% {
    box-shadow: 0 0 18px var(--gold-glow), 0 0 28px rgba(92, 31, 46, 0.5);
    border-color: var(--gold);
  }
}

@keyframes pulseSilver {
  0%, 100% {
    box-shadow: 0 0 4px rgba(143, 179, 201, 0.2);
    border-color: rgba(143, 179, 201, 0.4);
  }
  50% {
    box-shadow: 0 0 18px var(--lyra-glow), 0 0 28px rgba(143, 179, 201, 0.5);
    border-color: var(--lyra);
  }
}

/* --- Screen Container & State Machine --- */
#app {
  position: relative;
  z-index: 10;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(var(--safe-top) + 20px) 16px calc(var(--safe-bottom) + 40px);
}

body.has-hud-active #app {
  padding-top: calc(var(--safe-top) + 115px);
}

.screen {
  opacity: 0;
  transition: var(--transition-screen);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  max-width: 680px;
  margin: auto auto;
  padding: 10px 0 24px;
}

.screen.active {
  display: flex;
  opacity: 1;
}

.screen.hidden {
  display: none !important;
  opacity: 0 !important;
}

/* Card Panel Container */
.card-panel {
  background: var(--bg-card);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 8px;
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.8), inset 0 0 24px rgba(201, 162, 39, 0.05);
  padding: 28px 20px;
  width: 100%;
  position: relative;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

@media (min-width: 520px) {
  .card-panel {
    padding: 36px 30px;
  }
}

.card-panel::before, .card-panel::after {
  content: '❖';
  position: absolute;
  color: var(--gold);
  font-size: 11px;
  opacity: 0.6;
}
.card-panel::before { top: 8px; left: 10px; }
.card-panel::after { bottom: 8px; right: 10px; }

/* --- Solo RPG Scenic Illustration Banners --- */
.scene-banner-frame {
  width: 100%;
  height: 200px;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(201, 162, 39, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7), inset 0 0 20px rgba(0, 0, 0, 0.8);
  margin-bottom: 20px;
  cursor: zoom-in;
}

@media (min-width: 520px) {
  .scene-banner-frame {
    height: 240px;
  }
}

.scene-banner-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  filter: brightness(0.88) contrast(1.1);
  transition: transform 600ms ease;
}

.scene-banner-frame:hover .scene-banner-img {
  transform: scale(1.03);
}

.scene-banner-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, rgba(10, 10, 15, 0.15) 0%, rgba(10, 10, 15, 0.65) 100%);
  pointer-events: none;
}

/* --- Solo RPG Character Encounter Cards --- */
.character-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(18, 16, 26, 0.85);
  border: 1px solid rgba(201, 162, 39, 0.3);
  border-radius: 8px;
  padding: 16px;
  margin: 16px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

@media (min-width: 520px) {
  .character-card {
    flex-direction: row;
    align-items: center;
    padding: 18px;
  }
}

.character-portrait-frame {
  width: 120px;
  height: 160px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--gold);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.7), 0 0 10px var(--gold-dim);
  margin: 0 auto;
  cursor: zoom-in;
  transition: transform 200ms ease, box-shadow 200ms ease;
}

.character-portrait-frame:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 20px var(--gold-glow);
}

.character-portrait-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 400ms ease;
}

.character-card:hover .character-portrait-img {
  transform: scale(1.05);
}

.character-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.character-name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--gold-light);
  letter-spacing: 0.06em;
}

.character-title {
  font-size: 0.84rem;
  font-family: var(--font-display);
  color: var(--ivory-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.character-quote {
  font-style: italic;
  font-size: 0.98rem;
  color: var(--ivory);
  line-height: 1.5;
  border-left: 2px solid var(--gold);
  padding-left: 10px;
  margin-top: 4px;
}

/* Character Specific Border Glows */
.card-julian { border-color: rgba(92, 31, 46, 0.8); }
.card-julian .character-portrait-frame { border-color: var(--julian); box-shadow: 0 0 14px var(--julian-glow); }
.card-kaelen { border-color: rgba(58, 74, 92, 0.8); }
.card-kaelen .character-portrait-frame { border-color: var(--kaelen); box-shadow: 0 0 14px var(--kaelen-glow); }
.card-lyra { border-color: rgba(143, 179, 201, 0.8); }
.card-lyra .character-portrait-frame { border-color: var(--lyra); box-shadow: 0 0 14px var(--lyra-glow); }

/* --- Protagonist Avatar Selection Grid --- */
.avatar-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  margin: 16px 0 20px;
}

@media (min-width: 540px) {
  .avatar-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.avatar-card {
  background: rgba(14, 13, 20, 0.85);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  transition: all 200ms ease;
}

.avatar-card:hover {
  border-color: var(--gold);
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6), 0 0 12px var(--gold-dim);
}

.avatar-card.selected {
  border-color: var(--gold-light);
  background: rgba(36, 31, 44, 0.95);
  box-shadow: 0 0 18px var(--gold-glow);
  transform: scale(1.02);
}

.avatar-card-frame {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(201, 162, 39, 0.4);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
}

.avatar-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  transition: transform 300ms ease;
}

.avatar-card:hover .avatar-card-img {
  transform: scale(1.05);
}

.avatar-card-name {
  font-family: var(--font-display);
  font-size: 0.82rem;
  color: var(--gold-light);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.avatar-card-tag {
  font-size: 0.74rem;
  color: var(--ivory-muted);
}

/* Selected Avatar Preview (Step 4 & Grimoire) */
.selected-avatar-frame {
  width: 140px;
  height: 186px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--gold);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7), 0 0 16px var(--gold-dim);
  margin: 0 auto 16px;
  cursor: zoom-in;
  transition: transform 200ms ease, box-shadow 200ms ease;
}

.selected-avatar-frame:hover {
  transform: scale(1.03);
  box-shadow: 0 0 20px var(--gold-glow);
}

.selected-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}

/* --- Fullscreen Image Lightbox Modal --- */
.lightbox-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  transition: opacity 250ms ease;
}

.lightbox-modal.active {
  display: flex;
  opacity: 1;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 6, 10, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.lightbox-container {
  position: relative;
  z-index: 2;
  max-width: 92vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: lightboxPop 250ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes lightboxPop {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.lightbox-frame {
  border: 1px solid var(--gold);
  box-shadow: 0 0 35px rgba(201, 162, 39, 0.35), 0 24px 60px rgba(0, 0, 0, 0.95);
  border-radius: 8px;
  overflow: hidden;
  background: #0e0e16;
  display: flex;
  flex-direction: column;
}

.lightbox-frame img {
  max-width: min(88vw, 680px);
  max-height: 72vh;
  object-fit: contain;
  display: block;
}

.lightbox-caption {
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--gold-light);
  text-align: center;
  padding: 12px 18px;
  background: rgba(16, 16, 24, 0.98);
  border-top: 1px solid rgba(201, 162, 39, 0.25);
  letter-spacing: 0.04em;
}

.lightbox-close-btn {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 36px;
  height: 36px;
  background: var(--gold);
  color: #0a0a0f;
  border: 1px solid #ffffff;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7);
  transition: transform 150ms ease, background 150ms ease;
}

.lightbox-close-btn:hover {
  transform: scale(1.12);
  background: var(--gold-light);
}

.clickable-image {
  cursor: zoom-in;
  transition: transform 200ms ease, filter 200ms ease;
}

.clickable-image:hover {
  filter: brightness(1.08);
}

/* --- Typography --- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--gold);
  text-align: center;
  letter-spacing: 0.08em;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  font-size: 2.1rem;
  line-height: 1.2;
  margin-bottom: 8px;
  text-shadow: 0 2px 14px rgba(201, 162, 39, 0.35);
}

h2 {
  font-size: 1.45rem;
  margin-bottom: 16px;
  color: var(--gold-light);
}

h3 {
  font-size: 1.15rem;
  margin-bottom: 12px;
}

.subtitle {
  font-size: 0.92rem;
  letter-spacing: 0.18em;
  color: var(--ivory-muted);
  text-align: center;
  margin-bottom: 20px;
  text-transform: uppercase;
  font-family: var(--font-display);
}

p {
  margin-bottom: 16px;
  font-size: 1.06rem;
  color: var(--ivory);
}

.lead-text {
  font-size: 1.18rem;
  font-style: italic;
  text-align: center;
  line-height: 1.7;
  color: #f3efe6;
  margin-bottom: 24px;
}

.divider {
  width: 60px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 18px auto;
}

/* --- Buttons & Inputs --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 24px;
  font-family: var(--font-display);
  font-size: 0.92rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--bg);
  background: linear-gradient(135deg, #dfbc53 0%, var(--gold) 100%);
  border: 1px solid #ffd966;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6), 0 0 12px var(--gold-dim);
  transition: transform 150ms ease, box-shadow 200ms ease, filter 150ms ease;
  width: 100%;
  max-width: 380px;
  margin: 8px auto;
  font-weight: 700;
}

.btn:hover, .btn:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(201, 162, 39, 0.45);
  filter: brightness(1.08);
}

.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: rgba(16, 16, 24, 0.85);
  color: var(--ivory);
  border: 1px solid rgba(201, 162, 39, 0.4);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
}

.btn-secondary:hover, .btn-secondary:focus-visible {
  border-color: var(--gold);
  color: var(--gold-light);
  box-shadow: 0 0 15px var(--gold-dim);
}

.btn-blood {
  background: linear-gradient(135deg, #992938 0%, var(--blood) 100%);
  border-color: #ba3848;
  color: #fff;
}

.btn:disabled, .btn.disabled {
  opacity: 0.35 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
  box-shadow: none !important;
  filter: grayscale(0.8) !important;
  transform: none !important;
}

/* Choice Buttons Stack */
.choices-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin-top: 18px;
}

.choice-btn {
  background: rgba(16, 16, 24, 0.92);
  border: 1px solid rgba(201, 162, 39, 0.3);
  border-radius: 6px;
  padding: 14px 18px;
  color: var(--ivory);
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  transition: all 180ms ease;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.choice-btn:hover, .choice-btn:focus-visible {
  border-color: var(--gold);
  background: rgba(28, 26, 38, 0.95);
  transform: translateX(4px);
  box-shadow: 0 4px 16px rgba(201, 162, 39, 0.18);
}

.choice-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  color: var(--gold-light);
  letter-spacing: 0.05em;
}

.choice-consequence {
  font-size: 0.85rem;
  color: var(--ivory-muted);
  font-style: italic;
}

.order-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-family: var(--font-display);
  padding: 2px 8px;
  border-radius: 3px;
  background: rgba(201, 162, 39, 0.15);
  border: 1px solid rgba(201, 162, 39, 0.4);
  color: var(--gold-light);
  margin-bottom: 4px;
  width: fit-content;
}

/* Input Styles */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  margin-bottom: 20px;
}

.input-label {
  font-family: var(--font-display);
  font-size: 0.88rem;
  letter-spacing: 0.08em;
  color: var(--gold-light);
  text-transform: uppercase;
}

.text-input, .select-input, .textarea-input {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  background: rgba(10, 10, 15, 0.85);
  border: 1px solid rgba(201, 162, 39, 0.4);
  border-radius: 4px;
  color: var(--ivory);
  font-family: var(--font-body);
  font-size: 1.05rem;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}

.text-input:focus, .select-input:focus, .textarea-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 12px var(--gold-dim);
}

.textarea-input {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

/* Option Cards */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  width: 100%;
  margin: 16px 0 24px;
}

@media (min-width: 520px) {
  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.selection-card {
  background: rgba(14, 14, 20, 0.85);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 6px;
  padding: 16px;
  cursor: pointer;
  transition: all 200ms ease;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
}

.selection-card:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  background: rgba(22, 21, 30, 0.95);
}

.selection-card.selected {
  border-color: var(--gold);
  background: rgba(36, 31, 38, 0.95);
  box-shadow: 0 0 16px var(--gold-dim);
}

.selection-card .card-name {
  font-family: var(--font-display);
  font-size: 0.98rem;
  color: var(--gold-light);
  letter-spacing: 0.05em;
}

.selection-card .card-desc {
  font-size: 0.88rem;
  color: var(--ivory-muted);
  line-height: 1.4;
}

/* --- Typewriter Container --- */
.typewriter-text {
  cursor: pointer;
  position: relative;
  user-select: none;
}

.tap-to-skip {
  display: block;
  text-align: center;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
  color: var(--ivory-muted);
  margin-top: 10px;
  font-family: var(--font-display);
  opacity: 0.6;
}

/* --- Minigame 1: Mental Invasion Oscillating Bar --- */
.minigame-container {
  width: 100%;
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.oscillator-track {
  width: 100%;
  max-width: 440px;
  height: 38px;
  background: rgba(10, 10, 15, 0.9);
  border: 2px solid rgba(201, 162, 39, 0.4);
  border-radius: 19px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.8);
  cursor: pointer;
}

.oscillator-sweetspot {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 30px;
  height: 100%;
  background: rgba(201, 162, 39, 0.4);
  border-left: 2px solid var(--gold);
  border-right: 2px solid var(--gold);
  box-shadow: 0 0 16px var(--gold-glow);
}

@media (min-width: 600px) {
  .oscillator-sweetspot {
    width: 20px;
  }
}

.oscillator-needle {
  position: absolute;
  top: 3px;
  left: 50%;
  width: 6px;
  height: 32px;
  background: #ffffff;
  border-radius: 3px;
  box-shadow: 0 0 10px #fff, 0 0 16px var(--blood-glow);
  pointer-events: none;
  transform: translateX(-50%);
}

.minigame-feedback {
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: 0.08em;
  min-height: 28px;
  text-align: center;
}

.feedback-success {
  color: var(--gold-light);
  text-shadow: 0 0 10px var(--gold-glow);
}

.feedback-fail {
  color: #ea5b6c;
  text-shadow: 0 0 10px var(--blood-glow);
}

/* --- Minigame 2: Pure CSS 3D Dice Roll --- */
.dice-scene {
  width: 120px;
  height: 120px;
  perspective: 600px;
  margin: 20px auto;
}

.dice-cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 800ms cubic-bezier(0.2, 0.9, 0.3, 1.1);
  transform: rotateX(-15deg) rotateY(25deg);
}

.dice-face {
  position: absolute;
  width: 120px;
  height: 120px;
  background: radial-gradient(circle, #252028 20%, #121017 100%);
  border: 2px solid var(--gold);
  border-radius: 12px;
  box-shadow: inset 0 0 14px rgba(201, 162, 39, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--gold-light);
  text-shadow: 0 0 8px var(--gold-glow);
  backface-visibility: hidden;
}

.face-1 { transform: rotateY(0deg) translateZ(60px); }
.face-2 { transform: rotateY(180deg) translateZ(60px); }
.face-3 { transform: rotateY(90deg) translateZ(60px); }
.face-4 { transform: rotateY(-90deg) translateZ(60px); }
.face-5 { transform: rotateX(90deg) translateZ(60px); }
.face-6 { transform: rotateX(-90deg) translateZ(60px); }

.dice-cube[data-face="1"] { transform: rotateY(0deg) rotateX(0deg); }
.dice-cube[data-face="2"] { transform: rotateY(-180deg) rotateX(0deg); }
.dice-cube[data-face="3"] { transform: rotateY(-90deg) rotateX(0deg); }
.dice-cube[data-face="4"] { transform: rotateY(90deg) rotateX(0deg); }
.dice-cube[data-face="5"] { transform: rotateX(-90deg) rotateY(0deg); }
.dice-cube[data-face="6"] { transform: rotateX(90deg) rotateY(0deg); }

/* --- Minigame 2B: Kaelen's Enigma Rune Sequence --- */
.enigma-sequence {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 16px 0;
}

.rune-btn {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background: rgba(14, 14, 20, 0.9);
  border: 2px solid rgba(201, 162, 39, 0.4);
  color: var(--gold);
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 180ms ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.rune-btn:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 0 14px var(--gold-dim);
}

.rune-btn.active-glow {
  border-color: #fff;
  background: var(--kaelen);
  color: #fff;
  box-shadow: 0 0 24px var(--kaelen-glow);
  transform: scale(1.1);
}

/* --- Wax Seal Button --- */
.wax-seal-wrapper {
  margin: 24px auto 8px;
  text-align: center;
}

.wax-seal-btn {
  position: relative;
  background: radial-gradient(circle, #9e2333 0%, #681520 70%, #440d14 100%);
  border: 3px solid #b83445;
  border-radius: 50%;
  width: 90px;
  height: 90px;
  color: #f7e9d7;
  font-family: var(--font-display);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7), inset 0 2px 8px rgba(255, 255, 255, 0.3);
  margin: 0 auto;
  transition: transform 150ms ease, box-shadow 200ms ease;
}

.wax-seal-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 10px 28px rgba(122, 31, 43, 0.6), inset 0 2px 10px rgba(255, 255, 255, 0.4);
}

.wax-seal-btn:active {
  transform: scale(0.96);
}

.wax-seal-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  margin-bottom: 2px;
}

/* --- Grimoire Antique Format --- */
.grimoire-book {
  background: #111017;
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 36px 24px;
  position: relative;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.9), inset 0 0 35px rgba(201, 162, 39, 0.08);
  width: 100%;
}

.grimoire-header-ornament {
  text-align: center;
  font-size: 1.4rem;
  color: var(--gold);
  margin-bottom: 12px;
}

.grimoire-entry {
  background: rgba(18, 16, 24, 0.7);
  border-left: 3px solid var(--gold);
  padding: 16px 20px;
  margin: 20px 0;
  border-radius: 0 6px 6px 0;
}

.grimoire-entry-num {
  font-family: var(--font-display);
  font-size: 0.85rem;
  color: var(--gold-light);
  letter-spacing: 0.1em;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.grimoire-entry-content {
  font-size: 1.05rem;
  font-style: italic;
  color: var(--ivory);
  line-height: 1.6;
}

.grimoire-quoted-line {
  display: block;
  margin-top: 8px;
  padding: 8px 14px;
  background: rgba(201, 162, 39, 0.12);
  border-left: 2px solid var(--gold);
  font-size: 0.92rem;
  color: var(--gold-light);
  font-style: normal;
  border-radius: 0 4px 4px 0;
}

/* Stat Radar/Bar Summary */
.stat-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 24px 0;
}

@media (min-width: 520px) {
  .stat-summary-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.stat-pill {
  background: rgba(14, 13, 20, 0.85);
  border: 1px solid rgba(201, 162, 39, 0.3);
  border-radius: 6px;
  padding: 12px;
  text-align: center;
}

.stat-pill-label {
  font-family: var(--font-display);
  font-size: 0.75rem;
  color: var(--ivory-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stat-pill-value {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--gold-light);
  margin-top: 4px;
}

/* Sequel Teaser Rune */
.sequel-box {
  margin-top: 32px;
  text-align: center;
  padding: 24px 16px;
  border-top: 1px solid rgba(201, 162, 39, 0.25);
}

.sequel-rune {
  font-size: 2.2rem;
  color: var(--gold);
  animation: pulseRune 2.5s infinite ease-in-out;
  display: inline-block;
  margin-bottom: 8px;
}

@keyframes pulseRune {
  0%, 100% {
    transform: scale(1);
    filter: drop-shadow(0 0 6px var(--gold-glow));
  }
  50% {
    transform: scale(1.15);
    filter: drop-shadow(0 0 16px var(--gold-light));
  }
}

/* --- Reduced Motion Compliance (§6 & §10) --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #ember-canvas {
    display: none !important;
  }
  .meter-bar {
    transition: none !important;
  }
  .dice-cube {
    transition: none !important;
  }
}

/* --- Print Styling for 1-Click PDF Download --- */
@media print {
  body {
    background: #ffffff !important;
    color: #1a1a1a !important;
    font-size: 13pt;
  }

  #ember-canvas, .top-controls, #hud, .btn, .wax-seal-wrapper, .tap-to-skip, .bg-layer {
    display: none !important;
  }

  .screen {
    display: block !important;
    opacity: 1 !important;
    max-width: 100% !important;
    padding: 0 !important;
  }

  .card-panel, .grimoire-book {
    background: #ffffff !important;
    border: 1px solid #777777 !important;
    box-shadow: none !important;
    color: #1a1a1a !important;
    padding: 20px !important;
  }

  h1, h2, h3, .hud-player-info, .stat-pill-value {
    color: #8c6d17 !important;
    text-shadow: none !important;
  }

  .grimoire-entry {
    background: #f7f7f7 !important;
    border-left: 3px solid #8c6d17 !important;
    color: #1a1a1a !important;
  }

  .grimoire-quoted-line {
    background: #ebebeb !important;
    color: #333333 !important;
  }

  .stat-pill {
    background: #fafafa !important;
    border: 1px solid #ccc !important;
  }

  .character-card, .scene-banner-frame {
    border: 1px solid #999 !important;
    box-shadow: none !important;
  }
}

/* ==========================================================================
   ADDITIONS — new scenes, the sealing system, the modal, and a11y
   ========================================================================== */

/* --- Keyboard focus: previously almost nothing was focus-visible --- */
:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 3px;
  border-radius: 4px;
}
.choice-btn:focus-visible,
.selection-card:focus-visible,
.avatar-card:focus-visible,
.sigil-card:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 2px;
  box-shadow: 0 0 18px var(--gold-dim);
}

/* --- In-game modal (replaces alert / confirm) --- */
.game-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(6, 5, 10, 0.86);
  backdrop-filter: blur(3px);
}
.game-modal.active { display: flex; }

.game-modal-panel {
  width: 100%;
  max-width: 460px;
  background: var(--bg-card-solid);
  border: 1px solid var(--gold-dim);
  border-radius: 8px;
  padding: 26px 24px 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.85), 0 0 24px var(--gold-dim);
  animation: modalRise 260ms cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes modalRise {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.game-modal-panel h3 {
  font-family: var(--font-display);
  color: var(--gold-light);
  font-size: 1.2rem;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}
.game-modal-body {
  color: var(--ivory-muted);
  font-size: 1.02rem;
  line-height: 1.6;
  margin-bottom: 20px;
}
.game-modal-body strong { color: var(--ivory); }
.game-modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.game-modal-actions .btn {
  width: auto;
  min-width: 130px;
  margin: 0;
  flex: 1 1 130px;
}

/* --- Act V: the three trials --- */
.trial-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
  margin-bottom: 22px;
}
.trial-stage {
  border-left: 3px solid rgba(201, 162, 39, 0.3);
  transition: border-color 300ms ease, background 300ms ease, transform 300ms ease;
}
.trial-verdict {
  font-size: 0.95rem;
  color: var(--ivory-muted);
  line-height: 1.55;
  margin-top: 4px;
}
.trial-stage.trial-active {
  border-left-color: var(--gold-light);
  transform: translateX(4px);
  animation: trialPulse 900ms ease-in-out infinite;
}
@keyframes trialPulse {
  0%, 100% { box-shadow: 0 0 0 rgba(201, 162, 39, 0); }
  50% { box-shadow: 0 0 20px var(--gold-dim); }
}
.trial-stage.trial-pass {
  border-left-color: #6fae7c;
  background: rgba(58, 110, 70, 0.14);
}
.trial-stage.trial-pass .stat-pill-label { color: #9fd3a8; }
.trial-stage.trial-fail {
  border-left-color: var(--blood);
  background: rgba(122, 31, 43, 0.14);
}
.trial-stage.trial-fail .stat-pill-label { color: #d98d99; }

/* --- The wax sigil picker (replaces keyword sniffing) --- */
.sigil-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 12px 0 20px;
}
.sigil-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 14px 8px;
  background: rgba(14, 14, 20, 0.85);
  border: 1px solid rgba(201, 162, 39, 0.25);
  border-radius: 6px;
  cursor: pointer;
  color: var(--ivory-muted);
  font-family: var(--font-body);
  transition: all 200ms ease;
}
.sigil-card:hover { border-color: var(--gold); transform: translateY(-2px); }
.sigil-card.selected {
  border-color: var(--gold-light);
  background: rgba(201, 162, 39, 0.12);
  box-shadow: 0 0 18px var(--gold-dim);
}
.sigil-mark { font-size: 1.7rem; line-height: 1; }
.sigil-maris { color: #8fc4dd; }
.sigil-zephyr { color: #b6b0c9; }
.sigil-lyra { color: var(--lyra); }
.sigil-name {
  font-size: 0.78rem;
  line-height: 1.25;
  text-align: center;
  color: var(--ivory-muted);
}
.sigil-who {
  font-family: var(--font-display);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}
@media (max-width: 419px) {
  .sigil-grid { grid-template-columns: 1fr; }
  .sigil-card { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 14px; }
  .sigil-name { text-align: left; flex: 1; }
}

/* --- Sealed lines --- */
.seal-field { margin-top: 18px; }
.seal-input {
  border-color: rgba(201, 162, 39, 0.55);
  background: rgba(24, 18, 12, 0.75);
  font-style: italic;
}
.seal-word {
  max-width: 220px;
  text-align: center;
  font-style: normal;
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  text-transform: lowercase;
}
.seal-hint {
  display: block;
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--ivory-muted);
  opacity: 0.8;
  line-height: 1.45;
}
.field-optional {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ivory-muted);
  opacity: 0.75;
  font-size: 0.82rem;
}

/* "Write it short" — the escape hatch that keeps people from abandoning */
.btn-ghost {
  display: block;
  margin: 4px auto 0;
  padding: 8px 16px;
  min-height: 40px;
  background: none;
  border: 1px dashed rgba(201, 162, 39, 0.4);
  border-radius: 4px;
  color: var(--ivory-muted);
  font-family: var(--font-display);
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 180ms ease;
}
.btn-ghost:hover { border-color: var(--gold); color: var(--gold-light); }
.card-panel.short-mode .textarea-input,
.card-panel.short-mode .sigil-grid + .input-label { display: none; }
.card-panel.short-mode .textarea-input + .seal-field { margin-top: 8px; }

/* --- Warding Hour / Cut-In payoff prose --- */
.warding-payoff {
  margin-top: 20px;
  padding: 18px 20px;
  border-left: 3px solid var(--gold);
  background: rgba(201, 162, 39, 0.07);
  border-radius: 0 6px 6px 0;
  line-height: 1.7;
  animation: modalRise 400ms ease;
}
.warding-payoff p + p { margin-top: 12px; }

/* --- The Cut-In: two heirs, one scene --- */
.collision-pair {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 20px;
}
@media (min-width: 560px) {
  .collision-pair { grid-template-columns: 1fr 1fr; }
}
.collision-half { margin: 0; }

/* --- The per-Act Order beat --- */
.order-beat {
  margin: 14px 0 18px;
  padding: 12px 16px;
  border-left: 2px solid var(--gold-dim);
  background: rgba(201, 162, 39, 0.05);
  border-radius: 0 4px 4px 0;
  font-style: italic;
  color: var(--ivory-muted);
  font-size: 0.98rem;
  line-height: 1.6;
}
.order-beat-badge {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 8px;
  background: var(--gold-dim);
  border: 1px solid var(--gold);
  border-radius: 3px;
  font-family: var(--font-display);
  font-style: normal;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-light);
}

/* --- Julian's reason (Act I) --- */
.julian-reveal {
  margin-top: 22px;
  padding: 18px 20px;
  border: 1px solid rgba(92, 31, 46, 0.7);
  border-left: 3px solid var(--julian);
  border-radius: 6px;
  background: rgba(30, 14, 20, 0.6);
  text-align: left;
  line-height: 1.7;
  animation: modalRise 500ms ease;
}
.julian-reveal p + p { margin-top: 12px; }
.julian-reveal-note {
  font-size: 0.86rem;
  color: var(--gold-light);
  font-style: italic;
  opacity: 0.9;
}

/* --- Avatar: zoom without hijacking selection --- */
.avatar-card-frame { position: relative; }
.avatar-zoom-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(10, 10, 15, 0.78);
  border: 1px solid var(--gold-dim);
  border-radius: 50%;
  color: var(--gold-light);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: all 180ms ease;
}
.avatar-zoom-btn:hover { background: rgba(201, 162, 39, 0.25); border-color: var(--gold); }

/* --- Gala scarcity counter --- */
.gala-counter {
  margin: 4px 0 16px;
  font-family: var(--font-display);
  font-size: 0.86rem;
  letter-spacing: 0.06em;
  color: var(--gold-light);
  text-align: center;
}

/* --- Grimoire: sealed lines, the word, the chronicle --- */
.grimoire-seal-line {
  margin-top: 12px;
  padding: 10px 14px;
  border-left: 2px solid var(--gold);
  background: rgba(201, 162, 39, 0.08);
  border-radius: 0 4px 4px 0;
  font-style: italic;
  color: var(--gold-light);
  line-height: 1.6;
}
.grimoire-entry-blank {
  font-style: italic;
  opacity: 0.62;
}
.grimoire-sealword-wrap { text-align: center; margin: 18px 0 24px; }
.grimoire-sealword-label {
  display: block;
  font-family: var(--font-display);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ivory-muted);
  margin-bottom: 8px;
}
.grimoire-sealword {
  display: inline-block;
  padding: 10px 28px;
  border: 1px solid var(--gold);
  border-radius: 4px;
  background: rgba(201, 162, 39, 0.09);
  font-family: var(--font-display);
  font-size: 1.5rem;
  letter-spacing: 0.22em;
  color: var(--gold-light);
  text-transform: lowercase;
}
.grimoire-chronicle-list {
  margin: 6px 0 0 18px;
  padding: 0;
  line-height: 1.75;
}
.grimoire-chronicle-list li {
  color: var(--ivory-muted);
  font-size: 0.96rem;
  margin-bottom: 4px;
}

/* --- Grimoire export: the personal PDF is the hero --- */
.grimoire-export {
  text-align: center;
  margin-top: 30px;
  padding-top: 24px;
  border-top: 1px solid var(--gold-dim);
}
.btn-export {
  font-size: 1rem;
  min-height: 56px;
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.7), 0 0 26px var(--gold-glow);
}
.export-note {
  max-width: 420px;
  margin: 10px auto 18px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--ivory-muted);
}
.grimoire-export-secondary {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.grimoire-export-secondary .btn {
  width: auto;
  flex: 1 1 190px;
  max-width: 260px;
  font-size: 0.78rem;
  margin: 0;
}

/* --- Print: keep the new blocks legible on paper --- */
@media print {
  .game-modal,
  .btn-ghost,
  .avatar-zoom-btn,
  .grimoire-export,
  .order-beat { display: none !important; }

  .grimoire-seal-line,
  .grimoire-sealword {
    background: #f2eee4 !important;
    color: #6d540f !important;
    border-color: #8c6d17 !important;
  }
  .grimoire-chronicle-list li { color: #333 !important; }
}
