:root {
  --bg: #05030a;
  --panel: rgba(10, 6, 20, 0.72);
  --panel-solid: rgba(12, 8, 24, 0.94);
  --line: rgba(255, 255, 255, 0.1);
  --text: #eef0ff;
  --muted: #9b97b8;
  --cyan: #45f3ff;
  --jev: #ff5ad9;
  --gold: #ffd34f;
  --mint: #4fffb0;
  --danger: #ff2d55;
  --amber: #ffb23a;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --ui: 'Chakra Petch', system-ui, sans-serif;
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--ui); overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
body.playing canvas#game { cursor: none; }
body.screen-open #crosshair, body.touch #crosshair { display: none; }
[hidden] { display: none !important; }
body.touch .desktop-only, body:not(.touch) .touch-only { display: none !important; }
button { touch-action: manipulation; }
button, input, select { font: inherit; color: inherit; }
kbd {
  font-family: var(--mono); font-size: 0.78em; padding: 1px 6px; border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.06);
}
.muted { color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ---------- buttons & fields ---------- */
.primary, .ghost {
  border-radius: 8px; padding: 11px 18px; cursor: pointer; letter-spacing: 0.06em; text-transform: uppercase;
  font-weight: 600; font-size: 14px; transition: transform 0.12s, box-shadow 0.2s, background 0.2s, border-color 0.2s;
}
.primary {
  border: 1px solid rgba(255, 90, 217, 0.8);
  background: linear-gradient(135deg, rgba(255, 90, 217, 0.95), rgba(140, 60, 255, 0.95));
  box-shadow: 0 0 24px rgba(255, 90, 217, 0.35);
}
.primary:hover { transform: translateY(-1px); box-shadow: 0 0 34px rgba(255, 90, 217, 0.55); }
.primary:disabled { opacity: 0.55; cursor: progress; transform: none; }
.ghost { border: 1px solid rgba(255, 255, 255, 0.18); background: rgba(255, 255, 255, 0.04); }
.ghost:hover { border-color: rgba(69, 243, 255, 0.6); background: rgba(69, 243, 255, 0.08); }
.ghost.danger:hover { border-color: var(--danger); background: rgba(255, 45, 85, 0.12); }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; padding: 0; }
.link-btn:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); letter-spacing: 0.04em; }
.field > span { display: flex; justify-content: space-between; text-transform: uppercase; }
.field a { color: var(--cyan); text-decoration: none; text-transform: none; }
input[type='text'], input:not([type]), select {
  width: 100%; padding: 11px 12px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.35); color: var(--text); outline: none; font-size: 15px;
}
input:focus, select:focus { border-color: rgba(69, 243, 255, 0.7); box-shadow: 0 0 0 3px rgba(69, 243, 255, 0.15); }
.key-row { display: flex; gap: 8px; }
.key-row input { font-family: var(--mono); font-size: 13px; }
.secret:not(.revealed) { -webkit-text-security: disc; }
@supports not (-webkit-text-security: disc) {
  .secret:not(.revealed):not(:focus):not(:placeholder-shown) { filter: blur(5px); }
}
.key-row .ghost { padding: 0 12px; font-size: 12px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); cursor: pointer; }
.check input { accent-color: var(--jev); width: 16px; height: 16px; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 9px; background: rgba(0, 0, 0, 0.35); border: 1px solid rgba(255, 255, 255, 0.1); }
.segmented button { border: 0; background: none; padding: 8px 6px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.segmented button.on { background: rgba(255, 90, 217, 0.2); color: var(--text); box-shadow: inset 0 0 0 1px rgba(255, 90, 217, 0.6); }
.status { min-height: 20px; font-size: 13px; font-family: var(--mono); color: var(--muted); }
.status.error { color: #ff7a93; }
.status.ok { color: var(--mint); }
.status.busy::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- screens ---------- */
#screens { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; pointer-events: auto; }
.screen.modal { display: grid; place-items: center; background: rgba(3, 1, 8, 0.55); backdrop-filter: blur(4px); padding: 16px; }
.card { width: min(520px, 100%); padding: 26px; display: flex; flex-direction: column; gap: 16px; max-height: calc(100vh - 32px); overflow: auto; background: var(--panel-solid); }
.card h2 { margin: 0; letter-spacing: 0.08em; text-transform: uppercase; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; justify-content: space-between; gap: 10px; }

.title-screen {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, 420px); align-items: center; gap: 48px;
  padding: 48px clamp(24px, 6vw, 96px) 64px;
  background: radial-gradient(ellipse at 20% 40%, rgba(5, 2, 12, 0.55), transparent 65%), linear-gradient(90deg, rgba(5, 2, 12, 0.7), rgba(5, 2, 12, 0.1) 60%, rgba(5, 2, 12, 0.45));
}
.logo {
  position: relative; margin: 0; font-size: clamp(96px, 16vw, 220px); line-height: 0.85; font-weight: 700; letter-spacing: 0.04em;
  background: linear-gradient(180deg, #fff 10%, #ffc6f1 45%, var(--jev) 90%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 28px rgba(255, 90, 217, 0.55));
}
.logo::before, .logo::after {
  content: attr(data-text); position: absolute; inset: 0; background: inherit; -webkit-background-clip: text; background-clip: text;
  mix-blend-mode: screen; opacity: 0.7; animation: glitch 3.2s infinite steps(1);
}
.logo::before { color: var(--cyan); -webkit-text-fill-color: var(--cyan); transform: translate(-3px, 0); clip-path: inset(0 0 60% 0); }
.logo::after { color: var(--jev); -webkit-text-fill-color: var(--jev); transform: translate(3px, 0); clip-path: inset(55% 0 0 0); animation-delay: 0.4s; }
@keyframes glitch {
  0%, 86%, 100% { transform: translate(0, 0); opacity: 0; }
  87% { transform: translate(-6px, 2px); opacity: 0.8; }
  90% { transform: translate(5px, -2px); opacity: 0.8; }
  93% { transform: translate(-2px, 1px); opacity: 0.6; }
}
.subtitle { font-size: clamp(18px, 2.4vw, 30px); letter-spacing: 0.6em; color: var(--cyan); margin: 14px 0 22px 6px; text-shadow: 0 0 18px rgba(69, 243, 255, 0.6); }
.tagline { max-width: 520px; font-size: 17px; line-height: 1.55; color: #cfcbe6; margin: 0 0 18px; }
.features { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; color: var(--muted); }
.features li::before { content: '▸ '; color: var(--jev); }
.features b { color: var(--text); font-weight: 600; }
.connect { padding: 26px; display: flex; flex-direction: column; gap: 16px; background: var(--panel-solid); }
.connect h2 { margin: 0; font-size: 18px; letter-spacing: 0.14em; text-transform: uppercase; }
.fineprint { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.title-links { display: flex; gap: 18px; font-size: 13px; }
.credits { position: absolute; left: 0; right: 0; bottom: 16px; text-align: center; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.credits b { color: #d6d2ee; font-weight: 600; }

table.controls { width: 100%; border-collapse: collapse; font-size: 14px; }
table.controls td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
table.controls td:first-child { white-space: nowrap; color: var(--muted); width: 45%; }
.settings-grid { display: grid; gap: 14px; }
.settings-grid label:not(.check) { display: grid; grid-template-columns: 1fr 1.2fr; align-items: center; gap: 12px; font-size: 14px; color: var(--muted); }
input[type='range'] { accent-color: var(--jev); width: 100%; }
.pause-stats { font-family: var(--mono); font-size: 12px; color: var(--muted); display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud::before { content: ''; position: absolute; inset: 0; opacity: 0; transition: opacity 0.25s; background: radial-gradient(ellipse at center, transparent 45%, rgba(69, 243, 255, 0.16)); box-shadow: inset 0 0 0 2px rgba(69, 243, 255, 0.35); }
#hud.frozen::before { opacity: 1; }
.hud-player { position: absolute; top: 18px; left: 18px; width: 300px; padding: 12px 14px; }
.callsign { display: flex; justify-content: space-between; font-size: 13px; letter-spacing: 0.12em; margin-bottom: 8px; }
.callsign .tag { color: var(--muted); font-size: 11px; }
.hpbar { position: relative; height: 16px; border-radius: 4px; background: rgba(255, 255, 255, 0.06); overflow: hidden; border: 1px solid rgba(69, 243, 255, 0.25); }
.hp-fill, .hp-trail { position: absolute; inset: 0 auto 0 0; width: 100%; transition: width 0.15s; }
.hp-fill { background: linear-gradient(90deg, #1fb6ff, var(--cyan)); box-shadow: 0 0 14px rgba(69, 243, 255, 0.6); }
.hp-trail { background: rgba(255, 255, 255, 0.55); transition: width 0.8s 0.25s; }
.hpbar.low .hp-fill { background: linear-gradient(90deg, #ff2d55, #ff7a3d); box-shadow: 0 0 14px rgba(255, 45, 85, 0.7); animation: pulseLow 0.8s infinite; }
@keyframes pulseLow { 50% { filter: brightness(1.6); } }
#hp-text { position: absolute; right: 6px; top: -1px; font-family: var(--mono); font-size: 11px; text-shadow: 0 1px 2px #000; }
.abilities { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.dash { display: flex; gap: 6px; }
.dash i { width: 26px; height: 7px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); transform: skewX(-20deg); position: relative; overflow: hidden; }
.dash i.full { background: var(--cyan); box-shadow: 0 0 10px rgba(69, 243, 255, 0.8); }
.dash i b { position: absolute; inset: 0 auto 0 0; background: rgba(69, 243, 255, 0.45); }
.pulse {
  --p: 0; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-family: var(--mono); font-size: 12px;
  background: conic-gradient(var(--cyan) calc(var(--p) * 1turn), rgba(255, 255, 255, 0.1) 0); position: relative;
}
.pulse::before { content: ''; position: absolute; inset: 3px; border-radius: 50%; background: #0a0618; }
.pulse span { position: relative; color: var(--muted); }
.pulse.ready { box-shadow: 0 0 18px rgba(69, 243, 255, 0.9); animation: ready 1s infinite; }
.pulse.ready span { color: var(--cyan); }
@keyframes ready { 50% { box-shadow: 0 0 6px rgba(69, 243, 255, 0.4); } }

.hud-top { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); text-align: center; width: min(560px, 50vw); }
.sector-label { font-size: 13px; letter-spacing: 0.3em; color: var(--muted); }
.objective { margin-top: 4px; font-size: 18px; font-weight: 600; letter-spacing: 0.1em; text-shadow: 0 0 14px rgba(255, 255, 255, 0.35); }
.objective.portal { color: var(--mint); text-shadow: 0 0 16px rgba(79, 255, 176, 0.7); }
.chips { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }
.chip { font-size: 11px; letter-spacing: 0.12em; padding: 3px 9px; border-radius: 99px; border: 1px solid rgba(255, 178, 58, 0.6); color: var(--amber); background: rgba(40, 20, 0, 0.5); }
.bossbar { margin-top: 10px; }
.bossbar-name { display: flex; justify-content: space-between; font-size: 13px; letter-spacing: 0.3em; color: var(--jev); margin-bottom: 5px; text-shadow: 0 0 12px rgba(255, 90, 217, 0.7); }
.bossbar-track { position: relative; height: 12px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 90, 217, 0.4); overflow: hidden; }
.bossbar-fill, .bossbar-trail { position: absolute; inset: 0 auto 0 0; width: 100%; }
.bossbar-fill { background: linear-gradient(90deg, #ff1446, var(--jev)); box-shadow: 0 0 18px rgba(255, 20, 70, 0.7); transition: width 0.12s; }
.bossbar-trail { background: rgba(255, 255, 255, 0.6); transition: width 0.9s 0.3s; }
.bossbar-track i { position: absolute; top: 0; bottom: 0; width: 2px; background: rgba(0, 0, 0, 0.6); }
.bossbar.shielded .bossbar-fill { filter: saturate(0.2) brightness(1.3); }

.hud-jev { position: absolute; top: 18px; right: 18px; width: 268px; display: flex; flex-direction: column; gap: 8px; }
.portrait-frame { align-self: flex-end; width: 116px; height: 116px; border-radius: 50%; padding: 0; border: 1px solid rgba(255, 90, 217, 0.35); box-shadow: 0 0 30px rgba(255, 90, 217, 0.25); }
.portrait { width: 100%; height: 100%; border-radius: 50%; }
.jev-info { padding: 10px 12px; }
.jev-title { display: flex; justify-content: space-between; align-items: center; font-weight: 700; letter-spacing: 0.3em; color: var(--jev); font-size: 13px; }
.link { font-family: var(--mono); font-size: 10px; letter-spacing: 0.05em; color: var(--muted); display: flex; align-items: center; gap: 6px; font-weight: 400; }
.link .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.link.live .dot { background: var(--mint); box-shadow: 0 0 8px var(--mint); }
.link.degraded .dot { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.link.offline .dot, .link.severed .dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.mood { margin-top: 9px; display: flex; align-items: center; gap: 10px; font-size: 11px; letter-spacing: 0.16em; }
.mood-track { position: relative; flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; height: 8px; }
.mood-track i { border-radius: 2px; opacity: 0.25; }
.mood-track i:nth-child(1) { background: var(--jev); }
.mood-track i:nth-child(2) { background: var(--amber); }
.mood-track i:nth-child(3) { background: #ff3b30; }
.mood-track i:nth-child(4) { background: #ff1446; }
.mood-track i.lit { opacity: 1; box-shadow: 0 0 8px currentColor; }
.mood-track b { position: absolute; top: -3px; width: 2px; height: 14px; background: #fff; box-shadow: 0 0 6px #fff; transition: left 0.5s; }
#mood-label { width: 92px; text-align: right; color: var(--jev); }
.decision { padding: 10px 12px; opacity: 0; transform: translateY(-6px); transition: opacity 0.3s, transform 0.3s; }
.decision.show { opacity: 1; transform: none; }
.decision-head { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--muted); }
.badge { padding: 1px 6px; border-radius: 4px; border: 1px solid rgba(79, 255, 176, 0.5); color: var(--mint); }
.badge.instinct { border-color: rgba(255, 178, 58, 0.6); color: var(--amber); }
.decision-choice { margin: 6px 0 8px; font-size: 16px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: #fff; }
.decision.thinking .decision-choice { color: var(--muted); }
.decision.thinking .decision-choice::after { content: ''; animation: dots 1s steps(4) infinite; }
.bars { display: grid; gap: 5px; }
.bar { display: grid; grid-template-columns: 1fr 38px; gap: 8px; align-items: center; font-family: var(--mono); font-size: 10px; color: var(--muted); }
.bar-track { position: relative; height: 14px; border-radius: 3px; background: rgba(255, 255, 255, 0.05); overflow: hidden; }
.bar-track b { position: absolute; inset: 0 auto 0 0; background: rgba(255, 90, 217, 0.35); transition: width 0.6s cubic-bezier(0.2, 0.8, 0.2, 1); }
.bar.top .bar-track b { background: linear-gradient(90deg, rgba(255, 90, 217, 0.6), rgba(255, 90, 217, 0.9)); box-shadow: 0 0 10px rgba(255, 90, 217, 0.6); }
.bar-track span { position: relative; padding-left: 6px; line-height: 14px; color: #e8e4ff; white-space: nowrap; }
.bar em { font-style: normal; text-align: right; }
.decision-note { margin-top: 7px; font-family: var(--mono); font-size: 10px; color: var(--muted); }

.dialogue { position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%); width: min(820px, 92vw); display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.line { opacity: 0; transition: opacity 0.25s, transform 0.25s; transform: translateY(6px); }
.line.show { opacity: 1; transform: none; }
.player-line { font-size: 15px; color: var(--cyan); text-shadow: 0 1px 6px #000; }
.player-line::before { content: 'YOU › '; color: rgba(69, 243, 255, 0.6); font-family: var(--mono); font-size: 12px; }
.jev-line { padding: 12px 20px; border-radius: 12px; background: rgba(12, 4, 18, 0.72); border: 1px solid rgba(255, 90, 217, 0.4); box-shadow: 0 0 34px rgba(255, 90, 217, 0.2); backdrop-filter: blur(6px); font-size: 21px; line-height: 1.35; font-weight: 500; }
.jev-line .speaker { font-family: var(--mono); font-size: 12px; color: var(--jev); margin-right: 10px; letter-spacing: 0.2em; vertical-align: 2px; }
.jev-line.m1 { border-color: rgba(255, 178, 58, 0.5); } .jev-line.m1 .speaker { color: var(--amber); }
.jev-line.m2 { border-color: rgba(255, 59, 48, 0.55); box-shadow: 0 0 34px rgba(255, 59, 48, 0.25); } .jev-line.m2 .speaker { color: #ff5b4f; }
.jev-line.m3 { border-color: rgba(255, 20, 70, 0.8); box-shadow: 0 0 44px rgba(255, 20, 70, 0.4); animation: shudder 0.18s infinite; } .jev-line.m3 .speaker { color: #ff1446; }
.jev-line.typing .text::after { content: '▍'; animation: blink 0.6s infinite; color: var(--jev); }
.jev-line.composing .text { color: var(--muted); font-size: 16px; }
@keyframes shudder { 50% { transform: translate(0.6px, -0.4px); } }

.chat { position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); width: min(620px, 92vw); margin: 0; padding: 12px; border-radius: 12px; background: var(--panel-solid); border: 1px solid rgba(69, 243, 255, 0.55); box-shadow: 0 0 40px rgba(69, 243, 255, 0.25); pointer-events: auto; display: grid; gap: 8px; }
.chat label { font-size: 11px; letter-spacing: 0.2em; color: var(--cyan); text-transform: uppercase; }
.chat input { font-size: 17px; }
.chat-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.chat-meta { font-family: var(--mono); font-size: 10px; color: var(--muted); text-align: right; }
.chat-actions { display: flex; gap: 8px; }
.chat-actions button { padding: 8px 16px; }
.hint { position: absolute; left: 18px; bottom: 16px; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.hint span { margin: 0 6px; }
.tutorial { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); padding: 10px 18px; border-radius: 10px; background: rgba(5, 20, 30, 0.75); border: 1px solid rgba(69, 243, 255, 0.45); font-size: 16px; letter-spacing: 0.04em; animation: rise 0.4s; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

.announce { position: absolute; left: 0; right: 0; top: 34%; text-align: center; font-size: clamp(30px, 5vw, 64px); font-weight: 700; letter-spacing: 0.18em; opacity: 0; pointer-events: none; }
.announce.show { animation: announce 2.4s forwards; }
.announce.warn { color: var(--amber); text-shadow: 0 0 30px rgba(255, 178, 58, 0.8); }
.announce.danger { color: #ff3b5c; text-shadow: 0 0 34px rgba(255, 20, 70, 0.9); }
.announce.good { color: var(--mint); text-shadow: 0 0 30px rgba(79, 255, 176, 0.8); }
.announce.info { color: #fff; text-shadow: 0 0 30px rgba(255, 90, 217, 0.9); }
@keyframes announce {
  0% { opacity: 0; transform: scale(1.3); filter: blur(8px); }
  12% { opacity: 1; transform: scale(1); filter: blur(0); }
  16% { transform: translateX(-4px); } 20% { transform: translateX(3px); } 24% { transform: none; }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.98); }
}
.countdown { position: absolute; left: 0; right: 0; top: 26%; text-align: center; font-size: 120px; font-weight: 700; color: #ff1446; text-shadow: 0 0 40px rgba(255, 20, 70, 0.9); pointer-events: none; }
.countdown.tick { animation: tick 0.9s; }
@keyframes tick { from { transform: scale(1.5); opacity: 0.4; } 30% { transform: scale(1); opacity: 1; } }
.toasts { position: absolute; left: 18px; top: 140px; display: flex; flex-direction: column; gap: 6px; }
.toast { font-family: var(--mono); font-size: 12px; padding: 6px 10px; border-radius: 6px; background: rgba(5, 3, 12, 0.7); border-left: 3px solid currentColor; animation: toast 3s forwards; }
@keyframes toast { 0% { opacity: 0; transform: translateX(-10px); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }

.markers { position: absolute; inset: 0; pointer-events: none; }
.marker { position: absolute; left: 0; top: 0; width: 0; height: 0; border-left: 9px solid transparent; border-right: 9px solid transparent; border-bottom: 18px solid var(--c); filter: drop-shadow(0 0 6px var(--c)); opacity: 0.9; }
#crosshair { position: fixed; left: 0; top: 0; width: 28px; height: 28px; margin: -14px 0 0 -14px; pointer-events: none; z-index: 5; border: 2px solid rgba(69, 243, 255, 0.9); border-radius: 50%; box-shadow: 0 0 10px rgba(69, 243, 255, 0.7); }
#crosshair::after { content: ''; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px; border-radius: 50%; background: #fff; }

/* ---------- interlude ---------- */
.interlude { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 14px; padding: 24px 16px 40px; background: linear-gradient(180deg, transparent 30%, rgba(3, 1, 8, 0.75)); }
.interlude-head { font-size: 14px; letter-spacing: 0.4em; color: var(--mint); text-shadow: 0 0 14px rgba(79, 255, 176, 0.6); }
.convo { width: min(760px, 100%); max-height: 38vh; overflow: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; background: var(--panel-solid); }
.msg { font-size: 17px; line-height: 1.45; }
.msg .who { display: block; font-family: var(--mono); font-size: 11px; letter-spacing: 0.2em; margin-bottom: 2px; }
.msg.jev .who { color: var(--jev); }
.msg.you { color: #c7f9ff; }
.msg.you .who { color: var(--cyan); }
.msg.pending { color: var(--muted); }
.msg.pending .body::after { content: ''; animation: dots 1s steps(4) infinite; }
.reply { width: min(760px, 100%); display: grid; gap: 10px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; }
.quick button { border-radius: 99px; padding: 7px 12px; font-size: 13px; text-transform: none; letter-spacing: 0; }
.reply-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }

/* ---------- upgrades ---------- */
.upgrades { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: rgba(3, 1, 8, 0.6); padding: 16px; }
.upgrades h2 { margin: 0; letter-spacing: 0.2em; text-transform: uppercase; }
.cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 18px; margin-top: 18px; }
.ucard {
  width: 220px; padding: 22px 18px; text-align: left; cursor: pointer; border-radius: 12px; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel-solid); border: 1px solid rgba(69, 243, 255, 0.25); transition: transform 0.15s, border-color 0.2s, box-shadow 0.2s;
  animation: cardIn 0.4s backwards;
}
.ucard:nth-child(2) { animation-delay: 0.08s; } .ucard:nth-child(3) { animation-delay: 0.16s; }
@keyframes cardIn { from { opacity: 0; transform: translateY(16px); } }
.ucard:hover, .ucard:focus-visible { transform: translateY(-4px); border-color: var(--cyan); box-shadow: 0 0 30px rgba(69, 243, 255, 0.3); }
.ucard .glyph { font-size: 34px; color: var(--cyan); text-shadow: 0 0 16px rgba(69, 243, 255, 0.8); }
.ucard h3 { margin: 0; font-size: 17px; letter-spacing: 0.06em; }
.ucard p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.ucard .key { margin-top: auto; font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* ---------- planning ---------- */
.plan { display: grid; place-items: center; background: rgba(3, 1, 8, 0.45); padding: 16px; }
.plan-card { width: min(720px, 100%); padding: 22px 24px; background: var(--panel-solid); }
.plan-head { font-size: 14px; letter-spacing: 0.35em; color: var(--jev); text-shadow: 0 0 14px rgba(255, 90, 217, 0.6); }
.plan-sub { margin: 6px 0 16px; font-size: 13px; color: var(--muted); }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 18px; }
.plan-q h4 { margin: 0 0 8px; font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; color: var(--muted); font-weight: 400; }
.plan-q .bar { grid-template-columns: 1fr 34px; }
.plan-q .bar.win span { color: #fff; font-weight: 600; }
.plan-foot { margin-top: 16px; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.plan-q .bars { transition: opacity 0.35s, transform 0.35s; }
.plan-q.pending .bars { opacity: 0.45; }
.plan-q.revealed .bars { animation: rise-in 0.4s; }
@keyframes rise-in { from { opacity: 0; transform: translateY(6px); } }
.plan-progress { margin-top: 10px; height: 2px; border-radius: 2px; background: rgba(255, 255, 255, 0.08); overflow: hidden; }
.plan-progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--jev), var(--cyan)); box-shadow: 0 0 8px var(--jev); }

/* ---------- end screens ---------- */
.end .card { text-align: center; }
.danger-text { color: #ff3b5c; text-shadow: 0 0 20px rgba(255, 20, 70, 0.7); }
.win-text { color: var(--mint); text-shadow: 0 0 20px rgba(79, 255, 176, 0.7); }
.jev-quote { margin: 0; font-size: 19px; line-height: 1.45; padding: 14px 16px; border-radius: 10px; border: 1px solid rgba(255, 90, 217, 0.35); background: rgba(255, 90, 217, 0.06); }
.jev-quote::before { content: 'JEV › '; font-family: var(--mono); font-size: 12px; color: var(--jev); }
.jev-quote.pending { color: var(--muted); }
.end-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.end-stats div { padding: 10px 6px; border-radius: 8px; background: rgba(255, 255, 255, 0.04); }
.end-stats b { display: block; font-size: 22px; }
.end-stats span { font-size: 11px; letter-spacing: 0.1em; color: var(--muted); text-transform: uppercase; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; }
.fatal { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; background: var(--bg); z-index: 10; }

/* ---------- touch controls ---------- */
#touch { position: absolute; inset: 0; pointer-events: auto; touch-action: none; display: none; }
body.touch #touch { display: block; }
#hud.frozen #touch, body.screen-open #touch { display: none; }
.stick {
  position: absolute; width: 132px; height: 132px; margin: -66px 0 0 -66px; border-radius: 50%; pointer-events: none;
  border: 2px solid rgba(69, 243, 255, 0.22); background: radial-gradient(circle, rgba(69, 243, 255, 0.08), transparent 70%);
  opacity: 0.5; transition: opacity 0.25s;
}
.stick.move { left: calc(var(--sl) + 110px); top: calc(100% - var(--sb) - 100px); }
.stick.aim { left: calc(100% - var(--sr) - 210px); top: calc(100% - var(--sb) - 100px); border-color: rgba(255, 90, 217, 0.25); background: radial-gradient(circle, rgba(255, 90, 217, 0.08), transparent 70%); }
.stick.active { opacity: 1; transition: none; }
.stick i { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px; border-radius: 50%; background: rgba(69, 243, 255, 0.32); box-shadow: 0 0 16px rgba(69, 243, 255, 0.55); }
.stick.aim i { background: rgba(255, 90, 217, 0.38); box-shadow: 0 0 16px rgba(255, 90, 217, 0.55); }
.stick span { position: absolute; left: -20px; right: -20px; top: 50%; margin-top: -6px; text-align: center; font-size: 10px; line-height: 12px; letter-spacing: 0.2em; color: rgba(255, 255, 255, 0.55); }
.stick.active span { display: none; }
.tbtn {
  position: absolute; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; padding: 0;
  border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.22); background: rgba(10, 6, 20, 0.55); color: var(--text);
  font: 600 11px/1 var(--ui); letter-spacing: 0.14em; touch-action: none; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: transform 0.08s, opacity 0.2s;
}
.tbtn:active { transform: scale(0.92); }
.tbtn.dash { right: calc(var(--sr) + 22px); bottom: calc(var(--sb) + 24px); width: 84px; height: 84px; border-color: rgba(69, 243, 255, 0.65); box-shadow: 0 0 20px rgba(69, 243, 255, 0.3); }
.tbtn.dash.spent { opacity: 0.45; }
.pips { display: flex; gap: 4px; }
.pips i { width: 12px; height: 4px; border-radius: 2px; transform: skewX(-20deg); background: rgba(255, 255, 255, 0.18); }
.pips i.full { background: var(--cyan); box-shadow: 0 0 6px var(--cyan); }
.tbtn.pulse {
  --p: 0; right: calc(var(--sr) + 34px); bottom: calc(var(--sb) + 122px); width: 62px; height: 62px; color: var(--muted);
  background: conic-gradient(rgba(69, 243, 255, 0.6) calc(var(--p) * 1turn), rgba(10, 6, 20, 0.55) 0);
}
.tbtn.pulse::before { content: ''; position: absolute; inset: 4px; border-radius: 50%; background: rgba(10, 6, 24, 0.9); }
.tbtn.pulse span { position: relative; }
.tbtn.pulse.ready { color: var(--cyan); border-color: var(--cyan); animation: ready 1s infinite; }
.tbar { position: absolute; left: calc(var(--sl) + 18px); top: 92px; display: flex; gap: 8px; }
.tbar .tbtn { position: static; flex-direction: row; height: 36px; min-width: 44px; padding: 0 14px; border-radius: 8px; }
.pause-glyph { display: inline-block; width: 11px; height: 12px; border-left: 3px solid currentColor; border-right: 3px solid currentColor; vertical-align: -1px; }
body.touch .abilities { display: none; }
body.touch .toasts { top: 140px; }
body.touch .chat { top: 10px; bottom: auto; }
body.touch input { font-size: 16px; }

.rotate { display: none; position: fixed; inset: 0; z-index: 20; place-items: center; padding: 24px; text-align: center; background: var(--bg); }
.rotate .phone { display: block; width: 44px; height: 76px; margin: 0 auto 20px; border: 3px solid var(--cyan); border-radius: 9px; box-shadow: 0 0 18px rgba(69, 243, 255, 0.5); animation: turn 2.6s ease-in-out infinite; }
.rotate p { margin: 0; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
@keyframes turn { 0%, 20% { transform: rotate(0); } 50%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (orientation: portrait) { body.touch.playing .rotate { display: grid; } }

/* ---------- small windows ---------- */
@media (max-width: 900px) {
  .title-screen { grid-template-columns: 1fr; gap: 20px; overflow: auto; padding: 24px 16px 56px; align-content: start; }
  .tagline, .features { display: none; }
  .hud-jev { width: 200px; }
  .hud-player { width: 220px; }
  .hud-top { width: 40vw; top: 140px; }
}

/* Phones held sideways: everything tightens up so the arena keeps the middle of the screen. */
@media (max-height: 540px) {
  :root { --side-l: 200px; --side-r: 232px; --middle: calc(100% - 2 * (max(var(--side-l), var(--side-r)) + 22px)); }
  .title-screen {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 400px); align-items: start; gap: 24px; overflow-y: auto;
    padding: 14px calc(var(--sr) + 16px) 16px calc(var(--sl) + 16px);
  }
  .title-left { align-self: center; }
  .logo { font-size: clamp(64px, 24vh, 128px); }
  .subtitle { font-size: 15px; margin: 8px 0 12px 4px; }
  .tagline { display: block; font-size: 14px; margin: 0; }
  .features { display: none; }
  .connect { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; padding: 16px; }
  .connect > :is(h2, .wide, .primary, .status, .fineprint, .title-links) { grid-column: 1 / -1; }
  .connect .check { align-self: end; padding-bottom: 8px; }
  .credits { position: static; grid-column: 1 / -1; }
  input[type='text'], input:not([type]), select { padding: 9px 10px; }
  .segmented button { padding: 6px 4px; }

  .screen.modal { padding: 10px calc(var(--sr) + 10px) 10px calc(var(--sl) + 10px); }
  .card { padding: 16px 18px; gap: 10px; max-height: calc(100% - 4px); }
  .card h2 { font-size: 19px; }
  .stack { flex-direction: row; flex-wrap: wrap; }
  .stack > * { flex: 1 1 150px; }
  .primary, .ghost { padding: 9px 14px; font-size: 13px; }
  .pause-stats { grid-template-columns: repeat(4, auto); }
  table.controls { font-size: 13px; }
  table.controls td { padding: 5px 4px; }
  .settings-grid { grid-template-columns: 1fr 1fr; gap: 8px 22px; }
  .settings-grid label:not(.check) { font-size: 13px; }
  .jev-quote { font-size: 15px; padding: 10px 12px; }
  .end-stats b { font-size: 18px; }
  .end-stats div { padding: 6px; }

  .interlude { gap: 8px; padding: 10px calc(var(--sr) + 12px) 12px calc(var(--sl) + 12px); }
  .convo { max-height: 44vh; padding: 10px 14px; gap: 8px; }
  .msg { font-size: 14px; }
  .quick button { padding: 6px 10px; font-size: 12px; }
  .upgrades { overflow-y: auto; justify-content: safe center; }
  .upgrades h2 { font-size: 18px; }
  .cards { gap: 10px; margin-top: 10px; }
  .ucard { width: 200px; padding: 14px; gap: 6px; }
  .ucard .glyph { font-size: 26px; }
  .ucard p { font-size: 13px; }
  .plan { overflow-y: auto; }
  .plan-card { padding: 14px 16px; }
  .plan-sub { margin: 4px 0 10px; }
  .plan-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

  .hud-player { top: 10px; left: calc(var(--sl) + 12px); width: var(--side-l); padding: 8px 10px; }
  .callsign { font-size: 11px; margin-bottom: 6px; }
  .hpbar { height: 13px; }
  .hud-top { top: 8px; width: var(--middle); }
  .sector-label { font-size: 9px; letter-spacing: 0.2em; }
  .objective { font-size: 12px; margin-top: 2px; }
  .chips { margin-top: 4px; }
  .chip { font-size: 9px; padding: 2px 7px; }
  .bossbar { margin-top: 6px; }
  .bossbar-name { font-size: 10px; margin-bottom: 3px; }
  .bossbar-track { height: 9px; }
  .hud-jev { top: 10px; right: calc(var(--sr) + 12px); width: var(--side-r); display: grid; grid-template-columns: 1fr auto; gap: 6px; }
  .portrait-frame { grid-area: 1 / 2; width: 60px; height: 60px; }
  .jev-info { grid-area: 1 / 1; align-self: center; padding: 7px 9px; }
  .jev-title { font-size: 11px; }
  .mood { margin-top: 6px; gap: 6px; font-size: 9px; }
  #mood-label { width: auto; }
  .decision { grid-column: 1 / -1; padding: 7px 9px; }
  .decision-choice { margin: 3px 0 5px; font-size: 13px; }
  .decision .bar:nth-child(n + 4), .decision-note { display: none; }
  .bars { gap: 3px; }
  .bar-track { height: 12px; }
  .bar-track span { line-height: 12px; }
  .dialogue { bottom: calc(var(--sb) + 10px); width: min(52vw, 500px); gap: 4px; }
  .player-line { font-size: 12px; }
  .jev-line { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
  .jev-line .speaker { font-size: 10px; margin-right: 6px; }
  .jev-line.composing .text { font-size: 13px; }
  .hint { bottom: 8px; }
  .tutorial { top: 30%; font-size: 13px; padding: 7px 14px; width: max-content; max-width: var(--middle); text-align: center; }
  .countdown { font-size: 72px; }
  .toasts { left: calc(var(--sl) + 12px); top: 70px; }
  .toast { font-size: 11px; padding: 4px 8px; }
  .chat { padding: 10px; gap: 6px; }
  .tbar { left: calc(var(--sl) + 12px); top: 64px; }
  body.touch .toasts { top: 108px; }
}
@media (max-height: 540px) and (max-width: 720px) {
  :root { --side-l: 170px; --side-r: 200px; }
  .portrait-frame { width: 52px; height: 52px; }
}
@media (max-height: 380px) {
  .tbtn.dash { width: 74px; height: 74px; bottom: calc(var(--sb) + 16px); }
  .tbtn.pulse { width: 54px; height: 54px; bottom: calc(var(--sb) + 100px); right: calc(var(--sr) + 30px); }
  .stick.move, .stick.aim { top: calc(100% - var(--sb) - 86px); }
}
@media (prefers-reduced-motion: reduce) {
  .logo::before, .logo::after, .jev-line.m3, .rotate .phone { animation: none; }
}
