:root {
  --bg: #0e1014;
  --ink: #ede6d6;
  --gold: #e9c46a;
  --accent: #d4a373;
  --danger: #e05d5d;
  --panel: rgba(18, 20, 26, 0.92);
  --border: rgba(212, 163, 115, 0.35);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif; }
canvas#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }

.overlay { position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; overscroll-behavior: contain;                 /* a panel taller than the window must stay reachable — html/body are overflow:hidden, so the overlay scrolls itself. */
  padding: clamp(10px, 2.5vh, 28px) clamp(10px, 3vw, 20px);
  background: radial-gradient(ellipse at center, #1a1d26 0%, #0a0b0f 100%); z-index: 20; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  margin: auto;                                                   /* auto margins centre it when it fits and clamp to the top when it doesn't — align-items:center would make the overflowing top unscrollable. */
  width: 100%; max-width: 360px;
  padding: clamp(18px, 3.4vmin, 32px) clamp(20px, 3.8vmin, 36px); text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.panel h1 { font-family: Georgia, 'Times New Roman', serif; font-size: clamp(1.5rem, 5.2vmin, 2.4rem); letter-spacing: 2px;
  color: var(--gold); margin-bottom: 6px; }
.panel .sub { color: #b9b2a3; margin-bottom: 22px; font-size: .95rem; }
.panel input { width: 100%; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: #0c0e13; color: var(--ink); font-size: 1rem; margin-bottom: 14px; text-align: center; }
.panel input:focus { outline: none; border-color: var(--gold); }
.panel button { width: 100%; padding: 12px; border: none; border-radius: 8px; cursor: pointer;
  background: linear-gradient(180deg, var(--accent), #b07d4f); color: #2a1c0e; font-weight: 700;
  font-size: 1rem; letter-spacing: .5px; transition: filter .15s; }
.panel button:hover { filter: brightness(1.1); }
.panel .hint, #hint { color: #8a8475; font-size: .8rem; margin-top: 16px; }
.panel .hint b { color: var(--gold); }

.classLockNote { color: #cfe3d2; background: rgba(110,200,120,0.10); border: 1px solid rgba(110,200,120,0.35); border-radius: 9px; padding: 8px 11px; margin: 0 0 14px; font-size: .8rem; line-height: 1.45; text-align: left; }
#classPick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
/* #classPick prefix raises specificity above `.panel button`, so class cards render as intended
   (dark, consistent) instead of picking up the tan CTA-button gradient + dark low-contrast text. */
#classPick .classBtn { flex: 1 1 29%; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 9px 5px; border-radius: 10px; cursor: pointer; background: #14171f;
  border: 1px solid var(--border); color: var(--ink); transition: all .15s; font: inherit; width: auto; }
#classPick .classBtn:hover { filter: brightness(1.12); border-color: var(--gold); }
#classPick .classBtn.active { border-color: var(--gold); background: rgba(212, 163, 115, .18); box-shadow: 0 0 0 2px var(--gold) inset; }
.classBtn .cIcon { font-size: 1.7rem; }
.classBtn .cName { font-weight: 700; color: var(--gold); font-size: .95rem; }
.classBtn .cDesc { font-size: .74rem; color: #cdc6b6; line-height: 1.25; }   /* readable in every state (was #9b958a — low-contrast) */

#creator { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; background: #0c0e13;
  border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
#preview { background: radial-gradient(circle at 50% 38%, #2b3140, #14161c); border-radius: 8px; flex: 0 0 auto; }
#creatorRight { flex: 1; display: flex; flex-direction: column; gap: 6px; }
#parts { display: flex; flex-direction: column; gap: 5px; }
.partRow { display: flex; align-items: center; gap: 6px; }
.partRow button { width: 24px; height: 24px; padding: 0; border-radius: 6px; border: 1px solid var(--border);
  background: #15181f; color: var(--gold); cursor: pointer; font-size: 1rem; line-height: 1; }
.partRow button:hover { filter: brightness(1.35); }
.partLabel { flex: 1; text-align: center; font-size: .73rem; color: #cfc7b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#randomBtn { width: 100%; padding: 6px 10px; font-size: .78rem; border: 1px solid var(--border);
  background: #15181f; color: var(--ink); border-radius: 8px; cursor: pointer; margin: 0; font-weight: 600; }
#randomBtn:hover { filter: brightness(1.3); }

.hidden { display: none !important; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#topbar { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex;
  gap: 18px; align-items: center; background: var(--panel); border: 1px solid var(--border);
  border-radius: 30px; padding: 8px 22px; font-size: .95rem; font-weight: 600; }
#gold { color: var(--gold); }
#zone { padding: 2px 12px; border-radius: 20px; font-size: .8rem; }
#zone.zone-town { background: rgba(120, 200, 120, .18); color: #9ad99a; }
#zone.zone-wild { background: rgba(224, 93, 93, .18); color: #ee9a9a; }
#players { color: #9fb4d4; }
#level { color: #ffe08a; font-weight: 800; }

#xpwrap { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); width: 220px; height: 9px;
  background: #15171e; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
#xpbar { height: 100%; width: 0%; background: linear-gradient(90deg, #c9a227, #ffe08a); transition: width .2s; }
#xpwrap span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: .58rem; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000; }

#phasebar { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); padding: 5px 18px;
  border-radius: 20px; font-weight: 800; font-size: .9rem; white-space: nowrap; border: 1px solid var(--border);
  background: var(--panel); }
#phasebar.town { color: #9ad99a; }
#phasebar.battle { color: #ee9a9a; border-color: #e0564a; }
#phasebar.callable { cursor: pointer; pointer-events: auto; border-color: var(--gold); color: #ffe08a; animation: callPulse 1.6s infinite alternate; }
#phasebar.callable:hover { filter: brightness(1.2); }
@keyframes callPulse { from { box-shadow: 0 0 0 0 rgba(233,196,106,0); } to { box-shadow: 0 0 14px 2px rgba(233,196,106,0.35); } }
#buffbar { position: absolute; top: 96px; left: 50%; transform: translateX(-50%); font-size: .82rem;
  color: #d9d2c4; white-space: nowrap; text-shadow: 0 1px 3px #000; pointer-events: none; }

#potions { position: absolute; bottom: 54px; left: calc(50% - 170px); transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 6px 14px;
  font-size: .9rem; font-weight: 700; color: #9be0b0; }
#scrollSlot { position: absolute; bottom: 54px; left: calc(50% - 250px); transform: translateX(-50%);
  background: var(--panel); border: 1px solid rgba(150,110,220,0.5); border-radius: 20px; padding: 6px 12px;
  font-size: .9rem; font-weight: 700; color: #d6b6ff; }
#scrollSlot b { color: #fff; background: rgba(150,110,220,0.35); border-radius: 5px; padding: 0 5px; margin-right: 3px; }
#scrollSlot .ssN { color: #cfe3d2; font-size: .8rem; }
/* Scribe rows: stacked Equip/Buy buttons */
.scrollBtns { display: flex; flex-direction: column; gap: 4px; align-self: center; flex: 0 0 auto; }
.scrollEqBtn.on { background: #2a3a2c; color: #8fe0a0; border-color: rgba(120,200,140,0.4); }
.scrollCount { font-size: .72rem; color: #9bd0ff; font-weight: 700; }

/* Shop / town hall / wardrobe / apothecary / shrine / training — side panels (room stays visible behind them) */
#shop, #town, #wardrobe, #apothecary, #classShrine, #training, #reliquary, #market, #bank, #bakery, #church, #scribe, #plaque, #altar, #relicshop, #fruit, #inventory, #character { position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; display: flex; align-items: center;
  justify-content: flex-end; padding-right: 16px; background: none; pointer-events: none; }
#shop .shopPanel, #town .shopPanel, #wardrobe .shopPanel, #apothecary .shopPanel, #classShrine .shopPanel, #training .shopPanel, #reliquary .shopPanel, #market .shopPanel, #bank .shopPanel, #bakery .shopPanel, #church .shopPanel, #scribe .shopPanel, #plaque .shopPanel, #altar .shopPanel, #relicshop .shopPanel, #fruit .shopPanel, #inventory .shopPanel, #character .shopPanel { pointer-events: auto; }
#bank .shopPanel { width: 340px; }
#church .shopPanel { width: 340px; }
#scribe .shopPanel { width: 360px; }   /* the Scribe lists four scrolls with descriptions — a touch wider. */
.bankBalanceRow { display: flex; justify-content: space-between; align-items: center; margin: 10px 0 2px; padding: 10px 12px; background: rgba(120,200,140,0.10); border: 1px solid rgba(120,200,140,0.35); border-radius: 10px; }
.bankLbl { color: #b9b2a3; font-size: .85rem; }
.bankBig { font-size: 1.5rem; font-weight: 800; color: #9fe0b0; font-variant-numeric: tabular-nums; }
.bankRate { color: #8a8475; font-size: .78rem; margin: 4px 2px 12px; }
.bankForm { display: flex; gap: 8px; margin: 8px 0; }
.bankForm input { flex: 1; min-width: 0; background: #0c0e13; color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.bankForm button { padding: 8px 14px; border: none; border-radius: 8px; cursor: pointer; background: linear-gradient(180deg, var(--accent), #b07d4f); color: #2a1c0e; font-weight: 800; }
.bankAll button { flex: 1; background: #2a3a30; color: var(--ink); border: 1px solid rgba(120,200,140,0.3); }
.bankForm button:hover { filter: brightness(1.1); }
#market .shopPanel { width: 360px; }
#mktBody { max-height: 60vh; overflow-y: auto; margin-bottom: 6px; }
.mktListForm { display: flex; gap: 6px; margin: 10px 0 2px; }
.mktListForm select { flex: 1; min-width: 0; background: #0c0e13; color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.mktListForm input { width: 86px; background: #0c0e13; color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.mktListForm button { background: linear-gradient(180deg, var(--accent), #b07d4f); color: #2a1c0e; font-weight: 800; border: none; border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.relqRow.fBase { box-shadow: 0 0 0 2px #7fb6ff inset; }
.relqRow.fDonor { box-shadow: 0 0 0 2px #e0945a inset; }
.fusePane { margin-top: 10px; padding: 10px; border-radius: 10px; background: #0c0e13; border: 1px solid var(--border); }
.fuseRow { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 4px; }
.fuseLbl { color: #9a937f; } .fuseName { color: var(--ink); font-weight: 700; }
.fusePreview { font-size: .9rem; margin: 6px 0 10px; min-height: 18px; }
#fuseBtn { max-width: none; margin-top: 0; }
/* The skill-point (Training) screen: a large, centered modal with a dimmed backdrop + grids that fill the width. */
#training .shopPanel { width: min(720px, 95vw); max-height: 86vh; overflow-y: auto; padding: 20px 22px; }
#training .shopHead { font-size: 1.5rem; }
#training #trainPerks { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 7px; }
#training #trainSkills { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 7px; align-items: start; }
#training #trainPerks .trainRow, #training #trainSkills .trainRow { margin-bottom: 0; }
/* 🧝 Character sheet — centered modal with a stat-card grid. */
#character .shopPanel { width: min(560px, 94vw); max-height: 86vh; overflow-y: auto; padding: 20px 22px; }
/* MMO-style floating windows: no backdrop, freely dragged by their header, position remembered (left/top set by JS). */
#character, #training, #inventory { display: block; left: 0; align-items: initial; justify-content: initial; padding: 0; background: none; pointer-events: none; }   /* left:0 = full-viewport span so the absolutely-placed panel anchors to the LEFT (the shared rule only sets right:0) */
#character .shopPanel, #training .shopPanel, #inventory .shopPanel { position: absolute; top: 70px; left: 40px; pointer-events: auto; box-shadow: 0 14px 48px rgba(0,0,0,0.7); }
#character .shopHead, #training .shopHead, #inventory .shopHead { cursor: move; user-select: none; }
#inventory .shopPanel { width: 360px; }
#character .shopHead { font-size: 1.5rem; }
.charHeader { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; padding: 12px 14px; background: #0c0e13; border: 1px solid var(--border); border-radius: 10px; }
#charPortrait { flex: 0 0 auto; width: 130px; height: 160px; background: radial-gradient(ellipse at 50% 40%, #1b2230, #0a0c11); border: 1px solid var(--border); border-radius: 10px; }
#charSummary { flex: 1; min-width: 0; }
.csumRow { display: flex; justify-content: space-between; gap: 12px; padding: 5px 2px; font-size: .9rem; border-bottom: 1px solid #1a1d24; }
.csumRow:last-child { border-bottom: none; }
.csumLab { color: #9a937f; }
.csumVal { color: #f0e9da; font-weight: 700; }
.charRole { font-size: .82rem; color: #cfc7b8; line-height: 1.45; margin: 0 0 10px; }
.charXp { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.charXpBar { flex: 1; height: 10px; border-radius: 6px; background: #0c0e13; border: 1px solid var(--border); overflow: hidden; }
.charXpBar span { display: block; height: 100%; background: linear-gradient(90deg, #6fb6ff, #9be0ff); }
.charXpTxt { font-size: .74rem; color: #9be0ff; white-space: nowrap; font-weight: 700; }
.charTop { display: flex; gap: 18px; flex-wrap: wrap; font-size: .92rem; margin-bottom: 12px; color: #e6dfd2; }
.charGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(185px, 1fr)); gap: 9px; }
.charStat { background: #0c0e13; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.csTop { display: flex; align-items: center; gap: 7px; }
.csIcon { font-size: 1.05rem; }
.csLab { font-size: .77rem; color: #9a937f; }
.csVal { font-size: 1.3rem; font-weight: 800; color: #f0e9da; margin-top: 2px; }
.csSub { font-size: .71rem; color: #8b857a; margin-top: 3px; line-height: 1.4; }
.charRelic { margin-top: 12px; background: #0c0e13; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.charRelic .csLab { font-size: .94rem; color: #e6dfd2; margin-bottom: 6px; }
.relicAsp { margin: 6px 0; font-size: .82rem; line-height: 1.4; }
.aspTag { font-size: .62rem; text-transform: uppercase; letter-spacing: .04em; color: #8b857a; border: 1px solid #2a2d35; border-radius: 4px; padding: 0 4px; }
/* 📦 inventory wallet strip + 🔮 reliquary explainer */
.charWallet { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .82rem; color: #cfc7b8; margin: 0 0 10px; padding: 8px 11px; background: #0c0e13; border: 1px solid var(--border); border-radius: 10px; }
.relqIntro { font-size: .77rem; line-height: 1.5; color: #b9b1a4; background: #0c0e13; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
#reliquary .relqRow, #inventory #invBody .shopRow { align-items: flex-start; }
#reliquary .relqRow .shopBuy, #inventory #invBody .shopRow .shopBuy { align-self: center; }
.trainRole { font-size: .82rem; line-height: 1.4; color: #cfc7b8; margin: 0 0 8px; }
.trainRow { display: flex; gap: 10px; align-items: flex-start; padding: 9px 10px; border-radius: 10px; background: #0c0e13; border: 1px solid var(--border); margin-bottom: 7px; }
.trainRow.locked { opacity: 0.72; }
.trainKey { flex: 0 0 auto; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; border-radius: 6px; background: #2a2c33; color: #ffe08a; font-weight: 800; font-size: .85rem; }
.trainInfo { flex: 1; min-width: 0; font-size: .86rem; line-height: 1.3; }
.trainLock { color: #e0c060; font-size: .72rem; }
.trainRank { color: #9be0ff; font-size: .72rem; font-weight: 700; }
.trainRow.maxed { opacity: 0.78; }
.trainRow .trainBuy { flex: 0 0 auto; align-self: center; min-width: 50px; padding: 7px 9px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: #2a3a2c; color: #8fe0a0; font-weight: 800; font-size: .82rem; }
.trainRow .trainBuy:hover:not(:disabled) { filter: brightness(1.25); border-color: var(--gold); }
.trainRow .trainBuy:disabled { opacity: 0.4; cursor: default; color: var(--muted); background: #15171c; }
/* per-rank math readout under each perk/skill */
.trainProg { margin-top: 5px; font-size: .74rem; line-height: 1.45; color: #b9b1a4; }
.trainProg .now { color: #cfe8ff; font-weight: 700; }
.trainProg .nx { color: #8fe0a0; font-weight: 700; }
.trainProg .mx { color: #8b857a; }
.trainProg .arr { color: #6f6a61; margin: 0 3px; }
.trainStats { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px 6px; }
.trainStat { display: inline-flex; align-items: baseline; gap: 4px; padding: 2px 7px; border-radius: 6px; background: #14171d; border: 1px solid #23262e; font-size: .73rem; }
.trainStat .lab { color: #8b857a; }
.trainStat .v { color: #e6dfd2; font-weight: 700; }
.trainStat.grow .v { color: #cfe8ff; }
.trainStat .nx { color: #8fe0a0; font-weight: 700; }
.trainStat .nxarr { color: #5f5a52; margin: 0 1px; }
#trainPoints { color: var(--muted); font-weight: 800; font-size: .9rem; }
#trainPoints.has { color: #ffe08a; text-shadow: 0 0 8px rgba(255,224,138,0.6); }
#level.hasPts { animation: ptPulse 1.4s ease-in-out infinite; }
.ptBadge { color: #1a1208; background: var(--gold); border-radius: 7px; padding: 0 5px; font-size: .78rem; font-weight: 800; }
@keyframes ptPulse { 0%,100% { filter: brightness(1); } 50% { filter: brightness(1.5); } }
.shopBuy.arm { background: #5a2a2a; color: #ffb0a0; border-color: #b0584a; animation: ptPulse 1s ease-in-out infinite; }
#wardrobe .shopPanel { width: 340px; }
.wardTop { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
#wardPreview { background: #0c0e13; border: 1px solid var(--border); border-radius: 10px; flex: 0 0 auto; }
#wardParts { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.shopRow.owned { opacity: 0.72; border-color: #3c6b3c; }
.shopPanel { width: 360px; max-width: 92vw; background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.shopHead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px;
  font-family: Georgia, serif; font-size: 1.2rem; color: var(--gold); }
.shopHead #shopGold { color: var(--gold); font-family: Inter, sans-serif; font-size: .95rem; font-weight: 700; }
#shopClose { background: #15181f; border: 1px solid var(--border); color: var(--ink); border-radius: 8px;
  width: 30px; height: 30px; cursor: pointer; font-size: 1rem; }
#shopClose:hover { filter: brightness(1.3); }
.shopRow { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px;
  background: #0c0e13; border: 1px solid var(--border); margin-bottom: 8px; }
.shopIcon { font-size: 1.5rem; flex: 0 0 auto; }
.shopInfo { flex: 1; font-size: .9rem; line-height: 1.35; }
.shopRank { font-size: .72rem; color: #8a8475; }
.shopDesc { font-size: .78rem; color: #9b958a; }
.shopBuy { flex: 0 0 auto; background: linear-gradient(180deg, var(--accent), #b07d4f); color: #2a1c0e;
  border: none; border-radius: 8px; padding: 8px 12px; font-weight: 800; cursor: pointer; font-size: .85rem; }
.shopBuy:hover:not(:disabled) { filter: brightness(1.1); }
.shopBuy:disabled { background: #2a2c33; color: #6a6a6a; cursor: not-allowed; }
.shopBuy.poor { background: #2a2c33; color: #c07070; }   /* can't afford — still clickable so it can TELL you what's missing */
.shopHint { text-align: center; color: #8a8475; font-size: .74rem; margin-top: 8px; }
.shopHint b { color: var(--gold); }

/* Town hall panel (positioning shared with #shop above) */
#town .shopPanel { width: 380px; }
.townRowHead { font-size: .8rem; font-weight: 700; color: #cfc7b8; margin: 12px 0 6px; }
#donateWrap { position: relative; height: 18px; background: #15171e; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
#donateBar { height: 100%; width: 0%; background: linear-gradient(90deg, #c9a227, #ffe08a); transition: width .2s; }
#donateWrap span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: .62rem; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000; }
.donateBtns { display: flex; gap: 8px; margin-top: 8px; }
.donateBtns button, .wideBtn { flex: 1; padding: 9px; border: none; border-radius: 8px; cursor: pointer; font-weight: 800;
  background: linear-gradient(180deg, var(--accent), #b07d4f); color: #2a1c0e; font-size: .85rem; }
.donateBtns button:hover, .wideBtn:hover:not(:disabled) { filter: brightness(1.1); }
.wideBtn { width: 100%; }
.wideBtn:disabled { background: #2a2c33; color: #6a6a6a; cursor: not-allowed; }

#hpwrap { position: absolute; bottom: 26px; left: 50%; transform: translateX(-50%); width: 280px;
  height: 22px; background: #1a0e0e; border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; }
#hpbar { height: 100%; width: 100%; background: linear-gradient(90deg, #c0392b, #e05d5d);
  transition: width .2s; }
#hpwrap span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; text-shadow: 0 1px 2px #000; }
#rollwrap { position: absolute; bottom: 52px; left: 50%; transform: translateX(-50%); width: 180px;
  height: 12px; background: #15171e; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
#rollbar { height: 100%; width: 100%; background: linear-gradient(90deg, #4f86c6, #8fb3e0); transition: width .05s linear; }
#rollwrap span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: .62rem; font-weight: 800; letter-spacing: 1px; color: #fff; text-shadow: 0 1px 2px #000; }
#rollwrap.ready #rollbar { background: linear-gradient(90deg, #5fc15f, #9be09b); }

#stamwrap { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); width: 280px; height: 8px;
  background: #1a1508; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
#stambar { height: 100%; width: 100%; background: linear-gradient(90deg, #6fae3c, #b6e36a); transition: width .08s linear; }

#skills { position: absolute; bottom: 18px; right: 18px; display: flex; gap: 8px; }
.skillSlot { position: relative; width: 52px; height: 52px; border-radius: 10px; overflow: hidden;
  background: rgba(18,20,26,0.92); border: 1px solid var(--border); display: flex; flex-direction: column;
  align-items: center; justify-content: center; }
.skillSlot.ready { border-color: var(--gold); box-shadow: 0 0 8px rgba(233,196,106,.5); }
.skillSlot.locked { opacity: .55; filter: grayscale(.6); }
.skillKey { font-weight: 800; font-size: 1.1rem; color: var(--gold); line-height: 1; }
.skillName { font-size: .5rem; color: #b9b2a3; text-align: center; margin-top: 2px; padding: 0 2px; }
.skillCd { position: absolute; left: 0; bottom: 0; width: 100%; background: rgba(0,0,0,0.6); height: 0%; }
.skillLock { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: .62rem; font-weight: 800; color: #ffd36a; text-shadow: 0 1px 2px #000; }

#toast { position: absolute; top: 92px; left: 50%; transform: translateX(-50%) translateY(-8px); opacity: 0;
  background: rgba(18,20,26,0.95); border: 1px solid var(--gold); border-radius: 10px; padding: 10px 20px;
  font-weight: 800; color: var(--gold); font-size: 1rem; white-space: nowrap; pointer-events: none;
  transition: opacity .3s, transform .3s; text-shadow: 0 1px 3px #000; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* readable controls hint — a dark pill behind brighter text (was faint grey on the bright field). */
#hint { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); margin: 0; max-width: 96vw;
  color: #e2dccc; font-size: .8rem; background: rgba(8,10,14,0.66); padding: 5px 16px; border-radius: 11px;
  border: 1px solid rgba(255,255,255,0.06); text-shadow: 0 1px 2px #000; }

/* --- Onboarding + settings --- */
#helpBtn, #settingsBtn, #invBtn { position: absolute; top: 14px; width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--border); background: rgba(10,12,16,0.6); color: var(--ink); font-weight: 800;
  font-size: 1rem; cursor: pointer; pointer-events: auto; z-index: 12; line-height: 1; }
#helpBtn { right: 16px; }
#settingsBtn { right: 52px; font-size: .95rem; }
#invBtn { right: 88px; font-size: .95rem; }
#helpBtn:hover, #settingsBtn:hover, #invBtn:hover { filter: brightness(1.4); border-color: var(--gold); }
/* Inventory tabs + badges */
.invTabs { display: flex; gap: 6px; margin: 8px 0; }
.invTab { flex: 1; padding: 7px 4px; border-radius: 8px; border: 1px solid var(--border); background: rgba(10,12,16,0.5);
  color: var(--ink); font-weight: 700; font-size: .85rem; cursor: pointer; }
.invTab.on { background: var(--gold); color: #1a1208; border-color: var(--gold); }
.invTab:hover:not(.on) { border-color: var(--gold); }
.invBadge { font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 8px; vertical-align: middle; }
.invBadge.placed { background: rgba(110,200,120,0.2); color: #8fe0a0; }
.invBadge.stored { background: rgba(200,180,110,0.18); color: #e0c878; }
.invBadge.active { background: rgba(150,200,255,0.18); color: #9bd0ff; }
.invEmpty { color: var(--muted); font-size: .82rem; padding: 8px 2px; line-height: 1.4; }
.invBonusTip { font-size: .78rem; line-height: 1.5; color: #cfe3d2; background: rgba(110,200,120,0.10); border: 1px solid rgba(110,200,120,0.35); border-radius: 9px; padding: 9px 11px; margin: 0 0 10px; }
.invLootHead { padding: 6px 2px 8px; font-size: .92rem; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
#settings { position: absolute; top: 50px; right: 16px; width: 250px; max-height: 84vh; overflow-y: auto; z-index: 13; pointer-events: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.5); }
.setControls { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.setControlsHead { font-size: .82rem; font-weight: 800; color: var(--gold); margin: 0 2px 6px; }
.setKeyRow { display: flex; align-items: baseline; gap: 8px; padding: 2px 2px; font-size: .78rem; color: #cfc7b8; }
.setKeyRow .setKeys { flex: 0 0 74px; color: #9be0ff; }
.setKeyRow .setKeys b { color: #e9f3ff; }
.setKeysHint { font-weight: 400; color: #8a8475; font-size: .72rem; }
.keyBtn { flex: 0 0 74px; padding: 2px 4px; font: inherit; font-weight: 700; color: #9be0ff; background: #0c0e13;
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer; text-align: center; }
.keyBtn:hover { border-color: var(--gold); color: #e9f3ff; }
.keyBtn.listening { color: #ffd24a; border-color: var(--gold); animation: keyPulse 0.9s infinite alternate; }
@keyframes keyPulse { from { background: #0c0e13; } to { background: rgba(233, 196, 106, 0.22); } }
#keysReset { width: 100%; min-width: 0; margin-top: 6px; font-size: .74rem; }
.setRow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 6px; color: var(--ink); font-size: .86rem; }
.toggle { min-width: 52px; padding: 5px 0; border: 1px solid var(--border); border-radius: 7px; cursor: pointer;
  background: #3a2a2a; color: #e0a0a0; font-weight: 800; font-size: .78rem; }
.toggle.on { background: #2a3a2c; color: #8fe0a0; border-color: rgba(120,200,140,0.4); }
.toggle:hover { filter: brightness(1.15); }
.volSlider { width: 100%; margin: 0 0 10px; height: 18px; cursor: pointer; accent-color: var(--gold); }
#objective { position: absolute; top: 124px; left: 50%; transform: translateX(-50%); max-width: 74vw;
  text-align: center; color: var(--gold); font-size: .88rem; font-weight: 600; background: rgba(14,16,22,0.62);
  border: 1px solid rgba(233,196,106,0.3); border-radius: 999px; padding: 5px 16px; pointer-events: none;
  text-shadow: 0 1px 3px #000; white-space: nowrap; }
#objective:empty { display: none; }
#bigCue { position: absolute; top: 32%; left: 50%; transform: translate(-50%,-50%); text-align: center;
  pointer-events: none; z-index: 13; }
#bigCue .cueBig { font-family: Georgia, 'Times New Roman', serif; font-size: 3.2rem; letter-spacing: 3px;
  color: #fff; text-shadow: 0 2px 20px rgba(0,0,0,0.85); }
#bigCue .cueSub { font-size: 1.3rem; letter-spacing: 7px; color: var(--gold); margin-top: 2px; font-weight: 800; }
#bigCue.show { animation: cuePop .4s ease-out; }
#bigCue.fade { opacity: 0; transition: opacity .6s; }
@keyframes cuePop { from { opacity: 0; transform: translate(-50%,-50%) scale(.82); } to { opacity: 1; transform: translate(-50%,-50%) scale(1); } }
.introCard { max-width: 470px; text-align: left; }
.introCard h1, .introCard .sub { text-align: center; }
.introSteps { display: flex; flex-direction: column; gap: 13px; margin: 10px 0 16px; }
.introStep { display: flex; gap: 12px; align-items: flex-start; }
.introStep .iIcon { font-size: 1.7rem; line-height: 1.1; }
.introStep b { color: var(--gold); }
.introStep span { color: #b9b2a3; font-size: .85rem; line-height: 1.35; }
.introControls { text-align: center; color: #8a8475; font-size: .82rem; margin: 2px 0 16px; }
.introControls b { color: var(--ink); }
.firstTip { display: flex; align-items: center; gap: 10px; margin: 8px 0 6px; padding: 8px 12px;
  background: rgba(233,196,106,0.12); border: 1px solid var(--gold); border-radius: 10px;
  color: var(--ink); font-size: .82rem; line-height: 1.35; }
.firstTip button { flex: none; align-self: flex-start; padding: 5px 12px; border: none; border-radius: 8px;
  cursor: pointer; background: linear-gradient(180deg, var(--accent), #b07d4f); color: #2a1c0e; font-weight: 800; font-size: .78rem; }
.firstTip button:hover { filter: brightness(1.1); }
/* --- Wave vote banner --- */
#voteBox { position: absolute; top: 112px; left: 50%; transform: translateX(-50%); min-width: 300px; max-width: 92vw;
  text-align: center; background: rgba(14,16,22,0.93); border: 1px solid var(--gold); border-radius: 12px;
  padding: 10px 16px; pointer-events: auto; z-index: 14; box-shadow: 0 4px 22px rgba(0,0,0,0.55); }
#voteBox .voteHead { font-size: .94rem; color: var(--ink); }
#voteBox .voteHead b { color: var(--gold); }
#voteBox .voteTally { margin: 6px 0; font-weight: 800; font-size: 1.05rem; }
#voteBox .voteYes { color: #7fe0a0; }
#voteBox .voteNo { color: #e08080; }
#voteBox .voteSecs { color: #b9b2a3; font-weight: 600; }
#voteBox .voteHint { color: #8a8475; font-size: .82rem; }
#voteBox .voteBtns { display: flex; gap: 8px; justify-content: center; margin-top: 4px; }
#voteBox .voteBtns button { padding: 7px 16px; border: none; border-radius: 8px; cursor: pointer; font-weight: 800; }
#voteBox #voteYes { background: linear-gradient(180deg, #5fc15f, #3f9a3f); color: #0c1a0c; }
#voteBox #voteNo { background: linear-gradient(180deg, #d06a6a, #a84a4a); color: #1a0c0c; }
#voteBox button:hover { filter: brightness(1.1); }
.trainWave { color: #b9b2a3; font-size: .82rem; line-height: 1.4; margin: 4px 2px 12px; }
.trainWave b { color: var(--gold); }

/* Floating combat text */
.floater { position: fixed; pointer-events: none; z-index: 11; font-weight: 800; font-size: 1rem;
  text-shadow: 0 2px 3px #000; transition: transform .8s ease-out, opacity .8s ease-out; }
.floater.dmg { color: #ffd36a; }
.floater.hurt { color: #ff7a7a; }
.floater.gold { color: var(--gold); }

#nametags { position: fixed; inset: 0; pointer-events: none; z-index: 9; }
.nametag { position: absolute; transform: translate(-50%, -100%); font-size: .72rem; font-weight: 700;
  color: #fff; text-shadow: 0 1px 3px #000; white-space: nowrap; padding: 1px 6px;
  background: rgba(0,0,0,.4); border-radius: 6px; }

/* Post-battle scoreboard */
#results { background: rgba(6, 8, 11, 0.72); z-index: 30; }
.resCard { background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 26px 30px; min-width: 520px; max-width: 92vw; box-shadow: 0 24px 70px rgba(0,0,0,.6); text-align: center; }
#resTitle { font-family: Georgia, serif; font-size: 1.9rem; letter-spacing: 1px; margin-bottom: 4px; }
#resTitle.resWin { color: var(--gold); }
#resTitle.resLoss { color: var(--danger); }
.resSub { color: #c7bfae; font-size: .95rem; margin-bottom: 18px; }
#resTable { width: 100%; border-collapse: collapse; font-size: .9rem; }
#resTable th { color: #9a937f; font-weight: 700; font-size: .76rem; text-transform: uppercase;
  letter-spacing: .5px; padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: right; }
#resTable th.resName, #resTable td.resName { text-align: left; }
#resTable td { padding: 7px 8px; border-bottom: 1px solid rgba(212,163,115,0.12); text-align: right;
  font-variant-numeric: tabular-nums; }
#resTable tr:last-child td { border-bottom: none; }
.resName { font-weight: 600; color: var(--ink); }
.resScore { color: var(--gold); font-weight: 800; }
.resYou { background: rgba(233,196,106,0.12); }
.resYou .resName { color: var(--gold); }
.resYouTag { font-size: .62rem; background: var(--gold); color: #2a1c0e; border-radius: 5px;
  padding: 1px 5px; font-weight: 800; margin-left: 4px; vertical-align: middle; }
.resRev { color: #ff8fae; font-size: .8rem; }
#resClose { margin-top: 20px; max-width: 220px; }

/* Loot wheel */
#lootWheel { margin-top: 14px; display: flex; flex-direction: column; align-items: center; }
.lootHead { color: var(--gold); font-weight: 800; font-size: 1rem; margin-bottom: 8px; }
.wheelWrap { position: relative; width: 280px; height: 280px; }
#wheelPin { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); color: var(--gold);
  font-size: 26px; line-height: 1; text-shadow: 0 2px 3px #000; z-index: 2; }
.wheelResult { margin-top: 10px; min-height: 24px; font-weight: 800; font-size: 1.05rem; color: var(--ink); }
.wheelResult .win { color: var(--gold); }

/* ---------------------------------------------------------------------------
   Responsive intro/overlay panels. The login card is ~915px tall; on a plain
   1280x720 laptop that put "Enter the world" 32px below the fold with no way
   to scroll to it. The overlay now scrolls itself, and the rules below shrink
   the vertical rhythm so scrolling is rarely needed at all. */

@media (max-height: 800px), (max-width: 560px) {   /* short OR narrow: a narrow window stacks taller, so it needs the same tightening */
  .panel .sub { margin-bottom: 12px; }
  .panel input { margin-bottom: 10px; padding: 10px 12px; }
  .panel .hint, #hint { margin-top: 10px; }
  #classPick { gap: 6px; margin-bottom: 10px; }
  #creator { margin-bottom: 10px; padding: 8px; gap: 10px; }
  #parts { gap: 4px; }
  .classBtn .cIcon { font-size: 1.45rem; }
  .classBtn .cDesc { font-size: .7rem; line-height: 1.2; }
  .introSteps { gap: 9px; margin: 8px 0 12px; }
  .introControls { margin: 2px 0 12px; }
}

@media (max-height: 620px) {                    /* very short (netbook, split screen): drop to the essentials */
  .panel .sub { display: none; }
  .classBtn .cDesc { display: none; }           /* the icon + name still identify the class */
  .introStep .iIcon { font-size: 1.35rem; }
}

@media (max-width: 460px) {                     /* phones */
  /* Keep THREE class cards per row, not two: with 8 classes, two-per-row means four
     rows (434px) while three-per-row needs three (~210px). Height is the scarce axis
     here, not width. The blurb goes instead — icon + name still identify the class. */
  .classBtn .cDesc { display: none; }
  .classBtn .cName { font-size: .8rem; }
  .classBtn .cIcon { font-size: 1.5rem; }
  .panel { border-radius: 12px; }
}

@media (max-width: 360px) {
  #creator { flex-direction: column; align-items: stretch; }   /* portrait + part pickers stack */
  #creatorRight { width: 100%; }
}

/* Wide-but-short (the common laptop case: 1280x720, 1366x768). There are 8 classes,
   which stack into 3 rows at 360px and eat 351px of height. Trading spare width for
   scarce height puts them on 2 rows and lands the whole card inside the fold.
   Scoped to #login so .introCard/#results keep their own widths. */
@media (max-height: 800px) and (min-width: 680px) {
  #login .panel { max-width: 620px; }
  #login #classPick .classBtn { flex: 1 1 22%; }
}

/* ⟲ "Start over" lives in its own danger zone so it can't be mistaken for a toggle. */
.setDanger { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(224,93,93,.35); }
.setDangerNote { display: block; margin-top: 6px; color: #8a8475; font-size: .74rem; line-height: 1.3; }
.toggle.danger { width: 100%; background: transparent; color: var(--danger);
  border: 1px solid rgba(224,93,93,.55); font-weight: 700; }
.toggle.danger:hover { background: rgba(224,93,93,.14); }

/* ⛪ Chapel — opt out of the next wave. */
.churchText { color: #b9b2a3; font-size: .86rem; line-height: 1.45; margin: 10px 0 12px; }
.churchState { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; margin-bottom: 12px; background: #0c0e13;
  border: 1px solid var(--border); border-radius: 10px; }
.churchLbl { color: #8a8475; font-size: .78rem; }
.churchBig { font-weight: 700; color: var(--ink); }
.churchBig.churchStaying { color: var(--gold); }
#churchToggle { width: 100%; }

/* 🏆 Hall of Patrons — the donation leaderboard. */
#plaque .shopPanel { width: 340px; }
.plaqueTotal { color: #b9b2a3; font-size: .84rem; margin: 8px 0 10px; }
.plaqueRow { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; font-size: .88rem; }
.plaqueRow:nth-child(odd) { background: rgba(255,255,255,0.035); }
.plaqueRow.plaqueTop { background: rgba(233,196,106,0.14); border: 1px solid rgba(233,196,106,0.4); }
.plaqueRank { width: 26px; text-align: center; color: #8a8475; }
.plaqueName { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plaqueAmt { color: var(--gold); font-weight: 700; }
.donateNext { color: #b9b2a3; font-size: .78rem; line-height: 1.35; margin: 6px 2px 0; }
.donateNext b { color: var(--gold); }

/* Long lists must scroll inside the panel, or the buttons fall off-screen and become unclickable.
   .shopPanel has no max-height of its own — every long panel sets it (see #training / #character). */
#relicshop .shopPanel { width: 380px; max-height: 86vh; overflow-y: auto; }   /* 18 aspects with descriptions */
#scribe .shopPanel { max-height: 86vh; overflow-y: auto; }
#plaque .shopPanel { max-height: 86vh; overflow-y: auto; }

/* 🕯️ The Hanging Altar + ☠ the duel result card */
#altar .shopPanel { width: 340px; max-height: 86vh; overflow-y: auto; border-color: rgba(200,60,50,0.45); }
.altarLore { color: #c9b8b0; font-size: .84rem; font-style: italic; line-height: 1.4; margin: 8px 2px 10px; }
.altarStatus { background: rgba(160,30,40,0.10); border: 1px solid rgba(200,60,50,0.3); border-radius: 10px; padding: 8px 10px; font-size: .84rem; line-height: 1.55; color: #e0d6cc; }
.altarLock { color: #ff9a8a; font-weight: 700; }
.altarReward { color: var(--gold); font-size: .82rem; margin: 8px 2px; }
.altarGo { background: #8a1e24; color: #ffe6d8; }
.altarWhy { color: #b9a0a0; font-size: .76rem; text-align: center; margin: 4px 0 0; min-height: 1em; }
#duelResult { background: rgba(6, 4, 8, 0.78); z-index: 31; }
.duelCard { min-width: 360px; max-width: 520px; border-color: rgba(255,90,42,0.45); }
.duelList { list-style: none; margin: 4px 0 12px; padding: 0; text-align: left; display: inline-block; }
.duelList li { padding: 5px 4px; font-size: 1rem; color: var(--ink); border-bottom: 1px solid rgba(212,163,115,0.12); }
.duelList li:last-child { border-bottom: none; }
.duelNext { color: #ff9a6a; font-weight: 700; font-size: .92rem; margin-top: 4px; }
#duelClose { margin-top: 16px; max-width: 220px; }

/* 🗿 Heroes’ Row commission, in the Mayor’s Office. */
#statueSection { margin-top: 12px; }
.statueText { color: #b9b2a3; font-size: .8rem; line-height: 1.4; margin: 4px 2px 8px; }
#town .shopPanel { max-height: 86vh; overflow-y: auto; }   /* a new section must never push buttons off-screen */
