@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@500;700;900&family=Crimson+Pro:ital,wght@0,400;0,600;1,400&display=swap');

:root {
  --bg: #0d0b12;
  --panel: #17131f;
  --panel2: #1f1a2b;
  --ink: #e8ddc8;
  --ink-dim: #a99e8a;
  --gold: #c9a227;
  --gold-bright: #f0c94a;
  --blood: #8e2f2f;
  --teal: #2f7f8e;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0,0,0,.55);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: 'Crimson Pro', Georgia, serif; font-size: 17px;
  overflow-x: hidden;
}
h1, h2, h3, .cinzel { font-family: 'Cinzel', serif; letter-spacing: .06em; }
button {
  font-family: 'Cinzel', serif; letter-spacing: .08em; cursor: pointer;
  background: linear-gradient(180deg, #2a2338, #1c1728);
  color: var(--gold-bright); border: 1px solid #3d3352;
  border-radius: 10px; padding: 10px 20px; font-size: 15px;
  transition: all .2s;
}
button:hover { border-color: var(--gold); box-shadow: 0 0 18px rgba(201,162,39,.25); transform: translateY(-1px); }
button.primary { background: linear-gradient(180deg, #6d5516, #4a3a0e); color: #fff2cc; border-color: var(--gold); }
button:disabled { opacity: .4; cursor: default; transform: none; }
input, select, textarea {
  background: #241e33; color: var(--ink); border: 1px solid #3d3352;
  border-radius: 8px; padding: 10px 12px; font-family: inherit; font-size: 16px;
}
input:focus, textarea:focus { outline: none; border-color: var(--gold); }

.backdrop {
  position: fixed; inset: 0; z-index: -2;
  background-size: cover; background-position: center;
  filter: brightness(.45) saturate(1.1);
  transition: background-image 1.2s, opacity 1.2s;
}
.backdrop::after { content:''; position:absolute; inset:0; background: radial-gradient(ellipse at center, transparent 30%, rgba(8,6,12,.92) 100%); }
.vignette { position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(8,6,12,.85) 100%); }

.card {
  background: linear-gradient(160deg, var(--panel2), var(--panel));
  border: 1px solid #322a44; border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.gold-line { height: 2px; background: linear-gradient(90deg, transparent, var(--gold), transparent); border: 0; margin: 12px 0; }

/* ---------- Onboarding ---------- */
.onboard { max-width: 780px; margin: 0 auto; padding: 40px 20px 80px; }
.onboard .title { text-align: center; margin-bottom: 6px; font-size: 42px; color: var(--gold-bright);
  text-shadow: 0 0 30px rgba(201,162,39,.4); }
.onboard .subtitle { text-align: center; color: var(--ink-dim); font-style: italic; margin-bottom: 34px; font-size: 19px; }
.step { display: none; animation: fadein .5s; }
.step.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(14px);} to { opacity: 1; transform: none; } }
.field { margin-bottom: 18px; }
.field label { display: block; font-family: 'Cinzel'; font-size: 13px; color: var(--gold); margin-bottom: 7px; letter-spacing: .12em; text-transform: uppercase; }
.choice-row { display: flex; gap: 10px; flex-wrap: wrap; }
.choice {
  flex: 1; min-width: 120px; text-align: center; padding: 14px 10px; border-radius: 10px;
  border: 1px solid #3d3352; background: #241e33; cursor: pointer; transition: all .2s;
}
.choice:hover { border-color: var(--gold); }
.choice.sel { border-color: var(--gold-bright); background: #33285015; box-shadow: inset 0 0 24px rgba(201,162,39,.15), 0 0 14px rgba(201,162,39,.2); }
.choice .big { font-family: 'Cinzel'; font-size: 21px; color: var(--gold-bright); }
.choice .small { font-size: 13px; color: var(--ink-dim); }
.nav-row { display: flex; justify-content: space-between; margin-top: 26px; }

/* --- lore modal --- */
.lore-overlay { position: fixed; inset: 0; z-index: 90; background: rgba(5,4,9,.8); backdrop-filter: blur(5px);
  display: none; align-items: center; justify-content: center; padding: 18px; }
.lore-overlay.open { display: flex; }
.lore-box { max-width: 520px; width: 100%; max-height: 80vh; overflow-y: auto;
  background: linear-gradient(160deg, var(--panel2), var(--panel)); border: 1px solid var(--gold);
  border-radius: 14px; padding: 20px 22px; box-shadow: 0 0 50px rgba(201,162,39,.25), var(--shadow); animation: fadein .25s; }
.lore-box .lore-title { color: var(--gold-bright); font-size: 22px; }
.lore-box .lore-body { line-height: 1.65; font-size: 16.5px; margin: 10px 0 14px; white-space: pre-wrap; }
.lore-box .lore-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
[data-lore] { cursor: pointer; }
.cc-info { float: right; color: var(--teal); font-size: 15px; padding: 0 2px; }
.cc-info:hover { color: var(--gold-bright); }

/* --- adventure select screen --- */
.adv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; margin-top: 10px; }
.adv-card { background: linear-gradient(160deg, var(--panel2), var(--panel)); border: 1px solid #322a44; border-radius: 14px;
  overflow: hidden; cursor: pointer; transition: all .25s; box-shadow: var(--shadow); position: relative; }
.adv-card:hover { transform: translateY(-4px); border-color: var(--gold); box-shadow: 0 0 30px rgba(201,162,39,.25); }
.adv-card .cover { height: 130px; background-size: cover; background-position: center; background-color: #241e33;
  display: flex; align-items: center; justify-content: center; font-size: 40px; }
.adv-card .body { padding: 12px 14px 14px; }
.adv-card .t { font-family: 'Cinzel'; color: var(--gold-bright); font-size: 17px; }
.adv-card .meta { color: var(--ink-dim); font-size: 13.5px; margin-top: 4px; line-height: 1.45; }
.adv-card .badge { position: absolute; top: 10px; right: 10px; font-family: 'Cinzel'; font-size: 11px; letter-spacing: .1em;
  padding: 3px 10px; border-radius: 12px; background: #17131fdd; border: 1px solid #3d3352; color: var(--ink-dim); }
.adv-card .badge.live { color: #7cf59a; border-color: #2f8e4b; }
.adv-plus { display: flex; align-items: center; justify-content: center; flex-direction: column; min-height: 216px;
  border: 2px dashed #3d3352; border-radius: 14px; cursor: pointer; color: var(--gold); transition: all .25s; }
.adv-plus:hover { border-color: var(--gold); box-shadow: 0 0 24px rgba(201,162,39,.2); }
.adv-plus .plus { font-size: 56px; line-height: 1; }
.adv-plus .lab { font-family: 'Cinzel'; margin-top: 8px; letter-spacing: .1em; }

/* --- character creation wizard --- */
.cc-progress { display: flex; gap: 7px; justify-content: center; margin: 10px 0 2px; }
.cc-dot { width: 11px; height: 11px; border-radius: 50%; background: #322a44; border: 1px solid #3d3352; transition: all .3s; }
.cc-dot.done { background: var(--gold); }
.cc-dot.cur { background: var(--gold-bright); box-shadow: 0 0 10px rgba(240,201,74,.6); transform: scale(1.25); }
.cc-note { color: var(--ink-dim); font-style: italic; margin-bottom: 12px; font-size: 15px; }
.cc-chip { min-width: 150px; max-width: 240px; text-align: left; padding: 10px 12px; }
.cc-tip { font-size: 12px; color: var(--ink-dim); margin-top: 4px; line-height: 1.35; }
.cc-abgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 22px; }
.cc-abrow { display: flex; align-items: center; gap: 10px; }
.cc-ablab { font-family: 'Cinzel'; color: var(--teal); width: 42px; }
.cc-abbtn { width: 34px; height: 34px; padding: 0; font-size: 18px; border-radius: 8px; }
.cc-abval { font-family: 'Cinzel'; font-size: 20px; width: 30px; text-align: center; color: var(--ink); }
.cc-abmod { color: var(--gold-bright); width: 30px; }
.cc-preview { line-height: 1.7; }
.cc-errors { margin-top: 12px; background: #3a1c1c; border: 1px solid var(--blood); border-radius: 10px; padding: 10px 14px; color: #f0a0a0; }
@media (max-width: 700px) { .cc-abgrid { grid-template-columns: 1fr; } }

.char-wizard .portrait-frame { width: 240px; height: 300px; margin: 0 auto 14px; border-radius: 12px;
  border: 2px solid var(--gold); overflow: hidden; box-shadow: 0 0 40px rgba(201,162,39,.3); background:#241e33;
  display:flex; align-items:center; justify-content:center; color: var(--ink-dim); font-style: italic; }
.char-wizard .portrait-frame img { width: 100%; height: 100%; object-fit: cover; }
.qr-row { display:flex; gap:16px; align-items:center; background:#241e33; border-radius:10px; padding:12px; margin-top:10px; }
.qr-row img { width: 92px; height: 92px; border-radius: 6px; background:#fff; padding:4px; }

/* ---------- Table layout ---------- */
.table-layout { display: none; grid-template-columns: 300px 1fr 320px; gap: 16px; padding: 16px; height: 100vh; }
.table-layout.active { display: grid; }
.col { display: flex; flex-direction: column; gap: 14px; min-height: 0; }

.party-panel { overflow-y: auto; flex: 1; }
.pc-card { display: flex; gap: 12px; padding: 10px; border-radius: 10px; background: #241e3388; margin-bottom: 10px;
  border: 1px solid #322a44; transition: box-shadow .3s; }
.pc-card.flash { box-shadow: 0 0 24px rgba(240,201,74,.5); }
.pc-card img { width: 62px; height: 76px; object-fit: cover; border-radius: 8px; border: 1px solid var(--gold); }
.pc-card .qr { width: 72px; height: 72px; object-fit: contain; background: #fff; padding: 3px; border-radius: 6px;
  border: 1px solid #3d3352; flex-shrink: 0; align-self: center; }
.pc-card .nm:hover { text-decoration: underline dotted; cursor: text; }
.pc-card .info { flex: 1; min-width: 0; }
.pc-card .nm { font-family: 'Cinzel'; font-size: 15px; color: var(--gold-bright); }
.pc-card .cls { font-size: 13px; color: var(--ink-dim); }
.hp-bar { height: 9px; background: #0d0b12; border-radius: 5px; margin-top: 6px; overflow: hidden; border:1px solid #322a44; }
.hp-bar > div { height: 100%; background: linear-gradient(90deg, #7c2626, #c04545); transition: width .6s; border-radius:5px; }
.hp-text { font-size: 12px; color: var(--ink-dim); margin-top: 2px; }

.narration-panel { flex: 1; overflow-y: auto; scroll-behavior: smooth; padding-right: 6px; }
.narr { margin-bottom: 14px; animation: fadein .4s; }
.narr .who { font-family: 'Cinzel'; font-size: 12px; letter-spacing: .15em; text-transform: uppercase; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.replay-btn { padding: 2px 8px; font-size: 13px; border-radius: 8px; background: #241e33; border: 1px solid #3d3352; }
.replay-btn:hover { border-color: var(--gold); box-shadow: none; transform: none; }
.replay-btn.loading { border-color: var(--gold-bright); animation: pulse 1.1s infinite; }
.narr.dm .who { color: var(--gold); }
.narr.player .who { color: var(--teal); }
.narr .txt { background: #171320cc; border: 1px solid #2c2540; border-left: 3px solid var(--gold); border-radius: 10px;
  padding: 14px 18px; line-height: 1.65; font-size: 18px; white-space: pre-wrap; backdrop-filter: blur(3px); }
.narr.player .txt { border-left-color: var(--teal); font-style: italic; }
.narr.roll .txt { border-left-color: #7a5cc0; }
.scene-caption { text-align: center; font-style: italic; color: var(--gold-bright); font-family:'Cinzel';
  font-size: 15px; letter-spacing:.1em; text-shadow: 0 2px 12px #000; padding: 4px 0 2px; }

.input-bar { display: flex; gap: 8px; align-items: center; }
.input-bar select { max-width: 130px; }
.input-bar input { flex: 1; }
.mic-btn { width: 52px; height: 52px; border-radius: 50%; font-size: 20px; padding: 0; flex-shrink: 0; }
.level-bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0;
  background: linear-gradient(90deg, var(--gold), #ff6b6b); border-radius: 2px; transition: width .06s linear; pointer-events: none; }
.mic-fab { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 55;
  width: 76px; height: 76px; border-radius: 50%; font-size: 30px; padding: 0;
  box-shadow: 0 6px 30px rgba(0,0,0,.6); touch-action: none; }
.mic-fab.rec { background: var(--blood); border-color: #ff6b6b; animation: pulse 1s infinite; }
.mic-status { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%); z-index: 55;
  font-family: 'Cinzel'; font-size: 14px; color: var(--gold-bright); text-shadow: 0 2px 8px #000;
  background: #17131fdd; border: 1px solid #3d3352; border-radius: 20px; padding: 6px 18px; display: none; }
.mic-status.show { display: block; }
.mic-btn.rec { background: var(--blood); border-color: #ff6b6b; animation: pulse 1s infinite; }
.mic-btn.hold-on { background: linear-gradient(180deg,#6d5516,#4a3a0e); border-color: var(--gold-bright);
  box-shadow: 0 0 18px rgba(240,201,74,.5); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(200,60,60,.6);} 50% { box-shadow: 0 0 0 14px rgba(200,60,60,0);} }

.cards-panel { overflow-y: auto; flex: 1; }
.story-card { border-radius: 12px; overflow: hidden; border: 1px solid #3d3352; margin-bottom: 12px;
  background: var(--panel2); animation: fadein .6s; cursor: pointer; transition: transform .2s; }
.story-card:hover { transform: scale(1.02); }
.story-card img { width: 100%; height: 120px; object-fit: cover; display: block; }
.story-card .body { padding: 10px 12px; }
.story-card .kind { font-size: 10px; letter-spacing: .2em; text-transform: uppercase; color: var(--teal); font-family: 'Cinzel'; }
.story-card .t { font-family: 'Cinzel'; color: var(--gold-bright); font-size: 15px; margin: 2px 0 4px; }
.story-card .b { font-size: 13.5px; color: var(--ink-dim); line-height: 1.45; }

/* ---------- Battlemap ---------- */
.map-overlay { position: fixed; inset: 0; background: rgba(5,4,9,.88); z-index: 50; display: none;
  align-items: center; justify-content: center; flex-direction: column; backdrop-filter: blur(4px); }
.map-overlay.open { display: flex; }
.map-title { font-family:'Cinzel'; color: var(--gold-bright); font-size: 26px; margin-bottom: 4px; text-shadow: 0 0 24px rgba(201,162,39,.5); }
.map-desc { color: var(--ink-dim); font-style: italic; margin-bottom: 14px; max-width: 700px; text-align: center; }
#mapCanvas { border: 2px solid var(--gold); border-radius: 10px; box-shadow: 0 0 60px rgba(201,162,39,.25), var(--shadow);
  max-width: 92vw; max-height: 72vh; image-rendering: auto; }
.map-close { margin-top: 16px; }
.map-fab { position: fixed; bottom: 22px; left: 22px; z-index: 40; display: none; }
.map-fab.show { display: block; }

/* ---------- Dice ---------- */
.dice-tray { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.die-btn { width: 46px; height: 46px; padding: 0; font-size: 12px; border-radius: 12px; position: relative; }
.dice-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(5,4,9,.8); display: none;
  align-items: center; justify-content: center; flex-direction: column; backdrop-filter: blur(5px); }
.dice-overlay.open { display: flex; }
.die-visual { width: 190px; height: 190px; position: relative; filter: drop-shadow(0 0 34px rgba(201,162,39,.5)); }
.die-visual svg { width: 100%; height: 100%; }
.die-visual.rolling { animation: diceroll .9s cubic-bezier(.2,.8,.3,1); }
@keyframes diceroll {
  0% { transform: rotate(0) scale(.5) translateY(-140px); }
  55% { transform: rotate(600deg) scale(1.12) translateY(12px); }
  75% { transform: rotate(690deg) scale(.97); }
  100% { transform: rotate(720deg) scale(1); }
}
.die-number { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-family: 'Cinzel'; font-weight: 900; font-size: 56px; color: #fff8e1; text-shadow: 0 0 18px rgba(0,0,0,.8); }
.dice-result-line { margin-top: 18px; font-family: 'Cinzel'; font-size: 26px; color: var(--gold-bright); text-align:center; }
.dice-result-line .crit { color: #7cf59a; text-shadow: 0 0 20px #37e06355; }
.dice-result-line .fumble { color: #f57c7c; }
.dice-reason { color: var(--ink-dim); font-style: italic; margin-top: 6px; font-size: 17px; }

.roll-banner { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 45;
  background: linear-gradient(180deg,#3a2d5e,#241c3d); border: 1px solid #7a5cc0; border-radius: 12px;
  padding: 12px 22px; display: none; align-items: center; gap: 14px; box-shadow: 0 0 30px rgba(122,92,192,.4); animation: fadein .4s; }
.roll-banner.show { display: flex; }
.roll-banner .msg { font-size: 16px; }
.roll-banner b { color: #c9b6f5; font-family: 'Cinzel'; }

.pause-overlay { position: fixed; inset: 0; z-index: 80; background: rgba(5,4,9,.86); backdrop-filter: blur(6px);
  display: none; align-items: center; justify-content: center; flex-direction: column; text-align: center; padding: 20px; }
.pause-overlay.show { display: flex; }
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 70; display:flex; flex-direction:column; gap:8px; align-items:center; }
.toast { background: #241e33ee; border: 1px solid var(--gold); color: var(--ink); border-radius: 10px;
  padding: 10px 18px; animation: fadein .3s; font-size: 15px; box-shadow: var(--shadow); }
.toast.levelup { border-color: var(--gold-bright); font-family: 'Cinzel'; color: var(--gold-bright);
  box-shadow: 0 0 40px rgba(240,201,74,.5); font-size: 18px; }

.dm-thinking { display: none; align-items: center; gap: 10px; color: var(--ink-dim); font-style: italic; padding: 6px 2px; }
.dm-thinking.show { display: flex; }
.dm-thinking .orb { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); animation: orb 1.2s infinite; }
@keyframes orb { 0%,100% { opacity:.25; transform: scale(.8);} 50% { opacity:1; transform: scale(1.2);} }

.mute-btn { position: fixed; top: 16px; right: 16px; z-index: 45; width: 46px; height: 46px; border-radius: 50%; padding: 0; font-size: 18px; }

/* ---------- Player sheet page ---------- */
.sheet { max-width: 560px; margin: 0 auto; padding: 18px 14px 60px; }
.sheet-head { display: flex; gap: 16px; align-items: flex-end; margin-bottom: 14px; }
.sheet-head img { width: 128px; height: 160px; object-fit: cover; border-radius: 12px; border: 2px solid var(--gold);
  box-shadow: 0 0 30px rgba(201,162,39,.35); }
.sheet-head .nm { font-size: 27px; color: var(--gold-bright); }
.sheet-head .meta { color: var(--ink-dim); font-style: italic; }
.lvl-badge { display: inline-block; background: linear-gradient(180deg,#6d5516,#4a3a0e); border: 1px solid var(--gold);
  border-radius: 20px; padding: 2px 14px; font-family: 'Cinzel'; color: #fff2cc; font-size: 14px; margin-top: 4px; }
.stat-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 14px 0; }
.stat-hex { text-align: center; background: #241e33; border: 1px solid #3d3352; border-radius: 10px; padding: 10px 2px;
  clip-path: polygon(50% 0%, 100% 22%, 100% 78%, 50% 100%, 0% 78%, 0% 22%); }
.stat-hex .lab { font-size: 10px; letter-spacing: .15em; color: var(--teal); font-family: 'Cinzel'; }
.stat-hex .val { font-size: 22px; font-family: 'Cinzel'; color: var(--ink); }
.stat-hex .mod { font-size: 12px; color: var(--gold-bright); }
.sheet h3 { color: var(--gold); font-size: 14px; letter-spacing: .14em; text-transform: uppercase; margin: 16px 0 8px; }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { background: #241e33; border: 1px solid #3d3352; border-radius: 16px; padding: 4px 12px; font-size: 14px; }
.atk-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.atk-table td { padding: 6px 8px; border-bottom: 1px solid #2c2540; }
.atk-table td:first-child { font-family: 'Cinzel'; font-size: 13px; color: var(--gold-bright); }
.combat-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.combat-box { text-align: center; background: #241e33; border: 1px solid #3d3352; border-radius: 10px; padding: 10px; }
.combat-box .v { font-size: 24px; font-family: 'Cinzel'; color: var(--gold-bright); }
.combat-box .l { font-size: 11px; letter-spacing: .12em; color: var(--ink-dim); text-transform: uppercase; }
.secret-box { background: #2a1c3d; border: 1px solid #7a5cc0; border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
  font-style: italic; animation: fadein .5s; }
.secret-box::before { content: '🤫 Only you know: '; font-style: normal; font-family: 'Cinzel'; font-size: 12px; color: #c9b6f5; }
.sheet .backstory { line-height: 1.6; color: var(--ink-dim); font-size: 15.5px; }

/* --- bottom tab bar (phone sheet) --- */
.tab-bar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 60; display: flex;
  background: #17131fee; border-top: 1px solid #3d3352; backdrop-filter: blur(8px); }
.tab-bar button { flex: 1; border: 0; border-radius: 0; background: none; padding: 10px 0 12px;
  font-size: 12px; line-height: 1.5; color: var(--ink-dim); letter-spacing: .06em; }
.tab-bar button.on { color: var(--gold-bright); background: #241e3399; box-shadow: inset 0 2px 0 var(--gold); }
.sheet .mic-fab, body .mic-fab { bottom: 78px; }
.mic-status { bottom: 158px; }

@media (max-width: 1100px) {
  .table-layout.active { grid-template-columns: 1fr; height: auto; }
  .map-fab { left: 20px; }
}

/* side characters */
.pc-card.paused { opacity: .45; filter: grayscale(.85); }
