:root {
  --bg: #0f0b14;
  --panel: rgba(22, 16, 30, 0.86);
  --panel-solid: #1a1324;
  --line: #3a2d4a;
  --text: #ece4f4;
  --muted: #9b8fae;
  --accent: #b88cff;
  --accent-2: #ffb35c;
  --danger: #ff5a6a;
  --good: #7fe0a0;
  --aether: #5ee6ff;
  --hp: #e0505e;
  --shield: #a0e8ff;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
kbd {
  display: inline-block; min-width: 1.5em; padding: 0 0.35em; border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px; background: #241a31; font-size: 0.75rem;
  font-family: ui-monospace, monospace; text-align: center; line-height: 1.4;
}
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.error { color: var(--danger); min-height: 1.2em; margin: 0.5rem 0 0; }
.hidden { display: none !important; }

/* Screens */
.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

/* Buttons */
.btn {
  padding: 0.55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: #241a31;
  cursor: pointer; transition: background 0.1s, border-color 0.1s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(#7d4fd6, #5d33b0); border-color: #9a6cf0; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 0.15rem 0.5rem; font-size: 0.8rem; }
.btn.wide { width: 100%; }

/* Menu */
#screen-menu {
  display: none; place-items: center;
  background: radial-gradient(ellipse at 30% 40%, #2a1840 0%, var(--bg) 60%);
}
#screen-menu.active { display: grid; overflow: auto; }
.menu-layout { display: flex; gap: 1.5rem; align-items: flex-start; padding: 16px; flex-wrap: wrap; justify-content: center; }
.changelog {
  width: min(380px, calc(100vw - 32px)); max-height: min(520px, 80vh); overflow: auto; padding: 1.2rem 1.4rem;
  border-radius: 16px; background: var(--panel); border: 1px solid var(--line);
}
.changelog h2 { margin: 0 0 0.6rem; font-size: 1.1rem; color: #e6cf98; }
.cl-entry { padding: 0.6rem 0; border-top: 1px solid var(--line); }
.cl-entry:first-child { border-top: none; padding-top: 0; }
.cl-head { display: flex; justify-content: space-between; gap: 0.6rem; align-items: baseline; }
.cl-title { font-weight: 700; }
.cl-date { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.cl-entry ul { margin: 0.35rem 0 0; padding-left: 1.1rem; font-size: 0.85rem; color: #d6cce2; }
.cl-entry li { margin: 0.2rem 0; }
.menu-card {
  width: min(380px, calc(100vw - 32px)); padding: 2rem; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 0.8rem;
}
.logo {
  margin: 0; font-size: 2.6rem; letter-spacing: 0.04em; text-align: center;
  background: linear-gradient(90deg, var(--accent-2), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { margin: 0 0 0.5rem; text-align: center; color: var(--muted); font-size: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--muted); }
input, select {
  padding: 0.55rem 0.7rem; border-radius: 8px; border: 1px solid var(--line); background: #120d19; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.or { text-align: center; color: var(--muted); font-size: 0.8rem; }
.join-row { display: flex; gap: 0.5rem; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 0.3em; text-align: center; min-width: 0; }

.open-lobbies { border-top: 1px solid var(--line); padding-top: 0.8rem; }
.ol-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; margin-bottom: 0.4rem; }
#open-lobbies { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; max-height: 240px; overflow: auto; }
#open-lobbies li:not(.ol-empty) {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.6rem; border-radius: 8px; background: #120d19; border: 1px solid var(--line);
}
.ol-info { flex: 1; min-width: 0; }
.ol-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Lobby */
#screen-lobby { overflow: auto; background: radial-gradient(ellipse at 70% 20%, #24163a 0%, var(--bg) 60%); }
.lobby { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px; }
.lobby-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.code-row { display: flex; align-items: center; gap: 0.6rem; }
.code { font-size: 2rem; font-weight: 700; letter-spacing: 0.3em; color: var(--accent-2); }
.lobby-body { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.lobby-col { flex: 0 0 300px; min-width: 0; }
.lobby-col.grow { flex: 1 1 400px; }
.lobby h2 { font-size: 1rem; color: var(--muted); font-weight: 600; margin: 1rem 0 0.5rem; }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.players li {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.7rem; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line);
}
.players .dot { width: 12px; height: 12px; border-radius: 50%; background: #444; flex: none; }
.players .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .tag { font-size: 0.75rem; color: var(--muted); }
.settings { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.8rem; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.setting.check { justify-content: flex-start; }
.setting em { font-style: normal; font-size: 0.8rem; }
.mage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.8rem; }
.mage-card {
  text-align: left; padding: 0.9rem; border-radius: 12px; border: 2px solid var(--line); background: var(--panel);
  cursor: pointer; display: flex; flex-direction: column; gap: 0.35rem;
}
.mage-card:hover:not(:disabled) { border-color: var(--mc, var(--accent)); }
.mage-card.mine { border-color: var(--mc); box-shadow: 0 0 0 1px var(--mc), 0 0 18px -6px var(--mc); }
.mage-card:disabled { opacity: 0.5; cursor: not-allowed; }
.mage-card .mname { font-size: 1.15rem; font-weight: 700; color: var(--mc); display: flex; justify-content: space-between; }
.mage-card .mrole { font-size: 0.75rem; color: var(--muted); font-weight: 500; }
.mage-card .mdesc { font-size: 0.85rem; }
.mage-card .mstat { font-size: 0.78rem; color: var(--muted); }
.mage-card .mtaken { font-size: 0.78rem; color: var(--accent-2); }

/* Game */
#world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; }
#hud { position: absolute; inset: 0; pointer-events: none; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.5rem 0.6rem; }
.panel-title { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.3rem; }

.bar { position: relative; height: 14px; border-radius: 7px; background: #2a2032; overflow: hidden; }
.bar.big { height: 18px; }
.phase-mark { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: rgba(255, 240, 220, 0.75); z-index: 1; pointer-events: none; }
.bar.hp { height: 20px; border-radius: 6px; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; transform-origin: left; transition: transform 0.12s linear; }
.bar-text { position: absolute; inset: 0; display: grid; place-items: center; font-size: 0.72rem; font-weight: 600; text-shadow: 0 1px 2px #000; }
.nem-fill { background: linear-gradient(90deg, #8a1f35, #d23c55); }
.city-fill { background: linear-gradient(90deg, #6b5a3a, #c9a86a); }
.hp-fill { background: linear-gradient(90deg, #a83444, var(--hp)); }
.shield-fill { background: var(--shield); opacity: 0.8; }

.hud-top { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); width: min(560px, calc(100vw - 32px)); }
.nem-line { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 3px; text-shadow: 0 1px 3px #000; }
.nem-name { font-weight: 700; color: #ff8a9a; }
.powers { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.power { background: var(--panel); border: 1px solid #6a2a3a; border-radius: 8px; padding: 0.35rem 0.6rem; }
.power .ptitle { display: flex; justify-content: space-between; font-size: 0.85rem; font-weight: 600; }
.power .pdesc { font-size: 0.75rem; color: var(--muted); }
.power .pfail { font-size: 0.72rem; color: #ff9aa4; }
.power .pfail:empty { display: none; }
.power .pbar { height: 5px; border-radius: 3px; background: #2a2032; margin-top: 4px; overflow: hidden; }
.power .pbar > div { height: 100%; background: var(--danger); transform-origin: left; }
.power .pprog { font-size: 0.78rem; color: var(--accent-2); font-weight: 600; }
.power.paused { border-color: #79b8ff; }

.hud-left { position: absolute; top: 10px; left: 10px; width: 220px; display: flex; flex-direction: column; gap: 8px; }
.allies { display: flex; flex-direction: column; gap: 6px; }
.ally .aname { display: flex; justify-content: space-between; font-size: 0.8rem; margin-bottom: 2px; }
.ally .aname b { color: var(--ac); }
.ally .state { font-size: 0.7rem; font-weight: 700; }
.ally .bar { height: 8px; }
.ally.down .state { color: var(--danger); }
.ally.dead { opacity: 0.6; }

.hud-right { position: absolute; top: 10px; right: 10px; }
#minimap { display: block; border-radius: 8px; border: 1px solid var(--line); background: rgba(10, 8, 14, 0.8); }

.prompt {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); padding: 0.35rem 0.8rem;
  border-radius: 8px; background: var(--panel); border: 1px solid var(--line); font-size: 0.9rem; display: none;
}
.prompt.show { display: block; }
.banner {
  position: absolute; left: 50%; top: 32%; transform: translateX(-50%); font-size: 1.6rem; font-weight: 800;
  text-shadow: 0 2px 8px #000; opacity: 0; transition: opacity 0.3s; text-align: center; white-space: nowrap;
}
.banner.show { opacity: 1; }
.tip {
  position: absolute; left: 50%; top: 76px; transform: translateX(-50%); max-width: min(640px, calc(100vw - 32px));
  padding: 0.5rem 0.9rem; border-radius: 10px; background: var(--panel); border: 1px solid #5a4672; font-size: 0.95rem;
  text-align: center; opacity: 0; transition: opacity 0.4s; pointer-events: none;
}
.tip.show { opacity: 1; }
@keyframes aether-glow { 0%, 100% { box-shadow: 0 0 0 0 transparent; } 50% { box-shadow: 0 0 10px 1px var(--aether); } }
.aether.can-spend { border-radius: 8px; animation: aether-glow 1.6s ease-in-out infinite; }
.paused {
  position: absolute; left: 50%; top: 22%; transform: translateX(-50%); font-size: 1.1rem; font-weight: 700;
  padding: 0.3rem 0.9rem; border-radius: 8px; background: #2a4a6a; display: none;
}
.paused.show { display: block; }

.hud-bottom {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: flex-end; padding: 0.6rem 0.8rem; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); max-width: calc(100vw - 16px);
}
.vitals { width: 240px; display: flex; flex-direction: column; gap: 6px; }
/* One line whatever the values: the support pill gives way (ellipsis) first. */
.vitals-row { display: flex; gap: 4px; align-items: center; flex-wrap: nowrap; min-width: 0; }
.vitals-row .aether { flex: none; font-size: 0.95rem; margin-right: 2px; font-variant-numeric: tabular-nums; }
.vitals-row .pill { font-size: 0.66rem; padding: 0.12rem 0.38rem; font-variant-numeric: tabular-nums; }
#me-support { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#me-potion { flex: none; }
.aether { display: inline-flex; align-items: center; gap: 4px; color: var(--aether); font-size: 1.05rem; }
.aether.big { font-size: 1.4rem; }
.crystal-icon { width: 10px; height: 10px; background: var(--aether); transform: rotate(45deg); display: inline-block; border-radius: 2px; }
.pill { font-size: 0.72rem; padding: 0.15rem 0.45rem; border-radius: 999px; background: #241a31; border: 1px solid var(--line); white-space: nowrap; }
.pill.cd { color: var(--muted); }
.revive { position: absolute; right: 6px; top: 0; bottom: 0; display: flex; align-items: center; font-size: 0.72rem; font-weight: 700; color: #ffd76a; text-shadow: 0 1px 2px #000; pointer-events: auto; }
.revive.cd { color: #9a8fa8; }
.revive.hidden { display: none; }
.pill.toggle { pointer-events: auto; cursor: pointer; color: var(--muted); }
.pill.toggle.on { color: #1a1220; background: #ffd76a; border-color: #ffd76a; font-weight: 700; }
.group-title { font-size: 0.7rem; color: var(--text); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
.breaches, .spellbar { display: flex; gap: 6px; }

.breach {
  position: relative; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--bc, #555) calc(var(--p, 0) * 1turn), #2a2032 0);
}
.breach::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: #17111f; }
.breach.closed::before { background: repeating-linear-gradient(45deg, #17111f 0 6px, #1f1729 6px 12px); }
.breach.ready { box-shadow: 0 0 14px -2px var(--bc); }
.breach .bnum { position: absolute; top: 9px; font-size: 0.62rem; color: var(--muted); }
.breach .bspell { position: relative; font-size: 0.64rem; text-align: center; line-height: 1.1; padding: 0 6px; max-width: 64px; overflow: hidden; }
/* The cooldown counter: a pill on the ring's bottom edge, clear of the
   spell name (which may take two lines) and the focus line. */
.breach .bcd {
  position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%); z-index: 1;
  padding: 0 5px; border-radius: 7px; border: 1px solid var(--bc, #555); background: #17111f;
  font-size: 0.6rem; font-weight: 700; line-height: 1.45; color: #e6dcf2; white-space: nowrap;
}
.breach .bcd:empty { display: none; }
.tile-breach .breach .bcd {
  position: relative; bottom: auto; left: auto; transform: none; padding: 0; border: none; background: none;
  margin-top: 4px; font-size: 0.7rem; font-weight: 700; color: var(--text);
}
.breach .bfocus { position: absolute; bottom: 9px; font-size: 0.55rem; color: var(--muted); }
.breach .bspell.idle { font-size: 0.72rem; font-weight: 600; color: var(--muted); }
.breach kbd { position: absolute; bottom: -6px; right: -4px; }
.breach .bbadge:empty { display: none; }
.breach .bbadge {
  position: absolute; top: -5px; left: -6px; padding: 0 4px; border-radius: 6px; font-size: 0.55rem; font-weight: 700;
  line-height: 1.5; color: #1a1220; background: var(--tc, #ffb84d); box-shadow: 0 0 6px -1px var(--tc, #ffb84d);
}
.breach .bbadge.off { filter: grayscale(0.8); opacity: 0.55; box-shadow: none; }

.slot {
  position: relative; width: 74px; height: 64px; border-radius: 10px; border: 1px solid var(--line); background: #17111f;
  display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden; padding: 16px 4px 2px;
}
.slot .sname { font-size: 0.68rem; text-align: center; line-height: 1.1; position: relative; }
.slot .srec { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.6); transform-origin: bottom; }
.slot .stime { position: relative; font-size: 0.8rem; font-weight: 700; color: var(--accent-2); }
.slot kbd { position: absolute; top: 3px; left: 3px; font-size: 0.6rem; }
.slot.empty { opacity: 0.4; }
.slot .sbar { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--sc); }

.ability {
  position: relative; width: 120px; height: 64px; border-radius: 10px; border: 1px solid var(--line); background: #17111f;
  display: grid; place-items: center; overflow: hidden; font-size: 0.8rem; font-weight: 600; text-align: center;
}
.ability-fill { position: absolute; left: 0; bottom: 0; right: 0; height: 100%; background: var(--abc, var(--accent)); opacity: 0.35; transform-origin: bottom; }
.ability span { position: relative; }
.ability kbd { position: absolute; top: 3px; left: 3px; }
.ability.full { border-color: var(--abc); box-shadow: 0 0 16px -2px var(--abc); }
.ability.full .ability-fill { opacity: 0.6; }

/* Shop */
.shop {
  position: absolute; left: 50%; top: 52px; transform: translateX(-50%);
  width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 210px);
  display: flex; flex-direction: column; background: rgba(18, 13, 25, 0.96); border: 1px solid #5a4672;
  border-radius: 14px; box-shadow: 0 10px 40px #000a;
}
.shop-head { display: flex; align-items: center; gap: 1rem; padding: 0.6rem 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.shop-head h2 { margin: 0; font-size: 1.2rem; color: #e6cf98; }
.shop-head .small { margin-left: auto; }
.shop-body { display: flex; gap: 12px; padding: 12px; overflow: auto; min-height: 0; }
.shop-spells { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.shop-side { flex: 0 0 248px; display: flex; flex-direction: column; gap: 10px; }
.shop-section { background: #1a1324; border: 1px solid var(--line); border-radius: 10px; padding: 0.5rem 0.6rem; }
.shop-section h3 { margin: 0 0 0.4rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.shop-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 0.25rem 0; font-size: 0.85rem; }
.shop-row .sub { font-size: 0.72rem; color: var(--muted); }
.buy {
  display: inline-flex; align-items: center; gap: 4px; padding: 0.3rem 0.6rem; border-radius: 7px; cursor: pointer;
  border: 1px solid #3d7f8f; background: #143039; color: var(--aether); font-weight: 700; font-size: 0.95rem; white-space: nowrap;
}
.buy:hover:not(:disabled) { background: #1b4450; }
.buy:disabled { border-color: var(--line); background: #1e1826; color: #5d5468; cursor: not-allowed; }

.spell-card { background: #1a1324; border: 1px solid var(--line); border-radius: 10px; padding: 0.5rem 0.6rem; }
.spell-card.unlearned { border-style: dashed; }
/* The selected spell, in full on top */
.spell-card.full { border-color: var(--sc); padding: 0.55rem 0.8rem 0.6rem; }
.spell-card.full .spell-head { margin-bottom: 2px; }
.spell-card.full .sn { font-size: 1.1rem; }
.spell-desc { margin: 0 0 6px; font-size: 0.85rem; color: #cfc4dc; }
/* Every spell, compact, two per row */
.spell-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.spell-card.compact { display: flex; align-items: center; gap: 10px; padding: 0.35rem 0.6rem; cursor: pointer; }
.spell-card.compact:hover { border-color: var(--sc); }
.spell-card.compact.picked { border-color: var(--sc); background: color-mix(in srgb, var(--sc) 16%, #1a1324); }
.spell-card.compact .spell-head { flex: 1 1 auto; min-width: 0; margin: 0; flex-direction: column; align-items: flex-start; gap: 4px; }
.spell-card.compact .spell-head .slots, .spell-card.compact .castkey { margin-left: 0; }
.spell-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.spell-head .names { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.spell-card.compact .names { flex-direction: column; gap: 0; }
.spell-head .sn { font-weight: 700; color: var(--sc); white-space: nowrap; }
.spell-head .sk { font-size: 0.7rem; color: var(--muted); }
.spell-head .slots { margin-left: auto; display: flex; gap: 3px; pointer-events: auto; }
.slotbtn { min-width: 22px; height: 22px; padding: 0 4px; border-radius: 5px; border: 1px solid var(--line); background: #241a31; font-size: 0.72rem; cursor: pointer; }
.slotbtn.on { background: var(--sc); color: #111; border-color: var(--sc); font-weight: 700; }
.castkey {
  margin-left: auto; padding: 1px 7px; border-radius: 5px; border: 1px solid var(--sc); background: #241a31;
  font: inherit; font-size: 0.72rem; font-weight: 700; color: var(--sc); white-space: nowrap;
}
.tree { position: relative; display: grid; width: max-content; }
.tree svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.tree line { stroke: #4a3d5c; stroke-width: 2; vector-effect: non-scaling-stroke; }
.tree line.on { stroke: var(--sc); }
.node {
  position: relative; z-index: 1; margin: 4px 11px; padding: 0.25rem 0.35rem; border-radius: 8px; border: 1px solid var(--line);
  background: #241a31; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  text-align: center;
}
.node .nn { font-size: 0.7rem; line-height: 1.1; }
.node .nf { display: flex; align-items: baseline; gap: 6px; }
.node .nl { font-size: 0.62rem; color: var(--muted); }
.node .nc { font-size: 0.8rem; font-weight: 800; color: var(--aether); }
.node.major { border-color: #b8913a; background: #2d2416; }
.node.major .nn { color: #f0c870; font-weight: 700; }
.node.owned { border-color: var(--sc); }
.node.maxed { border-color: var(--sc); background: color-mix(in srgb, var(--sc) 22%, #1a1324); cursor: default; }
.node.maxed .nc { color: var(--good); font-size: 0.65rem; }
.node.poor .nc { color: #6d6278; }
.node.poor .nn { color: #b3a8c2; }
.node.locked, .node.excluded { background: #18121f; border-style: dashed; cursor: not-allowed; }
.node.locked .nn, .node.locked .nl, .node.locked .nc,
.node.excluded .nn, .node.excluded .nl, .node.excluded .nc { color: #574d63; }
.node.excluded .nn { text-decoration: line-through; }
.tree.mini .node {
  width: 21px; height: 21px; margin: 0; padding: 0; border-radius: 50%; place-self: center; cursor: inherit;
}
.tree.mini .node .nl { font-size: 0.5rem; color: var(--text); letter-spacing: -0.02em; }
.tree.mini .node.poor .nl, .tree.mini .node.locked .nl, .tree.mini .node.excluded .nl { color: #6d6278; }
.tree.mini .node.major { border-width: 2px; }
.node.buyable:hover { border-color: var(--aether); box-shadow: 0 0 10px -3px var(--aether); }
.shop-info {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 0.45rem 1rem;
  border-top: 1px solid var(--line); font-size: 0.8rem; color: var(--muted);
}
.legend { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-left: auto; font-size: 0.72rem; }
/* Colored numbers (richtext.js): one color per kind of stat, everywhere */
.v { font-weight: 700; }
.v-dmg { color: #ff9a4d; }
.v-cd { color: #c39bff; }
.v-def { color: #5fe0a0; }
.v-area { color: #ffd257; }
.v-dur { color: #e8dcc0; }
.v-cc { color: #ff7ab8; }
.v-spd { color: #c6f26b; }
.v-cnt { color: #7aa8ff; }
.v-ae { color: var(--aether); }

/* Controls */
.controls-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(5, 3, 8, 0.7); padding: 16px; }
.controls-overlay.hidden { display: none; }
.controls-card {
  width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 1.2rem 1.4rem;
  border-radius: 16px; background: var(--panel-solid); border: 1px solid var(--line);
}
.controls-card h2 { margin: 0 0 0.3rem; color: #e6cf98; }
.controls-list { list-style: none; margin: 0.6rem 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.controls-list li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.2rem 0; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.controls-list li.fixed { padding: 0.45rem 0; }
.controls-list .key { min-width: 7.5em; }
.controls-list .key.capturing { border-color: var(--accent); color: var(--accent-2); }
.controls-actions { display: flex; justify-content: space-between; gap: 0.6rem; }
.hud-buttons { display: flex; gap: 6px; }

/* Overlays */
.overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 3, 8, 0.7); }
.over-card {
  padding: 1.5rem 2rem; border-radius: 16px; background: var(--panel-solid); border: 1px solid var(--line);
  text-align: center; max-width: calc(100vw - 32px); overflow: auto; max-height: calc(100vh - 32px);
}
.over-card h1 { margin: 0 0 0.3rem; }
.over-card h1.win { color: var(--good); }
.over-card h1.lose { color: var(--danger); }
.stats { border-collapse: collapse; margin: 1rem auto; font-size: 0.85rem; }
.stats th, .stats td { padding: 0.3rem 0.6rem; border-bottom: 1px solid var(--line); }
.stats th { color: var(--muted); font-weight: 600; }

@media (max-width: 900px) {
  .hud-left { width: 170px; }
  #minimap { width: 160px !important; }
  .breach { width: 52px; height: 52px; }
  .slot { width: 60px; height: 52px; }
  .ability { width: 90px; height: 52px; }
  .vitals { width: 150px; }
}

/* Shop shelf (right side): icon tiles with a price tag, details in a tooltip */
.shelf { display: flex; flex-wrap: wrap; gap: 10px 6px; }
.shop-section.empty { display: none; }
.tile {
  width: 52px; padding: 0; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.tile.inert { cursor: default; }
/* Favorites: blue glow, green when affordable now. */
.tile.fav, .node.fav, .node.fav:hover { box-shadow: 0 0 0 2px #4da3ff, 0 0 12px 2px rgba(77, 163, 255, 0.7); border-radius: 10px; }
.tile.fav-buy, .node.fav-buy, .node.fav-buy:hover { box-shadow: 0 0 0 2px #5ee08a, 0 0 14px 3px rgba(94, 224, 138, 0.75); border-radius: 10px; }
.tree.mini .node.fav, .tree.mini .node.fav-buy { border-radius: 50%; }
.tile-visual { width: 48px; height: 48px; display: grid; place-items: center; transition: transform 0.08s; }
.tile-visual > svg { width: 48px; height: 48px; }
.tile:not(.inert):hover .tile-visual { transform: translateY(-2px) scale(1.07); filter: drop-shadow(0 0 6px rgba(94, 230, 255, 0.6)); }
.tile:hover .tile-visual { transform: translateY(-1px); }
.price { display: flex; align-items: center; gap: 3px; font-size: 0.85rem; font-weight: 800; color: var(--aether); line-height: 1; }
.price .crystal-icon { width: 7px; height: 7px; }
.price.poor { color: #d0606e; }
.price.poor .crystal-icon { background: #d0606e; }
.price.none { visibility: hidden; }
.tile.shared .price { flex-wrap: wrap; justify-content: center; row-gap: 1px; }
.price .each { flex-basis: 100%; text-align: center; font-size: 0.58rem; font-weight: 600; opacity: 0.85; }
.party-tag { margin-left: 4px; padding: 0 5px; border-radius: 6px; font-size: 0.6rem; letter-spacing: 0.05em; background: #2f4a6a; color: #bcd8ff; vertical-align: 1px; }
.tile.shared .tile-visual { box-shadow: 0 0 0 1px #4a6d96 inset; border-radius: 8px; }
.shared-hint { margin: 0.35rem 0 0; font-size: 0.68rem; color: var(--muted); }
.item-icon {
  position: relative; width: 48px; height: 48px; display: grid; place-items: center;
  background: #241a31; border: 1px solid var(--line); border-radius: 10px;
}
.item-icon svg { width: 38px; height: 38px; }
.item-icon .count {
  position: absolute; right: -5px; bottom: -5px; padding: 0 4px; font-size: 0.6rem; font-weight: 700;
  border-radius: 6px; background: #120d19; border: 1px solid var(--line);
}
.item-icon .count.zero { color: var(--muted); }
.tile-breach .breach { width: 48px; height: 48px; }
.tile-breach .breach::before { inset: 4px; }
.tile-breach .breach .bnum { top: 7px; font-size: 0.55rem; }
.tile-breach .tile-visual { width: 64px; height: auto; }
.breach-visual { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.breach-visual .bspell { font-size: 0.6rem; line-height: 1.1; text-align: center; color: #d9c4ff; max-width: 64px; }
.tile-breach .breach .bfocus { bottom: 6px; font-size: 0.5rem; }

.shop-tip {
  position: absolute; z-index: 5; width: 250px; padding: 0.5rem 0.65rem; pointer-events: none;
  background: #120d19; border: 1px solid #5a4672; border-radius: 8px; box-shadow: 0 6px 20px #000a;
}
/* Spectators: the followed player's cursor in the shop. */
.remote-cursor { position: absolute; z-index: 6; width: 18px; height: 18px; pointer-events: none; transition: left 0.1s linear, top 0.1s linear; }
.remote-cursor svg { display: block; width: 100%; height: 100%; overflow: visible; }

.tip-title { font-weight: 700; color: #e6cf98; margin-bottom: 3px; }
.tip-title.major { color: #f0c870; }
.tip-sub { display: block; font-size: 0.68rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.tip-hint { margin-top: 4px; font-size: 0.7rem; color: var(--muted); }
.tip-line { font-size: 0.8rem; line-height: 1.35; }
.tip-status { margin-top: 5px; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.tip-status:empty { display: none; }
.tip-status.poor { color: var(--danger); }

.item-icon.owned { border-color: #b8913a; box-shadow: inset 0 0 12px -4px #e6cf98; }
.tile.owned .tile-visual { opacity: 0.85; }
.tip-status.good { color: var(--good); }
.relic-row { display: flex; gap: 3px; min-height: 0; flex-wrap: wrap; }
.relic-row:empty { display: none; }
.relic-mini { width: 18px; height: 18px; display: inline-grid; place-items: center; pointer-events: auto; }
.relic-mini svg { width: 18px; height: 18px; }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.sound-toggle { pointer-events: auto; background: var(--panel); }
.spectate {
  pointer-events: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; padding: 0.45rem 0.7rem;
  border-radius: 8px; background: var(--panel); border: 1px solid #5a4672; font-size: 0.85rem;
}
.spectate.hidden { display: none; }
#shop.spectating .close-keys { display: none; }
#shop.spectating .tile, #shop.spectating .node { cursor: default; }

/* End-of-game feedback form */
.feedback { text-align: left; margin: 0.5rem auto 1rem; max-width: 520px; padding: 0.8rem 1rem; border: 1px solid var(--line); border-radius: 12px; background: #17111f; }
.feedback h3 { margin: 0 0 0.5rem; font-size: 1rem; }
.fb-row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; margin: 0.35rem 0; }
.fb-row > span { font-size: 0.85rem; color: var(--muted); }
.fb-choices { display: flex; gap: 4px; flex-wrap: wrap; }
.fb-choices button { padding: 0.25rem 0.6rem; border-radius: 7px; border: 1px solid var(--line); background: #241a31; color: var(--text); cursor: pointer; font-size: 0.85rem; }
.fb-choices button.on { background: var(--accent); border-color: var(--accent); color: #140d1c; font-weight: 700; }
.feedback textarea, .feedback input { width: 100%; box-sizing: border-box; margin: 0.4rem 0; resize: vertical; padding: 0.5rem 0.6rem; border-radius: 8px; border: 1px solid var(--line); background: #120d19; color: var(--text); font: inherit; font-size: 0.9rem; }
.fb-send { display: flex; align-items: center; gap: 0.8rem; }
.feedback p { margin: 0.5rem 0 0; }

#conn-lost { position: fixed; z-index: 60; }

/* HUD tooltips (ability boxes): hovering them needs pointer events. */
.hud-hover { pointer-events: auto; }
.shop-tip.hud-tip { position: fixed; z-index: 40; }

/* Spell stats in tooltips (spellstats.js): label, value, aligned for comparing. */
.tip-stats { display: grid; grid-template-columns: auto 1fr; gap: 1px 10px; margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--line); font-size: 0.78rem; }
.ts-label { color: var(--muted); white-space: nowrap; }
.ts-value { text-align: right; }
.ts-note { display: block; font-size: 0.66rem; color: var(--muted); }
.spell-head .names { cursor: help; }

/* Effects (buffs and debuffs): icons with a ring for the time left and a
   stack count; tooltips on hover (HUD rows). */
.fx-row { display: flex; gap: 4px; flex-wrap: wrap; min-height: 0; }
.fx-row:empty { display: none; }
.nem-fx { justify-content: center; margin-top: 4px; }
.fx {
  position: relative; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--fc, #fff) calc(var(--p, 1) * 360deg), rgba(255, 255, 255, 0.08) 0);
}
.fx::before { content: ''; position: absolute; inset: 2px; border-radius: 50%; background: #120d19; }
.fx.debuff::before { background: #2a0f16; }
.fx svg { position: relative; width: 18px; height: 18px; }
.fx-n {
  position: absolute; right: -4px; bottom: -4px; min-width: 12px; font-size: 0.62rem; font-weight: 800; line-height: 12px;
  text-align: center; color: #fff; text-shadow: 0 0 3px #000, 0 0 2px #000;
}
.fx-n:empty { display: none; }

/* Cast bar: the channel in progress (recall, Meteor…). */
.castbar {
  position: absolute; left: 50%; bottom: 200px; transform: translateX(-50%); width: min(280px, calc(100vw - 32px)); height: 20px;
  border-radius: 10px; background: rgba(18, 13, 25, 0.9); border: 1px solid var(--cc, #b88cff); overflow: hidden;
  display: flex; align-items: center; justify-content: space-between; padding: 0 10px; font-size: 0.75rem; font-weight: 700;
}
.castbar.hidden { display: none; }
.castbar .cb-fill { position: absolute; inset: 0; background: var(--cc, #b88cff); opacity: 0.45; transform-origin: left; transform: scaleX(0); }
.castbar span { position: relative; text-shadow: 0 0 3px #000; }

/* Results: damage per spell, in a tooltip on the damage number. */
.stats td.has-tip { cursor: help; white-space: nowrap; }
.tip-icon {
  display: inline-grid; place-items: center; width: 13px; height: 13px; border-radius: 50%; margin-left: 2px;
  font-size: 0.6rem; font-style: normal; font-weight: 800; color: #120d19; background: var(--muted); vertical-align: 1px;
}
.stats td.has-tip:hover .tip-icon { background: #e6cf98; }
.dmg-tip { width: auto; min-width: 200px; max-width: 340px; }
.dmg-rows { display: grid; gap: 2px 12px; font-size: 0.78rem; }
.dmg-rows > .th { color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; }
.dmg-rows > span:not(.dn) { text-align: right; font-variant-numeric: tabular-nums; }

/* Lobby: change your name. */
.rename-row { display: flex; gap: 6px; margin: 0.4rem 0 0.8rem; }
.rename-row input { flex: 1; min-width: 0; padding: 0.3rem 0.5rem; border-radius: 8px; border: 1px solid var(--line); background: #120d19; color: var(--text); font: inherit; font-size: 0.85rem; }
#game-code b { letter-spacing: 0.08em; }
.dmg-assist { margin-top: 8px; }
