:root {
    --color-text: #1d1d1f;
    --color-muted: #6b6b70;
    --color-border: #e2e2e7;
    --color-surface: #f6f6f8;
    --color-accent: #f6821f;
    --color-accent-dark: #c25a00;
    --color-ok: #2e7d4f;
    --connector: #d3d3da;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    color: var(--color-text);
    line-height: 1.5;
    width: 92%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 20px 72px;
    background: #fff;
}

a {
    color: var(--color-accent-dark);
}

/* ---------- Header ---------- */

header {
    margin-bottom: 24px;
}

header h1 {
    margin: 0 0 8px;
    font-size: 1.8rem;
    letter-spacing: -0.01em;
}

.intro {
    margin: 0;
    color: var(--color-muted);
    max-width: 80ch;
    font-size: 0.95rem;
}

/* ---------- Two-pane workspace ---------- */

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    gap: 24px;
    align-items: start;
}

.flow {
    min-width: 0;
}

.outputs {
    min-width: 0;
    position: sticky;
    top: 16px;
    align-self: start;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}

@media (max-width: 900px) {
    .workspace {
        grid-template-columns: minmax(0, 1fr);
    }

    .outputs {
        position: static;
        max-height: none;
        overflow: visible;
    }
}

/* ---------- Step cards (left) ---------- */

.card {
    position: relative;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    background: #fff;
    transition: opacity 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.card[data-level="1"] { margin-left: 20px; }
.card[data-level="2"] { margin-left: 40px; }
.card[data-level="3"] { margin-left: 60px; }

@media (max-width: 768px) {
    .card[data-level="1"] { margin-left: 12px; }
    .card[data-level="2"] { margin-left: 24px; }
    .card[data-level="3"] { margin-left: 36px; }
}

.card.ready {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 1px var(--color-accent);
}

/* ---------- Branching lines (only when a parent step is expanded) ---------- */

/* vertical rail down the gutter to the left of the unlocked children */
.show-connector::before {
    content: "";
    position: absolute;
    left: -14px;
    top: -12px;
    bottom: -12px;
    border-left: 2px solid var(--color-accent);
}

/* the rail stops at the last child's tick instead of running past it */
.show-connector.connector-last::before {
    bottom: calc(100% - 24px);
}

/* horizontal tick from the rail into each child's header */
.show-connector::after {
    content: "";
    position: absolute;
    left: -14px;
    top: 24px;
    width: 14px;
    border-top: 2px solid var(--color-accent);
}

/* ---------- Card head ---------- */

.card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 15px;
    cursor: pointer;
    user-select: none;
}

.card-headings {
    flex: 1 1 auto;
    min-width: 0;
}

.card-title {
    margin: 0;
    font-size: 1.02rem;
    overflow-wrap: anywhere;
}

.card-tagline {
    display: block;
    margin-top: 1px;
    color: var(--color-muted);
    font-size: 0.83rem;
    overflow-wrap: anywhere;
}

.state-dot {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--connector);
    background: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
    color: #fff;
}

.card.ready .state-dot {
    border-color: var(--color-accent);
    background: var(--color-accent);
}

.card.done .state-dot {
    border-color: var(--color-ok);
    background: var(--color-ok);
}

.card.done .state-dot::after {
    content: "✓";
}

.collapse-toggle {
    flex: 0 0 auto;
    color: var(--color-muted);
}

.collapse-toggle::before {
    content: "▾";
}

.card.collapsed .collapse-toggle {
    display: inline-block;
    transform: rotate(-90deg);
}

.card-body {
    padding: 0 15px 15px;
}

.card.collapsed .card-body {
    display: none;
}

/* ---------- Help disclosure ---------- */

.help {
    margin-bottom: 12px;
}

.help summary {
    cursor: pointer;
    color: var(--color-accent-dark);
    font-size: 0.84rem;
    width: fit-content;
}

.help p {
    margin: 8px 0 0;
    color: var(--color-muted);
    font-size: 0.9rem;
    max-width: 72ch;
}

/* ---------- Forms ---------- */

form {
    margin: 0;
}

label,
.field-group-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
    margin: 12px 0 4px;
}

.field-group-label {
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.72rem;
    margin-top: 14px;
}

input,
select {
    font-size: 0.92rem;
    padding: 8px 10px;
    margin: 0 6px 4px 0;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: #fff;
    font-family: inherit;
    min-width: 0;
}

/* keep the Turnstile widget inside its card on narrow screens */
.cf-turnstile {
    max-width: 100%;
    overflow-x: auto;
    margin: 4px 0;
}

input {
    width: 100%;
    max-width: 34em;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(246, 130, 31, 0.2);
}

.form-actions {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 4px;
}

button {
    font-size: 0.9rem;
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    background: var(--color-accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

button:hover {
    background: var(--color-accent-dark);
}

.view-result {
    display: none;
    background: transparent;
    color: var(--color-accent-dark);
    padding: 8px 8px;
}

.view-result:hover {
    background: var(--color-surface);
}

.card.done .view-result {
    display: inline-block;
}

/* ---------- Branch cue ---------- */

.branch-cue {
    margin: 14px 0 0;
    padding-top: 12px;
    border-top: 1px dashed var(--color-border);
    color: var(--color-muted);
    font-size: 0.82rem;
}

.branch-cue::before {
    content: "↳ ";
    color: var(--color-accent);
    font-weight: 700;
}

/* ---------- Output pane (right) ---------- */

.outputs-placeholder {
    color: var(--color-muted);
    font-size: 0.9rem;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    margin: 0;
}

.outputs-placeholder.hidden {
    display: none;
}

.out-panel {
    display: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    background: #fff;
}

.out-panel.shown {
    display: block;
}

.out-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 14px;
    cursor: pointer;
    user-select: none;
}

.out-title {
    font-weight: 600;
    font-size: 0.92rem;
}

.out-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

.out-toggle {
    color: var(--color-muted);
}

.out-toggle::before {
    content: "▾";
}

.out-panel:not(.expanded) .out-toggle {
    display: inline-block;
    transform: rotate(-90deg);
}

.out-body {
    display: none;
    padding: 0 14px 14px;
}

.out-panel.expanded .out-body {
    display: block;
}

.copy-btn {
    padding: 3px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.copy-btn:hover {
    background: #ececf0;
}

/* ---------- Output code ---------- */

code {
    display: block;
    background-color: var(--color-surface);
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-family: 'SF Mono', 'Courier New', monospace;
    font-size: 12.5px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.out-body code {
    max-height: 52vh;
    overflow: auto;
    margin: 0;
}

code.inline {
    display: inline;
    padding: 1px 5px;
    font-size: 0.85em;
    border: none;
    background-color: #ececf0;
    border-radius: 4px;
}

.display:empty {
    display: none;
}

/* ---------- Flash highlight (linking left <-> right) ---------- */

@keyframes flash {
    0% { box-shadow: 0 0 0 3px rgba(246, 130, 31, 0.55); }
    100% { box-shadow: 0 0 0 3px rgba(246, 130, 31, 0); }
}

.flash {
    animation: flash 1s ease-out;
}

/* ---------- Footer ---------- */

footer {
    margin-top: 44px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
    color: var(--color-muted);
    font-size: 0.85rem;
}
