:root {
  --bg: #15130f;
  --panel: #1f1c17;
  --edge: #3a342a;
  --ink: #e9e1cf;
  --dim: #9a8f7a;
  --gold: #d6a84a;
  --red: #c9554a;
  --green: #6fa65a;
  --blue: #5a8fc0;
  --violet: #a07ad0;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { background: var(--bg); }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--sans); display: flex; flex-direction: column; }
h1, h2 { font-family: var(--serif); font-weight: 600; margin: 0; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin-bottom: 8px; }
.hidden { display: none !important; }
.empty { color: var(--dim); font-style: italic; padding: 12px; }

header { display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--edge); }
header h1 { font-size: 20px; color: var(--gold); margin-right: auto; }
.badge { font-size: 12px; padding: 2px 8px; border: 1px solid var(--edge); border-radius: 10px; color: var(--dim); }
.badge.combat { color: var(--red); border-color: var(--red); }
.badge.turn { color: var(--bg); background: var(--gold); border-color: var(--gold); font-weight: 600; }
.conn { font-size: 12px; }
.conn.on { color: var(--green); }
.conn.off { color: var(--red); }

main { flex: 1; display: grid; grid-template-columns: 300px 1fr 270px; gap: 10px; padding: 10px; min-height: 0; }
.panel { background: var(--panel); border: 1px solid var(--edge); border-radius: 6px; padding: 10px; }
aside { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; min-height: 0; }
#sheet { overflow-y: auto; }
#center { display: grid; grid-template-rows: minmax(170px, 40%) minmax(170px, 1fr) auto auto auto auto auto; gap: 10px; min-height: 0; }

/* map */
#map-wrap { position: relative; padding: 0; overflow: hidden; }
#map { width: 100%; height: 100%; display: block; }
#map-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.room { fill: #2c2820; stroke: #6b5e48; stroke-width: 1.5; }
.gridline { stroke: #3a342a; stroke-width: .5; }
.room-label { fill: var(--dim); font: 10px var(--sans); }

/* log */
#story { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
#log { overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px 14px 14px; flex: 1; min-height: 0; }
.entry { max-width: 75ch; }
.entry.narration { font: 16px/1.55 var(--serif); }
.entry.narration .speaker { color: var(--gold); font-weight: 600; }
.entry.say .who, .entry.action .who { color: var(--blue); font-weight: 600; }
.entry.say .words { font-family: var(--serif); }
.entry.action { font-style: italic; color: #cfc6b0; }
.entry.roll { font: 12px var(--mono); color: var(--gold); }
.entry.system { font-size: 12px; color: var(--dim); }
.entry.whisper { border-left: 3px solid var(--violet); padding-left: 8px; color: #d9c8f0; font-family: var(--serif); }
.entry.whisper::before { content: "whisper  "; font: 11px var(--sans); color: var(--violet); text-transform: uppercase; letter-spacing: .08em; }

/* input */
#input { display: flex; gap: 8px; align-items: stretch; }
#input .kind { display: flex; flex-direction: column; gap: 4px; }
#input textarea { flex: 1; resize: none; background: var(--panel); color: var(--ink); border: 1px solid var(--edge); border-radius: 6px; padding: 8px; font: 15px var(--serif); }
#input textarea:focus { outline: 1px solid var(--gold); }
button { background: #2c2820; color: var(--ink); border: 1px solid var(--edge); border-radius: 6px; padding: 6px 12px; cursor: pointer; font: inherit; }
button:hover { border-color: var(--gold); }
button.on { background: var(--gold); color: var(--bg); border-color: var(--gold); font-weight: 600; }
#send { padding: 0 20px; }
button:disabled { opacity: .4; cursor: default; }

/* sheet */
.sheet-head h3 { font: 600 20px var(--serif); margin: 0; color: var(--gold); }
.sheet-head .sub { color: var(--dim); font-size: 12px; }
.vitals { display: flex; gap: 8px; margin: 10px 0; }
.vital { flex: 1; text-align: center; border: 1px solid var(--edge); border-radius: 6px; padding: 4px; }
.vital .n { font: 600 18px var(--serif); }
.vital .l { font-size: 10px; text-transform: uppercase; color: var(--dim); }
.bar { height: 6px; background: #3a2a26; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar > div { height: 100%; background: var(--green); }
.bar > div.low { background: var(--red); }
.abilities { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-bottom: 10px; }
.ab { text-align: center; border: 1px solid var(--edge); border-radius: 6px; padding: 3px 0; }
.ab .l { font-size: 10px; color: var(--dim); text-transform: uppercase; }
.ab .m { font: 600 16px var(--serif); }
.ab .s { font-size: 10px; color: var(--dim); }
.sec { margin-top: 10px; }
.sec h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin: 0 0 4px; }
.sec ul { margin: 0; padding-left: 16px; }
.sec li { margin-bottom: 2px; }
.atk { display: flex; justify-content: space-between; gap: 6px; }
.atk .d { color: var(--gold); font-family: var(--mono); font-size: 12px; white-space: nowrap; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 8px; background: #3a2a26; color: #f0b0a0; margin: 2px 2px 0 0; }
.pips { color: var(--gold); letter-spacing: 2px; }

/* party / foes / initiative */
.member { padding: 6px 0; border-bottom: 1px solid var(--edge); }
.member:last-child { border-bottom: 0; }
.member .top { display: flex; justify-content: space-between; }
.member .name { font-weight: 600; }
.member .who { color: var(--dim); font-size: 12px; }
.member.offline .who::after { content: " · away"; }
.foe .band { font-size: 12px; color: var(--dim); }
.foe .band.bloodied, .foe .band.near.death { color: var(--red); }
.foe .desc { font-size: 12px; color: var(--dim); }
#initiative { margin: 0; padding-left: 22px; }
#initiative li.current { color: var(--gold); font-weight: 600; }
.recap { font-family: var(--serif); white-space: pre-wrap; color: #cfc6b0; }

/* overlay */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; }
.dialog { background: var(--panel); border: 1px solid var(--edge); border-radius: 8px; padding: 20px; width: min(720px, 94vw); max-height: 90vh; overflow-y: auto; }
.dialog h2 { font-size: 22px; color: var(--gold); text-transform: none; letter-spacing: 0; }
.dialog label { display: flex; flex-direction: column; gap: 4px; margin: 12px 0; color: var(--dim); }
.dialog input { background: var(--bg); color: var(--ink); border: 1px solid var(--edge); border-radius: 6px; padding: 8px; font: 16px var(--serif); }
#premades { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.premade { text-align: left; padding: 12px; }
.premade .n { font: 600 16px var(--serif); color: var(--gold); }
.premade .c { font-size: 12px; color: var(--dim); }
.premade .d { font-size: 13px; margin-top: 6px; font-family: var(--serif); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--red); color: #fff; padding: 8px 14px; border-radius: 6px; }

/* roll requests */
#rolls:empty { display: none; }
#rolls { display: flex; flex-direction: column; gap: 6px; }
.rollreq { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--edge); border-radius: 6px; background: var(--panel); }
.rollreq.mine { border-color: var(--gold); box-shadow: 0 0 12px rgba(214,168,74,.25); }
.rollreq .why { color: var(--dim); font-size: 12px; font-style: italic; }
.rollreq .btns { display: flex; gap: 6px; }

/* tooltips */
#tip { position: fixed; z-index: 100; max-width: 320px; pointer-events: none; opacity: 0; transform: translateY(4px);
  transition: opacity .12s ease, transform .12s ease; background: #2a251d; border: 1px solid #5a4e3a; border-radius: 8px;
  padding: 10px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.55); font-size: 13px; line-height: 1.45; }
#tip.show { opacity: 1; transform: none; }
.tt-title { font: 600 15px var(--serif); color: var(--gold); margin-bottom: 4px; }
.tt-body { color: var(--ink); }
.tt-foot { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--edge); color: var(--dim); font-size: 12px; }
.tt-dim { color: var(--dim); font-weight: 400; font-family: var(--sans); font-size: 12px; }
.tt-stats { font: 12px var(--mono); color: #e8c77a; margin: 4px 0; }
.tt-flavour { font-family: var(--serif); font-style: italic; color: #cfc6b0; margin: 4px 0; }
.tt-die { display: inline-block; min-width: 22px; text-align: center; margin: 0 2px; padding: 0 4px; border-radius: 4px; background: #3a342a; font: 600 12px var(--mono); }
.tt-die.kept { background: var(--gold); color: var(--bg); }
.tt-die.crit { background: var(--green); color: #fff; }
.tt-die.fumble { background: var(--red); color: #fff; }
[data-tip] { cursor: help; }
.vital[data-tip]:hover, .ab[data-tip]:hover, .chip[data-tip]:hover, .item[data-tip]:hover, .atk[data-tip]:hover, .member[data-tip]:hover, .res li:hover, .feats li:hover { border-color: var(--gold); background: rgba(214,168,74,.06); }

/* sheet details */
.vital .of { color: var(--dim); font-size: 13px; }
.vital .temp { color: var(--blue); font-size: 13px; margin-left: 2px; }
.bar > div { transition: width .4s ease, background .4s ease; }
.bar > div.mid { background: #c9a24a; }
.atk { padding: 3px 4px; border: 1px solid transparent; border-radius: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-block; padding: 2px 8px; border: 1px solid var(--edge); border-radius: 10px; font-size: 12px; }
.chip b { color: var(--gold); font-weight: 600; }
.spell-lvl { margin-bottom: 6px; }
.spell-lvl .lvl { display: block; font-size: 11px; color: var(--dim); margin-bottom: 2px; }
.spell-lvl .chip { margin: 0 2px 3px 0; }
ul.res, ul.feats, ul.inv { list-style: none; padding: 0; margin: 0; }
.res li, .feats li { padding: 3px 4px; border-radius: 4px; display: flex; justify-content: space-between; }
.inv .item { display: flex; gap: 8px; align-items: flex-start; padding: 4px; border: 1px solid transparent; border-radius: 4px; }
.inv .ico { width: 16px; text-align: center; color: var(--gold); opacity: .8; }
.inv .nm { display: flex; flex-direction: column; }
.inv .qty { color: var(--dim); font-size: 12px; }
.inv .st { font: 11px var(--mono); color: var(--dim); }
.deathsaves .ok { color: var(--green); letter-spacing: 3px; }
.deathsaves .bad { color: var(--red); letter-spacing: 3px; }
.member { border: 1px solid transparent; border-radius: 4px; padding: 6px 4px; }
#initiative li { padding: 2px 0; }
#initiative li .init { color: var(--dim); font-size: 12px; }
#initiative li.monster { color: #e0a49a; }
#initiative li.current { color: var(--gold); }
#initiative li.current::marker { content: "▶ "; }
.foe .band.bloodied, .foe .band.near-death { color: var(--red); }
.foe .band.dead { color: var(--dim); text-decoration: line-through; }

/* dice tray */
#tray { position: absolute; right: 14px; bottom: 14px; min-width: 180px; padding: 12px 14px; border-radius: 10px;
  background: rgba(21,19,15,.92); border: 1px solid #5a4e3a; box-shadow: 0 10px 30px rgba(0,0,0,.6);
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
  opacity: 0; transform: translateY(12px) scale(.96); transition: opacity .18s ease, transform .18s ease; }
#tray.show { opacity: 1; transform: none; }
#tray.crit-flash { box-shadow: 0 0 0 2px var(--gold), 0 0 40px rgba(214,168,74,.6); }
.dice-label { font-size: 12px; color: var(--dim); text-align: center; max-width: 260px; }
.dice-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.dice-total { font: 600 22px var(--serif); color: var(--ink); opacity: 0; transform: scale(.7); transition: all .2s cubic-bezier(.3,1.6,.6,1); }
.dice-total.in { opacity: 1; transform: none; }
.dice-total i { font: italic 14px var(--serif); color: var(--gold); }
.die { width: 46px; height: 46px; display: grid; place-items: center; font: 700 17px var(--sans); color: #1b1712;
  background: linear-gradient(145deg, #f3e3bd, #c9a865); position: relative; }
.die span { position: relative; z-index: 1; }
.die.d20 { clip-path: polygon(50% 0, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%); }
.die.d12 { clip-path: polygon(50% 0, 97% 35%, 79% 95%, 21% 95%, 3% 35%); }
.die.d10 { clip-path: polygon(50% 0, 100% 45%, 50% 100%, 0 45%); }
.die.d8 { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); background: linear-gradient(145deg, #e9d7f5, #a07ad0); }
.die.d6 { border-radius: 9px; background: linear-gradient(145deg, #f6e0d6, #c97c64); }
.die.d4 { clip-path: polygon(50% 4%, 98% 92%, 2% 92%); padding-top: 12px; font-size: 15px; background: linear-gradient(145deg, #d9eccf, #6fa65a); }
.die.d10, .die.d12 { background: linear-gradient(145deg, #d6e6f5, #5a8fc0); }
.die.tumbling { animation: tumble .45s linear infinite; }
.die.landed { animation: land .35s cubic-bezier(.3,1.7,.5,1); }
.die.crit { background: linear-gradient(145deg, #fff6c9, #f0b83a); box-shadow: 0 0 18px #f0c060; }
.die.fumble { background: linear-gradient(145deg, #f3b8ae, #b23a2e); color: #fff; }
.die.dropped { opacity: .35; filter: grayscale(1); transform: scale(.85); }
@keyframes tumble {
  0% { transform: rotate(0) translateY(0) scale(1); }
  25% { transform: rotate(calc(var(--spin) * .25)) translateY(-8px) scale(1.05); }
  50% { transform: rotate(calc(var(--spin) * .5)) translateY(0) scale(.95); }
  75% { transform: rotate(calc(var(--spin) * .75)) translateY(-5px) scale(1.03); }
  100% { transform: rotate(var(--spin)) translateY(0) scale(1); }
}
@keyframes land { 0% { transform: scale(1.35) rotate(-12deg); } 100% { transform: none; } }
@media (prefers-reduced-motion: reduce) { .die.tumbling, .die.landed { animation: none; } }
.dice-total { text-align: center; }
.dice-total .sum { font: 14px var(--mono); color: var(--dim); }
.dice-total .dmg { font: 600 15px var(--serif); color: #f0b0a0; }

/* story panel */
.story-bar { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--edge); font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; }
.seg { display: flex; border: 1px solid var(--edge); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 3px 10px; font-size: 12px; text-transform: none; letter-spacing: 0; }
.seg button + button { border-left: 1px solid var(--edge); }
.entry .verb { color: var(--dim); font-style: italic; }

/* chapters */
.chapter { text-align: center; margin: 18px 0 6px; }
.chapter .orn { color: var(--gold); opacity: .7; font-size: 18px; }
.ch-title { font: 600 22px var(--serif); color: var(--gold); letter-spacing: .02em; }
.ch-mood { font: italic 13px var(--serif); color: var(--dim); }
.scene + .scene { margin-top: 6px; }
.scene { display: flex; flex-direction: column; gap: 8px; }

/* feed */
.entry.narration.drop::first-letter { float: left; font: 600 3.1em/0.85 var(--serif); color: var(--gold); padding: 4px 6px 0 0; }
.rchips { display: flex; flex-wrap: wrap; gap: 6px; }
.rchip { display: inline-flex; gap: 4px; align-items: baseline; padding: 2px 9px; border-radius: 10px; background: #2c2820; border: 1px solid var(--edge); font-size: 12px; color: #d8cdb4; }
.rchip b { color: var(--ink); font-size: 13px; }
.rchip i { font-style: normal; color: var(--dim); }
.rchip.good { border-color: #4f6e41; } .rchip.good i { color: var(--green); }
.rchip.bad { border-color: #6e4a41; } .rchip.bad i { color: #e09080; }
.rchip.crit { border-color: var(--gold); box-shadow: 0 0 8px rgba(214,168,74,.35); } .rchip.crit i { color: var(--gold); font-weight: 600; }
.rchip.fumble { border-color: var(--red); } .rchip.fumble i { color: var(--red); font-weight: 600; }
.view-feed .entry.system { font-size: 11px; opacity: .8; }

/* book */
#log.view-book { padding: 14px; background: radial-gradient(ellipse at center, #1c1913 0%, #110f0b 100%); }
.book { display: flex; flex-direction: column; gap: 10px; min-height: 100%; }
.page { flex: 1; background: linear-gradient(180deg, #efe2c4, #e4d3ad); color: #2b2216; border-radius: 4px 10px 10px 4px; padding: 22px 28px; box-shadow: inset 12px 0 18px -12px rgba(80,50,20,.45), 0 8px 24px rgba(0,0,0,.5); }
.page .ch-title { color: #6e3f17; text-align: center; font-size: 26px; }
.page .ch-mood { color: #7a6448; text-align: center; margin-bottom: 14px; }
.page-head { border-bottom: 1px solid rgba(110,63,23,.25); padding-bottom: 8px; margin-bottom: 14px; }
.page-body { display: grid; grid-template-columns: 1fr 210px; gap: 22px; }
.page .entry.narration { font: 17px/1.65 var(--serif); color: #2b2216; margin-bottom: 10px; }
.page .entry.narration.drop::first-letter { color: #8a2e1c; }
.page .entry.narration .speaker { color: #6e3f17; }
.page .entry.whisper { color: #4b2f6e; border-left-color: #7a5aa8; background: rgba(160,122,208,.12); padding: 6px 10px; }
.margin { border-left: 1px dashed rgba(110,63,23,.3); padding-left: 12px; display: flex; flex-direction: column; gap: 8px; font: italic 13px var(--serif); color: #5a4630; }
.mnote b { font-style: normal; color: #6e3f17; }
.mnote.sys { font-size: 12px; color: #8a7558; }
.mnote .rchip { background: rgba(110,63,23,.08); border-color: rgba(110,63,23,.3); color: #4a3a26; font-style: normal; }
.mnote .rchip b { color: #2b2216; }
.book-nav { display: flex; justify-content: space-between; align-items: center; color: var(--dim); font-size: 12px; }
.book-nav a { color: var(--gold); }

/* cards */
#log.view-cards { gap: 12px; }
.card { background: linear-gradient(180deg, #27231b, #1f1c16); border: 1px solid var(--edge); border-radius: 10px; padding: 14px 18px; opacity: .78; transition: opacity .3s; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.card:hover, .card.latest { opacity: 1; }
.card.latest { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(214,168,74,.25), 0 8px 24px rgba(0,0,0,.45); }
.card.talk { background: transparent; box-shadow: none; padding: 6px 4px; border-style: dashed; }
.card-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--edge); }
.card.talk .card-foot { margin: 0; padding: 0; border: 0; }
.bchip { font-size: 12px; padding: 3px 9px; border-radius: 10px; background: #2c2820; border: 1px solid var(--edge); max-width: 100%; }
.bchip b { color: var(--blue); }
.bchip.say { font-family: var(--serif); }
.bchip.sys { color: var(--dim); border-style: dashed; }
.bchip.whisper { border-color: var(--violet); color: #d9c8f0; }

/* map */
#map { cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
#map-wrap::after { content: ""; position: absolute; inset: 0; pointer-events: none; border-radius: 6px; box-shadow: inset 0 0 60px rgba(0,0,0,.75); }
.map-bar { position: absolute; top: 8px; left: 8px; z-index: 2; display: flex; gap: 6px; }
.map-bar button { padding: 2px 9px; font-size: 12px; background: rgba(31,28,23,.9); }
.feat-glyph { text-anchor: middle; dominant-baseline: central; }
#m-dark { fill: #050403; opacity: .62; pointer-events: none; }
#m-glow { mix-blend-mode: screen; pointer-events: none; }
#m-glow .glow { animation: flicker 3.2s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes flicker { 0% { opacity: .85; transform: scale(1); } 40% { opacity: 1; transform: scale(1.03); } 70% { opacity: .9; transform: scale(.99); } 100% { opacity: 1; transform: scale(1.02); } }
#map.painted .wall { fill: none; stroke: #0b0907; stroke-width: 10; stroke-linejoin: round; }
#map.painted .floor { stroke: none; }
#map.painted .gridline { stroke: rgba(0,0,0,.28); stroke-width: .8; }
.room-label.painted { fill: #e6d6b0; font: 600 10px var(--serif); letter-spacing: .04em; paint-order: stroke; stroke: rgba(0,0,0,.85); stroke-width: 3px; pointer-events: none; }
.door { fill: #8a5a2b; stroke: #2a1a0c; stroke-width: 1.5; }
.door.secret-door { fill: #6a4f8a; stroke-dasharray: 3 2; }

/* tokens */
.token { transition: transform .5s cubic-bezier(.3,.9,.4,1), opacity .4s; }
.token .t-base { stroke: #0b0907; stroke-width: 1.5; }
.token .t-ring-bg { fill: none; stroke: rgba(0,0,0,.55); stroke-width: 3; }
.token .t-ring { fill: none; stroke-width: 3; stroke-linecap: round; transition: stroke-dasharray .5s ease, stroke .5s; }
.token .t-glyph { fill: #fff; font-weight: 700; font-family: var(--sans); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.token.pc .t-base { fill: #3d6f9e; }
.token.me .t-base { fill: #b8862e; }
.token.npc .t-base { fill: #6e6a4e; }
.token.monster .t-base { fill: #9b3a30; }
.token.dead { opacity: .35; }
.token.dead .t-glyph { fill: #ccc; }
.token.current .t-ring-bg { stroke: var(--gold); stroke-width: 5; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { stroke-opacity: .35; } }
.map-bar button.on { background: var(--gold); color: var(--bg); }

/* snappiness */
.fresh { animation: fresh-in .45s cubic-bezier(.2,.8,.3,1) both; }
@keyframes fresh-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.entry.sending { opacity: .5; }
.sending-tag { font: italic 11px var(--sans); color: var(--dim); margin-left: 6px; }
.badge.dm.listening { color: var(--green); border-color: #4f6e41; }
.badge.dm.thinking { color: var(--gold); border-color: var(--gold); }
.badge.dm.away { color: var(--dim); }
.dots { display: inline-flex; gap: 2px; margin-left: 4px; }
.dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
#thinking { display: none; align-items: center; gap: 4px; padding: 6px 14px 8px; font: italic 13px var(--serif); color: var(--gold); border-top: 1px solid var(--edge); }
#thinking.show { display: flex; }
#thinking .quill { animation: scribble 1.4s ease-in-out infinite; display: inline-block; }
@keyframes scribble { 50% { transform: translateX(3px) rotate(-8deg); } }
@media (prefers-reduced-motion: reduce) { .fresh, .dots i, #thinking .quill, .token, #m-glow .glow { animation: none !important; transition: none !important; } }

/* clarity */
#hint { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border: 1px solid #4f6e41; border-radius: 8px; background: rgba(111,166,90,.08); font-size: 13px; }
#hint button { white-space: nowrap; }
.banner { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--edge); background: var(--panel); font-size: 13px; color: var(--dim); }
.banner b { color: var(--ink); }
.banner.mine { border-color: var(--gold); background: linear-gradient(90deg, rgba(214,168,74,.18), rgba(214,168,74,.04)); color: var(--ink); animation: fresh-in .35s both; }
.banner.mine b { color: var(--gold); }
body.my-turn #input textarea { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(214,168,74,.4); }
#chips:empty { display: none; }
#chips { display: flex; flex-wrap: wrap; gap: 6px; }
.qchip { font-size: 12px; padding: 3px 10px; border-radius: 12px; }
.qchip:hover { background: rgba(214,168,74,.1); }
.premade { display: flex; flex-direction: column; gap: 6px; }
.pm-top { display: flex; gap: 10px; align-items: center; }
.pm-glyph { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: #3d6f9e; color: #fff; font-size: 18px; flex: none; }
.premade .c b { color: var(--ink); font-weight: 600; }
.pm-blurb { font-size: 12px; color: var(--dim); }
.pm-stats { display: flex; gap: 10px; font-size: 12px; color: var(--dim); flex-wrap: wrap; }
.pm-stats b { color: var(--ink); font-size: 14px; }
.pm-best { color: var(--gold); }
.pm-atk { font: 12px var(--mono); color: #e8c77a; }
.pm-feats { display: flex; flex-wrap: wrap; gap: 4px; }
.pm-feats span { font-size: 11px; padding: 1px 7px; border-radius: 8px; border: 1px solid var(--edge); color: var(--dim); }
.pm-diff { font-size: 11px; color: var(--dim); font-style: italic; }
.premade:hover { border-color: var(--gold); transform: translateY(-2px); transition: transform .15s; }

#hint { padding: 6px 12px; font-size: 12px; justify-content: space-between; }
#hint button { padding: 2px 10px; font-size: 12px; }
#hint .more { color: var(--green); text-decoration: underline dotted; margin-left: 6px; }

.icon-btn { padding: 1px 7px; font-size: 14px; line-height: 1.4; background: transparent; }

/* phones and narrow windows: one column, the table first */
@media (max-width: 860px) {
  body { height: auto; min-height: 100%; }
  header { flex-wrap: wrap; gap: 6px; padding: 6px 10px; }
  header h1 { font-size: 17px; width: 100%; }
  main { display: flex; flex-direction: column; padding: 6px; gap: 8px; }
  #center { display: flex; flex-direction: column; gap: 8px; order: 1; }
  #map-wrap { height: 34vh; min-height: 200px; }
  #story { height: 52vh; min-height: 280px; }
  #input { position: sticky; bottom: 0; z-index: 5; background: var(--bg); padding: 6px 0; }
  #rolls { position: sticky; bottom: 92px; z-index: 5; }
  #rolls .rollreq { box-shadow: 0 -6px 18px rgba(0,0,0,.6); }
  #input textarea { font-size: 16px; } /* no zoom-on-focus on iOS */
  #sheet { order: 2; max-height: none; }
  #side { order: 3; overflow: visible; }
  aside { overflow: visible; }
  #tray { right: 8px; bottom: 8px; min-width: 150px; padding: 8px; }
  .die { width: 38px; height: 38px; font-size: 15px; }
  .page-body { grid-template-columns: 1fr; }
  .margin { border-left: 0; border-top: 1px dashed rgba(110,63,23,.3); padding: 10px 0 0; }
  .page { padding: 16px; }
  #premades { grid-template-columns: 1fr; }
  .rollreq { flex-direction: column; align-items: stretch; }
  .rollreq .btns button { flex: 1; padding: 10px; }
  #tip { max-width: calc(100vw - 24px); }
}

.join-error { color: #f0a090; font-size: 13px; margin: -4px 0 10px; }
#invite { font-size: 12px; padding: 2px 10px; border-color: var(--gold); color: var(--gold); }
.toast.ok { background: #3f6a33; }

/* The /debug table's ribbon (web/debug.js). */
#debug-ribbon { position: fixed; left: 10px; bottom: 10px; z-index: 200; font: 600 11px var(--sans); letter-spacing: .04em;
  color: #1a1400; background: #e8c547; border-radius: 6px; padding: 4px 8px; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
#debug-ribbon button { font: 600 11px var(--sans); margin-left: 4px; padding: 1px 8px; border-radius: 4px; border: 1px solid #1a1400; background: transparent; color: #1a1400; cursor: pointer; }

/* The UI comparison switcher (web/theme.js). Goes once Bill picks a theme. */
#theme-switch { position: fixed; left: 50%; top: 6px; transform: translateX(-50%); z-index: 200; font: 12px var(--sans); color: var(--dim);
  background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.15); border-radius: 8px; padding: 4px 8px; backdrop-filter: blur(4px); }
#theme-switch select { font: 12px var(--sans); background: transparent; color: #eee; border: none; outline: none; cursor: pointer; }
#theme-switch option { background: #222; color: #eee; }
@media (max-width: 860px) { #theme-switch { left: auto; right: 4px; top: 4px; transform: none; padding: 1px 4px; } #theme-switch select { max-width: 96px; } }
