:root {
  --bg: #15131a; --panel: #211e27; --panel2: #2a2631; --line: #3b3644;
  --text: #ece6da; --muted: #a59d90; --gold: #d9a63a; --red: #e05252; --green: #4fbf6a; --blue: #4f8fe0;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
/* phones/tablets: no double-tap zoom (pinch still works), no text selection from fast taps,
   and 16px text boxes so iPhones don't zoom in when one is tapped */
html, body, button, a, input, select, textarea, label, canvas { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, .btn, canvas { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
@media (pointer: coarse) { html input, html select, html textarea { font-size: 16px; } }   /* "html" outranks the input rule further down */
a { color: var(--gold); }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; letter-spacing: .3px; margin: 0 0 .6em; }
h1 { font-size: 26px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 18px; }
header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: #1a1820; }
header.top .brand { font-family: Georgia, serif; font-size: 22px; color: var(--gold); text-decoration: none; }
header.top .back { color: var(--muted); text-decoration: none; font-size: 13px; }
header.top .back:hover { color: var(--text); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select { width: 100%; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--line); background: #17151c; color: var(--text); font: inherit; }
button, .btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 13px; border-radius: 7px; border: 1px solid #514a5c; background: #34303d; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; }
button:hover:not(:disabled), .btn:hover { background: #3f3a4a; }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary, .btn.primary { background: #8a6420; border-color: #b8862d; }
button.primary:hover:not(:disabled) { background: #a0752a; }
button.danger { background: #5a2626; border-color: #7c3434; }
button.small { padding: 4px 9px; font-size: 13px; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button.on { background: #8a6420; border-color: #b8862d; }
.hero-card { border: 1px solid var(--line); border-radius: 9px; padding: 11px; background: var(--panel2); }
.hero-card + .hero-card { margin-top: 10px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: #3a3542; color: var(--muted); }
.pill.gold { background: #4a3a17; color: #f1cf86; }
.pill.red { background: #4b2323; color: #f2a0a0; }
.pill.green { background: #1f3f28; color: #9fe0b0; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); padding: 10px 16px; border-radius: 8px; background: #333; color: #fff; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; } #toast.err { background: #8b2c2c; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.modal.story { width: min(520px, 100%); }
.story-line { margin: 0 0 10px; line-height: 1.45; }
.story-speaker { color: var(--accent, #e0b84a); }
.story-narration { font-style: italic; opacity: .85; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: min(640px, 100%); max-height: 88vh; overflow: auto; }
table.items { width: 100%; border-collapse: collapse; font-size: 14px; }
table.items td, table.items th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }

/* ---- game ---- */
.game { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 14px; padding: 14px; max-width: 1320px; margin: 0 auto; }
@media (max-width: 1000px) { .game { grid-template-columns: 1fr; } }
.board-wrap { background: #0b0b0f; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; position: relative; }
canvas#board { width: 100%; height: auto; display: block; cursor: pointer; }
/* the spell you picked: what it does, then cast */
.spell-card { margin-top: 10px; padding: 10px 12px; border-radius: 9px; background: #241f2e; border: 1px solid #8a6aff; }
.spell-card .spell-name { font-weight: 700; color: #d8c8ff; margin-bottom: 4px; }
/* movement dice shown on the board after a roll */
.roll-dice { position: absolute; top: 14px; right: 14px; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px;
  background: rgba(10, 8, 14, .78); border: 1px solid #514a5c; opacity: 0; transform: translateY(-6px); transition: opacity .25s, transform .25s; pointer-events: none; }
.roll-dice.show { opacity: 1; transform: none; }
.d6 { width: 34px; height: 34px; padding: 4px; box-sizing: border-box; border-radius: 7px; background: #f4ead6; box-shadow: inset 0 -3px 0 #c9b68f, 0 2px 4px rgba(0,0,0,.5);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); }
.roll-dice:not(.landed) .d6 { animation: tumble .14s linear infinite; }
.d6 i { display: block; }
.d6 i.pip { width: 6px; height: 6px; border-radius: 50%; background: #2a1a10; place-self: center; }
.d6-total { color: #f1cf86; font-weight: 700; font-size: 13px; white-space: nowrap; }
@keyframes tumble { 0% { transform: rotate(0deg); } 50% { transform: rotate(14deg) translateY(-2px); } 100% { transform: rotate(0deg); } }
.side { display: flex; flex-direction: column; gap: 12px; }

/* ---- quest HUD: actions on the left, the board in the middle, dice / hit points / chat / chronicle on the right ---- */
.game.hud-layout { grid-template-columns: 230px minmax(0, 1fr) 280px; grid-template-areas: "left board right"; align-items: start; max-width: 1800px; }
.hud-left { grid-area: left; } .hud-board { grid-area: board; min-width: 0; } .hud-right { grid-area: right; }
.hud { display: flex; flex-direction: column; gap: 12px; min-width: 0; position: sticky; top: 10px; max-height: calc(100vh - 20px); overflow-y: auto; }
.hud .card { padding: 13px; }
.hud h3 { font-size: 16px; margin-bottom: .45em; }
.hud-left .actions { grid-template-columns: 1fr; }
.hud-left .actions .wide { grid-column: auto; }
.hud-right .log { max-height: 240px; }
/* the map keeps a readable size and scrolls (following your hero) when the screen is too small for all of it */
.board-scroll { overflow: auto; max-height: calc(100vh - 110px); -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.hud-board .board-wrap { padding: 4px; }
.dice-card .roll-box { min-height: 44px; }
.dice-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.dice-label { width: 74px; font-size: 13px; color: var(--muted); }
.die.big { width: 30px; height: 30px; font-size: 18px; border-radius: 6px; margin: 0; }
.roll-box.rolling .d6, .roll-box.rolling .die { animation: tumble .14s linear infinite; }
.roll-text { font-size: 13.5px; margin-top: 6px; line-height: 1.35; }
.hp-sub { margin-top: 10px; padding-top: 6px; border-top: 1px solid var(--line); }
.party-hero.foe { grid-template-columns: 20px 1fr auto; padding: 4px 0; }
.foe-icon { font-size: 16px; text-align: center; }
.chat-list { max-height: 170px; overflow-y: auto; font-size: 13.5px; display: flex; flex-direction: column; gap: 3px; overflow-wrap: anywhere; }
.chat-msg.me { color: #e9dcc0; }
.chat-form { display: flex; gap: 6px; margin-top: 8px; }
.chat-form input { flex: 1; min-width: 0; }
@media (max-width: 1180px) {
  .game.hud-layout { grid-template-columns: 230px minmax(0, 1fr); grid-template-areas: "left board" "left right"; }
  .hud-right { position: static; max-height: none; overflow: visible; }
}
@media (max-width: 760px) {
  .game.hud-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "board" "left" "right"; padding: 10px 16px; }
  .hud { position: static; max-height: none; overflow: visible; }
  .board-scroll { max-height: 62vh; }
}
.side .card { padding: 13px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.actions button { justify-content: center; }
.actions .wide { grid-column: span 2; }
.party-hero { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.party-hero:last-child { border-bottom: 0; }
.party-hero .dot { width: 12px; height: 12px; border-radius: 50%; }
.party-hero.current { background: rgba(217,166,58,.08); border-radius: 6px; }
.bar { height: 6px; background: #3a3542; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar > i { display: block; height: 100%; background: var(--green); }
.log { max-height: 290px; overflow-y: auto; font-size: 13.5px; }
.log div { padding: 4px 0; border-bottom: 1px dashed #332f3a; }
.die { display: inline-flex; width: 20px; height: 20px; align-items: center; justify-content: center; border-radius: 4px; font-size: 12px; margin: 1px; vertical-align: middle; }
.die.S { background: #e8e0d0; color: #2a0000; }
.die.W { background: #fff; color: #333; border: 1px solid #999; }
.die.B { background: #111; color: #eee; border: 1px solid #555; }
.hint { font-size: 13px; color: var(--muted); margin-top: 8px; }
.banner { padding: 14px; border-radius: var(--radius); text-align: center; font-family: Georgia, serif; font-size: 20px; }
.banner.won { background: #2b4a1f; border: 1px solid #4f8a3a; }
.banner.lost, .banner.abandoned { background: #4a1f1f; border: 1px solid #8a3a3a; }
#tip { position: absolute; pointer-events: none; background: rgba(20,18,26,.95); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; font-size: 13px; display: none; z-index: 5; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
