:root {
    color-scheme: dark;
    --ink: #12110e;
    --panel: #1c1a16;
    --line: #343027;
    --paper: #f3ecdf;
    --muted: #a39886;
    --amber: #ffb703;
    --cyan: #8fd0b4;
    --coral: #ff5a36;
    --blue: #7ea2ff;
    --violet: #c9a0ff;
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
}

html, body, #app {
    height: 100%;
}

body {
    margin: 0;
    background: var(--ink);
    color: var(--paper);
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
}

.app, .shell {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

button, textarea, input {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

a {
    color: var(--amber);
}

.menu {
    width: min(46rem, calc(100% - 2rem));
    margin: 0 auto;
    padding: 2.5rem 0 3rem;
    overflow: auto;
    flex: 1;
    min-height: 0;
}

.menu h1, .overlay h2, .results .grade {
    font-family: system-ui, sans-serif;
    font-weight: 760;
    letter-spacing: -0.04em;
    margin: 0;
}

.menu h1 {
    font-size: clamp(3.4rem, 10vw, 6rem);
    line-height: 0.9;
}

.kicker {
    margin: 0 0 0.4rem;
    color: var(--amber);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 0.75rem;
}

.lede, .hint, .warn {
    color: var(--muted);
    line-height: 1.5;
}

.warn {
    color: var(--coral);
}

.row, .packs, .check {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
}

.row {
    margin: 1.4rem 0;
}

.go, .ghost, .pack {
    border: 1px solid var(--line);
    background: var(--panel);
    border-radius: 999px;
    padding: 0.75rem 1.2rem;
}

.go {
    background: var(--amber);
    color: #231800;
    border-color: var(--amber);
}

.ghost, .pack.on {
    border-color: var(--paper);
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 1rem;
    margin: 0 0 1rem;
    padding: 0.9rem;
}

legend, .stat span, .hint, summary {
    color: var(--muted);
}

textarea {
    width: 100%;
    box-sizing: border-box;
    margin-top: 0.8rem;
    padding: 0.7rem;
    border-radius: 0.7rem;
    border: 1px solid var(--line);
    background: #100e0b;
    resize: vertical;
}

details {
    margin: 1rem 0 1.4rem;
}

details p {
    color: var(--muted);
    line-height: 1.5;
}

.boards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.boards h2 {
    font-size: 0.85rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin: 0 0 0.4rem;
}

.boards ol {
    list-style: none;
    margin: 0;
    padding: 0;
}

.boards li {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.35rem 0;
    border-top: 1px solid var(--line);
}

.boards li span {
    color: var(--muted);
    font-size: 0.78rem;
}

.board {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    outline: none;
    user-select: none;
}

.hud {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem 1.2rem;
    align-items: end;
    padding: 0.8rem 1rem 0.4rem;
}

.brand {
    font-family: system-ui, sans-serif;
    font-size: 1.4rem;
    letter-spacing: -0.04em;
    margin-right: auto;
}

.stat {
    display: flex;
    flex-direction: column;
    min-width: 4.2rem;
}

.stat span {
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.stat strong {
    font-size: 1.15rem;
    font-weight: 600;
}

.stat small {
    color: var(--muted);
    font-size: 0.75rem;
}

.lives {
    display: flex;
    gap: 0.35rem;
    padding-bottom: 0.3rem;
}

.pip {
    width: 0.7rem;
    height: 0.7rem;
    border: 1px solid var(--muted);
    transform: rotate(45deg);
}

.pip.on {
    background: var(--cyan);
    border-color: var(--cyan);
}

.stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.lane {
    /* Height of the blockade zone at the bottom; ships stop falling at its top edge. */
    --blockade: 5.5rem;
    /* Height of the word line above a hull, used to aim at the silhouette's center. */
    --word: 1.85rem;
    --hull: 6.3rem;
    position: relative;
    flex: 1;
    min-height: 12rem;
    overflow: hidden;
    container-type: size;
    background-color: #07080d;
    background-image:
        radial-gradient(1px 1px at 12% 22%, #fff 50%, transparent 52%),
        radial-gradient(1.5px 1.5px at 28% 68%, #d5e4ff 50%, transparent 52%),
        radial-gradient(1px 1px at 47% 14%, #fff 50%, transparent 52%),
        radial-gradient(1px 1px at 63% 46%, #f3ecdf 50%, transparent 52%),
        radial-gradient(1.5px 1.5px at 78% 28%, #fff 50%, transparent 52%),
        radial-gradient(1px 1px at 86% 74%, #c9d7ff 50%, transparent 52%),
        radial-gradient(1px 1px at 18% 84%, #fff 50%, transparent 52%),
        radial-gradient(1px 1px at 54% 82%, #fff 50%, transparent 52%),
        radial-gradient(1px 1px at 6% 52%, rgba(255, 255, 255, 0.7) 50%, transparent 52%),
        radial-gradient(1px 1px at 36% 36%, rgba(255, 255, 255, 0.6) 50%, transparent 52%),
        radial-gradient(1px 1px at 41% 90%, rgba(213, 228, 255, 0.7) 50%, transparent 52%),
        radial-gradient(1.5px 1.5px at 58% 6%, rgba(255, 255, 255, 0.8) 50%, transparent 52%),
        radial-gradient(1px 1px at 71% 60%, rgba(255, 255, 255, 0.6) 50%, transparent 52%),
        radial-gradient(1px 1px at 93% 18%, rgba(255, 255, 255, 0.7) 50%, transparent 52%),
        radial-gradient(1px 1px at 24% 8%, rgba(201, 215, 255, 0.6) 50%, transparent 52%),
        radial-gradient(1px 1px at 80% 92%, rgba(255, 255, 255, 0.5) 50%, transparent 52%),
        linear-gradient(180deg, #121722, #07080d 46%);
}

/* A planet limb behind the blockade. The circle is far wider than the lane, so only its top shows. */
.planet {
    position: absolute;
    left: 50%;
    top: calc(100cqh - var(--blockade) - 2.6rem);
    width: 240cqw;
    height: 240cqw;
    border-radius: 50%;
    transform: translateX(-50%);
    background:
        radial-gradient(ellipse 60% 3rem at 50% 0, rgba(150, 195, 255, 0.4), transparent),
        linear-gradient(180deg, #2b4f86 0, #15294e 3rem, #0a1428 9rem);
    box-shadow: 0 0 2.6rem 0.4rem rgba(110, 160, 255, 0.38);
    pointer-events: none;
}

.ship {
    position: absolute;
    top: 0;
    left: clamp(14%, var(--x, 50%), 86%);
    width: max-content;
    max-width: 46%;
    transform: translateX(-50%);
    text-align: center;
    animation-name: fall;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

/* Hull height (word plus silhouette) per class; shared by bolts, bursts, and turrets. */
.xwing { --hull: 6.3rem; }
.venator { --hull: 10.9rem; }
.destroyer { --hull: 11.9rem; }

.word {
    font-size: clamp(0.78rem, 2.6vw, 1.2rem);
    letter-spacing: 0.03em;
    color: var(--paper);
    text-shadow: 0 1px 0 #000;
    overflow-wrap: anywhere;
}

.typed {
    color: var(--amber);
}

.hull {
    position: relative;
}

.hull svg {
    display: block;
    height: auto;
    margin: 0.15rem auto 0;
    overflow: visible;
}

.xwing .hull svg { width: 3.7rem; }
.venator .hull svg { width: 5.7rem; }
.destroyer .hull svg { width: 6rem; }

.hull .body { fill: #d9dfe7; }
.hull .wing { fill: #c4ccd5; }
.hull .gun { fill: #6c7580; }
.hull .engine { fill: #8d97a4; }
.hull .glow { fill: #ff8fae; }
.hull .glow.blue { fill: #86d6ff; }
.hull .glass { fill: #8fd4ff; }
.hull .mark { fill: #d23b3b; }
.hull .panel { fill: #b9c2cd; }
.hull .panel2 { fill: #a3adb9; }
.hull .deck { fill: #e9edf3; }
.hull .trench { fill: #4f5862; }
.hull .tower { fill: #8d97a6; }
.hull .cap { fill: #f4f7fb; }
.hull .dome { fill: #e3e9f0; }
.hull .nozzle { fill: #5a636e; }
.destroyer .hull .body { fill: #b3bcc7; }
.destroyer .hull .panel { fill: #9ba5b1; }
.destroyer .hull .panel2 { fill: #87919d; }
.destroyer .hull .tower { fill: #76808d; }

/* Shield flicker: a fresh element per typed letter, timed to the bolt's arrival. */
.hit {
    position: absolute;
    inset: -8% -16%;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(150, 215, 255, 0.6), rgba(150, 215, 255, 0.15) 55%, transparent 72%);
    opacity: 0;
    animation: shield 240ms ease-out 220ms both;
    pointer-events: none;
}

.ship.locked .word {
    color: var(--amber);
}

.ship.locked .hull {
    filter: brightness(1.28) drop-shadow(0 0 8px rgba(127, 212, 255, 0.45));
}

/* Separatist blockade along the bottom of the lane. */
.blockade {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: var(--blockade);
    pointer-events: none;
}

.blockade .line {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 0.9rem;
    border-top: 1px solid rgba(217, 194, 154, 0.35);
    background: linear-gradient(180deg, rgba(133, 104, 62, 0.25), rgba(70, 52, 30, 0.8));
}

.blockade > svg {
    position: absolute;
    bottom: 0;
    width: auto;
}

.lucrehulk {
    left: 50%;
    height: var(--blockade);
    transform: translateX(-50%);
}

.munificent {
    height: calc(var(--blockade) * 0.92);
    transform: translateX(-50%);
}

.munificent.left { left: 15%; }
.munificent.right { left: 85%; }

.blockade .tan { fill: #b7976a; }
.blockade .brown { fill: #7a5f3f; }
.blockade .ring { stroke: #b7976a; }
.blockade .ring-line { stroke: #7a5f3f; }
.blockade .core { fill: #c9ad7f; }
.blockade .core-top { fill: #e2cfa6; }

/* Turrets sit on the top edge; the pivot is 0.6rem below it, where bolts start. */
.turret {
    --ang: 0deg;
    position: absolute;
    top: 0;
    left: calc(var(--tx) * 1%);
    width: 1.2rem;
    height: 1.2rem;
    border-radius: 50%;
    transform: translateX(-50%);
    background: radial-gradient(circle, #5d6775 0 35%, #3c434d 36% 70%, #262b33 71%);
    box-shadow: 0 0 0 2px rgba(217, 194, 154, 0.25);
}

.turret .head {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 1rem;
    height: 1.4rem;
    overflow: visible;
    transform-origin: 50% 71%;
    transform: translate(-50%, -71%) rotate(var(--ang));
    transition: transform 90ms ease-out;
}

.turret .barrel { fill: #9aa5b4; }
.turret .mount { fill: #6c7786; }

/*
 * Line from a turret pivot to the hull center of its target.
 * --sx: ship x in percent, --p: how far the ship had fallen (0..1), --tx: turret x in percent.
 * The ship's left edge is clamped exactly like .ship, so --hx is the hull's real center.
 */
.bolt,
.turret.aimed {
    --hx: clamp(14cqw, var(--sx, 50) * 1cqw, 86cqw);
    --dx: calc(var(--hx) - var(--tx, 50) * 1cqw);
    --dy: calc((1 - var(--p, 0)) * (100cqh - var(--hull) - var(--blockade)) + (var(--hull) - var(--word)) / 2 + 0.6rem);
    --ang: atan2(var(--dx), var(--dy));
    --len: hypot(var(--dx), var(--dy));
}

.bolt {
    --streak: 3rem;
    position: absolute;
    left: calc(var(--tx) * 1cqw);
    bottom: calc(var(--blockade) - 0.6rem);
    width: 8px;
    height: var(--len);
    transform-origin: 50% 100%;
    transform: translateX(-50%) rotate(var(--ang));
    pointer-events: none;
}

.bolt::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 0;
    width: 3px;
    height: var(--streak);
    border-radius: 2px;
    background: linear-gradient(180deg, #fff4f2, #ff3b2f 35%, rgba(255, 59, 47, 0.05));
    box-shadow: 0 0 8px 2px rgba(255, 59, 47, 0.65);
    transform: translateX(-50%);
    animation: travel 200ms linear 70ms both;
}

.bolt.heavy {
    --streak: 4.2rem;
}

.bolt.heavy::after {
    width: 5px;
    box-shadow: 0 0 14px 4px rgba(255, 70, 50, 0.8);
}

/* Explosion centered on the hull of a destroyed ship. */
.burst {
    --hx: clamp(14cqw, var(--sx, 50) * 1cqw, 86cqw);
    --size: calc(var(--hull) * 0.9);
    position: absolute;
    left: var(--hx);
    top: calc(var(--p, 0) * (100cqh - var(--hull) - var(--blockade)) + (var(--hull) + var(--word)) / 2 + 0.25rem);
    width: 0;
    height: 0;
    pointer-events: none;
}

.burst .flash,
.burst .ring {
    position: absolute;
    left: 0;
    top: 0;
    width: var(--size);
    height: var(--size);
    margin: calc(var(--size) / -2) 0 0 calc(var(--size) / -2);
    border-radius: 50%;
}

.burst .flash {
    background: radial-gradient(circle, #fff 0%, #ffd27a 28%, rgba(255, 128, 48, 0.7) 50%, rgba(255, 90, 30, 0) 70%);
    animation: flash 600ms ease-out both;
}

.burst .ring {
    border: 3px solid #ffb35a;
    box-shadow: 0 0 12px rgba(255, 140, 60, 0.8), inset 0 0 12px rgba(255, 140, 60, 0.5);
    animation: ring 600ms ease-out both;
}

.burst .shard {
    position: absolute;
    left: -1.5px;
    top: 0;
    width: 3px;
    height: 0.9rem;
    border-radius: 2px;
    background: linear-gradient(180deg, #fff1d6, #ffb35a);
    transform-origin: 50% 0;
    animation: shard 600ms ease-out both;
}

.burst .shard:nth-child(3) { --a: 15deg; }
.burst .shard:nth-child(4) { --a: 75deg; }
.burst .shard:nth-child(5) { --a: 135deg; }
.burst .shard:nth-child(6) { --a: 195deg; }
.burst .shard:nth-child(7) { --a: 255deg; }
.burst .shard:nth-child(8) { --a: 315deg; }

.board.paused .ship,
.board.paused .bolt::after,
.board.paused .burst > *,
.board.paused .hit {
    animation-play-state: paused;
}

.board.miss .lane {
    box-shadow: inset 0 0 0 3px var(--coral);
}

.overlay {
    position: absolute;
    inset: 0;
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 0.4rem;
    background: rgba(18, 17, 14, 0.62);
    text-align: center;
}

.overlay h2, .grade {
    font-size: clamp(3rem, 12vw, 6rem);
}

.results .grade {
    color: var(--amber);
}

.stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem 1.4rem;
    margin: 1.2rem 0 1.6rem;
}

.stats div {
    border-top: 1px solid var(--line);
    padding-top: 0.4rem;
}

.stats dt {
    color: var(--muted);
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.stats dd {
    margin: 0.15rem 0 0;
    font-size: 1.4rem;
}

@keyframes fall {
    from { top: 0.25rem; }
    to { top: calc(100% - var(--hull) - var(--blockade)); }
}

@keyframes travel {
    0% { bottom: 0; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { bottom: calc(100% - var(--streak)); opacity: 0; }
}

@keyframes shield {
    0% { opacity: 0; }
    30% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes flash {
    0% { transform: scale(0.3); opacity: 1; }
    35% { opacity: 1; }
    100% { transform: scale(1.3); opacity: 0; }
}

@keyframes ring {
    0% { transform: scale(0.2); opacity: 1; }
    100% { transform: scale(1.7); opacity: 0; }
}

@keyframes shard {
    0% { transform: rotate(var(--a)) translateY(0); opacity: 1; }
    100% { transform: rotate(var(--a)) translateY(var(--size)); opacity: 0; }
}

@media (max-width: 720px) {
    .boards { grid-template-columns: 1fr; }
    .menu { padding-top: 1.4rem; }
    .hud { gap: 0.55rem 0.8rem; }
    .lane { --blockade: 3.8rem; --word: 1.25rem; }
    .ship { left: clamp(22%, var(--x, 50%), 78%); max-width: 58%; }
    .bolt, .turret.aimed, .burst { --hx: clamp(22cqw, var(--sx, 50) * 1cqw, 78cqw); }
    .xwing { --hull: 4.4rem; }
    .venator { --hull: 7.6rem; }
    .destroyer { --hull: 8.3rem; }
    .xwing .hull svg { width: 2.6rem; }
    .venator .hull svg { width: 4rem; }
    .destroyer .hull svg { width: 4.2rem; }
}

@media (prefers-reduced-motion: reduce) {
    .bolt, .burst .shard, .hit { display: none; }
    .turret .head { transition: none; }
    .ship.locked .hull { filter: none; }
}

#blazor-error-ui {
    background: #2a130f;
    color: var(--paper);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.4);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #5c2418;
    padding: 1rem 1rem 1rem 1rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #343027;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--amber);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: 700;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}
