@font-face { font-family: "Grenze"; font-style: normal; font-weight: 100 900; font-display: swap; src: url(fonts/grenze-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Grenze"; font-style: normal; font-weight: 100 900; font-display: swap; src: url(fonts/grenze-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Grenze"; font-style: italic; font-weight: 400; font-display: swap; src: url(fonts/grenze-italic-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Grenze"; font-style: italic; font-weight: 400; font-display: swap; src: url(fonts/grenze-italic-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }

/* theme: primary/secondary as surfaces and components; text contrast via accent (6.5:1) / accent-hi (11:1) on black */
:root {
  --black: #131313; --white: #f5f5f5; --primary: #643A6B; --secondary: #2272b1;
  --accent: #b48bbb; --accent-hi: #e2c6e6; --secondary-hi: #5aa3dc;
  --bg: var(--black); --panel: rgba(22, 19, 23, .92); --panel-solid: #1a171b; --panel-2: #221d24;
  --border: #7a5582; --border-soft: rgba(180, 139, 187, .22);
  --text: var(--white); --muted: #a9a3ab;
  --danger: #ec7a6f; --ok: #9fd48f;
  --hp: #a8261d; --hp-hi: #d0453a; --trail: #e2b24c; --mana: #2d5fae; --mana-hi: #4f86d8; --focus: #6fc07a;
  --t0: #d9d2c3; --t1: #72d672; --t2: #bb84ff; --t3: #ffb040;
  --title: "Grenze", Georgia, serif;
  --body: "Grenze", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 17px/1.35 var(--body); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--secondary-hi); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
kbd { font: 600 11px var(--title); color: var(--accent); border: 1px solid var(--border); border-radius: 3px; padding: 0 4px; background: rgba(0, 0, 0, .5); }

/* ---------- Frames & controls ---------- */
.frame {
  position: relative; background: linear-gradient(180deg, rgba(29, 25, 31, .96), rgba(15, 13, 16, .96));
  border: 1px solid var(--border); box-shadow: 0 10px 40px rgba(0, 0, 0, .7), inset 0 0 30px rgba(0, 0, 0, .6);
}
.frame::before { content: ""; position: absolute; inset: 4px; border: 1px solid var(--border-soft); pointer-events: none; }
.frame::after {
  content: ""; position: absolute; inset: -1px; pointer-events: none;
  background:
    linear-gradient(var(--accent), var(--accent)) top left / 14px 2px, linear-gradient(var(--accent), var(--accent)) top left / 2px 14px,
    linear-gradient(var(--accent), var(--accent)) top right / 14px 2px, linear-gradient(var(--accent), var(--accent)) top right / 2px 14px,
    linear-gradient(var(--accent), var(--accent)) bottom left / 14px 2px, linear-gradient(var(--accent), var(--accent)) bottom left / 2px 14px,
    linear-gradient(var(--accent), var(--accent)) bottom right / 14px 2px, linear-gradient(var(--accent), var(--accent)) bottom right / 2px 14px;
  background-repeat: no-repeat;
}
h1, h2, h3, legend { font-family: var(--title); font-weight: 600; letter-spacing: .08em; }
h2 { margin: 0; font-size: 18px; color: var(--accent-hi); text-transform: uppercase; }
h3 { margin: 10px 0 6px; font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .16em; }
.btn {
  font: 600 14px var(--title); letter-spacing: .1em; text-transform: uppercase; cursor: pointer;
  color: var(--text); background: linear-gradient(180deg, #2a2030, #171418); border: 1px solid var(--border);
  padding: 8px 16px; transition: border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent-hi); box-shadow: 0 0 12px rgba(180, 139, 187, .25); }
.btn.primary { border-color: var(--accent); color: var(--white); background: var(--primary); }
.btn.primary:hover { color: var(--white); background: #74447c; }
.btn.small { font-size: 11px; padding: 4px 10px; }
.btn:disabled { opacity: .5; cursor: progress; }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; padding: 4px; }
.link:hover { color: var(--accent-hi); }
label { display: grid; gap: 4px; font: 600 12px var(--title); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
input:not([type=checkbox]):not([type=radio]):not([type=color]), select {
  font: 17px var(--body); letter-spacing: 0; text-transform: none; color: var(--text);
  background: rgba(0, 0, 0, .55); border: 1px solid var(--border); padding: 8px 10px;
}
input:focus { border-color: var(--accent); }
.color-pick { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.color-pick legend { font: 600 12px var(--title); color: var(--muted); text-transform: uppercase; letter-spacing: .12em; margin-bottom: 6px; }
.color-pick label { position: relative; display: block; cursor: pointer; }
.color-pick input { position: absolute; opacity: 0; }
.color-pick span { display: block; width: 32px; height: 32px; border: 2px solid var(--black); box-shadow: 0 0 0 1px var(--border); }
.color-pick input:checked + span { box-shadow: 0 0 0 2px var(--white); }
.color-pick input:focus-visible + span { outline: 2px solid var(--secondary-hi); outline-offset: 3px; }

/* ---------- Lobby ---------- */
#bg { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#lobby { position: relative; height: 100%; overflow-y: auto; display: grid; justify-items: center; align-content: start; gap: 22px; padding: 6vh 16px 40px; }
.title { text-align: center; }
.title h1 { margin: 0; font-size: clamp(40px, 9vw, 96px); font-weight: 700; letter-spacing: .15em; padding-left: .15em; color: var(--white);
  text-shadow: 0 0 30px rgba(100, 58, 107, .8), 0 2px 0 #000; }
.title p { margin: 0; font-style: italic; color: var(--muted); }
.title .rule { width: 260px; height: 1px; margin: 10px auto; background: linear-gradient(90deg, transparent, var(--accent), transparent); }
#authCard { width: min(400px, 100%); padding: 22px 24px 18px; display: grid; gap: 14px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tabs button { flex: 1; background: none; border: 0; cursor: pointer; padding: 8px; font: 600 14px var(--title); letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected=true] { color: var(--accent-hi); border-bottom-color: var(--accent); }
#authForm { display: grid; gap: 12px; }
#authForm .btn.primary { width: 100%; padding: 10px; }
.status { margin: 0; min-height: 1.3em; color: var(--danger); }
details.adv summary { cursor: pointer; color: var(--muted); font-size: 14px; }
details.adv label { margin-top: 8px; }
#charCard { width: min(860px, 100%); display: grid; gap: 16px; }
#charCard > header { display: flex; justify-content: space-between; align-items: center; }
.char-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.char-grid li { padding: 14px; display: grid; gap: 6px; justify-items: center; text-align: center; }
.char-grid canvas { width: 120px; height: 120px; }
.char-grid .cname { font: 600 18px var(--title); color: var(--accent-hi); letter-spacing: .06em; }
.char-grid .cmeta { color: var(--muted); font-size: 15px; }
.char-grid .empty { grid-column: 1 / -1; color: var(--muted); font-style: italic; }
#charForm { padding: 18px 20px; display: grid; gap: 14px; }
.weapon-pick { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.weapon-pick legend { font-size: 12px; color: var(--accent); text-transform: uppercase; letter-spacing: .16em; margin-bottom: 8px; }
.weapon-pick label { position: relative; display: grid; justify-items: center; gap: 4px; padding: 10px; cursor: pointer; text-transform: none; letter-spacing: 0;
  font: 15px var(--body); color: var(--text); border: 1px solid var(--border); background: rgba(0, 0, 0, .4); text-align: center; }
.weapon-pick label:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 18px rgba(180, 139, 187, .25), inset 0 0 20px rgba(180, 139, 187, .08); }
.weapon-pick label:has(input:focus-visible) { outline: 2px solid var(--accent-hi); outline-offset: 2px; }
.weapon-pick input { position: absolute; opacity: 0; }
.weapon-pick canvas { width: 90px; height: 90px; }
.weapon-pick b { font: 600 15px var(--title); color: var(--accent-hi); letter-spacing: .08em; }
.weapon-pick small { color: var(--muted); font-size: 14px; }
#charForm .row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
#charForm .row > label:first-child { flex: 1; min-width: 160px; }

/* ---------- Game ---------- */
#game { position: fixed; inset: 0; display: none; }
#game.on { display: block; }
#cv { display: block; width: 100%; height: 100%; cursor: crosshair; }
.hud { position: absolute; }

#stats { top: 16px; left: 16px; width: min(320px, calc(100% - 32px)); display: grid; gap: 5px; pointer-events: none;
  text-shadow: 0 1px 2px #000; }
#sName { font: 600 15px var(--title); letter-spacing: .06em; color: var(--accent-hi); }
#sName small { font: 14px var(--body); color: var(--muted); letter-spacing: 0; }
.gauge { position: relative; height: 18px; background: rgba(0, 0, 0, .7); border: 1px solid #3a2c3e; box-shadow: 0 0 0 1px #000; }
.gauge > div { position: absolute; inset: 0 auto 0 0; }
.gauge .trail { background: var(--trail); transition: width .5s ease-out .35s; }
.gauge .fill { transition: width .12s; }
.gauge.hp .fill { background: linear-gradient(180deg, var(--hp-hi), var(--hp)); }
.gauge.mana { height: 14px; }
.gauge.mana .fill { background: linear-gradient(180deg, var(--mana-hi), var(--mana)); }
.gauge span { position: absolute; inset: 0 6px 0 auto; display: grid; place-items: center; font: 600 15px/1 var(--title); letter-spacing: .04em; color: #fff; }
.gauge.mana span { font-size: 13px; }
#sFocus { display: flex; gap: 5px; }
#sFocus i { width: 12px; height: 12px; transform: rotate(45deg); border: 1px solid var(--focus); background: rgba(0, 0, 0, .6); }
#sFocus i.on { background: var(--focus); box-shadow: 0 0 8px var(--focus); }

#perf { top: 16px; right: 16px; margin: 0; padding: 6px 8px; font: 12px/1.4 ui-monospace, Consolas, monospace; color: #cfe; background: rgba(0, 0, 0, .75); pointer-events: none; z-index: 5; }
#targetFrame { top: 16px; left: 50%; transform: translateX(-50%); width: min(360px, calc(100% - 32px)); text-align: center; pointer-events: none; text-shadow: 0 1px 2px #000; }
#targetFrame .tname { font: 600 14px var(--title); letter-spacing: .1em; }
#targetFrame .gauge { height: 14px; margin-top: 3px; }
#targetFrame .tags { color: #ff9d3a; font-size: 13px; }

#zoneTitle { top: 30%; left: 0; right: 0; text-align: center; pointer-events: none; opacity: 0; }
#zoneTitle.show { animation: zoneIn 4s ease forwards; }
#zoneTitle div { font: 600 clamp(28px, 5vw, 52px) var(--title); letter-spacing: .25em; color: var(--white); text-shadow: 0 0 20px rgba(0, 0, 0, .9); }
#zoneTitle .rule { width: 50%; max-width: 520px; height: 1px; margin: 6px auto 0; background: linear-gradient(90deg, transparent, var(--accent), transparent); }
@keyframes zoneIn { 0% { opacity: 0; letter-spacing: .1em; } 20%, 70% { opacity: 1; } 100% { opacity: 0; } }
/* intro narration (event `narration` with intro): zone name plus text, longer */
#zoneTitle p { max-width: min(640px, calc(100% - 32px)); margin: 12px auto 0; font: italic 19px/1.45 var(--body); color: var(--text); text-shadow: 0 1px 3px #000, 0 0 12px #000; }
#zoneTitle p:empty { display: none; }
#zoneTitle.long.show { animation: zoneLong 12s ease forwards; }
@keyframes zoneLong { 0% { opacity: 0; } 8%, 85% { opacity: 1; } 100% { opacity: 0; } }

#banner { top: 38%; left: 0; right: 0; text-align: center; pointer-events: none; opacity: 0;
  background: linear-gradient(90deg, transparent, rgba(0, 0, 0, .75) 25%, rgba(0, 0, 0, .75) 75%, transparent); padding: 14px 0; }
#banner.show { animation: banner 3.6s ease forwards; }
#banner div { font: 700 clamp(34px, 6vw, 64px) var(--title); letter-spacing: .2em; color: #f6d77e;
  text-shadow: 0 0 24px rgba(255, 190, 60, .8), 0 0 60px rgba(255, 140, 20, .5); }
#banner.dead div { color: #b3261e; letter-spacing: .12em; text-shadow: 0 0 24px rgba(180, 20, 10, .7), 0 2px 0 #000; }
#banner small { display: block; font: italic 18px var(--body); color: var(--text); }
#banner.small { top: 24%; padding: 8px 0; }
#banner.small div { font-size: clamp(20px, 3vw, 32px); letter-spacing: .14em; }
@keyframes banner { 0% { opacity: 0; transform: scale(1.15); } 12% { opacity: 1; transform: scale(1); } 75% { opacity: 1; } 100% { opacity: 0; } }

#log { left: 16px; bottom: 140px; width: min(440px, calc(100% - 32px)); max-height: 22vh; overflow-y: auto; margin: 0; padding: 0;
  list-style: none; font-size: 15px; text-shadow: 0 1px 2px #000, 0 0 4px #000; scrollbar-width: none; }
#log li { animation: logFade 1s ease 8s forwards; }
#log:hover li, #log.show li, #log:focus-within li { animation: none; opacity: 1; }
#log li.sys { color: var(--muted); } #log li.bad { color: var(--danger); } #log li.good { color: var(--ok); }
#log li.narr { color: var(--accent-hi); font-style: italic; }
@keyframes logFade { to { opacity: 0; } }
#chat { left: 16px; bottom: 100px; width: min(440px, calc(100% - 32px)); display: flex; gap: 6px; padding: 6px; }
#chat input { flex: 1; min-width: 0; }

#castbar { left: 50%; bottom: 134px; transform: translateX(-50%); width: 260px; text-align: center; display: none; pointer-events: none;
  font: 600 12px var(--title); letter-spacing: .1em; text-shadow: 0 1px 2px #000; }
#castbar.on { display: block; }
#castbar .gauge { height: 10px; margin-top: 3px; }
#castbar .fill { background: linear-gradient(90deg, var(--primary), var(--accent-hi)); }

/* combo ring (chain window, hit count) and utility slots 1–4 above the progress bars;
   Q/E/R appear above them only while they can be pressed or cool down */
#bottom { left: 50%; bottom: 60px; transform: translateX(-50%); display: flex; align-items: end; gap: 22px; }
#combo { display: flex; align-items: end; gap: 10px; }
#qte { position: absolute; left: 50%; bottom: calc(100% + 14px); transform: translateX(-50%); display: flex; gap: 10px; pointer-events: none; }
#qte .sk { visibility: hidden; opacity: 0; transform: scale(.6); transition: opacity .12s, transform .12s, visibility 0s .12s; pointer-events: auto; }
#qte .sk.show { visibility: visible; opacity: 1; transform: none; transition: opacity .12s, transform .15s cubic-bezier(.3, 1.6, .6, 1); }
#qte .sk.show.chain { box-shadow: 0 0 16px rgba(90, 163, 220, .55); }
#qte .sk kbd { left: 50%; top: auto; bottom: -9px; transform: translateX(-50%); font-size: 11px; }
#hitBonus { position: absolute; left: 50%; top: -18px; transform: translateX(-50%); font: 700 11px var(--title); white-space: nowrap;
  color: var(--black); background: var(--accent-hi); padding: 0 4px; border-radius: 2px; }
#comboCur { position: relative; width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent-hi) calc(var(--w, 0) * 1turn), rgba(100, 58, 107, .5) 0); }
#comboCur::before { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: radial-gradient(circle at 50% 40%, #2a2230, #0c0b0d); }
#comboIcon { position: relative; width: 26px; height: 26px; color: var(--accent-hi); }
img.px { image-rendering: pixelated; }
#comboIcon :is(svg, img), .sk :is(svg, img) { width: 100%; height: 100%; display: block; }
#comboCur.idle #comboIcon { color: #6e6472; }
#comboN { position: absolute; right: -6px; bottom: -4px; font: 700 15px var(--title); color: var(--accent-hi); text-shadow: 0 0 6px #000, 0 1px 2px #000; }
#util { display: flex; gap: 6px; }
.sk { position: relative; width: 44px; height: 44px; padding: 9px; cursor: pointer; color: var(--accent-hi);
  background: radial-gradient(circle at 50% 40%, #2a2230, #0f0d10); border: 1px solid var(--border);
  box-shadow: inset 0 0 0 2px #0a090b, 0 3px 10px rgba(0, 0, 0, .6); }
.sk::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: conic-gradient(rgba(0, 0, 0, .7) calc(var(--cd, 0) * 1turn), transparent 0); }
.sk kbd { position: absolute; left: 1px; top: 1px; font-size: 9px; padding: 0 3px; z-index: 1; }
.sk:hover { border-color: var(--accent); }
.sk.empty { color: #3d3340; cursor: default; }
.sk.off { color: #6e6472; }
.sk.chain { border-color: var(--accent-hi); animation: chainPulse 1s ease-in-out infinite; }
.sk.drop { border-color: var(--accent-hi); box-shadow: 0 0 12px rgba(226, 198, 230, .5); }
#util .sk { width: 38px; height: 38px; padding: 7px; }
@keyframes chainPulse { 50% { box-shadow: inset 0 0 0 2px #0a090b, inset 0 0 14px rgba(90, 163, 220, .6), 0 0 14px rgba(90, 163, 220, .6); } }

/* full width at the bottom: mastery | SP progress above, xp below; each with its number centered */
#progress { left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 0 0 2px;
  background: linear-gradient(0deg, rgba(0, 0, 0, .75), transparent); pointer-events: auto; }
.pbar { position: relative; height: 22px; background: rgba(0, 0, 0, .75); box-shadow: inset 0 0 0 1px #2a2230; overflow: hidden; }
.pbar .fill { height: 100%; width: 0; transition: width .4s; }
.pbar > span { position: absolute; inset: 0; display: grid; place-items: center; font: 700 15px/1 var(--title); letter-spacing: .03em; color: #fff;
  white-space: nowrap; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 1px 2px #000; }
.pbar.sp .fill { background: linear-gradient(90deg, #2c524f, #5fb3a6); }
.pbar.mastery .fill { background: linear-gradient(90deg, #5a3322, #c0703f); }
.pbar.xp { grid-column: 1 / -1; }
.pbar.xp .fill { background: linear-gradient(90deg, #3f2443, var(--primary), var(--accent)); }
.pbar[hidden] { display: block; visibility: hidden; }
#xp.flash { animation: xpFlash 1.2s ease 3; }
@keyframes xpFlash { 50% { box-shadow: 0 0 14px var(--accent-hi); background: rgba(180, 139, 187, .4); } }
.chip { display: inline-flex; align-items: center; gap: 3px; font: 600 12px var(--title); color: var(--text); white-space: nowrap; }
.chip :is(svg, img) { width: 14px; height: 14px; color: var(--accent); }
.chip.big { font-size: 17px; color: #7fd6c8; }
.chip.big :is(svg, img) { color: #7fd6c8; }
.chip.dim { opacity: .45; }

#icons { right: 16px; bottom: 60px; display: flex; gap: 6px; }
#icons button { position: relative; width: 44px; height: 44px; padding: 0; cursor: pointer; color: var(--accent); background: rgba(15, 13, 16, .85); border: 1px solid var(--border); }
#icons button:hover, #icons button[aria-expanded=true] { color: var(--accent-hi); border-color: var(--accent); }
#icons button :is(svg, img) { width: 22px; height: 22px; display: block; margin: auto; }
#icons button kbd { position: absolute; right: -4px; top: -7px; font-size: 10px; }
#icons button .dot { position: absolute; left: -3px; top: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent-hi); box-shadow: 0 0 8px var(--accent-hi); }

/* ---------- Windows ---------- */
.window { padding: 16px 18px; display: flex; flex-direction: column; max-height: calc(100% - 120px); }
.window > header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.window .close { background: none; border: 0; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; }
.window .close:hover { color: var(--accent-hi); }
.window .scroll { overflow-y: auto; overscroll-behavior: contain; padding-right: 4px; min-height: 0; scrollbar-color: var(--border) transparent; }
#inv { right: 16px; top: 16px; width: min(440px, calc(100% - 32px)); max-height: calc(100% - 96px); }
#party { right: 16px; top: 16px; width: min(280px, calc(100% - 32px)); }
#inv:not([hidden]) ~ #party { top: auto; bottom: 76px; right: 472px; }
#tree { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(900px, calc(100% - 32px)); height: min(600px, calc(100% - 140px)); }
#tree .subtabs { display: flex; gap: 6px; margin-top: 8px; }
#tree .subtabs button { position: relative; width: 40px; height: 40px; padding: 8px; cursor: pointer; color: #8c8290; background: rgba(0, 0, 0, .4); border: 1px solid #3d3042; }
#tree .subtabs button :is(svg, img) { width: 100%; height: 100%; display: block; }
#tree .subtabs button[aria-selected=true] { color: var(--accent-hi); border-color: var(--accent); }
#tree .subtabs .active-tree::after { content: ""; position: absolute; right: 2px; top: 2px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent-hi); }
#treePanel { display: flex; flex-direction: column; min-height: 0; flex: 1; }
#treeInfo { margin: 8px 0; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
#treeInfo .tname { font: 600 14px var(--title); letter-spacing: .06em; color: var(--accent-hi); margin-right: auto; }
/* fixed viewport: drag (or wheel) pans the graph */
#tree .scroll { flex: 1; overflow: auto; cursor: grab; border: 1px solid #2a2230; background: rgba(0, 0, 0, .25); scrollbar-width: thin; }
#tree .scroll.panning { cursor: grabbing; user-select: none; }
#treeGraph { position: relative; display: flex; gap: 56px; align-items: stretch; padding: 24px; width: max-content; height: max-content; min-width: 100%; min-height: 100%;
  box-sizing: border-box; justify-content: center; }
#treeGraph .edges { position: absolute; left: 0; top: 0; pointer-events: none; }
#treeGraph .edges path { fill: none; stroke: #6a4f70; stroke-width: 2; }
#treeGraph .edges path.open { stroke: #9a73a1; stroke-dasharray: 5 4; }
#treeGraph .edges path.on { stroke: var(--accent); }
.tcolwrap { display: grid; grid-template-rows: auto 1fr; gap: 12px; justify-items: center; }
.tgate { min-height: 1.3em; font: 600 10px/1.3 var(--title); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.tgate.locked { color: var(--danger); }
.tcol { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; align-content: center; }
#treeInfo .gatehint { flex-basis: 100%; margin: 0; font-size: 14px; color: var(--danger); }
#treeInfo .selhint { flex-basis: 100%; margin: 0; font-size: 14px; }
#tree .na { opacity: .35; }
#tree .tn.target { border-color: var(--accent-hi); cursor: copy; }
.tn { position: relative; width: 48px; height: 48px; padding: 10px; cursor: pointer; color: #6e6472; filter: saturate(.3);
  background: radial-gradient(circle at 50% 40%, #221c25, #0c0b0d); border: 1px solid #3d3042; }
.tn :is(svg, img) { width: 100%; height: 100%; display: block; }
.tn.passive { border-radius: 50%; }
.tn.open { color: var(--accent); filter: none; border-color: var(--accent); animation: chainPulse 1.6s ease-in-out infinite; }
.tn.unlocked { color: var(--accent-hi); filter: drop-shadow(0 0 3px rgba(226, 198, 230, .3)); border-color: var(--accent); }
.tn .rk { position: absolute; right: -6px; bottom: -6px; font: 600 10px var(--title); padding: 0 3px; color: var(--text); background: var(--black); border: 1px solid var(--border); }
.tn.unlocked .rk { color: var(--accent-hi); border-color: var(--accent); }
.tn .rk.gate { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, #000); }
.tn kbd { position: absolute; left: -6px; top: -6px; font-size: 9px; padding: 0 3px; }
#tip .trow { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
#tip .trow > :last-child { white-space: nowrap; color: var(--muted); }
#tip .trow.sub { font-style: normal; color: var(--accent); border-top: 1px solid var(--border-soft); padding-top: 4px; margin-top: 2px; }
#tip .trow.sub > :last-child { color: var(--text); white-space: normal; text-align: right; }
#tip .trow > .bad { color: var(--danger); }
#tip .desc { margin: 0; font-size: 15px; }
#tip .nums { margin: 0; font-size: 13px; color: var(--muted); }
#tip .hint { margin: 2px 0 0; font-size: 13px; color: var(--muted); font-style: italic; }
.hint { margin: 8px 0 0; color: var(--accent-hi); font-size: 14px; }
#codex { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(760px, calc(100% - 32px)); height: min(560px, calc(100% - 140px)); }
#codexTabs { margin-bottom: 10px; overflow-x: auto; }
#codexTabs button { flex: 1 0 auto; font-size: 12px; letter-spacing: .08em; }
#codexBody { display: grid; grid-template-columns: 220px 1fr; gap: 14px; min-height: 0; flex: 1; }
#codexList { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
#codexList button { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px; cursor: pointer; text-align: left;
  font: 600 13px var(--title); color: var(--text); background: rgba(0, 0, 0, .35); border: 1px solid transparent; }
#codexList button[aria-current=true] { border-color: var(--accent); color: var(--accent-hi); }
#codexList button.unseen { color: var(--muted); font-style: italic; }
#codexList small { font: 600 11px var(--title); color: var(--muted); white-space: nowrap; }
#codexList .max { color: var(--accent-hi); }
:is(#codexEntry, #readBody) h3 { margin: 0 0 6px; font: 600 18px var(--title); color: var(--accent-hi); letter-spacing: .06em; }
#codexEntry h4 { margin: 14px 0 4px; font: 600 12px var(--title); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
:is(#codexEntry, #readBody) .lore { margin: 0 0 8px; font-style: italic; }
#codexEntry .locked { margin: 0; color: var(--muted); font-size: 14px; }
#codexEntry dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; margin: 0; }
#codexEntry dd { margin: 0; color: var(--muted); }
#codexEntry .pbar { margin: 6px 0 10px; }
#codexEntry .pbar .fill { background: linear-gradient(90deg, #4a3a5c, #8f74b8); }
.btn.audio { margin: 0 0 10px; }
.btn.audio[aria-disabled="true"] { cursor: default; opacity: .6; }
#read { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(520px, calc(100% - 32px)); }
#read .lore { line-height: 1.5; }
#tBook[hidden] { display: none; }
#tBook :is(svg, img) { width: 100%; height: 100%; display: block; }
.tname .book { display: inline-block; width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px; color: var(--accent-hi); }
@media (max-width: 640px) { #codexBody { grid-template-columns: 1fr; grid-template-rows: minmax(0, 40%) 1fr; } }
#help { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100% - 32px)); }
#menu { left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(300px, calc(100% - 32px)); gap: 10px; text-align: center; }
#menu .btn { width: 100%; }
#menu label { text-align: left; }
#help dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
#help dt { text-align: right; white-space: nowrap; }
#help dd { margin: 0; color: var(--muted); }

.equip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.equip .slotwrap { display: grid; justify-items: center; gap: 3px; font: 600 10px var(--title); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.slot {
  position: relative; width: 58px; height: 58px; padding: 0; cursor: pointer; color: var(--t0);
  background: radial-gradient(circle at 50% 45%, #231d26, #0c0b0d); border: 1px solid #3d3042;
  box-shadow: inset 0 0 0 2px #070607, inset 0 0 10px rgba(0, 0, 0, .8);
}
.equip .slot { width: 72px; height: 72px; }
.slot :is(svg, img) { width: 60%; height: 60%; display: block; margin: auto; }
.slot.empty :is(svg, img) { color: #3d3340; }
.slot[aria-pressed=true] { border-color: var(--accent-hi); box-shadow: inset 0 0 0 2px #070607, 0 0 12px rgba(226, 198, 230, .45); }
.slot .qty, .slot .plus { position: absolute; font-size: 12px; line-height: 1; text-shadow: 0 1px 2px #000, 0 0 3px #000; }
.slot .qty { right: 4px; bottom: 3px; color: var(--text); }
.slot .plus { left: 4px; top: 4px; font-weight: 700; }
.slot.tier-t1 { border-color: color-mix(in srgb, var(--t1) 55%, #000); }
.slot.tier-t2 { border-color: color-mix(in srgb, var(--t2) 60%, #000); }
.slot.tier-t3 { border-color: color-mix(in srgb, var(--t3) 65%, #000); }
#invGrid { display: grid; grid-template-columns: repeat(6, 58px); gap: 6px; justify-content: start; padding: 4px; border: 1px solid transparent; }
#invGrid .none { grid-column: 1 / -1; color: var(--muted); font-style: italic; }
/* selection (shard / elixir / item): valid targets light up, the rest dims */
#invBar { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
#invBar h3 { margin: 0; }
#invTools { display: flex; gap: 4px; }
#invTools button { width: 34px; height: 34px; padding: 6px; cursor: pointer; color: var(--accent); background: rgba(0, 0, 0, .4); border: 1px solid #3d3042; }
#invTools button :is(svg, img) { width: 100%; height: 100%; display: block; }
#invTools button:hover { border-color: var(--accent); }
#invStock { margin-left: auto; display: flex; gap: 4px; }
.stock { display: inline-flex; align-items: center; gap: 3px; height: 30px; padding: 0 7px; cursor: pointer; font: 600 12px var(--title); color: var(--text);
  background: rgba(0, 0, 0, .4); border: 1px solid #3d3042; }
.stock :is(svg, img) { width: 15px; height: 15px; color: var(--accent); }
.stock:hover { border-color: var(--accent); }
.stock[aria-pressed=true] { border-color: var(--accent-hi); box-shadow: 0 0 10px rgba(226, 198, 230, .45); background: rgba(180, 139, 187, .18); }
#invModeHint { margin: 6px 0; min-height: 1.2em; font-size: 14px; }
#invFilter { margin-bottom: 6px; }
#invFilter button { font-size: 12px; padding: 6px; }
#inv .na { opacity: .35; }
#inv .slot.target, #inv .stock.target { border-color: var(--accent-hi); cursor: copy; }
#inv .slot.drop { border-color: var(--accent-hi); box-shadow: 0 0 12px rgba(226, 198, 230, .5); }
#tip { position: fixed; z-index: 10; width: 250px; padding: 10px 12px; display: grid; gap: 4px; pointer-events: none; }
#tip .iname { font: 600 17px var(--title); letter-spacing: .04em; }
#tip .sub { color: var(--muted); font-size: 14px; font-style: italic; }
#tip ul { list-style: none; margin: 2px 0; padding: 0; }
#tip li { display: flex; justify-content: space-between; font-size: 15px; }
#tip li b { color: var(--text); font-weight: 600; }
#tip li { flex-wrap: wrap; }
#tip li small { flex-basis: 100%; text-align: right; font-size: 12px; color: var(--muted); }
#tip .eff { margin: 0; font-size: 14px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.list li .acts { display: flex; gap: 4px; flex-shrink: 0; }
#salvageMenu { margin-top: 10px; }
#salvageMenu summary { cursor: pointer; font: 600 12px var(--title); letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
#salvageMenu .salvage { display: grid; gap: 6px; margin-top: 8px; }
#salvageMenu label { display: flex; align-items: center; gap: 8px; font: 15px var(--body); letter-spacing: 0; text-transform: none; color: var(--text); }
#salvageMenu input[type=number] { width: 64px; padding: 2px 6px; }
#salvageMenu small { color: var(--muted); }
#partyForm { display: flex; gap: 6px; margin-top: 8px; }
#partyForm input { flex: 1; min-width: 0; padding: 4px 8px; }
#invite { left: 50%; top: 90px; transform: translateX(-50%); padding: 12px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }

/* ---------- Item rarity: color by tier, glow by plus ---------- */
.iname { color: var(--t0); }
.tier-t1 { --rc: var(--t1); } .tier-t2 { --rc: var(--t2); } .tier-t3 { --rc: var(--t3); }
.iname.tier-t1, .iname.tier-t2, .iname.tier-t3, .slot.tier-t1, .slot.tier-t2, .slot.tier-t3 { color: var(--rc); }
.p5 { --glow: var(--rc, #fff6dc); text-shadow: 0 0 6px color-mix(in srgb, var(--glow) 70%, transparent); }
.slot.p5 { box-shadow: inset 0 0 0 2px #070607, inset 0 0 14px color-mix(in srgb, var(--rc, #fff6dc) 35%, transparent); }
.slot.p5 :is(svg, img) { filter: drop-shadow(0 0 4px var(--rc, #fff6dc)); }
.iname.p10 {
  background: linear-gradient(100deg, var(--rc, #f3ead2) 0%, var(--rc, #f3ead2) 40%, #fff 50%, var(--rc, #f3ead2) 60%, var(--rc, #f3ead2) 100%) 0 0 / 250% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none;
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--rc, #fff6dc) 70%, transparent)); animation: shimmer 2.4s linear infinite;
}
.slot.p10 { animation: slotGlow 2s ease-in-out infinite; }
@keyframes shimmer { from { background-position: 125% 0; } to { background-position: -125% 0; } }
@keyframes slotGlow { 50% { box-shadow: inset 0 0 0 2px #070607, inset 0 0 22px color-mix(in srgb, var(--rc, #fff6dc) 55%, transparent), 0 0 10px color-mix(in srgb, var(--rc, #fff6dc) 45%, transparent); } }
/* particles: two sparks orbit/rise on the highest grades */
.slot.p13::before, .slot.p13::after, .slot.tier-t3::before, .slot.tier-t3::after {
  content: ""; position: absolute; width: 4px; height: 4px; border-radius: 50%; background: var(--rc, #fff6dc);
  box-shadow: 0 0 6px 2px var(--rc, #fff6dc); left: 20%; bottom: 10%; animation: spark 1.8s ease-in infinite; pointer-events: none;
}
.slot.p13::after, .slot.tier-t3::after { left: 70%; animation-delay: .9s; }
@keyframes spark { 0% { transform: translateY(0); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(-46px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition: none !important; }
  .iname.p10 { animation: none; }
  #zoneTitle.show, #banner.show { animation: none; opacity: 1; }
}
@media (max-width: 760px) {
  #bottom { bottom: 110px; gap: 12px; }
  #icons { bottom: 60px; }
  #log { bottom: 214px; } #castbar { bottom: 184px; } #chat { bottom: 174px; }
  #inv:not([hidden]) ~ #party { right: 16px; }
  #invGrid { grid-template-columns: repeat(5, 54px); }
  .slot { width: 54px; height: 54px; }
}
