:root {
    color-scheme: light;
    --ink: #18201d;
    --muted: #56635e;
    --paper: #f8f6ef;
    --panel: #ffffff;
    --line: #d8ded2;
    --green: #16735b;
    --green-dark: #0f4f42;
    --red: #b63d2c;
    --amber: #c47a16;
    --blue: #256b93;
    --violet: #6952a6;
    --shadow: 0 18px 50px rgba(24, 32, 29, 0.14);
    --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        linear-gradient(90deg, rgba(37, 107, 147, 0.06) 1px, transparent 1px),
        linear-gradient(0deg, rgba(22, 115, 91, 0.07) 1px, transparent 1px),
        var(--paper);
    background-size: 42px 42px;
    font-family: var(--sans);
}

button,
textarea {
    font: inherit;
}

button {
    border: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: minmax(210px, 1fr) auto minmax(210px, 1fr);
    align-items: center;
    gap: 20px;
    padding: 14px clamp(18px, 4vw, 44px);
    border-bottom: 1px solid rgba(24, 32, 29, 0.11);
    background: rgba(248, 246, 239, 0.92);
    backdrop-filter: blur(18px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    width: fit-content;
}

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 8px;
    background: var(--green-dark);
    color: #fff9ea;
    font-family: var(--mono);
    font-weight: 800;
    letter-spacing: 0;
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 16px;
}

.brand small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}

.topnav {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px;
    border: 1px solid rgba(24, 32, 29, 0.12);
    border-radius: 999px;
    background: #fffaf0;
}

.topnav a {
    padding: 8px 14px;
    border-radius: 999px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 750;
}

.topnav a:hover {
    background: #e8efe3;
    color: var(--ink);
}

.top-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid rgba(22, 115, 91, 0.28);
    border-radius: 999px;
    background: rgba(22, 115, 91, 0.09);
    color: var(--green-dark);
    font-size: 13px;
    font-weight: 800;
}

.icon-button,
.toolbar-actions button,
.run-button,
.kit-card button {
    min-height: 38px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 800;
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.icon-button {
    padding: 0 13px;
    border: 1px solid rgba(24, 32, 29, 0.16);
    background: #ffffff;
    color: var(--ink);
}

.icon-button:hover,
.toolbar-actions button:hover,
.kit-card button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(24, 32, 29, 0.12);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
    gap: clamp(18px, 3vw, 34px);
    min-height: calc(100vh - 72px);
    padding: clamp(18px, 4vw, 44px);
}

.mission-rail,
.lab-panel,
.kits-section,
.campaign-section {
    border: 1px solid rgba(24, 32, 29, 0.12);
    background: rgba(255, 255, 255, 0.86);
    box-shadow: var(--shadow);
}

.mission-rail {
    display: flex;
    flex-direction: column;
    gap: 22px;
    align-self: start;
    padding: clamp(18px, 3vw, 26px);
    border-radius: 8px;
}

.eyebrow {
    margin: 0 0 9px;
    color: var(--green);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.rail-heading h1,
.section-heading h2 {
    margin: 0;
    font-size: clamp(36px, 5.2vw, 76px);
    line-height: 0.93;
    letter-spacing: 0;
}

.rail-heading p,
.section-heading p {
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.55;
}

.mission-list {
    display: grid;
    gap: 10px;
}

.mission-card {
    display: grid;
    gap: 7px;
    width: 100%;
    padding: 13px;
    border: 1px solid var(--line);
    border-left: 5px solid transparent;
    border-radius: 8px;
    background: #fffdf7;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.mission-card:hover {
    border-left-color: var(--amber);
}

.mission-card.is-active {
    border-color: rgba(22, 115, 91, 0.38);
    border-left-color: var(--green);
    background: #edf5ed;
}

.mission-card strong {
    font-size: 15px;
}

.mission-card span {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.signal-panel {
    padding: 16px;
    border: 1px solid rgba(37, 107, 147, 0.2);
    border-radius: 8px;
    background: #eef6f8;
}

.signal-label,
.brief-card span,
.campaign-board span {
    display: inline-flex;
    margin-bottom: 8px;
    color: var(--blue);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.signal-panel strong {
    display: block;
    line-height: 1.35;
}

.signal-panel p {
    margin: 9px 0 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.lab-panel {
    display: grid;
    gap: 18px;
    padding: clamp(18px, 3vw, 28px);
    border-radius: 8px;
}

.lab-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 20px;
}

.lab-header h2 {
    margin: 0;
    font-size: clamp(30px, 4vw, 54px);
    line-height: 0.98;
}

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

.lab-meta span {
    padding: 8px 11px;
    border-radius: 999px;
    background: #f0eadc;
    color: #4c4231;
    font-size: 12px;
    font-weight: 850;
}

.brief-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.brief-card {
    min-height: 138px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf7;
}

.brief-card p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.editor-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
    gap: 14px;
    min-height: 560px;
}

.editor-card,
.verifier-card {
    overflow: hidden;
    border: 1px solid rgba(24, 32, 29, 0.14);
    border-radius: 8px;
    background: #101512;
}

.card-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 54px;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
    color: #dbe8dd;
}

.card-toolbar span {
    overflow: hidden;
    font-family: var(--mono);
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

.toolbar-actions button {
    padding: 0 11px;
    background: #26322c;
    color: #f8f6ef;
}

#hint-btn {
    background: #543f1a;
}

#solve-btn {
    background: #174c42;
}

#code-editor {
    display: block;
    width: 100%;
    min-height: 506px;
    padding: 18px;
    border: 0;
    outline: 0;
    resize: none;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
        #101512;
    background-size: 52px 52px;
    color: #ecf4e8;
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1.62;
    tab-size: 3;
}

.verifier-card {
    display: grid;
    grid-template-rows: auto auto auto 1fr;
    gap: 14px;
    padding: 14px;
    background: #fdfcf7;
}

.verifier-visual {
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f5f1e6;
}

.packet-track {
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 5px;
}

.packet-byte {
    display: grid;
    min-height: 38px;
    place-items: center;
    border: 1px solid #c8d2c5;
    border-radius: 6px;
    background: #ffffff;
    color: var(--muted);
    font-family: var(--mono);
    font-weight: 800;
}

.packet-byte.warn {
    border-color: rgba(182, 61, 44, 0.4);
    background: rgba(182, 61, 44, 0.12);
    color: var(--red);
}

.packet-byte.pass {
    border-color: rgba(22, 115, 91, 0.4);
    background: rgba(22, 115, 91, 0.13);
    color: var(--green-dark);
}

.proof-line {
    display: grid;
    grid-template-columns: 1fr 0.7fr 1.2fr;
    gap: 7px;
    margin-top: 13px;
}

.proof-line span {
    height: 8px;
    border-radius: 999px;
    background: #cad8c7;
}

.proof-line span:nth-child(2) {
    background: #e5b95d;
}

.proof-line span:nth-child(3) {
    background: #82b8a6;
}

.checklist {
    display: grid;
    gap: 8px;
}

.check-row {
    display: grid;
    grid-template-columns: 20px 1fr;
    gap: 9px;
    align-items: start;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.35;
}

.check-row::before {
    content: "";
    width: 16px;
    height: 16px;
    margin-top: 2px;
    border: 2px solid #c4cec0;
    border-radius: 50%;
    background: #ffffff;
}

.check-row.pass::before {
    border-color: var(--green);
    background: radial-gradient(circle at center, var(--green) 0 45%, #ffffff 47%);
}

.check-row.fail::before {
    border-color: var(--red);
    background: linear-gradient(45deg, transparent 43%, var(--red) 45% 55%, transparent 57%),
        linear-gradient(-45deg, transparent 43%, var(--red) 45% 55%, transparent 57%),
        #ffffff;
}

.run-button {
    width: 100%;
    background: var(--green);
    color: #ffffff;
    font-size: 15px;
}

.run-button:hover {
    background: var(--green-dark);
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(22, 115, 91, 0.24);
}

#verifier-output {
    min-height: 210px;
    max-height: 260px;
    margin: 0;
    overflow: auto;
    padding: 14px;
    border-radius: 8px;
    background: #111612;
    color: #dbe8dd;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.kits-section,
.campaign-section {
    margin: 0 clamp(18px, 4vw, 44px) clamp(22px, 4vw, 44px);
    padding: clamp(22px, 4vw, 40px);
    border-radius: 8px;
}

.section-heading {
    display: grid;
    max-width: 880px;
    margin-bottom: 24px;
}

.kit-grid,
.campaign-board {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.kit-card,
.campaign-board article,
.launch-plan > div {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf7;
}

.kit-card {
    display: grid;
    gap: 13px;
    padding: 16px;
}

.kit-card h3,
.campaign-board h3 {
    margin: 0;
    font-size: 20px;
    line-height: 1.15;
}

.kit-card p,
.campaign-board p,
.launch-plan p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.kit-card code {
    display: block;
    overflow: auto;
    padding: 12px;
    border-radius: 8px;
    background: #17201b;
    color: #e5f1e6;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.kit-card button {
    justify-self: start;
    padding: 0 13px;
    border: 1px solid rgba(24, 32, 29, 0.14);
    background: #f1f5ee;
    color: var(--green-dark);
}

.campaign-board article {
    min-height: 190px;
    padding: 18px;
}

.campaign-board h3 {
    margin-bottom: 12px;
}

.launch-plan {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.launch-plan > div {
    display: grid;
    gap: 9px;
    padding: 16px;
}

.step-number {
    color: var(--amber);
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 900;
}

.launch-plan strong {
    font-size: 17px;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 20;
    max-width: min(360px, calc(100vw - 36px));
    padding: 12px 14px;
    border: 1px solid rgba(24, 32, 29, 0.16);
    border-radius: 8px;
    background: #18201d;
    color: #ffffff;
    box-shadow: var(--shadow);
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 1180px) {
    .workspace,
    .editor-layout {
        grid-template-columns: 1fr;
    }

    .mission-rail {
        align-self: stretch;
    }

    .brief-grid,
    .kit-grid,
    .campaign-board {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .launch-plan {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 760px) {
    .topbar {
        position: static;
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .topnav {
        justify-content: center;
        width: 100%;
    }

    .top-actions {
        justify-content: space-between;
    }

    .workspace,
    .kits-section,
    .campaign-section {
        margin: 0;
        padding: 16px;
        border-right: 0;
        border-left: 0;
        border-radius: 0;
    }

    .mission-rail,
    .lab-panel {
        border-radius: 8px;
    }

    .rail-heading h1,
    .section-heading h2 {
        font-size: 40px;
    }

    .lab-header,
    .card-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .lab-meta,
    .toolbar-actions {
        justify-content: flex-start;
    }

    .brief-grid,
    .kit-grid,
    .campaign-board,
    .launch-plan {
        grid-template-columns: 1fr;
    }

    #code-editor {
        min-height: 440px;
    }
}
