:root {
  --bg: #120d0a;
  --bg2: #1c1510;
  --panel: #241a13;
  --line: #3a2a1d;
  --ink: #f3e6d2;
  --muted: #b39d82;
  --dim: #7d6a55;
  --torch: #f2a33a;
  --torch2: #ffcf7a;
  --ember: #d4572a;
  --good: #7fbf6a;
  --bad: #e0664d;
  --magic: #a98bea;
  --radius: 14px;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: radial-gradient(1200px 700px at 50% -10%, #2b1c10 0%, var(--bg) 60%) fixed, var(--bg); color: var(--ink); font-family: var(--sans); font-size: 17px; line-height: 1.5; }
body { min-height: 100vh; min-height: 100dvh; }
a { color: var(--torch2); }
h1, h2, h3, .serif { font-family: var(--serif); font-weight: 600; letter-spacing: 0.01em; }
h1 { font-size: clamp(2.6rem, 8vw, 4.6rem); margin: 0; line-height: 1; color: var(--torch2); text-shadow: 0 0 30px rgba(242, 163, 58, 0.35); }
h2 { font-size: 1.6rem; margin: 0 0 0.4rem; }
h3 { font-size: 1.25rem; margin: 0; }
button, .btn { font: inherit; font-weight: 600; border: 0; border-radius: 999px; padding: 0.8rem 1.4rem; background: var(--torch); color: #2a1606; cursor: pointer; transition: transform 0.08s, filter 0.15s; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; }
button:hover, .btn:hover { filter: brightness(1.08); }
button:active, .btn:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost, .btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
button.big { font-size: 1.2rem; padding: 1rem 2rem; }
input, textarea { font: inherit; color: var(--ink); background: var(--bg2); border: 1.5px solid var(--line); border-radius: 12px; padding: 0.75rem 0.9rem; width: 100%; }
input:focus, textarea:focus { outline: none; border-color: var(--torch); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }
.narrow { max-width: 560px; }
.panel { background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent), var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); font-size: 0.9rem; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 14px; }
.center { text-align: center; }
.hidden { display: none !important; }
.flame { display: inline-block; width: 0.7em; height: 1em; background: radial-gradient(ellipse at 50% 75%, var(--torch2), var(--torch) 45%, var(--ember) 70%, transparent 72%); border-radius: 50% 50% 45% 45%; animation: flicker 1.6s infinite alternate; vertical-align: -0.1em; }
@keyframes flicker { 0% { transform: scale(1, 1) rotate(-2deg); opacity: 0.9; } 50% { transform: scale(0.94, 1.05) rotate(2deg); opacity: 1; } 100% { transform: scale(1.03, 0.96) rotate(-1deg); opacity: 0.85; } }
.code { font-family: var(--serif); font-size: clamp(3rem, 10vw, 6rem); letter-spacing: 0.25em; color: var(--torch2); line-height: 1; }
.pill { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); font-size: 0.85rem; color: var(--muted); }
.error-toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #3b1710; color: #ffd9cf; border: 1px solid var(--ember); border-radius: 12px; padding: 0.7rem 1rem; z-index: 50; max-width: calc(100% - 32px); }

/* Heroes */
.heroes { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.hero { position: relative; border: 1.5px solid var(--line); border-radius: var(--radius); padding: 14px; background: var(--bg2); text-align: left; color: var(--ink); font-weight: 400; display: block; width: 100%; border-radius: var(--radius); }
.hero.pickable { cursor: pointer; }
.hero.mine { border-color: var(--torch); box-shadow: 0 0 0 3px rgba(242, 163, 58, 0.18); }
.hero.taken { opacity: 0.5; }
.hero .calling { color: var(--torch); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }
.hero .look { color: var(--muted); font-size: 0.92rem; margin: 6px 0; }
.hero ul { margin: 6px 0 0; padding-left: 1.1rem; font-size: 0.9rem; }
.hero .who { position: absolute; top: 12px; right: 12px; }
.hp { height: 8px; background: #3a231b; border-radius: 99px; overflow: hidden; margin-top: 8px; }
.hp > i { display: block; height: 100%; background: linear-gradient(90deg, var(--ember), var(--good)); border-radius: 99px; transition: width 0.4s; }
.hero.fallen { filter: grayscale(1); opacity: 0.55; }
.hero.spot { border-color: var(--torch2); box-shadow: 0 0 22px rgba(255, 207, 122, 0.25); }

/* Story */
.story { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; scroll-behavior: smooth; }
.line { padding: 2px 0; animation: rise 0.35s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.line .who { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--dim); display: block; }
.line.gm { font-family: var(--serif); font-size: 1.28rem; line-height: 1.45; }
.line.gm.npc .who { color: var(--magic); }
.line.player { color: var(--torch2); padding-left: 12px; border-left: 2px solid var(--torch); }
.line.roll { color: var(--muted); font-size: 0.95rem; }
.line.system { color: var(--dim); font-size: 0.9rem; font-style: italic; }
.line.speaking { text-shadow: 0 0 18px rgba(255, 207, 122, 0.35); }

/* Dice */
.dice { display: flex; gap: 10px; align-items: center; }
.die { width: 54px; height: 54px; border-radius: 12px; background: #f6ead5; color: #2a1606; display: grid; place-items: center; font-family: var(--serif); font-size: 2rem; font-weight: 700; box-shadow: inset 0 -4px 0 rgba(0,0,0,0.15), 0 6px 16px rgba(0,0,0,0.35); }
.die.rolling { animation: tumble 0.7s cubic-bezier(.2,.8,.3,1); }
@keyframes tumble { 0% { transform: translateY(-30px) rotate(-200deg) scale(0.6); opacity: 0; } 70% { transform: translateY(4px) rotate(10deg) scale(1.05); opacity: 1; } 100% { transform: none; } }
.verdict { font-weight: 700; }
.verdict.ok { color: var(--good); }
.verdict.no { color: var(--bad); }
.twist { color: var(--torch2); font-weight: 700; }

/* Map */
.map svg { width: 100%; height: auto; display: block; }
.map .room rect { fill: var(--bg2); stroke: var(--line); stroke-width: 1.5; }
.map .room.here rect { fill: #3a2612; stroke: var(--torch); stroke-width: 2.5; }
.map .room text { fill: var(--ink); font-size: 11px; font-family: var(--sans); }
.map .link { stroke: var(--dim); stroke-width: 2; }
.map .stub { stroke: var(--dim); stroke-width: 1.5; stroke-dasharray: 3 4; }

/* Banner */
.banner { border-radius: var(--radius); padding: 14px 16px; background: #3a2612; border: 1.5px solid var(--torch); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.banner .t { font-variant-numeric: tabular-nums; color: var(--torch2); font-weight: 700; }
.thinking { color: var(--muted); font-style: italic; }
.thinking::after { content: "…"; animation: dots 1.2s infinite steps(4); display: inline-block; width: 1em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1em; } }

/* Recap */
.recap { max-width: 680px; margin: 0 auto; text-align: center; background: radial-gradient(500px 220px at 50% 0%, rgba(242, 163, 58, 0.2), transparent), var(--panel); }
.recap .outcome { font-family: var(--serif); font-size: 2.6rem; color: var(--torch2); margin: 4px 0; }
.recap ul { text-align: left; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 14px 0; }
.stat { background: var(--bg2); border-radius: 12px; padding: 10px; }
.stat b { display: block; font-size: 1.4rem; color: var(--torch2); font-family: var(--serif); }

/* Table screen layout */
.tablegrid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.tablegrid .story { height: min(68vh, 760px); padding-right: 6px; }
@media (max-width: 860px) { .tablegrid { grid-template-columns: 1fr; } .tablegrid .story { height: 52vh; } }

/* Phone */
.phone .story { max-height: 42vh; }
.composer { position: sticky; bottom: 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.composer textarea { min-height: 52px; max-height: 140px; resize: none; }
.talk { width: 100%; padding: 1rem; font-size: 1.1rem; user-select: none; -webkit-user-select: none; touch-action: none; }
.talk.on { background: var(--ember); color: #fff; }
.secret { font-size: 0.92rem; }
.secret summary { cursor: pointer; color: var(--torch); }
