/* ---------- Tokens ---------- */
:root {
    color-scheme: light;
    --bg: #f6f8fa;
    --surface: #ffffff;
    --surface-2: #f2f4f7;
    --surface-3: #e8ebef;
    --border: #d9dee4;
    --border-strong: #c3cad3;
    --text: #1f2328;
    --text-muted: #59636e;
    --text-faint: #818b98;
    --accent: #1a7f37;
    --accent-strong: #116329;
    --accent-contrast: #ffffff;
    --accent-soft: #dafbe1;
    --danger: #cf222e;
    --danger-soft: #ffebe9;
    --focus: #0969da;
    --shadow: 0 1px 2px rgb(31 35 40 / 6%), 0 8px 24px rgb(31 35 40 / 6%);
    --stage-light: #ffffff;
    --stage-dark: #0d1117;
    --radius: 10px;
    --radius-sm: 6px;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial,
        sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono',
        monospace;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme='light']) {
        color-scheme: dark;
        --bg: #0b0e13;
        --surface: #11161d;
        --surface-2: #161c24;
        --surface-3: #1e2630;
        --border: #262e38;
        --border-strong: #36404c;
        --text: #e6edf3;
        --text-muted: #9aa5b1;
        --text-faint: #6e7883;
        --accent: #3fb950;
        --accent-strong: #56d364;
        --accent-contrast: #04140a;
        --accent-soft: #12261a;
        --danger: #ff7b72;
        --danger-soft: #2d1416;
        --focus: #58a6ff;
        --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 12px 32px rgb(0 0 0 / 25%);
    }
}

:root[data-theme='dark'] {
    color-scheme: dark;
    --bg: #0b0e13;
    --surface: #11161d;
    --surface-2: #161c24;
    --surface-3: #1e2630;
    --border: #262e38;
    --border-strong: #36404c;
    --text: #e6edf3;
    --text-muted: #9aa5b1;
    --text-faint: #6e7883;
    --accent: #3fb950;
    --accent-strong: #56d364;
    --accent-contrast: #04140a;
    --accent-soft: #12261a;
    --danger: #ff7b72;
    --danger-soft: #2d1416;
    --focus: #58a6ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 12px 32px rgb(0 0 0 / 25%);
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.55 var(--font-sans);
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
}

code,
pre,
.mono {
    font-family: var(--font-mono);
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

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

.skip-link {
    position: absolute;
    left: 16px;
    top: -48px;
    z-index: 10;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.skip-link:focus {
    top: 12px;
}

[hidden] {
    display: none !important;
}

/* ---------- Top bar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 1280px;
    margin: 0 auto;
    padding: 16px 24px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.brand img {
    border-radius: 7px;
}

.brand-sep {
    color: var(--text-faint);
    margin: 0 1px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ghost-link {
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
}

.ghost-link:hover {
    color: var(--text);
    background: var(--surface-2);
}

.icon-button {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    margin-left: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
}

.icon-button .icon-github {
    fill: currentColor;
    stroke: none;
}

a.icon-button {
    text-decoration: none;
}

.icon-button:hover {
    color: var(--text);
    border-color: var(--border-strong);
}

.icon-button svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
}

.icon-moon {
    display: none;
}

:root[data-theme='dark'] .icon-sun {
    display: none;
}

:root[data-theme='dark'] .icon-moon {
    display: block;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme='light']) .icon-sun {
        display: none;
    }
    :root:not([data-theme='light']) .icon-moon {
        display: block;
    }
}

/* ---------- Hero ---------- */
main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px;
}

.hero {
    padding: 40px 0 32px;
    max-width: 760px;
}

.eyebrow {
    margin: 0 0 12px;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.hero h1 {
    margin: 0;
    font-size: clamp(30px, 5vw, 46px);
    line-height: 1.1;
    letter-spacing: -0.03em;
    font-weight: 700;
}

.lede {
    margin: 16px 0 28px;
    max-width: 580px;
    color: var(--text-muted);
    font-size: 17px;
}

.username-form {
    display: flex;
    gap: 10px;
    max-width: 620px;
}

.input-shell {
    flex: 1;
    display: flex;
    align-items: center;
    min-width: 0;
    height: 46px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color 120ms, box-shadow 120ms;
}

.input-shell:focus-within {
    border-color: var(--focus);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent);
}

.input-shell.is-invalid {
    border-color: var(--danger);
}

.input-prefix {
    padding-left: 14px;
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 14px;
    user-select: none;
}

.input-shell input {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0 14px 0 1px;
    border: 0;
    background: transparent;
    color: var(--text);
    font: 500 15px var(--font-mono);
    outline: none;
}

.form-message {
    min-height: 22px;
    margin: 10px 0 0;
    font-size: 14px;
    color: var(--text-muted);
}

.form-message.is-error {
    color: var(--danger);
}

/* ---------- Buttons ---------- */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: 600 14px var(--font-sans);
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 120ms, border-color 120ms;
}

.button:hover:not(:disabled) {
    border-color: var(--border-strong);
    background: var(--surface-2);
}

.button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.button svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.button-primary {
    border-color: transparent;
    background: var(--accent);
    color: var(--accent-contrast);
}

.button-primary:hover:not(:disabled) {
    border-color: transparent;
    background: var(--accent-strong);
}

.username-form .button {
    height: 46px;
    padding: 0 20px;
    border-radius: var(--radius);
    font-size: 15px;
}

.button-quiet {
    background: transparent;
}

.spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

.is-loading .spinner {
    display: inline-block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---------- Workspace ---------- */
.workspace {
    display: grid;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    padding-bottom: 48px;
}

.panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.controls {
    margin: 0;
}

.group {
    margin: 0;
    padding: 16px 18px 18px;
    border: 0;
    border-bottom: 1px solid var(--border);
    min-width: 0;
}

.group-title {
    float: left; /* lets the legend sit inside the fieldset padding */
    width: 100%;
    margin: 0 0 12px;
    padding: 0;
    color: var(--text-faint);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.group-title + * {
    clear: both;
}

.segmented {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 4px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.segmented label,
.canvas-switch label {
    position: relative;
}

.segmented input,
.canvas-switch input {
    position: absolute;
    opacity: 0;
    inset: 0;
    margin: 0;
    cursor: pointer;
}

.segmented span {
    display: block;
    padding: 6px 4px;
    border-radius: 4px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.segmented input:checked + span {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 0 0 1px var(--border);
}

.segmented input:focus-visible + span,
.canvas-switch input:focus-visible + span,
.toggle input:focus-visible + span::before {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

.color-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
}

.color-grid:not(:empty) {
    margin-top: 12px;
}

#color-grid {
    margin-top: 0;
}

.color-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.color-input {
    display: flex;
    align-items: center;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
}

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

.color-input input[type='color'] {
    flex: none;
    width: 30px;
    height: 100%;
    padding: 0;
    border: 0;
    border-right: 1px solid var(--border);
    background: none;
    cursor: pointer;
}

.color-input input[type='color']::-webkit-color-swatch-wrapper {
    padding: 5px;
}

.color-input input[type='color']::-webkit-color-swatch {
    border: 1px solid rgb(0 0 0 / 15%);
    border-radius: 3px;
}

.color-input input[type='color']::-moz-color-swatch {
    border: 1px solid rgb(0 0 0 / 15%);
    border-radius: 3px;
}

.color-input input[type='text'] {
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 0 8px;
    border: 0;
    background: transparent;
    color: var(--text);
    font: 13px var(--font-mono);
    outline: none;
}

.color-input input[aria-invalid='true'] {
    color: var(--danger);
}

.field-label {
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
    font-size: 13px;
}

.field-label output {
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 12px;
}

.field:first-child {
    margin-top: 0;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.field-row .field {
    margin-top: 0;
}

.field input[type='text'],
.field input[type='number'],
.field select {
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: 14px var(--font-sans);
}

.field input[type='number'] {
    font-family: var(--font-mono);
    font-size: 13px;
}

.field input:focus,
.field select:focus {
    border-color: var(--focus);
    outline: none;
}

.hint {
    margin: 8px 0 0;
    color: var(--text-faint);
    font-size: 12.5px;
}

.slider {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 12px;
}

.slider input[type='range'] {
    width: 100%;
    margin: 4px 0 0;
    accent-color: var(--accent);
}

.toggles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
}

.toggle {
    position: relative;
    display: flex;
    align-items: center;
    min-height: 26px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 30px;
    height: 18px;
    margin: 0;
    cursor: pointer;
}

.toggle span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle span::before {
    content: '';
    flex: none;
    width: 30px;
    height: 18px;
    border-radius: 9px;
    background: var(--surface-3);
    box-shadow: inset 0 0 0 1px var(--border-strong);
    transition: background-color 120ms;
}

.toggle span::after {
    content: '';
    position: absolute;
    left: 3px;
    top: 50%;
    width: 12px;
    height: 12px;
    margin-top: -6px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: transform 120ms, background-color 120ms;
}

.toggle input:checked + span {
    color: var(--text);
}

.toggle input:checked + span::before {
    background: var(--accent);
    box-shadow: none;
}

.toggle input:checked + span::after {
    background: #fff;
    transform: translateX(12px);
}

.reset-button {
    width: calc(100% - 36px);
    margin: 14px 18px 16px;
}

/* ---------- Graph type cards ---------- */
.type-cards {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
}

.type-card {
    position: relative;
    display: block;
    cursor: pointer;
}

.type-card input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
}

.type-card-body {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    transition: border-color 120ms, background-color 120ms;
}

.type-card:hover .type-card-body {
    border-color: var(--border-strong);
}

.type-card input:checked + .type-card-body {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.type-card input:focus-visible + .type-card-body {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.type-card-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.type-card-label {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.type-card-desc {
    color: var(--text-muted);
    font-size: 12px;
}

.type-icon {
    flex: none;
    width: 58px;
    height: 28px;
}

.type-icon .type-icon-bar {
    fill: color-mix(in srgb, var(--focus) 75%, var(--surface-3));
}

.type-icon rect {
    fill: var(--surface-3);
}

.type-icon rect.l1 {
    fill: color-mix(in srgb, var(--accent) 30%, var(--surface-3));
}

.type-icon rect.l2 {
    fill: color-mix(in srgb, var(--accent) 55%, var(--surface-3));
}

.type-icon rect.l3 {
    fill: color-mix(in srgb, var(--accent) 80%, var(--surface-3));
}

.type-icon rect.l4 {
    fill: var(--accent);
}

.type-icon-area {
    fill: color-mix(in srgb, var(--accent) 22%, transparent);
}

.type-icon-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2.2;
    stroke-linecap: round;
}

.segmented-3 {
    grid-template-columns: repeat(3, 1fr);
    margin-bottom: 4px;
}

.custom-range {
    margin-top: 10px;
}

.field input[type="date"] {
    height: 34px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: 13px var(--font-mono);
    min-width: 0;
}

/* ---------- Preview tooltip ---------- */
.chart-tooltip {
    position: absolute;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
    font-size: 12.5px;
    white-space: nowrap;
    pointer-events: none;
    transform: translate(-50%, calc(-100% - 12px));
}

.chart-tooltip.is-below {
    transform: translate(-50%, 14px);
}

.chart-tooltip strong {
    font-weight: 600;
}

.chart-tooltip span {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 12px;
    /* keep explicit line breaks between values, never wrap inside one */
    white-space: pre;
}

.chart-band {
    position: absolute;
    z-index: 0;
    background: rgb(255 255 255 / 7%);
    border-radius: 4px;
    pointer-events: none;
}

.stage[data-canvas='light'] .chart-band {
    background: rgb(127 127 127 / 10%);
}

.chart-marker {
    position: absolute;
    z-index: 1;
    width: 12px;
    height: 12px;
    margin: -6px 0 0 -6px;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgb(0 0 0 / 35%);
    pointer-events: none;
}

/* ---------- Output column ---------- */
.output {
    position: sticky;
    top: 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-width: 0;
}

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    min-width: 0;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px 12px 18px;
    border-bottom: 1px solid var(--border);
}

.card-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.badge {
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-3);
    color: var(--text-muted);
    font: 500 11.5px var(--font-mono);
}

.badge.is-live {
    background: var(--accent-soft);
    color: var(--accent);
}

.canvas-switch {
    display: flex;
    padding: 3px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.canvas-switch span {
    display: block;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.canvas-switch input:checked + span {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 0 0 1px var(--border);
}

.stage {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 260px;
    padding: 28px 20px;
    background: var(--stage-light);
    transition: background-color 150ms;
    overflow: hidden;
}

.stage[data-canvas='dark'] {
    background: var(--stage-dark);
}

.preview {
    width: 100%;
    display: grid;
    place-items: center;
    transition: opacity 150ms;
}

.preview svg {
    display: block;
    max-width: 100%;
    height: auto;
}

.stage.is-busy .preview {
    opacity: 0.35;
}

.stage-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
}

.state {
    max-width: 380px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    text-align: center;
    box-shadow: var(--shadow);
}

.state-title {
    margin: 0 0 4px;
    font-weight: 600;
}

.state-message {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

.state.is-error .state-title {
    color: var(--danger);
}

.state .button {
    margin-top: 12px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    margin: 0;
    border-top: 1px solid var(--border);
}

.stats div {
    padding: 12px 18px;
    border-right: 1px solid var(--border);
}

.stats div:last-child {
    border-right: 0;
}

.stats dt {
    color: var(--text-faint);
    font-size: 12px;
}

.stats dd {
    margin: 2px 0 0;
    font: 600 15px var(--font-mono);
}

.tabs {
    display: flex;
    gap: 2px;
    padding: 10px 14px 0;
}

.tabs button {
    padding: 6px 12px;
    border: 0;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: transparent;
    color: var(--text-muted);
    font: 500 13px var(--font-sans);
    cursor: pointer;
    box-shadow: inset 0 -2px 0 transparent;
}

.tabs button:hover {
    color: var(--text);
}

.tabs button[aria-selected='true'] {
    color: var(--text);
    box-shadow: inset 0 -2px 0 var(--accent);
}

.snippet {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 14px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.snippet pre {
    flex: 1;
    min-width: 0;
    margin: 0;
    max-height: 140px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

.snippet code {
    font-size: 12.5px;
    line-height: 1.6;
    color: var(--text);
}

.snippet.is-empty code {
    color: var(--text-faint);
    font-family: var(--font-sans);
}

.copy-button {
    flex: none;
    height: 32px;
    min-width: 72px;
}

.export-card .hint {
    margin: 10px 18px 16px;
}

/* ---------- API section ---------- */
.api {
    padding: 24px 0 48px;
    border-top: 1px solid var(--border);
}

.api h2 {
    margin: 0 0 6px;
    font-size: 20px;
    letter-spacing: -0.01em;
}

.api > p {
    margin: 0 0 18px;
    color: var(--text-muted);
}

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

.api-item {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.api-item p {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 14px;
}

.api-route {
    display: block;
    font-size: 13px;
    color: var(--accent);
    overflow-wrap: anywhere;
}

p code {
    padding: 1px 5px;
    border-radius: 4px;
    background: var(--surface-2);
    font-size: 0.88em;
}

/* ---------- Footer & toast ---------- */
.footer {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px 24px 36px;
    color: var(--text-faint);
    font-size: 13px;
}

.footer p {
    margin: 0;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--bg);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow);
    z-index: 20;
}

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

    /* Preview first on narrow screens, controls after it. */
    .output {
        position: static;
        order: -1;
    }

    .group {
        padding: 16px;
    }

    .panel .controls {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .panel .group:nth-child(odd) {
        border-right: 1px solid var(--border);
    }

    .reset-button {
        grid-column: 1 / -1;
        width: auto;
        margin: 14px 16px 16px;
    }
}

@media (max-width: 640px) {
    .topbar,
    main,
    .footer {
        padding-left: 16px;
        padding-right: 16px;
    }

    .ghost-link {
        display: none;
    }

    .hero {
        padding: 20px 0 20px;
    }

    .lede {
        font-size: 16px;
    }

    .username-form {
        flex-direction: column;
    }

    .input-shell {
        flex: none;
    }

    .username-form .button {
        width: 100%;
    }

    .panel .controls {
        display: block;
    }

    .panel .group:nth-child(odd) {
        border-right: 0;
    }

    .reset-button {
        width: calc(100% - 32px);
    }

    .stage {
        min-height: 180px;
        padding: 16px 12px;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats div:nth-child(2) {
        border-right: 0;
    }

    .stats div:nth-child(-n + 2) {
        border-bottom: 1px solid var(--border);
    }

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

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

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