:root {
    color-scheme: light;
    --bg: #f5f6f4;
    --ink: #1f252b;
    --muted: #687480;
    --line: #ccd3d1;
    --panel: #fff;
    --accent: #116466;
    --accent-strong: #0b3f40;
    --source: #fbfcfb;
    --input-panel: #f3f8f6;
    --terminal: #11161a;
    --terminal-line: #d7e3dd;
    --terminal-input: #9fd3c7;
    --terminal-error: #ffb4a8;
}

/* Reset and base */
* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Page layout */
.shell {
    width: min(1280px, calc(100vw - 40px));
    margin: 0 auto;
    padding: 30px 0;
}

header {
    display: grid;
    gap: 16px;
    margin-bottom: 30px;
}

h1,
h2 {
    margin: 0 0 6px;
    line-height: 1.05;
    letter-spacing: 0;
}

h1 {
    font-size: 34px;
}

h2 {
    font-size: 25px;
}

p {
    margin: 0;
    max-width: 680px;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.5;
}

p a {
    color: var(--accent-strong);
    font-weight: 650;
}

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

/* Buttons and controls */
button {
    height: 38px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 0 14px;
    background: var(--accent);
    color: white;
    font: inherit;
    font-weight: 650;
    cursor: pointer;
}

button.secondary {
    background: transparent;
    color: var(--accent-strong);
}

button:disabled,
input:disabled {
    cursor: not-allowed;
    opacity: 0.52;
}

/* Example sections and their workspace grids */
.example {
    scroll-margin-top: 24px;
}

.example + .example {
    margin-top: 42px;
}

.example-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 14px;
}

.workspace {
    display: grid;
    min-height: 460px;
    border: 1px solid var(--line);
    background: var(--panel);
}

.workspace-batch {
    grid-template-columns: minmax(0, 1.12fr) minmax(240px, 0.62fr) minmax(300px, 0.76fr);
}

.workspace-interactive {
    grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
}

.workspace-lsystem {
    grid-template-columns: minmax(420px, 1.1fr) minmax(170px, 0.55fr) minmax(320px, 1fr);
}

.workspace-ca {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 1fr);
}

.workspace-shape {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 1fr);
}

/* L-system: generations list */
.strings {
    flex: 1;
    overflow: auto;
    padding: 12px 14px;
    background: var(--source);
    font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.strings-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 8px;
    padding: 6px 0;
    border-top: 1px dashed var(--line);
    word-break: break-all;
}

.strings-row:first-child {
    border-top: 0;
    padding-top: 0;
}

.strings-row .gen {
    color: var(--muted);
    font-weight: 700;
}

.strings-row .gen .len {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.strings-row .body {
    color: var(--ink);
}

/* Canvas panes (L-system, cellular automata) */
.canvas-pane {
    background: #11161a;
}

.canvas-pane .pane-header {
    border-bottom-color: #2a3439;
    color: #a8b4b0;
}

.canvas-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    min-height: 0;
}

.canvas-pane canvas {
    max-width: 100%;
    max-height: 100%;
    background: #0a0e11;
    border: 1px solid #2a3439;
    border-radius: 4px;
}

/* Preset picker (L-system, cellular automata) */
.picker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--accent-strong);
    font-weight: 650;
}

.picker select {
    height: 38px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 0 10px;
    background: var(--panel);
    color: var(--ink);
    font: inherit;
}

/* Shape grammar: 3-D scene */
.scene-pane .pane-header {
    justify-content: space-between;
}

.scene-pane .hint {
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.02em;
    text-transform: none;
}

#shape-grammar-canvas {
    display: block;
    flex: 1;
    width: 100%;
    min-height: 460px;
    background: #eef2ee;
    touch-action: none;
    cursor: grab;
}

#shape-grammar-canvas:active {
    cursor: grabbing;
}

p code {
    padding: 1px 5px;
    border-radius: 4px;
    background: #e6ece6;
    color: var(--accent-strong);
    font: 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* Panes and the source/output editors they hold */
.pane {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

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

.input-pane textarea {
    background: var(--input-panel);
}

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 44px;
    padding: 0 14px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.status {
    color: var(--accent-strong);
    text-transform: none;
}

textarea,
pre {
    flex: 1;
    width: 100%;
    margin: 0;
    border: 0;
    padding: 18px;
    color: #15191f;
    background: var(--source);
    font: 13px/1.48 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    tab-size: 8;
}

textarea {
    resize: none;
    outline: none;
}

pre {
    overflow: auto;
    white-space: pre-wrap;
}

/* Interactive I/O: terminal transcript and input prompt */
.conversation-pane {
    background: var(--terminal);
}

.conversation-pane .pane-header {
    border-bottom-color: #2a3439;
    color: #a8b4b0;
}

.conversation-pane .status {
    color: #9fd3c7;
}

.terminal {
    flex: 1;
    overflow: auto;
    padding: 18px;
    color: var(--terminal-line);
    font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    white-space: pre-wrap;
}

.terminal-line {
    min-height: 1.55em;
}

.terminal-line.input {
    color: var(--terminal-input);
}

.terminal-line.error {
    color: var(--terminal-error);
}

.prompt {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 10px;
    min-height: 58px;
    padding: 10px 12px;
    border-top: 1px solid #2a3439;
    color: var(--terminal-input);
    font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.prompt input {
    min-width: 0;
    height: 36px;
    border: 1px solid #425258;
    border-radius: 6px;
    padding: 0 10px;
    color: var(--terminal-line);
    background: #182126;
    font: inherit;
    outline: none;
}

.prompt input:focus {
    border-color: var(--terminal-input);
}

.prompt button {
    height: 36px;
}

.prompt button.secondary {
    border-color: #52646c;
    color: var(--terminal-line);
}

/* Narrow screens: stack panes vertically */
@media (max-width: 860px) {
    .shell {
        width: min(100vw - 24px, 720px);
        padding: 20px 0;
    }

    .actions {
        align-items: stretch;
        flex-direction: column;
    }

    .example-header {
        align-items: stretch;
        flex-direction: column;
    }

    h1 {
        font-size: 29px;
    }

    h2 {
        font-size: 23px;
    }

    .workspace {
        grid-template-columns: 1fr;
        min-height: 0;
    }

    .workspace-batch,
    .workspace-interactive,
    .workspace-lsystem,
    .workspace-ca,
    .workspace-shape {
        grid-template-columns: 1fr;
    }

    .pane {
        min-height: 240px;
    }

    .input-pane {
        min-height: 150px;
    }

    .conversation-pane {
        min-height: 280px;
    }

    .pane + .pane {
        border-top: 1px solid var(--line);
        border-left: 0;
    }

    .prompt {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .prompt button {
        grid-column: span 1;
    }
}
