:root{
  color-scheme: dark;
  --bg:#02030a;
  --panel:#0d1119;
  --panel-hi:#141926;
  --slot:#0a0d15;
  --frame:#171d28;
  --frame-2:#222c3b;
  --dock-side:#010206;
  --stone:#10141f;
  --stone-dark:#0a0d15;
  --gold:#a8914a;
  --gold-hi:#cbb780;
  --gold-lo:#6f6132;
  --text:#c3c8d2;
  --text-dim:#7e8795;
  --shadow:#020309;
  --rar-common:#b7bdc8;
  --rar-uncommon:#8fce6a;
  --rar-rare:#6ea8dc;
  --rar-veryrare:#b478d6;
  --rar-legendary:#e0a55a;
  --moss:#6f8f5a;
  --moss-hi:#7fbf5f;
  --ink:#3b2b16;
  --ink-dim:#6b5432;
  --font-display:"Cinzel Decorative","Cinzel",Georgia,serif;
  --font-head:"Cinzel","Times New Roman",serif;
  --font-body:"IM Fell English",Georgia,serif;
}
*{box-sizing:border-box;}
html,body{height:100%; overflow:hidden; overscroll-behavior:none;}
body{
  margin:0; font-family:var(--font-body); font-size:16px; color:var(--text);
  background-color:var(--bg);
  -webkit-overflow-scrolling:touch;
  -webkit-user-select:none; user-select:none; -webkit-touch-callout:none;
}
input, textarea, [contenteditable="true"]{
  -webkit-user-select:text; user-select:text; -webkit-touch-callout:default;
}
button{font-family:inherit; color:inherit; cursor:pointer;}
input,textarea,select{font-family:inherit; color:var(--text); background:var(--slot); border:1px solid var(--frame-2); border-radius:4px;}
input:focus,textarea:focus,select:focus{outline:2px solid var(--gold-lo); outline-offset:1px;}
:focus-visible{outline:2px solid var(--gold-hi); outline-offset:2px;}

#app{height:100%; height:100dvh; display:flex; flex-direction:column; position:relative; overflow:hidden;}

/* inner scroll regions scroll independently, never chain to the page */
.sidebar, .roll-log, .sheet-body, .win-body, .dice-status{
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
}

/* ---------- top bar ---------- */
.topbar{
  flex:none; display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap;
  padding:3px 10px; margin:0 0 3px;
  background:linear-gradient(180deg, var(--panel-hi), var(--panel));
  border:1px solid var(--frame-2); border-radius:5px;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.05), inset 0 -1px 0 rgba(0,0,0,.4), 0 1px 3px rgba(0,0,0,.3);
}
.tb-item{font-family:var(--font-head); font-size:11.5px; letter-spacing:.04em; color:var(--text-dim); white-space:nowrap;}
.tb-item b{color:var(--gold-hi); font-weight:700;}
.tb-item .when{color:var(--gold); text-transform:capitalize;}
.coin-icon{width:14px; height:14px; border-radius:50%; display:inline-block; vertical-align:-2px; margin-right:4px; box-shadow:inset 0 0 0 1px rgba(0,0,0,.45), 0 1px 2px rgba(0,0,0,.4);}
.coin-icon.pp{background:radial-gradient(circle at 35% 30%, #f0f4f8, #b8c2cc 60%, #7e8892);}
.coin-icon.gp{background:radial-gradient(circle at 35% 30%, #e0be6a, #9a7228 60%, #6a4e18);}
.coin-icon.ep{background:radial-gradient(circle at 35% 30%, #f2e8c0, #c6b87e 60%, #8a7a4e);}
.coin-icon.sp{background:radial-gradient(circle at 35% 30%, #f0f0f6, #a8a8b8 60%, #6c6c7c);}
.coin-icon.cp{background:radial-gradient(circle at 35% 30%, #e0a06a, #a06030 60%, #6a3a1c);}
.coin-bit{display:inline-flex; align-items:center; gap:3px; margin-right:7px;}
.coin-bit:last-child{margin-right:0;}
.coins{display:grid; grid-template-columns:repeat(5, 1fr); gap:6px;}
.coin-cell{display:flex; flex-direction:column; align-items:center; gap:3px; padding:6px 4px; border:1px solid var(--frame-2); border-radius:5px; background:var(--slot); min-width:0;}
.coin-cell .coin-icon{margin-right:0;}
.coin-abbr{font-family:var(--font-head); font-size:9px; letter-spacing:.08em; color:var(--text-dim);}
.coin-total-v{font-family:var(--font-head); font-weight:700; font-variant-numeric:tabular-nums; font-size:15px; color:var(--gold-hi);}
.coin-carried-wrap{font-family:var(--font-head); font-variant-numeric:tabular-nums; font-size:11px; color:var(--text-dim);}
.coin-carried-wrap input{width:3ch; min-width:0; text-align:center; font-size:11px; padding:0;}
.coin-cell b{font-size:14px;}
.corner{position:fixed; z-index:9500; width:26px; height:26px; color:var(--gold); pointer-events:none; opacity:.9;}
.corner svg{display:block;}
.c-tl{top:5px; left:5px;}
.c-tr{top:5px; right:5px; transform:rotate(90deg);}
.c-br{bottom:5px; right:5px; transform:rotate(180deg);}
.c-bl{bottom:5px; left:5px; transform:rotate(270deg);}

/* ---------- main ---------- */
.main{flex:1; min-height:0; display:flex;}

/* ---------- right bar (party portraits) ---------- */
.sidebar{
  width:142px; flex:none; display:flex; flex-direction:column; align-items:stretch; gap:5px; padding:5px 4px;
  background-color:#0c1018;
  background-image:
    radial-gradient(300px 200px at 50% 0%, rgba(255,255,255,.03), transparent 70%),
    repeating-linear-gradient(92deg, rgba(0,0,0,.16) 0 2px, transparent 2px 90px);
  border:1px solid var(--frame-2);
  box-shadow:inset 1px 1px 0 rgba(255,255,255,.03), inset 0 0 18px rgba(0,0,0,.65);
  overflow-y:auto; scrollbar-width:thin; scrollbar-color:#1c2331 transparent;
}
.pmate{display:flex; flex-direction:row; justify-content:center; align-items:stretch; padding:0; background:none; border:0; cursor:pointer; width:100%; min-height:132px;}
.pmate.hidden{opacity:.38; filter:grayscale(.6);}
.pm-hpwrap{position:relative; width:9px; flex:none; background:#04060b; box-shadow:inset 0 0 4px #000;}
.pm-hpwrap i{position:absolute; left:0; right:0; bottom:0; background:linear-gradient(0deg,#6d1f16,#c0452f);}
.pm-frame{position:relative; width:126px; height:156px; flex:none; border:2px solid #141a26; background:#04060b; box-shadow:inset 0 0 8px rgba(0,0,0,.7); overflow:hidden;}
.pmate:hover .pm-frame{border-color:var(--frame-2);}
.pmate.sel .pm-frame{border-color:var(--moss-hi); box-shadow:inset 0 0 6px rgba(0,0,0,.6), 0 0 10px rgba(127,191,95,.5);}
.pm-frame img{display:block; width:100%; height:100%; object-fit:cover;}
.pm-frame::after{content:""; position:absolute; inset:0; box-shadow:inset 0 0 14px rgba(0,0,0,.6); pointer-events:none;}
.pm-frame.wound-low::after{background:radial-gradient(ellipse at center, transparent 55%, rgba(120,8,8,.65) 100%);}
.pm-frame.wound-mid::after{background:radial-gradient(ellipse at center, transparent 40%, rgba(165,4,4,.85) 100%);}
.pm-frame.wound-high::after{background:radial-gradient(ellipse at center, transparent 24%, rgba(200,0,0,.96) 100%);}
.pm-name{position:absolute; left:0; right:0; bottom:0; z-index:1; padding:3px 4px; font-family:var(--font-head); font-weight:600; font-size:9.5px; letter-spacing:.02em; color:#e8d9b0; text-align:center; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; background:linear-gradient(0deg, rgba(0,0,0,.88), rgba(0,0,0,0)); pointer-events:none;}
.pm-ko{position:absolute; top:4px; left:4px; z-index:2; width:20px; height:20px; display:grid; place-items:center; color:#fff; background:rgba(120,0,0,.92); border:1px solid rgba(255,255,255,.3); border-radius:50%; box-shadow:0 1px 3px rgba(0,0,0,.6); pointer-events:none;}
.pm-ko svg{width:14px; height:14px; display:block;}

/* ---------- table (game view) ---------- */
.table{flex:1; min-width:0; display:flex; flex-direction:column; padding:6px; position:relative;}
.game-window{
  flex:1; min-width:0; position:relative; overflow:hidden;
  background-color:#07111e;
  background-image:
    radial-gradient(ellipse at 50% 38%, #0e2036, #081728 70%, #040a14 100%),
    repeating-linear-gradient(0deg, rgba(255,255,255,.02) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, rgba(0,0,0,.03) 0 1px, transparent 1px 4px);
  border:1px solid #000;
  box-shadow:inset 0 0 0 3px #020309, inset 0 0 0 4px var(--frame), inset 0 0 0 5px var(--frame-2), inset 0 0 0 6px #020309, inset 0 0 70px rgba(0,0,0,.6), 0 4px 16px rgba(0,0,0,.6);
}
.game-window canvas{position:absolute; inset:0; width:100%; height:100%; display:block;}
.gcorner{position:absolute; z-index:1; width:20px; height:20px; color:var(--gold); opacity:.85; pointer-events:none;}
.gcorner svg{display:block;}
.gc-tl{top:7px; left:7px;}
.gc-tr{top:7px; right:7px; transform:rotate(90deg);}
.gc-br{bottom:7px; right:7px; transform:rotate(180deg);}
.gc-bl{bottom:7px; left:7px; transform:rotate(270deg);}
.rivet{position:absolute; z-index:1; width:7px; height:7px; border-radius:50%; pointer-events:none;
  background:radial-gradient(circle at 35% 30%, #d9b56a, #6b4d1c); box-shadow:0 1px 2px #000, inset 0 -1px 1px rgba(0,0,0,.6);}
.r-tl{top:10px; left:10px;} .r-tr{top:10px; right:10px;} .r-br{bottom:10px; right:10px;} .r-bl{bottom:10px; left:10px;}

.roll-log{
  position:absolute; left:10px; bottom:10px; z-index:2; width:min(400px, calc(100% - 20px));
  max-height:220px; overflow-y:auto; display:flex; flex-direction:column; gap:3px; padding:8px 10px;
  background:linear-gradient(180deg, rgba(4,6,11,.9), rgba(4,6,11,.62));
  border:1px solid var(--frame-2); border-radius:6px; pointer-events:auto; cursor:pointer;
  font-size:13.5px; line-height:1.4;
}
.roll-log.collapsed{max-height:88px; overflow:hidden;}
.roll-log:empty{display:none;}
.rl{color:var(--text); text-shadow:0 1px 2px rgba(0,0,0,.7);}
.rl .who{font-family:var(--font-head); font-weight:700; color:var(--gold);}
.rl .lbl{color:var(--gold-hi);}
.rl .tot{font-family:var(--font-head); font-weight:700; color:#fff;}
.rl .dice{color:var(--text-dim); font-style:italic;}
.rl.sys{font-style:italic; color:var(--text-dim); font-size:12.5px;}
.rl.hidden{border-left:2px solid #a03a2e; padding-left:6px;}

/* ---------- dock ---------- */
.dock{flex:none; display:flex; justify-content:center; align-items:center; background:var(--dock-side); border-top:1px solid var(--frame-2); padding:8px 0 10px;}
.dock-center{display:flex; gap:18px; padding:6px 16px 8px; background:#080b12; border:1px solid var(--frame); border-radius:8px; box-shadow:inset 1px 1px 0 rgba(255,255,255,.04), 0 2px 10px rgba(0,0,0,.6);}
.dock-btn{display:grid; place-items:center; width:52px; height:52px; border-radius:8px; padding:0; background:none; border:0;}
.dock-btn .gem{width:52px; height:52px; border-radius:8px; display:grid; place-items:center; background:linear-gradient(180deg, #141a26, #0a0d15 46%, #06080d); border:1px solid #171d28; color:var(--gold-lo); box-shadow:inset 1px 1px 0 rgba(255,255,255,.12), inset -1px -1px 0 rgba(0,0,0,.55), inset 0 0 0 1px #020309, 0 2px 3px rgba(0,0,0,.7), 0 5px 11px rgba(0,0,0,.35);}
.dock-btn:hover .gem{border-color:var(--gold-lo); color:var(--gold);}
.dock-btn.lit .gem{border-color:var(--gold); color:var(--gold-hi);}

/* ---------- dice popover ---------- */
.dice-pop{position:fixed; z-index:8500; width:min(470px, calc(100vw - 24px)); padding:14px; background:var(--stone); border:1px solid var(--frame-2); box-shadow:inset 0 0 0 2px var(--bg), inset 0 0 0 3px var(--frame), 0 14px 34px rgba(0,0,0,.8);}
.dice-pop[hidden]{display:none !important;}
.dice-row{display:flex; gap:8px; flex-wrap:wrap;}
.die-btn{width:52px; aspect-ratio:1; border-radius:10px; color:var(--gold); font-family:var(--font-head); font-weight:700; font-size:14px; border:1px solid #171d28; background:#070a10; box-shadow:inset 1px 1px 0 rgba(255,255,255,.04), inset 0 0 8px rgba(0,0,0,.7), 0 2px 5px rgba(0,0,0,.55);}
.die-btn.sel{border-color:var(--gold); color:var(--gold-hi); box-shadow:0 0 12px rgba(168,133,60,.3);}
.dice-ctrl{display:flex; align-items:center; gap:12px; flex-wrap:wrap; margin-top:12px;}
.stepper{display:flex; align-items:center; gap:4px; border:1px solid #171d28; background:#05070c; padding:4px 6px; border-radius:4px;}
.stepper button{width:26px; height:26px; border:1px solid #171d28; background:#04060b; color:var(--gold); font-family:var(--font-head); font-weight:700; font-size:14px; border-radius:3px;}
.stepper .stv{min-width:26px; text-align:center; font-family:var(--font-head); font-weight:700; color:var(--gold-hi); font-variant-numeric:tabular-nums;}
.stepper .stl{font-family:var(--font-head); font-size:9px; letter-spacing:.1em; text-transform:uppercase; color:var(--text-dim); padding-right:5px;}
.roll-btn{padding:10px 22px; font-family:var(--font-head); font-weight:700; font-size:13px; letter-spacing:.12em; text-transform:uppercase; color:#f0e0b0; border-radius:6px; background:linear-gradient(180deg,#5c4217,#33270c 60%,#231a08); border:1px solid var(--gold); box-shadow:inset 0 1px 0 rgba(238,217,160,.5), 0 3px 9px rgba(0,0,0,.5);}
.dice-status{font-style:italic; font-size:12px; color:var(--text-dim); text-align:center; padding-top:8px;}
.hidden-roll{display:flex; align-items:center; gap:6px; margin-top:8px; font-family:var(--font-head); font-size:11px; color:var(--text-dim);}
.hidden-roll input{width:15px; height:15px;}

/* paper / parchment panels (spellbook, notes, background) */
.paper{
  color:var(--ink); padding:16px 18px; font-family:var(--font-body); font-size:15px; line-height:1.6;
  background:
    repeating-linear-gradient(0deg, rgba(120,84,40,.05) 0 1px, transparent 1px 26px),
    radial-gradient(ellipse at 50% 20%, rgba(255,244,214,.55), transparent 70%),
    linear-gradient(160deg,#ecdbae,#e1c892 55%,#d3b37c);
  border:1px solid #8a6a3a; border-radius:3px;
  box-shadow:inset 0 0 40px rgba(96,64,26,.35), 0 3px 10px rgba(0,0,0,.4);
}
textarea.paper{width:100%; resize:vertical; min-height:110px;}
div.paper{white-space:pre-wrap;}
textarea.paper:focus{outline:2px solid rgba(122,74,31,.5);}
.field-val{display:block; min-height:1.1em;}
.scorner{position:absolute; z-index:2; width:20px; height:20px; color:var(--gold); opacity:.85; pointer-events:none;}
.scorner svg{display:block;}
.sc-tl{top:6px; left:6px;}
.sc-tr{top:6px; right:6px; transform:rotate(90deg);}
.sc-br{bottom:6px; right:6px; transform:rotate(180deg);}
.sc-bl{bottom:6px; left:6px; transform:rotate(270deg);}

/* hide native number-input spin buttons */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button{ -webkit-appearance:none; margin:0; }
input[type=number]{ -moz-appearance:textfield; appearance:textfield; }

/* ---------- sheet overlay ---------- */
.sheet-overlay{position:fixed; inset:0; z-index:9000; background:rgba(0,0,0,.6); display:grid; place-items:center; padding:16px;}
.sheet-overlay[hidden]{display:none !important;}
.sheet{
  position:relative; width:min(680px, 100%); max-height:92vh; display:flex; flex-direction:column; overflow:hidden;
  background-color:var(--stone);
  background-image:
    radial-gradient(420px 280px at 28% 0%, rgba(255,255,255,.04), transparent 65%),
    radial-gradient(500px 420px at 90% 110%, rgba(0,0,0,.5), transparent 60%),
    repeating-linear-gradient(93deg, rgba(0,0,0,.15) 0 2px, transparent 2px 90px);
  border:1px solid var(--frame-2);
  box-shadow:inset 1px 1px 0 rgba(255,255,255,.04), inset -1px -1px 0 rgba(0,0,0,.6), inset 0 0 0 2px var(--bg), inset 0 0 0 3px var(--frame), 0 18px 46px rgba(0,0,0,.8);
}
.sheet::before{content:""; position:absolute; inset:8px; border:1px solid rgba(201,164,76,.13); pointer-events:none; z-index:0;}
.sheet-head{
  position:relative; z-index:1; flex:none; display:flex; align-items:center; gap:12px; padding:8px 10px;
  background:linear-gradient(180deg, #0e121c, #06080d);
  border-bottom:1px solid var(--frame-2);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.04), inset 0 -1px 0 rgba(0,0,0,.55);
}
.sh-portrait{width:60px; height:66px; border:1px solid var(--frame-2); background:#04060b; overflow:hidden; border-radius:4px; flex:none;}
.sh-portrait img{width:100%; height:100%; object-fit:cover; display:block;}
.sh-portrait.editable{cursor:pointer; position:relative;}
.sh-portrait.editable:hover{outline:1px solid var(--gold);}
.sh-portrait-add{display:flex; align-items:center; justify-content:center; width:100%; height:100%; color:var(--text-dim); font-size:26px; line-height:1;}
.sh-portrait.editable:hover .sh-portrait-add{color:var(--gold-hi);}
.sh-id{min-width:0; flex:1;}
.sh-name{font-family:var(--font-display); font-weight:700; font-size:21px; letter-spacing:.06em; color:var(--gold-hi); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.sh-sub{font-family:var(--font-head); font-size:13px; letter-spacing:.06em; color:var(--text-dim); text-transform:capitalize; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.sh-stats{display:flex; gap:12px; flex:none; flex-wrap:wrap;}
.sh-stat{font-family:var(--font-head); font-size:11px; color:var(--text-dim); text-align:center;}
.sh-stat b{display:block; font-size:14px; color:var(--text);}
.sh-stat input{width:52px; text-align:center; font-family:var(--font-head); font-size:13px; color:var(--gold-hi);}
.hp-btns{display:flex; gap:2px; margin-top:3px; justify-content:center;}
.hp-btns button{width:20px; height:20px; padding:0; line-height:1; background:var(--slot); border:1px solid var(--frame-2); color:var(--gold); font-size:12px; border-radius:3px;}
.sh-close{flex:none; width:26px; height:26px; background:var(--slot); border:1px solid var(--frame-2); color:var(--gold-lo); font-family:var(--font-head); font-size:14px; border-radius:4px;}

.sheet-tabs{flex:none; display:flex; gap:4px; padding:6px 10px; background:var(--slot); border-bottom:1px solid var(--frame-2);}
.tab{padding:6px 14px; font-family:var(--font-head); font-weight:600; font-size:11.5px; letter-spacing:.08em; text-transform:uppercase; color:var(--text-dim); background:none; border:1px solid transparent; border-radius:4px;}
.tab.sel{color:var(--gold-hi); border-color:var(--gold-lo); background:rgba(168,133,60,.08);}

.sheet-body{flex:1; min-height:0; overflow-y:auto; padding:10px 12px 48px;}
.sec{margin:0 0 5px; font-family:var(--font-head); font-weight:600; font-size:11px; letter-spacing:.16em; text-transform:uppercase; color:var(--text-dim);}

/* character sheet stat rows */
.cv-row{display:flex; align-items:baseline; gap:18px; margin:8px 0;}
.cv-l{flex:none; min-width:76px; font-family:var(--font-head); font-weight:700; font-size:12px; letter-spacing:.16em; text-transform:uppercase; color:var(--gold);}
.cv-v{font-family:var(--font-head); font-size:19px; color:var(--text); font-variant-numeric:tabular-nums; letter-spacing:.02em;}
.cv-v input{font-family:var(--font-head); font-size:19px; color:var(--gold-hi);}
.xp-sep{color:var(--text-dim); font-size:16px; font-weight:400;}
.cv-btns{display:inline-flex; gap:4px; margin-left:2px;}

/* HP readout + stepper */
.hp-line{align-items:center; gap:14px;}
.hp-btn{flex:none; width:40px; height:40px; display:grid; place-items:center; font-family:var(--font-head); font-size:22px; line-height:1; color:var(--gold-hi); background:var(--panel-hi); border:1px solid var(--gold-lo); border-radius:7px; cursor:pointer;}
.hp-btn:hover, .hp-btn:active{border-color:var(--gold); background:var(--panel);}
.hp-val{display:inline-flex; align-items:baseline; gap:8px; font-family:var(--font-head); font-variant-numeric:tabular-nums; font-size:30px; color:var(--text);}
.hp-cur{color:var(--gold-hi); font-weight:700;}
.hp-sep{color:var(--text-dim); font-size:20px; font-weight:600;}
.hp-max{color:var(--text); font-size:22px;}
#sheet .hp-in, .win .hp-in{width:2ch; min-width:2ch; padding:0; text-align:center; font-family:var(--font-head); font-variant-numeric:tabular-nums; font-weight:700; font-size:30px; color:var(--gold-hi); background:transparent; border:none; box-shadow:none;}
#sheet .hp-in.hp-max, .win .hp-in.hp-max{font-size:22px; font-weight:400; color:var(--text);}

/* boxed ability scores */
.ab-grid{display:grid; grid-template-columns:repeat(6, 1fr); gap:8px; margin:8px 0 2px;}
.ab-box{position:relative; border:1px solid var(--frame-2); border-radius:6px; padding:8px 2px 7px; text-align:center;
  background:linear-gradient(180deg, #0c1119, #06080d);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.05), inset 0 -1px 0 rgba(0,0,0,.6), 0 2px 6px rgba(0,0,0,.45);}
.ab-k{display:block; font-family:var(--font-head); font-weight:600; font-size:9px; letter-spacing:.14em; color:var(--text-dim); text-transform:uppercase;}
.ab-v{display:block; font-family:var(--font-display); font-weight:700; font-size:24px; line-height:1; color:var(--gold-hi); margin-top:3px;}
#sheet .ab-box input.ab-v, .win .ab-box input.ab-v{width:100%; text-align:center; font-family:var(--font-display); font-weight:700; font-size:24px; line-height:1; color:var(--gold-hi);}

/* to-hit row */
.th-table{border-collapse:collapse; margin-bottom:16px; width:100%; table-layout:fixed;}
.th-table th, .th-table td{border:1px solid var(--frame-2); padding:5px 2px; text-align:center; font-family:var(--font-head);}
.th-table th{color:var(--text-dim); font-weight:600; font-size:10px; letter-spacing:.05em; text-transform:uppercase; background:var(--slot); white-space:normal; word-break:break-word;}
.th-table td{color:var(--text); font-size:14px; min-width:0;}
.th-table tr:first-child td{color:var(--text-dim); font-weight:600; font-size:12px;}
.th-table tr:nth-child(2) td{color:var(--gold-hi); font-weight:700; font-size:17px; background:rgba(168,133,60,.06);}
.th-table th:first-child{width:56px;}
.th-table input{width:100%; text-align:center; font-family:var(--font-head); font-size:16px; color:var(--gold-hi); font-weight:700;}

/* sheet fields are bare: no boxes, even when editing */
#sheet input:not(.paper), #sheet select:not(.paper), #sheet textarea:not(.paper),
.win input:not(.paper), .win select:not(.paper), .win textarea:not(.paper){
  background:transparent; border:none; box-shadow:none; color:var(--text); padding:0;
}

/* tables */
.tbl{width:100%; border-collapse:collapse; margin-bottom:14px;}
.tbl th{font-family:var(--font-head); font-weight:600; font-size:10px; letter-spacing:.08em; text-transform:uppercase; color:var(--text-dim); text-align:left; padding:3px 6px; border-bottom:1px solid var(--frame-2);}
.tbl td{padding:4px 7px; border-bottom:1px solid var(--frame); font-size:13.5px; vertical-align:top; line-height:1.45;}
.tbl input,.tbl select,.tbl textarea{width:100%; padding:3px 5px; font-size:13px;}
.tbl textarea{min-height:34px; resize:vertical;}
.save-tbl td:first-child, .item-tbl td:first-child{font-family:var(--font-head); font-weight:600; color:var(--text);}
.save-tbl td:nth-child(2){color:var(--gold-hi); font-weight:700;}
.num{width:64px !important; text-align:right !important; font-variant-numeric:tabular-nums;}
.wid{width:70px !important;}
.row-actions{display:flex; gap:4px; flex-wrap:wrap;}
.rolls{white-space:nowrap;}
.rolls .mini-btn{margin-right:4px;}
.mini-btn{padding:3px 8px; font-family:var(--font-head); font-weight:600; font-size:10.5px; letter-spacing:.05em; color:var(--gold-hi); background:var(--panel-hi); border:1px solid var(--gold-lo); border-radius:4px;}
.mini-btn:hover{border-color:var(--gold);}
.mini-btn.danger{color:#e6e8ee; border-color:#8a93a3; background:rgba(255,255,255,.06);}

/* spells */
.spell-cast{display:flex; align-items:center; gap:8px;}
.spell-cast input{width:16px; height:16px;}
.cons-row{display:flex; align-items:center; gap:10px; padding:8px 8px; border-radius:5px; margin-bottom:3px;}
.cons-row:hover{background:rgba(255,255,255,.03);}
.cons-name{flex:1; min-width:0; font-size:17px; color:var(--text);}
.cons-qty{min-width:30px; text-align:center; font-family:var(--font-head); font-variant-numeric:tabular-nums; font-weight:700; font-size:16px; color:var(--gold-hi);}

/* containers & holdings */
.tbl-scroll{overflow-x:auto; -webkit-overflow-scrolling:touch;}
.cont-load{font-family:var(--font-head); font-variant-numeric:tabular-nums; font-size:12px; color:var(--text-dim); white-space:nowrap;}
.cont-load.over{color:#e08a7a;}
.add-spacer{margin-top:18px;}

/* hierarchical inventory: carried + container headings */
.inv-sec{margin-top:26px;}
.sec-row{display:flex; align-items:center; justify-content:space-between; gap:8px; margin-bottom:12px;}
.sec-row .sec{margin:0;}
.add-inline{width:24px; height:24px; display:inline-grid; place-items:center; padding:0; font-family:var(--font-head); font-weight:700; font-size:18px; line-height:1; color:var(--gold-hi); background:transparent; border:1px solid var(--gold-lo); border-radius:5px; cursor:pointer;}
.add-inline:hover{border-color:var(--gold); background:var(--panel-hi);}
.holdings-sec{margin-top:40px;}

/* mobile keyboard: give the sheet the full height */
body.kbd-open .dock{display:none !important;}
body.kbd-open .sidebar{display:none !important;}
.inv-item{display:flex; align-items:center; gap:10px; padding:8px 8px; border-radius:5px; margin-bottom:3px; font-size:17px; -webkit-user-select:none; user-select:none; -webkit-touch-callout:none; touch-action:pan-y;}
.inv-item:hover{background:rgba(255,255,255,.03);}
.inv-item .inv-name{flex:1; min-width:0; font-size:17px; color:var(--text);}
.inv-item .inv-count{flex:none; width:46px; text-align:center; font-family:var(--font-head); font-variant-numeric:tabular-nums; font-size:16px; color:var(--text);}
.inv-item .inv-weight{flex:none; width:66px; text-align:right; font-family:var(--font-head); font-variant-numeric:tabular-nums; font-size:16px; color:var(--text-dim); white-space:nowrap;}
.inv-item.dropped .inv-name{color:var(--text-dim); font-style:italic;}

/* edit mode for item rows and container/holding headings */
#sheet .inv-item.editing input, .win .inv-item.editing input,
#sheet .inv-cont-head.editing input, .win .inv-cont-head.editing input{background:var(--slot); border:1px solid var(--frame-2); border-radius:3px; padding:2px 4px; color:var(--text); box-shadow:none; font-size:16px;}
#sheet .inv-item.editing input:focus, .win .inv-item.editing input:focus,
#sheet .inv-cont-head.editing input:focus, .win .inv-cont-head.editing input:focus{border-color:var(--gold-lo); outline:none;}
.inv-item.editing .inv-name, .inv-cont-head.editing .inv-head-name{flex:1; min-width:0;}
.inv-item.editing .inv-count{width:46px; text-align:center; font-family:var(--font-head); font-variant-numeric:tabular-nums;}
.inv-item.editing .inv-weight-num{width:50px; min-width:0; text-align:right; font-family:var(--font-head); font-variant-numeric:tabular-nums;}
.inv-cont-head.editing .inv-head-cap{width:6ch; min-width:0; text-align:center; font-family:var(--font-head); font-variant-numeric:tabular-nums;}
.edit-actions{flex:none; display:inline-flex; gap:4px;}
.edit-ok, .edit-cancel{width:26px; height:26px; display:inline-grid; place-items:center; padding:0; font-size:15px; line-height:1; border-radius:4px; cursor:pointer; background:var(--panel-hi); border:1px solid var(--frame-2);}
.edit-ok{color:#7ec98a; border-color:#3f7d4e;}
.edit-cancel{color:#e08a7a; border-color:#7d3f3f;}
.cont-chev{flex:none; width:14px; text-align:center; color:var(--text-dim); font-size:14px;}
.inv-cont-head{display:flex; align-items:center; gap:8px; margin:18px 0 4px; padding:6px 8px; background:linear-gradient(180deg, var(--panel-hi), var(--panel)); border:1px solid var(--frame-2); border-radius:6px;}
.inv-head-body{flex:1; min-width:0; display:flex; align-items:baseline; gap:8px; -webkit-user-select:none; user-select:none; -webkit-touch-callout:none; touch-action:pan-y;}
.inv-head-body .inv-head-name{font-family:var(--font-display); font-weight:700; font-size:14px; letter-spacing:.04em; color:var(--gold-hi);}
.inv-head-body input.inv-head-name{width:auto; min-width:60px; max-width:160px; font-family:var(--font-display); font-weight:700; font-size:14px; color:var(--gold-hi);}
.inv-cont-items{margin-left:12px; border-left:1px solid var(--frame-2); padding-left:6px;}

/* encumbrance */
.enc-line{font-family:var(--font-head); font-size:13px; color:var(--text); margin:4px 0;}
.enc-line b{color:var(--gold-hi);}

/* dm panel */
.dm-panel{position:fixed; right:12px; top:52px; z-index:8600; width:min(360px, calc(100vw - 24px)); max-height:80vh; overflow-y:auto; background:var(--stone); border:1px solid var(--frame-2); box-shadow:inset 0 0 0 2px var(--bg), 0 14px 34px rgba(0,0,0,.8); padding:12px;}
.dm-panel[hidden]{display:none !important;}
.dm-menu{position:fixed; z-index:9000; min-width:170px; background:var(--stone); border:1px solid var(--frame-2); box-shadow:inset 0 0 0 2px var(--bg), 0 10px 28px rgba(0,0,0,.8); padding:4px;}
.dm-menu-item{display:block; width:100%; text-align:left; padding:8px 10px; font-family:var(--font-head); font-weight:600; font-size:12px; letter-spacing:.06em; color:var(--gold-hi); background:transparent; border:none; border-radius:3px; cursor:pointer;}
.dm-menu-item:hover{background:var(--panel-hi); color:var(--gold);}
#win-journal .win-body, .sheet-body.journal-body{
  background:
    repeating-linear-gradient(0deg, rgba(120,84,40,.05) 0 1px, transparent 1px 26px),
    radial-gradient(ellipse at 50% 20%, rgba(255,244,214,.55), transparent 70%),
    linear-gradient(160deg,#ecdbae,#e1c892 55%,#d3b37c);
  color:var(--ink);
  display:flex;
  flex-direction:column;
}
.journal-notepad{
  flex:1 1 auto;
  width:100%;
  min-height:340px;
  resize:vertical;
  padding:16px 18px !important;
  background:transparent;
  border:none;
  outline:none;
  color:var(--ink) !important;
  font-family:var(--font-body);
  font-size:18px;
  line-height:1.6;
  white-space:pre-wrap;
  overflow-wrap:break-word;
}
@media (max-width:760px){
  .journal-notepad{font-size:20px; line-height:1.55;}
}
.inv-encumbrance{display:flex; align-items:baseline; gap:8px; margin-top:16px; font-family:var(--font-head); font-size:12.5px; letter-spacing:.04em; color:var(--text-dim);}
.inv-encumbrance b{color:var(--gold-hi); font-size:14px; font-variant-numeric:tabular-nums;}
.inv-encumbrance .enc-label{color:var(--text-dim); font-size:11px; font-style:italic;}
.inv-divider{height:1px; margin:10px 0 14px; background:linear-gradient(90deg, transparent, var(--gold-lo) 20%, var(--gold-lo) 80%, transparent); opacity:.55;}
.dm-row{display:flex; gap:6px; align-items:center; flex-wrap:wrap; margin-bottom:8px;}
.dm-row input{flex:1; min-width:80px; padding:4px 6px; font-size:12.5px;}
.dm-row label{font-family:var(--font-head); font-size:11px; color:var(--text-dim);}
.grave{display:flex; align-items:center; gap:8px; padding:5px 6px; border:1px solid var(--frame); border-radius:4px; margin-bottom:5px; font-size:12.5px;}
.grave .g{flex:1; min-width:0;}
.grave b{font-family:var(--font-head); color:var(--gold-hi);}
.gravy{display:flex; align-items:center; gap:8px; padding:5px 6px; border:1px solid var(--frame); border-radius:4px; margin-bottom:5px; font-size:12.5px;}
.gravy .g{flex:1; min-width:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.gravy b{font-family:var(--font-head); color:var(--gold-hi);}
.gravy .mini-btn{flex:none;}
.grave input.dm-name{display:block; width:100%; min-width:0; padding:2px 4px; margin:-1px 0 3px; font-family:var(--font-head); font-weight:600; font-size:12.5px; color:var(--gold-hi); background:transparent; border:1px solid transparent; border-radius:3px;}
.grave input.dm-name:hover, .grave input.dm-name:focus{border-color:var(--frame); background:var(--panel-hi);}
.grave input.dm-class{display:block; width:100%; min-width:0; padding:2px 4px; margin:0 0 3px; font-family:var(--font-head); font-size:12px; color:var(--text); background:transparent; border:1px solid transparent; border-radius:3px;}
.grave input.dm-class:hover, .grave input.dm-class:focus{border-color:var(--frame); background:var(--panel-hi);}
.grave select.dm-owner{padding:2px 4px; font-size:11px; max-width:130px; background:var(--panel-hi); color:var(--text); border:1px solid var(--frame); border-radius:3px;}
.grave .gm{color:var(--text-dim); font-style:italic; font-size:11.5px; line-height:1.3;}

/* banner */
.banner{position:fixed; top:12px; left:50%; transform:translateX(-50%); z-index:9999; padding:10px 16px; background:#3a1510; border:1px solid #a03a2e; color:#f0d0c0; font-family:var(--font-head); font-size:13px; border-radius:6px; box-shadow:0 8px 22px rgba(0,0,0,.6);}
.banner[hidden]{display:none !important;}

/* create character overlay */
.create-overlay{position:fixed; inset:0; z-index:9600; display:grid; place-items:center; padding:16px; background:rgba(0,0,0,.72);}
.create-overlay[hidden]{display:none !important;}
.create-box{width:min(420px, 100%); display:flex; flex-direction:column; gap:10px; padding:18px; background:var(--stone); border:1px solid var(--frame-2); border-radius:8px; box-shadow:inset 0 0 0 2px var(--bg), inset 0 0 0 3px var(--frame), 0 16px 40px rgba(0,0,0,.8);}
.create-title{font-family:var(--font-display); font-weight:700; font-size:18px; letter-spacing:.06em; color:var(--gold-hi);}
.create-box input{font-size:16px; padding:8px 10px;}
.create-error{min-height:1em; font-family:var(--font-head); font-size:12px; color:#e08a7a;}

.confirm-overlay{position:fixed; inset:0; z-index:9700; display:flex; justify-content:center; overflow-y:auto; padding:16px; background:rgba(0,0,0,.72);}
.confirm-overlay[hidden]{display:none !important;}
.confirm-overlay > .confirm-box{margin:auto 0;}
.confirm-box{width:min(380px, 100%); display:flex; flex-direction:column; gap:14px; padding:18px; background:var(--stone); border:1px solid var(--frame-2); border-radius:8px; box-shadow:inset 0 0 0 2px var(--bg), inset 0 0 0 3px var(--frame), 0 16px 40px rgba(0,0,0,.8);}
.confirm-msg{font-family:var(--font-head); font-size:15px; line-height:1.45; color:var(--text);}
.confirm-btns{display:flex; gap:10px; justify-content:flex-end;}
.confirm-btns .mini-btn{padding:6px 14px; font-size:12px;}
.stash-actions{justify-content:space-between;}
.confirm-ok{color:#fff !important; background:#8a2f2f !important; border-color:#b0534a !important;}
.confirm-box select{font-size:16px; padding:8px 10px; background:var(--panel-hi); color:var(--text); border:1px solid var(--frame-2); border-radius:4px;}
.confirm-box input{font-size:16px; padding:8px 10px; background:var(--panel-hi); color:var(--text); border:1px solid var(--frame-2); border-radius:4px;}

/* stash-coins dialog */
.stash-box{width:min(360px, 100%);}
.stash-rows{display:flex; flex-direction:column; gap:9px;}
.stash-row{display:flex; align-items:center; gap:10px;}
.stash-row .coin-icon{width:20px; height:20px; margin-right:0; flex:none; vertical-align:middle;}
.stash-lbl{width:30px; flex:none; font-family:var(--font-head); font-size:12px; letter-spacing:.08em; color:var(--text-dim);}
.stash-btn{flex:none; width:42px; height:42px; display:grid; place-items:center; padding:0; font-family:var(--font-head); font-size:24px; line-height:1; color:var(--gold-hi); background:var(--panel-hi); border:1px solid var(--gold-lo); border-radius:7px; cursor:pointer;}
.stash-btn:hover{border-color:var(--gold); background:var(--panel);}
.stash-num{flex:1; min-width:0; text-align:center; font-family:var(--font-head); font-variant-numeric:tabular-nums; font-size:20px; padding:8px; background:var(--slot); border:1px solid var(--frame-2); border-radius:5px; color:var(--gold-hi);}
.stash-item .inv-name{color:var(--gold);}

/* long-press context menu */
.ctx-menu{position:fixed; z-index:9800; min-width:190px; padding:5px; background:var(--stone); border:1px solid var(--frame-2); border-radius:6px; box-shadow:inset 0 0 0 2px var(--bg), 0 12px 30px rgba(0,0,0,.8);}
.ctx-menu[hidden]{display:none !important;}
.ctx-item{display:block; width:100%; text-align:left; padding:8px 10px; font-family:var(--font-head); font-size:13px; color:var(--text); background:transparent; border:none; border-radius:3px; cursor:pointer;}
.ctx-item:hover, .ctx-item:focus{background:var(--panel-hi); color:var(--gold-hi);}
.ctx-item.danger{color:#e08a7a;}

/* ---------- windows (draggable, PC) ---------- */
.win{
  position:absolute; z-index:100; display:none; flex-direction:column; min-width:0;
  background-color:var(--stone);
  background-image:
    radial-gradient(420px 280px at 28% 0%, rgba(255,255,255,.04), transparent 65%),
    radial-gradient(500px 420px at 90% 110%, rgba(0,0,0,.5), transparent 60%),
    repeating-linear-gradient(93deg, rgba(0,0,0,.15) 0 2px, transparent 2px 90px);
  border:1px solid var(--frame-2);
  box-shadow:
    inset 1px 1px 0 rgba(255,255,255,.04),
    inset -1px -1px 0 rgba(0,0,0,.6),
    inset 0 0 0 2px var(--bg),
    inset 0 0 0 3px var(--frame),
    0 14px 38px rgba(0,0,0,.85);
  max-width:calc(100% - 8px); max-height:82%;
}
.win.open{display:flex;}
.win-title{
  display:flex; align-items:center; gap:6px; padding:4px 6px 4px 10px; cursor:grab; user-select:none; touch-action:none;
  background:linear-gradient(180deg,#0e121c,#06080d);
  border-bottom:1px solid var(--frame-2);
  box-shadow:inset 0 1px 0 rgba(255,255,255,.04), inset 0 -1px 0 rgba(0,0,0,.55);
}
.win-title:active{cursor:grabbing;}
.wt{flex:1; min-width:0; font-family:var(--font-head); font-weight:600; font-size:11px; letter-spacing:.12em; text-transform:uppercase; color:var(--gold); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.win-x{
  width:20px; height:20px; flex:none; cursor:pointer; display:grid; place-items:center;
  font-family:var(--font-head); font-weight:700; font-size:12px; line-height:1; color:var(--gold-lo);
  background:linear-gradient(180deg,#0b0e16,#06080d); border:1px solid #141a26;
  box-shadow:inset 0 1px 0 rgba(168,133,60,.06);
}
.win-x:hover{color:var(--gold-hi); border-color:var(--gold-lo);}
.win-body{flex:1; min-height:0; overflow:auto; padding:12px 12px 48px; scrollbar-width:thin; scrollbar-color:#1c2331 transparent;}
#win-character{width:600px;}
#win-inventory{width:680px;}
#win-spells{width:560px;}
#win-combat{width:660px;}
#win-dm-players{width:400px;}
#win-dm-characters{width:460px;}
#win-dm-world{width:420px;}
#win-dm-tools{width:340px;}
#win-journal{width:560px;}

@media (max-width:760px){
  .main{flex-direction:column;}
  .table{padding:6px 0;}
  /* top bar: 2×2 grid — coins TL, date TR, food BL, speed BR */
  .topbar{display:grid; grid-template-columns:1fr 1fr; grid-template-areas:"coins date" "food speed"; gap:2px 10px; padding:4px 8px;}
  .tb-coins{grid-area:coins; justify-self:start;}
  .tb-date{grid-area:date; justify-self:end;}
  .tb-food{grid-area:food; justify-self:start;}
  .tb-speed{grid-area:speed; justify-self:end;}
  .tb-clock{display:none;}
  .tb-dm{grid-column:1 / -1; justify-self:end;}
  /* stop iOS auto-zoom on focused fields: keep inputs at 16px+ */
  input, select, textarea{font-size:16px !important;}
  .sidebar{width:100%; flex-direction:row; flex-wrap:wrap; justify-content:center; border-left:none; border-top:1px solid var(--frame-2); padding:5px;}
  .pmate{width:auto; min-height:0;}
  .pm-hpwrap{width:8px;}
  .pm-frame{width:76px; height:88px;}
  .pm-name{font-size:9px;}
  .pm-ko{width:14px; height:14px; top:2px; left:2px;}
  .pm-ko svg{width:10px; height:10px;}
  .sheet-overlay{position:absolute; inset:0; padding:0; background:rgba(0,0,0,.55);}
  .sheet{width:100%; height:100%; max-height:none; border:none; border-radius:0;}
  .sheet-head{flex-wrap:wrap; gap:6px; padding:6px 8px;}
  .sh-portrait{width:64px; height:72px;}
  .sh-name{font-size:19px;}
  .sh-sub{font-size:11.5px;}
  .sh-stats{width:100%; gap:8px; justify-content:space-between;}
  .sheet-tabs{overflow-x:auto; padding:4px 6px;}
  .tab{padding:5px 10px; font-size:10px; white-space:nowrap;}
  .sheet-body{padding:8px 10px 48px;}
  .tbl th, .tbl td{padding:4px 5px;}
  .tbl td{font-size:13px;}
  .th-table th, .th-table td{padding:7px 2px;}
  .th-table th{font-size:8.5px; letter-spacing:.03em;}
  .th-table th:first-child{width:46px;}
  .win{display:none !important;}
  .win.open{display:flex !important;}
  .ab-grid{grid-template-columns:repeat(3, 1fr);}
  .hp-line{gap:12px;}
  .hp-btn{width:46px; height:46px; font-size:24px;}
  .hp-val{font-size:34px;}
  #sheet .hp-in, .win .hp-in{font-size:34px;}
  #sheet .hp-in.hp-max, .win .hp-in.hp-max{font-size:24px;}
}
@media (min-width:761px){
  #sheet-overlay{display:none !important;}
}
