:root {
  --ink: oklch(15% .012 70);
  --ink-deep: oklch(10% .01 70);
  --surface: oklch(21% .014 70);
  --surface-raised: oklch(26% .016 70);
  --line: oklch(48% .025 70);
  --line-soft: oklch(36% .018 70);
  --text: oklch(91% .018 82);
  --muted: oklch(72% .025 75);
  --brass: oklch(73% .11 78);
  --danger: oklch(64% .18 25);
  --health: oklch(69% .15 145);
  --energy: oklch(70% .12 235);
  --xp: oklch(78% .12 85);
  --radius: 10px;
  --shadow: 0 8px 24px oklch(5% .01 70 / .45);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; background: var(--ink-deep);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--text);
  touch-action: none; user-select: none; -webkit-user-select: none; }
button, input { font: inherit; }
button:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid var(--brass); outline-offset: 3px; }
.hidden { display: none !important; }

/* ============ menu ============ */
#menu { position: fixed; inset: 0; overflow-y: auto; touch-action: pan-y;
  background: radial-gradient(100% 65% at 50% 0%, oklch(27% .035 65), var(--ink) 72%); }
.menu-inner { max-width: 460px; margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    calc(56px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
h1 { text-align: center; font-size: 1.65rem; line-height: 1.1; letter-spacing: .16em;
  margin-top: 8px; color: var(--text); }
.tagline { text-align: center; color: var(--muted); font-size: .88rem; margin: 6px 0 16px; }
#preview-wrap { height: 220px; border-radius: 14px 14px 8px 8px; overflow: hidden;
  background: radial-gradient(75% 90% at 50% 100%, oklch(32% .025 70), var(--ink-deep));
  border: 1px solid var(--line); border-bottom-width: 3px; box-shadow: var(--shadow); }
#preview { width: 100%; height: 100%; display: block; }
.form { margin-top: 18px; }
.form label { display: block; font-size: .75rem; text-transform: uppercase;
  letter-spacing: .12em; color: var(--muted); margin: 16px 0 7px; font-weight: 700; }
.form input { width: 100%; min-height: 48px; padding: 11px 12px; font-size: 1rem;
  border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  color: var(--text); outline: none; box-shadow: inset 0 1px 0 oklch(95% .01 80 / .05); }
.form input::placeholder { color: var(--muted); opacity: .75; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row button { position: relative; flex: 1; min-width: 64px; min-height: 48px; padding: 8px;
  border-radius: var(--radius); border: 1px solid var(--line-soft); background: var(--surface);
  color: var(--text); font-size: .85rem; font-weight: 700; cursor: pointer;
  box-shadow: inset 0 1px 0 oklch(95% .01 80 / .05); }
.row button:hover { background: var(--surface-raised); border-color: var(--line); }
.row button.sel { border: 2px solid var(--text); background: var(--surface-raised); padding: 7px; }
.row button.sel::after { content: "✓"; position: absolute; top: 3px; right: 5px; min-width: 16px;
  color: var(--ink-deep); background: var(--text); border-radius: 50%; font-size: 11px; line-height: 16px; }
.row.swatches button { min-width: 44px; max-width: 56px; min-height: 44px; }
.row.swatches button.sel::after { box-shadow: 0 1px 4px oklch(5% .01 70 / .65); }
#elements button { padding: 10px 4px; }
#elements button svg { vertical-align: -3px; color: var(--c, currentColor); }
#elements button.sel { border-color: var(--c, var(--text)); box-shadow: inset 0 -3px 0 var(--c, var(--text)); }
.hint { font-size: .8rem; color: var(--muted); margin-top: 8px; min-height: 1.2em; line-height: 1.4; }
.big-btn { width: 100%; min-height: 54px; margin-top: 20px; padding: 14px; font-size: 1rem;
  font-weight: 850; letter-spacing: .13em; border: 1px solid oklch(84% .1 82);
  border-radius: var(--radius); background: var(--brass); color: var(--ink-deep); cursor: pointer;
  box-shadow: 0 4px 0 oklch(42% .07 72), var(--shadow); }
.big-btn:hover { filter: brightness(1.06); }
.big-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 oklch(42% .07 72); }
.help { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-soft);
  font-size: .82rem; color: var(--muted); }
.help p { margin: 10px 0; line-height: 1.5; }
.help summary { min-height: 44px; display: flex; align-items: center; cursor: pointer;
  color: var(--text); font-weight: 700; }
.orb-health { color: var(--health); } .orb-energy { color: var(--energy); }
.orb-xp { color: var(--xp); } .orb-avatar { color: var(--text); }

/* ============ game hud ============ */
#game { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  filter: grayscale(0) contrast(1); transition: filter .35s ease; }
#scene.dead { filter: grayscale(.7) contrast(1.06); transition: filter 1.5s ease; }
#labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
#damage-flash { position: absolute; inset: 0; pointer-events: none; opacity: 0;
  box-shadow: inset 0 0 56px 18px oklch(55% .2 25 / .72); }
#damage-flash.hit { animation: damage-flash .22s ease-out; }
@keyframes damage-flash { from { opacity: .72; } to { opacity: 0; } }
#respawn-flash { position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, oklch(96% .02 82 / .5) 0%, transparent 62%); }
#respawn-flash.on { animation: respawn-flash .3s ease-out; }
@keyframes respawn-flash { from { opacity: .8; } to { opacity: 0; } }
#vignette { position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 52%, oklch(38% .16 25 / .8) 100%);
  transition: opacity .3s ease-out; }
#vignette.pulse { animation: vignette-pulse 1.4s ease-in-out infinite; }
@keyframes vignette-pulse { 50% { opacity: .85; } }
.tag { position: absolute; transform: translate(-50%, -100%); text-align: center;
  pointer-events: none; will-change: left, top; }
.tag .nm { font-size: 11px; font-weight: 800; text-shadow: 0 1px 3px var(--ink-deep); white-space: nowrap; }
.tag .hpb { width: 58px; height: 6px; background: oklch(8% .01 70 / .8); border: 1px solid var(--text);
  border-radius: 2px; margin: 2px auto 0; overflow: hidden; }
.tag .hpb i { display: block; height: 100%; background: var(--health); }
.tag .lv { font-size: 9px; color: var(--xp); text-shadow: 0 1px 2px var(--ink-deep); }
.dmg { position: absolute; font-weight: 850; font-size: 16px; color: var(--xp);
  text-shadow: 0 1px 3px var(--ink-deep); pointer-events: none; animation: dmgfloat .9s ease-out forwards; }
.dmg.crit { color: var(--danger); font-size: 22px; animation-name: dmgfloat-crit; }
.dmg.healn { color: var(--health); }
.dmg.gone { visibility: hidden; }
@keyframes dmgfloat { from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -46px); } }
@keyframes dmgfloat-crit { from { opacity: 1; transform: translate(-50%, 0) scale(1.3); }
  22% { transform: translate(-50%, -8px) scale(1); }
  to { opacity: 0; transform: translate(-50%, -46px) scale(1); } }

#topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between;
  padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 0
    calc(10px + env(safe-area-inset-left)); pointer-events: none; }
#self-stats { width: min(52vw, 240px); padding: 5px; border: 1px solid var(--line-soft);
  border-radius: 8px; background: oklch(13% .01 70 / .9); box-shadow: var(--shadow); }
.bar { position: relative; height: 17px; border-radius: 3px; background: oklch(8% .01 70 / .9);
  margin-bottom: 4px; overflow: hidden; border: 1px solid oklch(64% .02 70 / .45); }
.bar:last-child { margin-bottom: 0; }
.bar span { position: absolute; inset: 0; font-size: 10px; line-height: 15px; text-align: center;
  color: var(--text); text-shadow: 0 1px 2px var(--ink-deep); font-weight: 750; }
.bar div { height: 100%; width: 50%; transition: width .15s ease-out; }
.bar.hp div { background: repeating-linear-gradient(135deg, var(--health) 0 7px, oklch(61% .13 145) 7px 9px); }
#hpghost { position: absolute; left: 0; top: 0; bottom: 0; background: var(--text);
  opacity: .5; transition: width .3s ease-out; }
#hpfill { position: relative; }
.bar.en div { background: repeating-linear-gradient(90deg, var(--energy) 0 8px, oklch(61% .1 235) 8px 10px); }
.bar.en::after { content: ""; position: absolute; inset: 0; background: var(--text);
  opacity: 0; pointer-events: none; }
.bar.en.flash::after { animation: bar-flash .35s ease-out; }
@keyframes bar-flash { from { opacity: .55; } to { opacity: 0; } }
.bar.xp { height: 14px; } .bar.xp span { font-size: 10px; line-height: 12px; }
.bar.xp div { background: var(--xp); }
#top-right { display: flex; gap: 8px; pointer-events: auto; }
.chip { min-width: 44px; min-height: 44px; padding: 6px; border-radius: 8px; border: 1px solid var(--line);
  background: oklch(16% .012 70 / .94); color: var(--text); font-size: 15px; cursor: pointer;
  box-shadow: 0 3px 10px oklch(5% .01 70 / .35); }
.chip:active { transform: translateY(1px); }
.chip svg { vertical-align: middle; }
#btn-sound .ic-off { display: none; }
#btn-sound.muted .ic-on { display: none; }
#btn-sound.muted .ic-off { display: inline; }

#minimap { position: absolute; top: calc(82px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left)); width: 104px; height: 104px;
  border-radius: 50%; pointer-events: none; opacity: .9;
  filter: drop-shadow(0 3px 8px oklch(5% .01 70 / .45)); }

#killfeed { position: absolute; top: calc(66px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right)); display: flex; flex-direction: column;
  gap: 3px; align-items: flex-end; pointer-events: none; }
#killfeed div { background: oklch(12% .01 70 / .88); border: 1px solid var(--line-soft);
  border-radius: 4px; padding: 4px 8px; font-size: 11px; animation: fadein .2s; }
#announce { position: absolute; top: 18%; left: 10%; right: 10%; text-align: center;
  font-size: clamp(16px, 4.5vw, 26px); font-weight: 850; text-shadow: 0 2px 8px var(--ink-deep);
  pointer-events: none; }
#match-clock { position: absolute; top: calc(82px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%); min-width: 86px; padding: 6px 10px; text-align: center;
  border-radius: 8px; background: oklch(13% .01 70 / .86); border: 1px solid var(--line-soft);
  font-size: .75rem; font-weight: 800; letter-spacing: .08em; pointer-events: none; }
#match-clock.final { color: var(--danger); border-color: var(--danger); }
@keyframes fadein { from { opacity: 0; } }

#btn-upgrade { position: absolute; left: calc(10px + env(safe-area-inset-left));
  top: calc(194px + env(safe-area-inset-top)); background: var(--surface); border-color: var(--brass);
  color: var(--xp); font-weight: 800; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: translateY(-2px); } }

.panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(92vw, 420px); max-height: min(78vh, 620px); overflow-y: auto; touch-action: pan-y;
  background: var(--surface); border: 1px solid var(--line); border-bottom-width: 3px;
  border-radius: 12px; padding: 18px; z-index: 30; box-shadow: var(--shadow); }
.panel h3 { margin: 4px 50px 14px 0; letter-spacing: .06em; }
.panel .close { position: absolute; top: 8px; right: 8px; width: 44px; height: 44px;
  border-radius: 8px; border: 1px solid var(--line-soft); background: var(--surface-raised);
  color: var(--text); cursor: pointer; }
.attr { display: flex; align-items: center; gap: 8px; min-height: 54px; padding: 6px 2px;
  border-bottom: 1px solid var(--line-soft); font-size: .85rem; }
.attr .lbl { flex: 1; } .attr .val { color: var(--muted); font-size: .75rem; }
.attr button { width: 44px; height: 44px; border-radius: 8px; border: 1px solid oklch(84% .1 82);
  background: var(--brass); color: var(--ink-deep); font-size: 1.1rem; font-weight: 850; cursor: pointer; }
.attr button:disabled { background: var(--line-soft); border-color: var(--line); color: var(--muted); }
#board-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
#board-table td, #board-table th { padding: 9px 4px; text-align: left; border-bottom: 1px solid var(--line-soft); }
#board-table th { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
#perk-list { display: grid; gap: 10px; }
#perk-list button { min-height: 58px; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-raised);
  color: var(--text); cursor: pointer; }
#perk-list b { color: var(--xp); letter-spacing: .08em; }
#perk-list span { color: var(--muted); font-size: .75rem; }

#death { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; background: oklch(18% .09 25 / .76); z-index: 20; pointer-events: none; }
#death h2 { font-size: 1.6rem; text-shadow: 0 2px 10px var(--ink-deep); }
#death p { margin-top: 8px; font-size: 1.1rem; color: var(--text); }
#death p:empty { display: none; }
#death p.streak { margin-top: 4px; font-size: .85rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; }
#victory { position: absolute; inset: 0; z-index: 25; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; padding: 24px;
  background: oklch(12% .015 70 / .88); }
#victory h2 { font-size: 1.8rem; color: var(--xp); }
#victory p { margin: 8px 0 4px; color: var(--muted); }
#victory .big-btn { width: min(280px, 80vw); }

/* touch controls */
#joy-zone { position: absolute; left: 0; bottom: 0; width: 50%; height: 55%; }
#joy-base { position: absolute; width: 110px; height: 110px; border-radius: 50%;
  background: oklch(18% .01 70 / .55); border: 2px solid oklch(80% .02 70 / .48); display: none;
  box-shadow: inset 0 0 0 8px oklch(90% .01 70 / .04); }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px;
  border-radius: 50%; background: oklch(78% .025 70 / .72); border: 2px solid var(--text);
  transform: translate(-50%, -50%); }
#actions { position: absolute; right: calc(8px + env(safe-area-inset-right));
  bottom: calc(14px + env(safe-area-inset-bottom)); display: grid;
  grid-template-columns: repeat(2, auto); gap: 10px; justify-items: end; align-items: end; }
#attack-mode { position: absolute; right: calc(8px + env(safe-area-inset-right));
  bottom: calc(270px + env(safe-area-inset-bottom)); width: 84px; min-height: 44px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: .65rem; font-weight: 850; letter-spacing: .08em; }
#attack-mode.charge { color: var(--xp); border-color: var(--xp); }
.act { position: relative; border-radius: 50%; border: 2px solid var(--line); background: oklch(15% .01 70 / .94);
  color: var(--text); font-weight: 850; font-size: .72rem; letter-spacing: .08em; overflow: hidden;
  cursor: pointer; box-shadow: 0 4px 12px oklch(5% .01 70 / .45), inset 0 1px 0 oklch(95% .01 70 / .1); }
.act.big { width: 84px; height: 84px; font-size: .86rem; border-color: var(--c, var(--text)); border-width: 3px; }
.act.mid { width: 64px; height: 64px; border-color: var(--c, var(--line)); }
.act.epic { width: 72px; height: 72px; grid-column: 1; border-color: var(--xp); border-style: double;
  box-shadow: 0 4px 12px oklch(5% .01 70 / .45), inset 0 0 0 2px var(--surface); }
.act.epic.charging { animation: epic-charge .7s ease-out infinite alternate; }
@keyframes epic-charge { to { transform: scale(1.06); box-shadow: 0 0 20px var(--xp); } }
.act.small { width: 56px; height: 56px; }
.act .alabel.long { font-size: .78em; letter-spacing: .04em; }
.act .cd { position: absolute; inset: 0; background: oklch(8% .01 70 / .88); display: none;
  align-items: center; justify-content: center; font-size: .95rem; color: var(--xp); }
.act .cost { position: absolute; bottom: 6px; left: 0; right: 0; font-size: .62rem;
  color: var(--energy); font-weight: 750; }
.act .cost:not(:empty)::before { content: "◆ "; }
.charge-meter { position: absolute; left: 8px; right: 8px; bottom: 2px; height: 4px;
  border-radius: 2px; background: var(--xp); transform: scaleX(0); transform-origin: left;
  transition: transform .06s linear; }
#act-primary.charging { box-shadow: 0 0 18px var(--xp), inset 0 1px 0 oklch(95% .01 70 / .15); }
.act.noenergy { border-color: var(--danger); color: var(--muted); filter: saturate(.35); }
.act.noenergy::after { content: "!"; position: absolute; top: 4px; right: 8px; color: var(--text);
  background: var(--danger); width: 16px; height: 16px; border-radius: 50%; line-height: 16px; }
.act:active { transform: scale(.94); }
.act.deny { animation: deny-shake .3s linear; }
@keyframes deny-shake { 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }
#act-sprint.on { background: var(--energy); border-color: var(--text); color: var(--ink-deep); }
#act-sprint.on::after { content: "ON"; display: block; font-size: .55rem; letter-spacing: .06em; }

@media (min-width: 900px) { #actions { transform: scale(1.05); transform-origin: bottom right; } }

/* keybind hints: fine-pointer devices have the keys, phones don't */
.act .kbd { display: none; }
@media (pointer: fine) {
  .act .kbd { display: block; position: absolute; top: 9px; left: 0; right: 0;
    font-size: .5rem; letter-spacing: .08em; color: var(--muted); font-weight: 700;
    pointer-events: none; }
}

/* the phone HUD verbatim is a sliver on a large screen: scale the readouts */
@media (min-width: 900px) and (pointer: fine) {
  #self-stats { width: 300px; padding: 6px; }
  .bar { height: 21px; }
  .bar span { font-size: 12px; line-height: 19px; }
  .bar.xp { height: 15px; }
  .bar.xp span { font-size: 10px; line-height: 13px; }
  #minimap { width: 128px; height: 128px; top: calc(100px + env(safe-area-inset-top)); }
  #match-clock { font-size: .85rem; }
  #killfeed div { font-size: 12px; }
  #btn-upgrade { top: calc(240px + env(safe-area-inset-top)); }
}

@media (max-height: 500px) and (orientation: landscape) {
  #self-stats { width: min(38vw, 220px); }
  #killfeed { top: calc(58px + env(safe-area-inset-top)); }
  #minimap { top: calc(66px + env(safe-area-inset-top)); width: 88px; height: 88px; }
  #match-clock { top: calc(66px + env(safe-area-inset-top)); }
  #btn-upgrade { top: calc(162px + env(safe-area-inset-top)); }
  #actions { gap: 7px; bottom: calc(7px + env(safe-area-inset-bottom)); }
  #attack-mode { bottom: calc(211px + env(safe-area-inset-bottom)); width: 72px; }
  .act.big { width: 72px; height: 72px; }
  .act.mid { width: 58px; height: 58px; }
  .act.epic { width: 64px; height: 64px; }
  .act.small { width: 50px; height: 50px; }
  .panel { max-height: calc(100vh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important;
    animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
  .dmg, .dmg.crit { animation: fadein .01ms both; }
  #damage-flash.hit { animation-duration: .01ms; }
  #respawn-flash.on { animation-duration: .01ms; }
  #scene.dead { filter: grayscale(.45) contrast(1.02); }
  #vignette.pulse { animation: none; }
}
