:root {
    --bg: #061014;
    --bg-2: #0a1c22;
    --panel: rgba(8, 28, 34, 0.88);
    --ink: #e7f7f4;
    --muted: #8aaeb0;
    --gold: #1ec9b5;
    --gold-2: #7ef0dc;
    --amber: #f0c14b;
    --hit: #3eea9a;
    --miss: #ff5d6c;
    --line: rgba(126, 240, 220, 0.14);
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
    --font: "IBM Plex Sans", system-ui, sans-serif;
    --display: Sora, "IBM Plex Sans", sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}

.grain {
    pointer-events: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    opacity: 0.06;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}
.grid-bg {
    pointer-events: none;
    position: fixed;
    inset: 0;
    z-index: 0;
    background:
        radial-gradient(900px 420px at 8% -8%, rgba(30, 201, 181, 0.16), transparent 55%),
        radial-gradient(700px 380px at 100% 0%, rgba(240, 193, 75, 0.08), transparent 50%),
        linear-gradient(rgba(126, 240, 220, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(126, 240, 220, 0.035) 1px, transparent 1px);
    background-size: auto, auto, 28px 28px, 28px 28px;
}

a { color: var(--gold-2); }
a:hover { color: var(--gold); }

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.35rem;
    position: sticky;
    top: 0;
    background: rgba(6, 16, 20, 0.9);
    backdrop-filter: blur(14px);
    z-index: 5;
}
.brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--ink);
    text-decoration: none;
}
.brand-mark {
    width: 2rem;
    height: 2rem;
    color: var(--gold);
    display: grid;
    place-items: center;
    animation: mark-pulse 2.8s ease-in-out infinite;
}
.brand-mark svg { display: block; }
.brand-text { display: grid; line-height: 1.05; }
.brand-name {
    font-family: var(--display);
    font-weight: 700;
    letter-spacing: -0.03em;
    font-size: 1.12rem;
}
.brand-sub {
    font-family: var(--mono);
    font-size: 0.62rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--gold);
}

.nav {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    font-size: 0.92rem;
}
.nav a { color: var(--muted); text-decoration: none; }
.nav a[aria-current="page"], .nav a:hover { color: var(--ink); }

.grade-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: rgba(30, 201, 181, 0.1);
    border: 1px solid rgba(30, 201, 181, 0.35);
    border-radius: 999px;
    padding: 0.22rem 0.55rem 0.22rem 0.28rem;
    font-variant-numeric: tabular-nums;
}
.grade-chip-rank {
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    background: var(--gold);
    color: #042326;
    border-radius: 999px;
    padding: 0.18rem 0.45rem;
    font-weight: 600;
}
.nav-score { color: var(--gold-2); font-size: 0.85rem; }

.ecg-strip {
    height: 16px;
    overflow: hidden;
    background: #040b0e;
    border-bottom: 1px solid var(--line);
    position: relative;
    z-index: 4;
}
.ecg-strip svg {
    display: block;
    width: 200%;
    height: 16px;
    animation: ecg-scroll 4.5s linear infinite;
}
.ecg-strip polyline {
    fill: none;
    stroke: var(--gold);
    stroke-width: 1.6;
    stroke-linejoin: round;
}

.wrap {
    width: min(1080px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2.2rem 0 4rem;
    position: relative;
    z-index: 1;
}
.narrow { width: min(28rem, calc(100% - 2rem)); }

h1, h2 {
    font-family: var(--display);
    font-weight: 700;
    line-height: 1.12;
    letter-spacing: -0.04em;
}
h1 { font-size: clamp(2rem, 5.4vw, 3.7rem); margin: 0.15rem 0 0.8rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.4rem; }

.kicker {
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-size: 0.7rem;
    font-family: var(--mono);
    color: var(--gold);
    margin: 0 0 0.55rem;
}
.lede { color: var(--muted); font-size: 1.08rem; max-width: 40rem; }
.meta-line { color: var(--muted); font-size: 0.92rem; }

.hero { padding: 1.2rem 0 1.6rem; }
.hero-split {
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 2rem;
    align-items: center;
}
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin: 1.4rem 0; }
.vital-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}
.vital-pills li {
    font-family: var(--mono);
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    background: rgba(8, 28, 34, 0.6);
}
.vital-pills strong { color: var(--gold-2); font-weight: 600; }

.station-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1.1rem;
    padding: 1.1rem 1.15rem 1.2rem;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.station-card::before {
    content: "";
    position: absolute;
    inset: 10px;
    border: 1px dashed rgba(126, 240, 220, 0.18);
    border-radius: 0.8rem;
    pointer-events: none;
}
.station-label {
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--amber);
    margin: 0 0 0.4rem;
}
.station-preview {
    height: 9.5rem;
    margin: 0.6rem 0 0.8rem;
    border-radius: 0.7rem;
    background:
        radial-gradient(circle at 50% 42%, rgba(30, 201, 181, 0.18), transparent 42%),
        linear-gradient(180deg, #0a2228, #071318);
    position: relative;
    overflow: hidden;
}
.reticle {
    position: absolute;
    width: 4.4rem;
    height: 4.4rem;
    left: 50%;
    top: 44%;
    transform: translate(-50%, -50%);
    border: 2px solid var(--gold-2);
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(126, 240, 220, 0.2), 0 0 24px rgba(30, 201, 181, 0.35);
    animation: reticle-breathe 2.2s ease-in-out infinite;
}
.reticle::before, .reticle::after {
    content: "";
    position: absolute;
    background: var(--gold-2);
}
.reticle::before { left: 50%; top: -8px; bottom: -8px; width: 1px; transform: translateX(-50%); }
.reticle::after { top: 50%; left: -8px; right: -8px; height: 1px; transform: translateY(-50%); }
.station-ask {
    margin: 0;
    font-family: var(--display);
    font-weight: 700;
    letter-spacing: -0.03em;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--gold);
    color: #042326;
    text-decoration: none;
    border: 0;
    border-radius: 0.55rem;
    padding: 0.72rem 1.15rem;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 0 0 1px rgba(126, 240, 220, 0.25), 0 8px 24px rgba(30, 201, 181, 0.18);
}
.btn:hover { background: var(--gold-2); color: #042326; }
.btn-ghost {
    background: transparent;
    color: var(--ink);
    box-shadow: inset 0 0 0 1px var(--line);
}
.btn-ghost:hover { color: var(--gold-2); box-shadow: inset 0 0 0 1px var(--gold); }
.btn-small { padding: 0.38rem 0.8rem; font-size: 0.86rem; }
[hidden] { display: none !important; }

.cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}
.cards article, .strip, .form, .complete, .table-wrap {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1rem;
    padding: 1.2rem 1.3rem;
    box-shadow: var(--shadow);
}
.cards article {
    position: relative;
    overflow: hidden;
}
.cards article .step {
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--amber);
    margin: 0 0 0.45rem;
}
.cards p, .strip li { color: var(--muted); }
.strip ul { margin: 0; padding-left: 1.1rem; }
.mark-scheme {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.45rem 1rem;
    margin: 0.6rem 0 0;
}
.mark-scheme dt {
    font-family: var(--mono);
    color: var(--gold-2);
    font-size: 0.85rem;
}
.mark-scheme dd { margin: 0; color: var(--muted); }

.form { display: grid; gap: 0.9rem; }
label { display: grid; gap: 0.35rem; font-size: 0.92rem; color: var(--muted); }
input {
    background: #071015;
    border: 1px solid var(--line);
    color: var(--ink);
    border-radius: 0.5rem;
    padding: 0.7rem 0.8rem;
    font: inherit;
}
input:focus { outline: 2px solid var(--gold); border-color: transparent; }

.errors {
    background: rgba(255, 93, 108, 0.12);
    border: 1px solid rgba(255, 93, 108, 0.4);
    color: #ffc4ca;
    border-radius: 0.8rem;
    padding: 0.8rem 1rem 0.8rem 1.6rem;
}
.flash {
    width: min(1080px, calc(100% - 2rem));
    margin: 1rem auto 0;
    padding: 0.7rem 1rem;
    border-radius: 0.7rem;
    position: relative;
    z-index: 1;
}
.flash-ok { background: rgba(62, 234, 154, 0.12); color: var(--hit); }
.flash-error { background: rgba(255, 93, 108, 0.12); color: #ffc4ca; }

.stage {
    display: grid;
    grid-template-columns: minmax(16rem, 22rem) 1fr;
    gap: 1.4rem;
    align-items: start;
}
.brief {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 1rem;
    padding: 1.15rem 1.2rem 1.3rem;
    position: sticky;
    top: 5.4rem;
    box-shadow: var(--shadow);
}
.brief h1 { font-size: clamp(1.45rem, 3vw, 2rem); }
.chart-flag {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--amber);
    margin: 0 0 0.7rem;
}
.chart-flag::before {
    content: "";
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--hit);
    box-shadow: 0 0 0 4px rgba(62, 234, 154, 0.18);
    animation: live-dot 1.4s ease-in-out infinite;
}
.prompt { font-size: 1.12rem; margin: 0 0 0.8rem; }
.hint {
    color: var(--amber);
    background: rgba(240, 193, 75, 0.1);
    border: 1px solid rgba(240, 193, 75, 0.28);
    border-radius: 0.6rem;
    padding: 0.65rem 0.75rem;
    font-size: 0.92rem;
}
.pack-meter {
    height: 0.4rem;
    background: #071015;
    border-radius: 999px;
    overflow: hidden;
    margin: 0.3rem 0 0.9rem;
}
.pack-meter span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--gold), var(--gold-2));
    border-radius: inherit;
}
.grade-note {
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--muted);
    margin: 0 0 0.9rem;
}
.meters {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin: 1rem 0;
}
.meters div {
    background: #071015;
    border: 1px solid var(--line);
    border-radius: 0.6rem;
    padding: 0.55rem;
}
.meters dt {
    color: var(--muted);
    font-size: 0.68rem;
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
.meters dd { margin: 0.15rem 0 0; font-variant-numeric: tabular-nums; font-size: 1.12rem; font-family: var(--mono); }
.result {
    font-weight: 700;
    font-family: var(--display);
    letter-spacing: -0.02em;
    margin: 0.85rem 0 0.4rem;
    padding: 0.7rem 0.8rem;
    border-radius: 0.6rem;
}
.result.hit {
    color: #042326;
    background: var(--hit);
    animation: stamp-in 0.35s ease-out;
}
.result.miss {
    color: #ffd5d9;
    background: rgba(255, 93, 108, 0.16);
    border: 1px solid rgba(255, 93, 108, 0.35);
}

.viewport { min-width: 0; }
.viewer {
    background: #03090c;
    border: 1px solid var(--line);
    border-radius: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.viewer-bar {
    display: flex;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.45rem 0.75rem;
    font-family: var(--mono);
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
    background: #08151a;
    border-bottom: 1px solid var(--line);
}
.viewer-bar .live { color: var(--hit); }
.frame {
    position: relative;
    background: #03080a;
    overflow: hidden;
    cursor: crosshair;
    user-select: none;
    touch-action: manipulation;
}
.frame img {
    display: block;
    width: 100%;
    height: auto;
    vertical-align: middle;
}
.frame.is-locked { pointer-events: none; cursor: default; }
.frame.is-hit { box-shadow: inset 0 0 0 3px var(--hit); }
.frame.is-miss { animation: miss-shake 0.32s ease-in-out; }
.viewfinder {
    pointer-events: none;
    position: absolute;
    inset: 10px;
    z-index: 2;
}
.vf {
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(126, 240, 220, 0.7);
}
.vf-tl { top: 0; left: 0; border-right: 0; border-bottom: 0; }
.vf-tr { top: 0; right: 0; border-left: 0; border-bottom: 0; }
.vf-bl { bottom: 0; left: 0; border-right: 0; border-top: 0; }
.vf-br { bottom: 0; right: 0; border-left: 0; border-top: 0; }
.scanline {
    pointer-events: none;
    position: absolute;
    inset: 0;
    z-index: 1;
    background: linear-gradient(180deg, transparent 0%, rgba(126, 240, 220, 0.07) 50%, transparent 100%);
    background-size: 100% 140%;
    animation: scan 3.6s linear infinite;
    mix-blend-mode: screen;
    opacity: 0.28;
}
.markers { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.mark {
    position: absolute;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border-radius: 50%;
    border: 2px solid var(--miss);
    background: rgba(255, 93, 108, 0.28);
    animation: ping 0.45s ease-out;
}
.mark.target {
    border-color: var(--hit);
    background: rgba(62, 234, 154, 0.12);
    box-shadow: 0 0 0 3px rgba(62, 234, 154, 0.35);
    margin: 0;
    transform: translate(-50%, -50%);
    animation: target-pop 0.4s ease-out;
}
.score-burst {
    position: absolute;
    transform: translate(-50%, -50%);
    font-family: var(--display);
    font-weight: 800;
    color: var(--hit);
    font-size: 1.35rem;
    text-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
    animation: burst-up 0.9s ease-out forwards;
    white-space: nowrap;
}
.frame-help { color: var(--muted); font-size: 0.85rem; margin: 0.7rem 0 0; }

.board { width: 100%; border-collapse: collapse; }
.board th, .board td {
    text-align: left;
    padding: 0.75rem 0.5rem;
    border-bottom: 1px solid var(--line);
}
.board th {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.75rem;
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.board tr.you td { color: var(--gold-2); }
.rank-cell {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-family: var(--mono);
}
.medal {
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #042326;
}
.medal-1 { background: var(--amber); }
.medal-2 { background: #c9d4d8; }
.medal-3 { background: #d08a4a; }
.tag {
    font-size: 0.68rem;
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--gold);
}
.grade-tag {
    display: inline-block;
    margin-left: 0.35rem;
    font-family: var(--mono);
    font-size: 0.65rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #042326;
    background: var(--gold);
    border-radius: 999px;
    padding: 0.12rem 0.4rem;
}
.empty { color: var(--muted); }

.admin-grid {
    display: grid;
    grid-template-columns: minmax(16rem, 22rem) 1fr;
    gap: 1.4rem;
    align-items: start;
}
.admin-fields { display: grid; gap: 0.9rem; }
.check-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--ink);
}
.check-row input { width: auto; }
.inline-form { margin: 0; }
.inline-form .check-row { margin: 0; }
.case-actions { white-space: nowrap; }
.case-delete-form { display: inline; }
.link-danger {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-size: inherit;
    color: #ff9aa3;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 0.15em;
}
.link-danger:hover { color: #ffc4ca; }
.case-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.thumb {
    width: 3.2rem;
    height: 3.2rem;
    object-fit: cover;
    border-radius: 0.4rem;
    background: #071015;
    border: 1px solid var(--line);
}
.target-frame {
    cursor: crosshair;
    border: 1px solid var(--line);
    border-radius: 1rem;
    box-shadow: var(--shadow);
}
.target-frame img { touch-action: none; }
.target-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.target-svg polygon {
    fill: rgba(30, 201, 181, 0.22);
    stroke: var(--gold);
    stroke-width: 0.7;
    stroke-linejoin: round;
}
.target-svg .other-poly,
.target-svg .other-circle {
    fill: rgba(240, 193, 75, 0.1);
    stroke: rgba(240, 193, 75, 0.7);
    stroke-width: 0.55;
    stroke-dasharray: 1.4 0.9;
}
.library {
    border: 1px solid var(--line);
    border-radius: 0.7rem;
    padding: 0.7rem 0.75rem 0.85rem;
    margin: 0;
}
.library legend {
    font-size: 0.92rem;
    color: var(--muted);
    padding: 0 0.25rem;
}
.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(6.4rem, 1fr));
    gap: 0.55rem;
    margin-top: 0.45rem;
}
.library-pick {
    display: grid;
    gap: 0.28rem;
    text-align: left;
    background: #071015;
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: 0.55rem;
    padding: 0.35rem;
    cursor: pointer;
    font: inherit;
    font-size: 0.75rem;
    line-height: 1.25;
}
.library-pick img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 0.35rem;
    background: #040b0e;
}
.library-pick.is-selected {
    border-color: var(--gold);
    box-shadow: 0 0 0 1px var(--gold);
}
.library-pick .meta-line { font-size: 0.7rem; }
.editor-move-note {
    margin: 0.2rem 0 0.6rem;
    padding: 0.75rem 0.9rem;
    border-radius: 0.7rem;
    border: 1px solid rgba(255, 196, 92, 0.45);
    background: rgba(255, 196, 92, 0.1);
    color: #ffe3ad;
    font-size: 0.92rem;
    line-height: 1.4;
}
.editor-move-note a { color: inherit; text-decoration: underline; }
.page-play .target-svg polygon {
    fill: rgba(62, 234, 154, 0.18);
    stroke: var(--hit);
}
.page-admin-edit .wrap, .page-admin .wrap { width: min(1180px, calc(100% - 2rem)); }
input[type="range"] { padding: 0.2rem 0; }

.foot {
    border-top: 1px solid var(--line);
    padding: 1.4rem;
    color: var(--muted);
    font-size: 0.88rem;
    text-align: center;
    position: relative;
    z-index: 1;
}
.foot p { width: min(42rem, 100%); margin: 0 auto; }

@keyframes ecg-scroll {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}
@keyframes mark-pulse {
    0%, 100% { color: var(--gold); filter: drop-shadow(0 0 0 transparent); }
    50% { color: var(--gold-2); filter: drop-shadow(0 0 8px rgba(30, 201, 181, 0.55)); }
}
@keyframes reticle-breathe {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
    50% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
}
@keyframes live-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}
@keyframes scan {
    from { background-position: 0 -40%; }
    to { background-position: 0 140%; }
}
@keyframes ping {
    from { transform: scale(0.4); opacity: 0.2; }
    to { transform: scale(1); opacity: 1; }
}
@keyframes target-pop {
    from { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
@keyframes burst-up {
    0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
    20% { opacity: 1; transform: translate(-50%, -80%) scale(1.05); }
    100% { opacity: 0; transform: translate(-50%, -140%) scale(1); }
}
@keyframes stamp-in {
    from { transform: scale(0.92); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
@keyframes miss-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
    .ecg-strip svg, .brand-mark, .reticle, .scanline, .chart-flag::before {
        animation: none;
    }
}

@media (max-width: 860px) {
    .cards, .stage, .admin-grid, .hero-split { grid-template-columns: 1fr; }
    .brief { position: static; }
    .grade-chip { display: none; }
    .top { padding: 0.75rem 1rem; }
    .station-card { display: none; }
}
