:root {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-soft: #f4f5f6;
    --ink: #1f2328;
    --ink-soft: #3d444d;
    --muted: #697179;
    --line: #e3e6e9;
    --line-strong: #c9ced3;
    --accent: #1d5b94;
    --accent-strong: #23282d;
    --accent-soft: #f1f3f5;
    --canvas: #fafbfb;
    --panel: #3b6fb6;
    --clean: #1b9e6f;
    --close: #c98500;
    --crash: #d64545;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #15181b;
    --surface: #15181b;
    --surface-soft: #1e2226;
    --ink: #e3e6e9;
    --ink-soft: #c3c9cf;
    --muted: #949da6;
    --line: #2c3136;
    --line-strong: #434a51;
    --accent: #8dbbe8;
    --accent-strong: #e3e6e9;
    --accent-soft: #23282d;
    --canvas: #1a1d20;
    --panel: #7fa8e6;
    --clean: #3cc28f;
    --close: #e0a526;
    --crash: #e66767;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    min-width: 300px;
    min-height: 100vh;
    margin: 0;
    padding: 18px;
    color: var(--ink);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
    text-rendering: optimizeLegibility;
}

button {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
    outline-offset: 2px;
}

.demo-shell {
    width: min(100%, 980px);
    margin: 0 auto;
    padding: 24px 0;
}

.standalone-back {
    display: inline-flex;
    margin-bottom: 13px;
    color: var(--accent-strong);
    font-size: 0.72rem;
    font-weight: 750;
    text-decoration: none;
}

.standalone-back:hover {
    text-decoration: underline;
}

.is-embedded .standalone-back {
    display: none;
}

.demo-heading {
    margin-bottom: 16px;
}

.demo-topline {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 7px;
}

.demo-kicker {
    margin: 0;
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 750;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.language-switcher {
    display: flex;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-soft);
}

.lang-btn {
    min-width: 36px;
    min-height: 30px;
    padding: 4px 9px;
    border: 0;
    border-radius: 999px;
    color: var(--muted);
    background: transparent;
    font-size: 0.72rem;
    font-weight: 750;
    cursor: pointer;
}

.lang-btn:hover {
    color: var(--ink);
}

.lang-btn.active {
    color: var(--ink);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 7px;
    color: var(--ink);
    font-size: clamp(1.65rem, 4vw, 2.25rem);
    font-weight: 680;
    letter-spacing: -0.045em;
    line-height: 1.05;
}

.demo-intro {
    max-width: 760px;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.94rem;
}

/* Heads-up display */

.hud {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 22px;
    align-items: baseline;
    padding: 8px 2px 10px;
}

.hud-item {
    display: flex;
    gap: 6px;
    align-items: baseline;
    color: var(--muted);
    font-size: 0.7rem;
}

.hud-item output {
    color: var(--accent-strong);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
    font-weight: 750;
}

.hud-item.score output {
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.hud-item.clean output {
    color: var(--clean);
}

.hud-item.close output {
    color: var(--close);
}

.lives {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-left: auto;
}

.life {
    width: 18px;
    height: 18px;
    fill: var(--crash);
    stroke: var(--crash);
    stroke-width: 1.5;
    transition: fill 200ms ease, stroke 200ms ease, transform 200ms ease;
}

.life.lost {
    fill: transparent;
    stroke: var(--line-strong);
    transform: scale(0.86);
}

/* Stage */

.stage {
    position: relative;
}

canvas {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--canvas);
    touch-action: none;
    cursor: crosshair;
}

.overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    border-radius: 9px;
    background: color-mix(in srgb, var(--canvas) 38%, transparent);
}

.overlay[hidden] {
    display: none;
}

.overlay-card {
    width: min(100%, 360px);
    padding: 20px 22px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    box-shadow: 0 12px 36px rgba(20, 26, 32, 0.12);
    text-align: center;
    backdrop-filter: blur(6px);
}

.overlay-card h2 {
    margin-bottom: 6px;
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.overlay-card p {
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 0.82rem;
}

.overlay-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 0 0 16px;
}

.overlay-stats[hidden] {
    display: none;
}

.overlay-stats div {
    padding: 7px 6px;
    border-radius: 8px;
    background: var(--surface-soft);
}

.overlay-stats dt {
    color: var(--muted);
    font-size: 0.66rem;
}

.overlay-stats dd {
    margin: 0;
    color: var(--ink);
    font-size: 1rem;
    font-variant-numeric: tabular-nums;
    font-weight: 750;
}

.overlay-badge {
    display: inline-block;
    margin-bottom: 12px;
    padding: 3px 9px;
    border-radius: 999px;
    color: var(--clean);
    background: color-mix(in srgb, var(--clean) 14%, transparent);
    font-size: 0.7rem;
    font-weight: 750;
}

.overlay-badge[hidden] {
    display: none;
}

.button {
    min-height: 36px;
    padding: 7px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    color: var(--ink);
    background: var(--surface);
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 150ms ease, background-color 150ms ease;
}

.button:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.button-primary {
    min-width: 140px;
    color: #ffffff;
    border-color: var(--accent-strong);
    background: var(--accent-strong);
}

[data-theme="dark"] .button-primary {
    color: #15181b;
}

.button-primary:hover {
    color: #ffffff;
    border-color: var(--accent);
    background: var(--accent);
}

[data-theme="dark"] .button-primary:hover {
    color: #15181b;
}

/* Controls and legend */

.controls-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
    align-items: start;
    margin-top: 12px;
}

.hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.75rem;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.mode-switch {
    display: flex;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface-soft);
}

.mode-btn {
    min-height: 30px;
    padding: 4px 12px;
    border: 0;
    border-radius: 7px;
    color: var(--muted);
    background: transparent;
    font-size: 0.74rem;
    font-weight: 700;
    cursor: pointer;
}

.mode-btn:hover {
    color: var(--ink);
}

.mode-btn.active {
    color: var(--ink);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--line);
}

/* Joint sliders (hard mode) */

.joint-panel {
    display: grid;
    gap: 4px;
    margin-top: 12px;
    padding: 10px 14px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface-soft);
}

.joint-panel[hidden] {
    display: none;
}

.joint-title {
    margin: 0 0 2px;
    color: var(--ink);
    font-size: 0.76rem;
    font-weight: 720;
}

.joint-row {
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr) 3rem;
    gap: 12px;
    align-items: center;
    min-height: 26px;
    color: var(--muted);
    font-size: 0.74rem;
}

.joint-row input {
    width: 100%;
    margin: 0;
    accent-color: var(--panel);
    cursor: ew-resize;
}

.joint-row output {
    color: var(--ink);
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
}

.joint-symbol {
    color: var(--panel);
    font-weight: 750;
}

.legend {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px 18px;
    margin: 16px 0 0;
    padding: 14px 0 0;
    border-top: 1px solid var(--line);
    list-style: none;
    font-size: 0.75rem;
}

.legend li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 2px 9px;
    color: var(--muted);
}

.legend strong {
    color: var(--ink);
    font-size: 0.78rem;
}

.legend-dot {
    grid-row: span 2;
    width: 9px;
    height: 9px;
    margin-top: 5px;
    border-radius: 50%;
}

.legend-dot.clean {
    background: var(--clean);
}

.legend-dot.close {
    background: var(--close);
}

.legend-dot.crash {
    background: var(--crash);
}

.note {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 0.72rem;
}

.references {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.references h2 {
    margin: 0 0 8px;
    color: var(--ink);
    font-size: 0.82rem;
    font-weight: 720;
}

.reference-list {
    margin: 0;
    padding-left: 1.3rem;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.5;
}

.reference-list li + li {
    margin-top: 4px;
}

.reference-list em {
    color: var(--ink-soft);
}

.reference-list a,
.references-extra a {
    color: var(--accent);
}

.references-extra {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 0.72rem;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 720px) {
    body {
        padding: 10px;
    }

    .demo-shell {
        padding: 16px 6px;
    }

    canvas {
        aspect-ratio: 4 / 3;
    }

    .controls-row,
    .legend {
        grid-template-columns: 1fr;
    }

    .joint-row {
        grid-template-columns: 6.5rem minmax(0, 1fr) 2.6rem;
        gap: 8px;
    }

    .actions {
        justify-content: flex-start;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0.01ms !important;
    }
}
