:root {
    --ink: #e8f7ff;
    --muted: #8ba6b7;
    --panel: rgba(6, 17, 28, 0.88);
    --panel-strong: rgba(5, 14, 24, 0.96);
    --line: rgba(132, 211, 255, 0.2);
    --cyan: #53d7ff;
    --cyan-strong: #00b8f0;
    --blue: #1677ff;
    --green: #7cf1b8;
    --warning: #ffc261;
    --danger: #ff6f91;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    width: 100%;
    min-height: 100%;
}

body {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(83, 215, 255, 0.52);
    outline-offset: 3px;
}

#genesis-lab-body {
    position: relative;
    min-height: 100svh;
    overflow: hidden;
    background: #02070d;
    color: var(--ink);
}

#genesis-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    touch-action: none;
}

#genesis-canvas:active {
    cursor: grabbing;
}

.genesis-vignette,
.genesis-grid {
    position: fixed;
    inset: 0;
    pointer-events: none;
}

.genesis-vignette {
    z-index: 1;
    background:
        radial-gradient(circle at center, transparent 34%, rgba(0, 5, 10, 0.26) 69%, rgba(0, 3, 7, 0.72) 100%),
        linear-gradient(to bottom, rgba(2, 8, 15, 0.35), transparent 26%, transparent 72%, rgba(2, 8, 15, 0.58));
}

.genesis-grid {
    z-index: 2;
    opacity: 0.12;
    background-image:
        linear-gradient(rgba(83, 215, 255, 0.11) 1px, transparent 1px),
        linear-gradient(90deg, rgba(83, 215, 255, 0.11) 1px, transparent 1px);
    background-size: 46px 46px;
    mask-image: linear-gradient(to bottom, black, transparent 76%);
}

.genesis-skip {
    position: fixed;
    top: -80px;
    left: 16px;
    z-index: 100;
    padding: 10px 14px;
    border-radius: 9px;
    background: white;
    color: #07111f;
    font-weight: 800;
    text-decoration: none;
}

.genesis-skip:focus {
    top: 16px;
}

.genesis-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    min-height: 68px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 10px clamp(16px, 3vw, 36px);
    border-bottom: 1px solid var(--line);
    background: rgba(3, 11, 19, 0.78);
    backdrop-filter: blur(16px);
}

.genesis-back {
    width: max-content;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #b8d5e5;
    font-size: 0.83rem;
    font-weight: 800;
    text-decoration: none;
    transition: color 0.2s ease, transform 0.2s ease;
}

.genesis-back:hover {
    color: white;
    transform: translateX(-3px);
}

.genesis-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.15;
}

.genesis-brand strong {
    font-size: 0.94rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.genesis-brand span,
.genesis-stage-counter span {
    color: var(--muted);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.genesis-stage-counter {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 12px;
}

.genesis-stage-counter strong {
    color: var(--cyan);
    font-size: 0.84rem;
}

.genesis-stage-rail {
    position: fixed;
    top: 84px;
    left: 50%;
    z-index: 18;
    display: flex;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: rgba(5, 15, 25, 0.83);
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(14px);
    transform: translateX(-50%);
}

.genesis-stage-rail button {
    min-width: 112px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 13px;
    border: 0;
    border-right: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    font-size: 0.69rem;
    font-weight: 800;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.genesis-stage-rail button:last-child {
    border-right: 0;
}

.genesis-stage-rail button span {
    color: #5d7b8d;
    font-size: 0.6rem;
}

.genesis-stage-rail button:hover,
.genesis-stage-rail button.active {
    background: rgba(83, 215, 255, 0.12);
    color: white;
}

.genesis-stage-rail button.active span {
    color: var(--cyan);
}

.genesis-panel {
    position: fixed;
    z-index: 15;
    width: min(320px, calc(100vw - 32px));
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 17px;
    background: var(--panel);
    box-shadow: 0 22px 55px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(18px);
}

.genesis-controls {
    top: 138px;
    left: clamp(16px, 2.3vw, 32px);
}

.genesis-telemetry {
    top: 88px;
    right: clamp(16px, 2.3vw, 32px);
    width: min(282px, calc(100vw - 32px));
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 15px 16px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.025);
}

.panel-heading span {
    color: var(--cyan);
    font-size: 0.59rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.panel-heading h2 {
    margin-top: 3px;
    color: white;
    font-size: 0.9rem;
}

.panel-collapse {
    width: 30px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    color: white;
    cursor: pointer;
}

.telemetry-light {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 16px rgba(124, 241, 184, 0.86);
}

.telemetry-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
}

.telemetry-grid div {
    min-width: 0;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(132, 211, 255, 0.11);
}

.telemetry-grid div:nth-child(odd) {
    border-right: 1px solid rgba(132, 211, 255, 0.11);
}

.telemetry-grid div:nth-last-child(-n + 2) {
    border-bottom: 0;
}

.telemetry-grid dt {
    color: var(--muted);
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.telemetry-grid dd {
    margin-top: 4px;
    overflow: hidden;
    color: white;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.75rem;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.control-content {
    max-height: min(55vh, 510px);
    overflow-y: auto;
    padding: 8px 16px 16px;
}

.genesis-controls.collapsed .control-content {
    display: none;
}

.control-group {
    padding: 12px 0;
    border-bottom: 1px solid rgba(132, 211, 255, 0.12);
}

.control-group:last-child {
    border-bottom: 0;
}

.control-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 8px;
}

.control-label-row label {
    color: #d9edf7;
    font-size: 0.74rem;
    font-weight: 800;
}

.control-value {
    color: var(--cyan);
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.69rem;
    font-weight: 900;
}

.control-help {
    margin-top: 7px;
    color: #718b9b;
    font-size: 0.63rem;
    line-height: 1.45;
}

.control-content input[type="range"] {
    width: 100%;
    accent-color: var(--cyan-strong);
}

.control-content select {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #071522;
    color: white;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    color: #d9edf7;
    font-size: 0.74rem;
    font-weight: 800;
}

.toggle-row input {
    width: 38px;
    height: 20px;
    accent-color: var(--cyan-strong);
}

.segmented-control {
    display: grid;
    grid-template-columns: 1fr 1fr;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 9px;
}

.segmented-control button {
    padding: 9px 7px;
    border: 0;
    background: rgba(255, 255, 255, 0.025);
    color: var(--muted);
    font-size: 0.67rem;
    font-weight: 850;
    cursor: pointer;
}

.segmented-control button + button {
    border-left: 1px solid var(--line);
}

.segmented-control button.active {
    background: rgba(83, 215, 255, 0.15);
    color: white;
}

.genesis-intro {
    position: fixed;
    left: clamp(20px, 5vw, 74px);
    bottom: clamp(28px, 6vh, 76px);
    z-index: 16;
    width: min(720px, calc(100vw - 40px));
    padding: clamp(24px, 3.3vw, 42px);
    border: 1px solid var(--line);
    border-radius: 24px;
    background: linear-gradient(145deg, rgba(5, 16, 28, 0.95), rgba(5, 14, 24, 0.82));
    box-shadow: 0 32px 80px rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(18px);
}

.genesis-kicker {
    color: var(--cyan);
    font-size: 0.68rem;
    font-weight: 950;
    letter-spacing: 0.13em;
    text-transform: uppercase;
}

.genesis-intro h1 {
    max-width: 680px;
    margin-top: 10px;
    color: white;
    font-size: clamp(2rem, 4.5vw, 4.3rem);
    font-weight: 920;
    letter-spacing: -0.052em;
    line-height: 0.98;
}

.genesis-intro > p:not(.genesis-kicker) {
    max-width: 650px;
    margin-top: 18px;
    color: #abc1cf;
    font-size: clamp(0.88rem, 1.2vw, 1rem);
    line-height: 1.72;
}

.intro-actions,
.story-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 24px;
}

.genesis-intro small {
    display: block;
    margin-top: 14px;
    color: #668396;
    font-size: 0.7rem;
}

.genesis-button {
    min-height: 43px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 17px;
    border-radius: 10px;
    font-size: 0.76rem;
    font-weight: 900;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.genesis-button:hover {
    transform: translateY(-2px);
}

.genesis-button-primary {
    border: 1px solid var(--cyan);
    background: linear-gradient(135deg, #0da9dc, #1472e4);
    color: white;
    box-shadow: 0 12px 28px rgba(0, 136, 220, 0.25);
}

.genesis-button-secondary {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    color: #d9edf7;
}

.genesis-story {
    position: fixed;
    left: 50%;
    bottom: 20px;
    z-index: 17;
    width: min(880px, calc(100vw - 40px));
    max-height: 40vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 24px;
    overflow-y: auto;
    padding: 22px 24px 20px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel-strong);
    box-shadow: 0 30px 75px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(18px);
    transform: translateX(-50%);
}

.story-progress {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.05);
}

.story-progress span {
    display: block;
    width: 20%;
    height: 100%;
    background: linear-gradient(90deg, var(--cyan), var(--blue));
    transition: width 0.35s ease;
}

.story-copy h2 {
    margin-top: 5px;
    color: white;
    font-size: clamp(1.3rem, 2.2vw, 1.9rem);
    letter-spacing: -0.03em;
}

.story-copy p,
.story-copy li {
    color: #abc1cf;
    font-size: 0.78rem;
    line-height: 1.62;
}

.story-copy p {
    margin-top: 8px;
}

.story-copy ul {
    display: grid;
    gap: 4px;
    margin-top: 9px;
    padding-left: 18px;
}

.story-copy strong {
    color: white;
}

.story-actions {
    align-self: end;
    justify-content: flex-end;
    margin-top: 0;
}

.genesis-hint {
    position: fixed;
    left: 50%;
    bottom: 8px;
    z-index: 10;
    color: rgba(173, 208, 226, 0.55);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    transform: translateX(-50%);
    pointer-events: none;
}

.genesis-loading,
.genesis-error,
.genesis-noscript {
    position: fixed;
    z-index: 50;
    left: 50%;
    top: 50%;
    padding: 13px 17px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: rgba(4, 13, 22, 0.94);
    color: white;
    font-size: 0.78rem;
    font-weight: 800;
    transform: translate(-50%, -50%);
}

.genesis-error,
.genesis-noscript {
    color: #ffd8df;
}

.is-hidden {
    display: none !important;
}

@media (max-width: 980px) {
    .genesis-stage-rail {
        max-width: calc(100vw - 32px);
        overflow-x: auto;
    }

    .genesis-stage-rail button {
        min-width: 94px;
    }

    .genesis-telemetry {
        display: none;
    }

    .genesis-controls {
        top: 134px;
    }
}

@media (max-width: 720px) {
    .genesis-topbar {
        grid-template-columns: auto 1fr auto;
        min-height: 62px;
    }

    .genesis-brand {
        align-items: flex-start;
        margin-left: 14px;
    }

    .genesis-brand span,
    .genesis-stage-counter span {
        display: none;
    }

    .genesis-stage-rail {
        top: 72px;
        justify-content: flex-start;
        border-radius: 12px;
    }

    .genesis-stage-rail button {
        min-width: 76px;
        flex-direction: column;
        gap: 2px;
        padding: 8px 9px;
        font-size: 0.58rem;
    }

    .genesis-controls {
        top: 134px;
        left: 12px;
        width: min(278px, calc(100vw - 24px));
    }

    .genesis-intro {
        left: 14px;
        bottom: 18px;
        width: calc(100vw - 28px);
        padding: 23px;
    }

    .genesis-intro h1 {
        font-size: clamp(2rem, 10vw, 3.25rem);
    }

    .genesis-story {
        bottom: 12px;
        width: calc(100vw - 24px);
        max-height: 45vh;
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 20px;
    }

    .story-actions {
        justify-content: stretch;
    }

    .story-actions .genesis-button {
        flex: 1;
    }

    .genesis-hint {
        display: none;
    }
}

@media (max-width: 480px) {
    .genesis-back {
        font-size: 0;
    }

    .genesis-back span {
        font-size: 1rem;
    }

    .genesis-brand strong {
        font-size: 0.76rem;
    }

    .genesis-controls {
        top: 126px;
    }

    .genesis-intro h1 {
        font-size: 2.35rem;
    }

    .intro-actions .genesis-button {
        width: 100%;
    }
}

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

/* Publish-ready story placement and mobile fallback */
.genesis-story {
    left: auto;
    right: 22px;
    bottom: 22px;
    width: min(520px, calc(100vw - 44px));
    max-height: 54vh;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 24px 22px 20px;
    transform: none;
}

.genesis-story-toggle {
    position: absolute;
    top: 13px;
    right: 13px;
    z-index: 2;
    min-height: 30px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.055);
    color: #d8edf7;
    font-size: 0.62rem;
    font-weight: 900;
    cursor: pointer;
}

.genesis-story .story-copy {
    padding-right: 66px;
}

.genesis-story.stage-updated .story-copy {
    animation: genesisStoryIn 0.28s ease both;
}

@keyframes genesisStoryIn {
    from { opacity: 0.25; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

body.story-hidden .genesis-story {
    width: auto;
    max-height: none;
    overflow: visible;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
}

body.story-hidden .genesis-story > :not(.genesis-story-toggle) {
    display: none;
}

body.story-hidden .genesis-story-toggle {
    position: relative;
    top: auto;
    right: auto;
    min-height: 40px;
    padding: 9px 14px;
    background: rgba(5, 17, 29, 0.92);
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.38);
}

.genesis-mobile-disabled {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    align-content: center;
    justify-items: start;
    gap: 16px;
    padding: 30px;
    background: linear-gradient(145deg, #06111e, #0a2436);
}

.genesis-mobile-disabled h1 {
    max-width: 620px;
    color: white;
    font-size: clamp(2.2rem, 10vw, 4rem);
    line-height: 1;
    letter-spacing: -0.05em;
}

.genesis-mobile-disabled p:not(.genesis-kicker) {
    max-width: 620px;
    color: #a9c0cf;
    line-height: 1.75;
}

@media (max-width: 980px) {
    .genesis-story {
        right: 16px;
        bottom: 16px;
        width: min(470px, calc(100vw - 32px));
    }
}
