:root {
  --bg: #0a0d12; --panel: rgba(13, 17, 24, .94); --line: #273040;
  --text: #ece6d3; --muted: #8c95a5; --gold: #ffd76a;
  --thorn: #ff7a4d; --wind: #5ec8ff; --bloom: #7be38a; --graft: #c7a6ff; --core: #f6e7b8;
  --heartwood: #d6a86a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
#game { position: fixed; inset: 0; display: block; cursor: crosshair; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0 0 auto 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px 18px; pointer-events: none; z-index: 5; }
.hud-left, .hud-right { width: 300px; }
.hud-left { display: flex; flex-direction: column; gap: 6px; }
.hud-right { display: flex; justify-content: flex-end; }
.bar { position: relative; height: 18px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12);
  border-radius: 9px; overflow: hidden; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; }
.bar.hp .fill { background: linear-gradient(90deg, #c9363f, #ff7b69); }
.bar.xp { height: 11px; }
.bar.xp .fill { background: linear-gradient(90deg, #3fae5e, #b4f59a); }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 11px; font-weight: 700; line-height: 16px; text-shadow: 0 1px 2px #000; }
.bar.xp span { font-size: 9px; line-height: 10px; }
.hud-row { display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
#dashPips { display: flex; gap: 4px; }
.pip { width: 20px; height: 6px; border-radius: 3px; background: rgba(94,200,255,.18); }
.pip.on { background: var(--wind); box-shadow: 0 0 6px var(--wind); }
#shieldInd { color: var(--gold); }
#shieldInd.down { color: #5d5440; }
.hud-center { text-align: center; padding-top: 2px; }
#waveText { font-size: 18px; font-weight: 800; letter-spacing: .2em; }
#waveSub { font-size: 12px; color: var(--muted); margin-top: 2px; }
#pointsBadge { pointer-events: auto; border: 1px solid var(--gold); background: rgba(255,215,106,.12); color: var(--gold);
  padding: 8px 14px; border-radius: 999px; font-weight: 700; font-size: 13px; animation: glowPulse 1.6s ease-in-out infinite; }
@keyframes glowPulse { 50% { box-shadow: 0 0 18px rgba(255,215,106,.5); } }

#quests { position: fixed; left: 18px; bottom: 16px; width: 250px; pointer-events: none; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
#quests .q-head { font-size: 10px; letter-spacing: .18em; text-transform: uppercase; color: var(--gold); opacity: .8; }
#quests .q { background: rgba(10,13,18,.7); border: 1px solid rgba(255,215,106,.2); border-radius: 8px; padding: 6px 9px; font-size: 12px; }
#quests .q .top { display: flex; justify-content: space-between; gap: 8px; }
#quests .q .num { color: var(--muted); font-variant-numeric: tabular-nums; }
#quests .q .qb { height: 3px; margin-top: 5px; background: rgba(255,215,106,.15); border-radius: 2px; overflow: hidden; }
#quests .q .qb div { height: 100%; background: var(--gold); }

#bossBar { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); width: min(520px, 60vw); z-index: 5; pointer-events: none; text-align: center; }
#bossBar .label { font-size: 11px; letter-spacing: .3em; text-transform: uppercase; color: #ff8a9c; margin-bottom: 4px; }
#bossBar .track { height: 10px; border-radius: 5px; background: rgba(255,255,255,.08); overflow: hidden; border: 1px solid rgba(255,80,110,.4); }
#bossFill { height: 100%; width: 100%; background: linear-gradient(90deg, #9e1838, #ff4f6d); }

#banner { position: fixed; top: 22%; left: 0; right: 0; text-align: center; pointer-events: none; z-index: 6; opacity: 0; }
#banner.show { animation: bannerAnim 2.6s ease forwards; }
#banner .b-title { font-size: 42px; font-weight: 800; letter-spacing: .14em; text-shadow: 0 0 24px rgba(0,0,0,.8); }
#banner .b-sub { font-size: 16px; color: var(--muted); margin-top: 6px; }
#banner.gold .b-title { color: var(--gold); text-shadow: 0 0 30px rgba(255,215,106,.6); }
#banner.gold .b-sub { color: #f3e3b0; }
@keyframes bannerAnim { 0% { opacity: 0; transform: translateY(10px); } 12% { opacity: 1; transform: none; } 75% { opacity: 1; } 100% { opacity: 0; } }

#toasts { position: fixed; right: 18px; top: 70px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; z-index: 7; pointer-events: none; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--bloom); padding: 9px 14px;
  border-radius: 8px; font-size: 13px; max-width: 320px; animation: toastAnim 3.6s ease forwards; }
.toast.gold { border-left-color: var(--gold); color: #fbeec2; }
@keyframes toastAnim { 0% { opacity: 0; transform: translateX(20px); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Screens ---------- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(5,7,10,.78); backdrop-filter: blur(3px); z-index: 10; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px 40px; text-align: center; max-width: 760px; }
.eyebrow { font-size: 12px; letter-spacing: .3em; text-transform: uppercase; color: var(--muted); }
.title-card h1 { font-size: 64px; letter-spacing: .22em; margin: 8px 0 4px; font-weight: 800;
  background: linear-gradient(90deg, var(--thorn), var(--core) 45%, var(--bloom) 70%, var(--wind)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tag { color: #cfc8b4; margin: 0 0 22px; }
.pillars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 24px; text-align: left; }
.pillars div { background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.pillars b { display: block; margin-bottom: 4px; }
.pillars span { font-size: 13px; color: var(--muted); }
.btn { border: 1px solid var(--line); background: #18202c; padding: 10px 26px; border-radius: 10px; font-weight: 700; letter-spacing: .06em; }
.btn.primary { background: linear-gradient(180deg, #f6e7b8, #d9c48c); color: #1a1408; border-color: #f6e7b8; }
.btn.primary:hover { filter: brightness(1.08); }
.controls { margin-top: 20px; font-size: 13px; color: var(--muted); }
kbd { background: #1b2330; border: 1px solid #2f3a4b; border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; font-family: inherit; font-size: 12px; color: var(--text); }
#bestLine { margin-top: 10px; font-size: 12px; }

/* ---------- Tree screen ---------- */
.screen.tree { display: grid; grid-template-columns: 270px minmax(0, 1fr) 310px; gap: 16px; align-items: stretch; padding: 18px; }
.tree-side { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; overflow-y: auto; font-size: 13px; }
.tree-side h3 { margin: 0 0 10px; font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.tree-main { display: flex; flex-direction: column; align-items: center; min-height: 0; gap: 8px; }
.tree-top { min-height: 28px; display: flex; align-items: center; }
.pts { font-size: 14px; color: var(--muted); }
.pts.on { color: var(--gold); font-weight: 700; font-size: 16px; text-shadow: 0 0 14px rgba(255,215,106,.4); }
#treeSvg { flex: 1; width: 100%; min-height: 0; }

#statList table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
#statList td { padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,.05); }
#statList td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
#statList em { color: var(--muted); font-style: normal; font-weight: 400; font-size: 11px; }
#statList h4 { margin: 6px 0 8px; font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.run-line { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.ab { padding: 6px 8px; border-left: 3px solid var(--c); background: rgba(255,255,255,.03); border-radius: 4px; margin-bottom: 5px; }
.ab.aw { border-left-color: var(--gold); color: #fbeec2; }

#nodeInfo h2 { margin: 4px 0 6px; font-size: 20px; }
.info-kind { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; font-weight: 700; }
.info-meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.desc { font-size: 14px; line-height: 1.5; }
.note { color: var(--muted); }
.warn { color: #ffb38f; background: rgba(255,122,77,.08); border: 1px solid rgba(255,122,77,.25); border-radius: 8px; padding: 8px 10px; }
.legend { padding-left: 18px; line-height: 1.5; }
.legend li { margin-bottom: 6px; }
.challenge { border: 1px solid rgba(255,215,106,.35); background: rgba(255,215,106,.05); border-radius: 10px; padding: 10px 12px; margin: 12px 0; line-height: 1.45; }
.challenge.done { background: rgba(255,215,106,.12); }
.ch-title { color: var(--gold); font-weight: 700; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; margin-bottom: 4px; }
.ch-bar { height: 5px; background: rgba(255,215,106,.15); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.ch-bar div { height: 100%; background: var(--gold); }
.ch-num { font-size: 11px; color: var(--muted); margin-top: 4px; }
.ch-reward { margin-top: 6px; color: #f3e3b0; }
.action { margin-top: 12px; text-align: center; padding: 9px; border-radius: 8px; font-weight: 700; }
.action.go { background: rgba(255,215,106,.15); color: var(--gold); border: 1px solid rgba(255,215,106,.4); }
.action.off { background: rgba(255,255,255,.03); color: var(--muted); }
.action.done { color: var(--bloom); background: rgba(123,227,138,.08); }

/* SVG tree */
svg .ring { fill: none; stroke: rgba(246,231,184,.07); stroke-dasharray: 2 7; }
svg .blabel { font-size: 15px; font-weight: 800; letter-spacing: .3em; text-anchor: middle; dominant-baseline: middle; opacity: .85; }
svg .edge { stroke: #252d3a; stroke-width: 3; stroke-linecap: round; }
svg .edge.open { stroke: #5b6576; stroke-dasharray: 6 6; animation: dashMove 1.1s linear infinite; }
svg .edge.lit { stroke: var(--c); stroke-width: 4; }
svg .edge.sealed { stroke: #181d25; }
@keyframes dashMove { to { stroke-dashoffset: -12; } }
.node { cursor: pointer; }
.node .hit { fill: transparent; }
.node .body { fill: #111720; stroke: #394353; stroke-width: 2.5; }
.node .glyph { font-size: 15px; text-anchor: middle; dominant-baseline: central; fill: #5f6878; pointer-events: none; }
.node.k-keystone .glyph { font-size: 21px; }
.node.k-core .glyph { font-size: 28px; }
.node.k-fork .glyph { font-size: 17px; }
.node .rank { font-size: 11px; font-weight: 700; text-anchor: middle; fill: #8c95a5; pointer-events: none; }
.node .inner { fill: none; stroke: #394353; stroke-width: 1.5; }
.node.st-locked { opacity: .45; }
.node.st-sealed { opacity: .25; cursor: not-allowed; }
.node.st-available .body { stroke: var(--c); stroke-dasharray: 4 3; }
.node.buyable .body { stroke: var(--c); stroke-dasharray: none; animation: nodePulse 1.4s ease-in-out infinite; }
.node.buyable .glyph { fill: var(--c); }
@keyframes nodePulse { 50% { stroke-width: 5; } }
.node.st-partial .body, .node.st-maxed .body { fill: color-mix(in srgb, var(--c) 32%, #0f141b); stroke: var(--c); }
.node.st-partial .glyph { fill: var(--c); }
.node.st-maxed .glyph { fill: #fff; }
.node.st-maxed .rank { fill: var(--c); }
.node.st-partial .inner, .node.st-maxed .inner { stroke: var(--c); stroke-opacity: .5; }
.node.sel .body { stroke-width: 4; }
.node:hover .body { stroke-width: 4; }
.node .prog-bg { fill: none; stroke: rgba(255,215,106,.15); stroke-width: 3; }
.node .prog { fill: none; stroke: var(--gold); stroke-width: 3; stroke-linecap: round; }
.node.awake .body { stroke: var(--gold); }
.node.awake .glyph { fill: #fff6d6; }
.node .halo { fill: none; stroke: var(--gold); stroke-width: 2; animation: halo 2.4s ease-in-out infinite; }
@keyframes halo { 50% { opacity: .35; } }
.node .seal { stroke: #ff5a5a; stroke-width: 2.5; stroke-linecap: round; }
#deathSvg .node { cursor: default; }
#deathSvg .node.buyable .body { animation: none; }

/* Death */
.death-card { max-width: 640px; width: 100%; max-height: 100%; overflow-y: auto; }
.death-card h1 { margin: 6px 0 10px; font-size: 34px; color: var(--core); }
#deathStats { display: flex; justify-content: center; gap: 22px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
#deathStats b { display: block; font-size: 20px; color: var(--text); }
#deathSvg { width: 100%; max-height: 46vh; margin: 8px 0 14px; }

@media (max-width: 1000px) {
  .screen.tree { grid-template-columns: 1fr; grid-template-rows: auto minmax(320px, 1fr) auto; overflow-y: auto; }
  .tree-side { max-height: 30vh; }
  .pillars { grid-template-columns: 1fr; }
  .title-card h1 { font-size: 42px; }
}

/* ---------- v0.2 additions ---------- */
#hint { position: fixed; left: 50%; bottom: 62px; transform: translate(-50%, 10px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 16px; font-size: 14px; z-index: 6; pointer-events: none; opacity: 0; transition: opacity .35s, transform .35s; max-width: 90vw; text-align: center; }
#hint.show { opacity: 1; transform: translate(-50%, 0); }
#soundBtn { position: fixed; right: 16px; bottom: 14px; z-index: 12; background: rgba(13,17,24,.8); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: 12px; color: var(--muted); }
#soundBtn:hover { color: var(--text); }
#soundBtn.off { color: #5d6573; text-decoration: line-through; }
.audio-ctl { display: flex; flex-direction: column; gap: 10px; margin: 6px 0 20px; min-width: 260px; }
.audio-ctl label { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.audio-ctl span { width: 56px; text-align: left; }
.audio-ctl input { flex: 1; accent-color: var(--core); }
#deathRings { margin-top: 12px; font-size: 13px; color: var(--heartwood); }

#statList tr.changed td { background: rgba(255,255,255,.03); }
#statList .old { color: var(--muted); font-weight: 400; }
#statList .delta.up { color: var(--bloom); }
#statList .delta.down { color: #ff8a7a; }
.preview-line { font-size: 12px; color: var(--gold); margin: -4px 0 8px; }
.ab.preview { border-left-style: dashed; color: var(--gold); background: rgba(255,215,106,.06); }
.ch-hw { margin-top: 8px; padding-top: 8px; border-top: 1px dashed rgba(214,168,106,.35); color: var(--heartwood); font-size: 12px; }

.node .hw { fill: none; stroke: var(--heartwood); stroke-width: 1.2; opacity: .75; pointer-events: none; }
.node .shape { transform-box: fill-box; transform-origin: center; }
.node.pop .shape { animation: nodePop .55s cubic-bezier(.3,1.6,.5,1); }
@keyframes nodePop { 0% { transform: scale(.6); } 100% { transform: scale(1); } }
.node .burst { fill: none; stroke: var(--c); stroke-width: 3; transform-box: fill-box; transform-origin: center; animation: nodeBurst .65s ease-out forwards; pointer-events: none; }
@keyframes nodeBurst { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(2.4); opacity: 0; } }
svg .edge.grow { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: edgeGrow .45s ease-out forwards; }
@keyframes edgeGrow { to { stroke-dashoffset: 0; } }
