:root {
  --bg: #0d0a0f;
  --bg2: #16101c;
  --panel: #1c1424;
  --ink: #e8dfd0;
  --muted: #9a8f9e;
  --gold: #c9a227;
  --gold-dim: #8a7020;
  --blood: #8b2e3a;
  --bone: #d4c4a8;
  --flesh: #b85a5a;
  --spirit: #7eb8c9;
  --ok: #6a9b6a;
  --fail: #a65d5d;
  --border: #3a2d45;
  --shadow: 0 12px 40px rgba(0,0,0,.55);
  --serif: "Crimson Pro", Georgia, "Times New Roman", serif;
  --display: "Cinzel", "Palatino Linotype", serif;
  --sans: "Source Sans 3", system-ui, sans-serif;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#app { min-height: 100%; }
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* —— Title —— */
#screen-title {
  position: relative;
  display: none;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#screen-title.active { display: flex; }

.title-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, #3a1a2a 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, #1a2035 0%, transparent 45%),
    linear-gradient(160deg, #1a0f18, #0d0a0f 60%, #121820);
  background-size: cover;
  background-position: center;
}
.title-bg.has-img {
  background-image: linear-gradient(180deg, rgba(8,6,10,.35), rgba(8,6,10,.75)), var(--art-url);
}
.title-veil {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 20%, rgba(8,6,10,.85) 75%);
  pointer-events: none;
}
.title-content {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 2rem 1.25rem 3rem;
  max-width: 40rem;
}
.eyebrow {
  font-family: var(--sans);
  font-size: .78rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0 0 .75rem;
}
.title-content h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.85rem, 5.5vw, 3rem);
  letter-spacing: .04em;
  margin: 0 0 .4rem;
  text-shadow: 0 2px 24px rgba(0,0,0,.7);
}
.subtitle {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--bone);
  margin: 0 0 1rem;
}
.title-blurb {
  color: var(--muted);
  margin: 0 0 1.75rem;
  font-size: .98rem;
}
.title-actions { display: flex; flex-direction: column; gap: .65rem; align-items: center; }
.title-note { margin-top: 1.4rem; color: var(--muted); font-size: .82rem; }

/* —— Buttons —— */
.btn {
  font-family: var(--sans);
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink);
  padding: .7rem 1.25rem;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  min-width: 12rem;
}
.btn:hover:not(:disabled) { border-color: var(--gold-dim); background: #241a2e; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #5a2430, #3d1820);
  border-color: #8b3a48;
  color: #f2e6d8;
  min-width: 14rem;
}
.btn.primary:hover:not(:disabled) { border-color: var(--gold); }
.btn.ghost { background: transparent; min-width: 10rem; }
.btn.tiny {
  min-width: 0;
  padding: .35rem .65rem;
  font-size: .8rem;
  font-weight: 600;
}
.btn.choice {
  display: block;
  width: 100%;
  text-align: left;
  min-width: 0;
  padding: .85rem 1rem;
  margin: 0;
  background: #1a1322;
  border-color: #463554;
  font-weight: 500;
  line-height: 1.35;
}
.btn.choice:hover:not(:disabled) {
  border-color: var(--gold);
  background: #241a2e;
}
.btn.choice .hint {
  display: block;
  font-size: .78rem;
  color: var(--muted);
  margin-top: .25rem;
  font-weight: 400;
}
.btn.choice.danger { border-color: #6a3040; }
.btn.choice.skill { border-left: 3px solid var(--gold-dim); }

/* —— Create —— */
#screen-create.active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem 3rem;
  background:
    radial-gradient(ellipse at top, #2a1520 0%, transparent 55%),
    var(--bg);
}
.create-panel { width: min(720px, 100%); }
.create-panel h2 {
  font-family: var(--display);
  font-size: 1.6rem;
  margin: 0 0 1.25rem;
  color: var(--bone);
}
.field { display: block; margin-bottom: 1.25rem; }
.field span, .field-label {
  display: block;
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: .4rem;
  letter-spacing: .03em;
}
.field input {
  width: 100%;
  padding: .75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--ink);
  font-size: 1.05rem;
  font-family: var(--serif);
}
.field input:focus { outline: none; border-color: var(--gold-dim); }
.fasc-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .85rem;
  margin: 0 0 1.5rem;
}
@media (min-width: 700px) {
  .fasc-grid { grid-template-columns: repeat(3, 1fr); }
}
.fasc-card {
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.fasc-card:hover { border-color: var(--gold-dim); }
.fasc-card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), var(--shadow);
}
.fasc-art {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2a2030, #1a1520);
  background-size: cover;
  background-position: center;
  position: relative;
}
.fasc-art[data-art="thrall-bone"] { background: linear-gradient(135deg, #3a3428, #1c1810); }
.fasc-art[data-art="thrall-flesh"] { background: linear-gradient(135deg, #3a2020, #1c1010); }
.fasc-art[data-art="thrall-spirit"] { background: linear-gradient(135deg, #203038, #101820); }
.fasc-art.has-img .motif { display: none; }
.fasc-art .motif { font-size: 2.4rem; opacity: .85; }
.fasc-card h3 {
  font-family: var(--display);
  margin: .75rem 1rem .35rem;
  font-size: 1.1rem;
}
.fasc-card p {
  margin: 0 1rem 1rem;
  font-size: .88rem;
  color: var(--muted);
  font-family: var(--serif);
}
.fasc-card[data-fasc="bone"].selected { border-color: var(--bone); }
.fasc-card[data-fasc="flesh"].selected { border-color: var(--flesh); }
.fasc-card[data-fasc="spirit"].selected { border-color: var(--spirit); }
#btn-start { margin-bottom: .6rem; width: 100%; max-width: 20rem; }
#btn-create-back { width: 100%; max-width: 20rem; }

/* —— HUD / Play —— */
#screen-play.active { display: flex; flex-direction: column; min-height: 100vh; }
.hud {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; gap: .5rem .75rem;
  align-items: center; justify-content: space-between;
  padding: .55rem .85rem;
  background: rgba(13,10,15,.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.hud-left { display: flex; flex-wrap: wrap; gap: .4rem .6rem; align-items: baseline; }
.hud-name { font-family: var(--display); font-weight: 600; font-size: .95rem; }
.hud-tag {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: .15rem .45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
.hud-tag.bone { color: var(--bone); border-color: #6a5a40; }
.hud-tag.flesh { color: var(--flesh); border-color: #6a4040; }
.hud-tag.spirit { color: var(--spirit); border-color: #406070; }
.hud-chapter { font-size: .8rem; color: var(--muted); }
.hud-stats {
  display: flex; flex-wrap: wrap; gap: .35rem .55rem;
  font-size: .78rem; color: var(--muted);
}
.hud-stats .stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: .2rem .45rem;
  white-space: nowrap;
}
.hud-stats .stat strong { color: var(--ink); font-weight: 600; }
.hud-stats .stat.vit strong { color: #e8a0a8; }
.hud-actions { display: flex; gap: .35rem; }

.stage {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 0 0 4rem;
}
.scene-art {
  margin: 0;
  position: relative;
  height: clamp(160px, 32vw, 280px);
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  background: #141018;
}
.art-placeholder, .scene-art img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.art-placeholder {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, #2a1a28, #121820 55%, #1a1525);
}
.art-placeholder .motif { font-size: 3rem; opacity: .55; filter: grayscale(.2); }
.scene-art.has-img .art-placeholder { opacity: 0; }
.scene-art figcaption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: .45rem .9rem;
  font-size: .78rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--bone);
  background: linear-gradient(transparent, rgba(0,0,0,.75));
}

.prose {
  font-family: var(--serif);
  font-size: clamp(1.05rem, 2.6vw, 1.18rem);
  line-height: 1.65;
  padding: 1.25rem 1.1rem .5rem;
  color: #ebe3d4;
}
.prose p { margin: 0 0 1rem; }
.prose p:last-child { margin-bottom: 0; }
.prose .lead { color: var(--gold); font-family: var(--display); font-size: .95rem; letter-spacing: .04em; }

.roll-banner {
  margin: .75rem 1.1rem;
  padding: .75rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1a1522;
  font-size: .92rem;
  font-family: var(--sans);
}
.roll-banner.success { border-color: #3d6a3d; background: #152018; }
.roll-banner.crit { border-color: var(--gold); background: #221c10; }
.roll-banner.fail { border-color: #6a3d3d; background: #201515; }
.roll-banner .dice { font-weight: 700; color: var(--gold); }

.choices {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  padding: 1rem 1.1rem 0;
}

/* —— Combat —— */
.combat-panel {
  margin: .5rem 1.1rem 0;
  padding: 1rem;
  border: 1px solid #4a3040;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #1e1218, #16101a);
}
.combat-panel h4 {
  margin: 0 0 .65rem;
  font-family: var(--display);
  font-size: .95rem;
  color: var(--bone);
  letter-spacing: .04em;
}
.combat-status {
  display: grid;
  gap: .5rem;
  margin-bottom: .85rem;
  font-size: .88rem;
}
.combat-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: .5rem; flex-wrap: wrap;
  padding: .4rem .55rem;
  background: rgba(0,0,0,.25);
  border-radius: 6px;
}
.bar {
  flex: 1; min-width: 80px; height: 8px;
  background: #2a2030; border-radius: 99px; overflow: hidden;
}
.bar > i { display: block; height: 100%; background: var(--blood); width: 100%; }
.bar.enemy > i { background: #7a4050; }
.bar.ally > i { background: #5a8a6a; }
.combat-log {
  font-family: var(--serif);
  font-size: .95rem;
  color: var(--muted);
  max-height: 140px;
  overflow-y: auto;
  margin-bottom: .75rem;
  padding-right: .25rem;
}
.combat-log p { margin: 0 0 .4rem; }
.combat-actions {
  display: flex; flex-direction: column; gap: .45rem;
}

/* —— Modal —— */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.65);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 1rem;
}
@media (min-width: 640px) {
  .modal { align-items: center; }
}
.modal[hidden] { display: none !important; }
.modal-card {
  width: min(520px, 100%);
  max-height: min(80vh, 640px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.modal-card header {
  display: flex; justify-content: space-between; align-items: center;
  padding: .85rem 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel);
}
.modal-card h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.05rem;
}
.modal-body { padding: 1rem; font-size: .95rem; }
.modal-body .entry { margin-bottom: 1rem; padding-bottom: .85rem; border-bottom: 1px solid var(--border); }
.modal-body .entry:last-child { border: 0; margin: 0; padding: 0; }
.modal-body h4 { margin: 0 0 .35rem; font-family: var(--display); font-size: .95rem; color: var(--bone); }
.modal-body p { margin: 0; color: var(--muted); font-family: var(--serif); }
.thrall-card {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: .75rem;
  margin-bottom: .85rem;
  padding: .65rem;
  background: var(--bg2);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.thrall-card .thumb {
  width: 64px; height: 64px; border-radius: 6px;
  background-size: cover; background-position: center;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
}
.thrall-card .meta strong { display: block; font-family: var(--display); }
.thrall-card .meta span { font-size: .82rem; color: var(--muted); }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  z-index: 60;
  background: #2a2030;
  border: 1px solid var(--gold-dim);
  color: var(--ink);
  padding: .65rem 1.1rem;
  border-radius: 999px;
  font-size: .88rem;
  box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast[hidden] { display: none !important; }

/* Art gradients by scene key */
.art-placeholder.mausoleum { background: linear-gradient(145deg, #2a2430, #121018 50%, #1a1520); }
.art-placeholder.fen { background: linear-gradient(145deg, #1a2a22, #0e1814 50%, #152018); }
.art-placeholder.chapel { background: linear-gradient(145deg, #2a2220, #181210 50%, #201818); }
.art-placeholder.choir { background: linear-gradient(145deg, #1a1828, #100e18 50%, #181428); }
.art-placeholder.boss { background: linear-gradient(145deg, #2a1018, #120810 40%, #1a1020); }
.art-placeholder.thrall { background: linear-gradient(145deg, #242018, #141210); }
