:root {
    color-scheme: dark;
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: #e8edf7;
    background: #161618;
    --bg: #161618;
    --panel: #1b1b1f;
    --panel-raised: #202127;
    --line: rgba(255, 255, 255, 0.085);
    --line-strong: rgba(255, 255, 255, 0.14);
    --muted: #8993a5;
    --text: #e8edf7;
    --brand: #2ad6bf;
    --brand-strong: #00bfa6;
    --danger: #ff7a8b;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input { font: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.9em; }

.app-shell {
    min-height: 100vh;
    background:
        radial-gradient(circle at 68% -10%, rgba(102, 126, 234, 0.13), transparent 32rem),
        radial-gradient(circle at 5% 25%, rgba(0, 191, 166, 0.07), transparent 25rem),
        var(--bg);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(22, 22, 24, 0.85);
    backdrop-filter: blur(12px);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand strong { color: var(--brand); font-weight: 700; }
.topbar-links { display: flex; gap: 20px; font-size: 0.92rem; }
.topbar-links a { color: var(--muted); }
.topbar-links a:hover { color: var(--text); text-decoration: none; }

.content { max-width: 1320px; margin: 0 auto; padding: 32px 24px 64px; }

.intro h1 { margin: 0 0 8px; font-size: clamp(1.6rem, 3vw, 2.2rem); letter-spacing: -0.02em; }
.intro p { margin: 0; max-width: 680px; color: var(--muted); line-height: 1.6; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 28px 0 12px; }
.tab {
    padding: 8px 16px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.tab:hover { color: var(--text); border-color: var(--brand-strong); }
.tab.is-active { background: rgba(0, 191, 166, 0.14); border-color: var(--brand-strong); color: var(--brand); }

.summary { margin: 0 0 16px; color: var(--muted); }

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
}

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

.panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-raised);
    color: var(--muted);
    font-size: 0.88rem;
}

.file-name { font-family: var(--mono); color: var(--text); }

.code {
    margin: 0;
    padding: 14px 0;
    max-height: 70vh;
    overflow: auto;
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.6;
    color: #d4dae6;
}
.code code { font-size: inherit; }
.code-line { display: block; padding-right: 16px; white-space: pre; }
.line-number {
    display: inline-block;
    width: 3.2em;
    padding-right: 1.2em;
    text-align: right;
    color: #4d5566;
    user-select: none;
}

.run-button {
    padding: 6px 14px;
    border: 0;
    border-radius: 8px;
    background: var(--brand-strong);
    color: #06201c;
    font-weight: 600;
    cursor: pointer;
}
.run-button:hover:not(:disabled) { background: var(--brand); }
.run-button:disabled { opacity: 0.6; cursor: progress; }

.output { display: flex; flex-direction: column; gap: 10px; min-height: 240px; max-height: 70vh; padding: 14px; overflow: auto; }
.log-entry { padding-left: 12px; border-left: 2px solid var(--brand-strong); }
.log-message { font-size: 0.9rem; }
.log-entry pre {
    margin: 6px 0 0;
    padding: 8px 10px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.25);
    font-family: var(--mono);
    font-size: 0.78rem;
    white-space: pre-wrap;
    word-break: break-word;
    color: #c3cad8;
}
.muted { margin: 0; color: var(--muted); }
.error { margin: 0; color: var(--danger); }

.preview { padding: 18px; }

.demo-form { display: flex; gap: 8px; }
.demo-form input {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
}
.demo-form input:focus { outline: 2px solid var(--brand-strong); outline-offset: -1px; }
.demo-form button {
    padding: 9px 16px;
    border: 0;
    border-radius: 8px;
    background: var(--brand-strong);
    color: #06201c;
    font-weight: 600;
    cursor: pointer;
}

.demo-list { margin: 16px 0 0; padding: 0; list-style: none; }
.demo-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--line);
}
.demo-list label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.demo-list input[type='checkbox'] { accent-color: var(--brand-strong); width: 16px; height: 16px; }
.demo-list li.is-done span { color: var(--muted); text-decoration: line-through; }
.demo-list small { display: block; margin-top: 2px; color: var(--muted); font-size: 0.75rem; }
.demo-list button {
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.demo-list button:hover { color: var(--danger); }
.demo-footer { margin: 14px 0 0; color: var(--muted); font-size: 0.88rem; }
.link-button { padding: 0; border: 0; background: none; color: var(--brand); cursor: pointer; }

/* Wide examples: preview on top, code below */
.workspace.is-wide { grid-template-columns: minmax(0, 1fr); }
.workspace.is-wide > .panel:last-child { order: -1; }
.workspace.is-wide .code { max-height: 60vh; }

/* Live data grid */
.grid-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.grid-toolbar input[type='search'],
.grid-demo select {
    padding: 8px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
}
.grid-toolbar input[type='search'] { flex: 1 1 220px; min-width: 0; }
.grid-toolbar input:focus, .grid-demo select:focus { outline: 2px solid var(--brand-strong); outline-offset: -1px; }
.grid-toolbar button {
    padding: 8px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}
.grid-toolbar button:hover { border-color: var(--brand-strong); }
.grid-toolbar .toggle.is-on { background: rgba(0, 191, 166, 0.16); border-color: var(--brand-strong); color: var(--brand); }

/* position: relative keeps the absolutely positioned hidden header label inside the scroller. */
.grid-scroll { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.grid { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.grid th { padding: 0; background: var(--panel-raised); border-bottom: 1px solid var(--line-strong); text-align: left; white-space: nowrap; }
.grid th button {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
}
.grid th.numeric button { justify-content: flex-end; }
.grid th button:hover { color: var(--text); }
.grid th[aria-sort='ascending'] button,
.grid th[aria-sort='descending'] button { color: var(--brand); }
.grid th button:focus-visible { outline: 2px solid var(--brand-strong); outline-offset: -2px; }
.sort-indicator { display: inline-block; width: 0.9em; font-size: 0.7em; }
.grid td { padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: rgba(255, 255, 255, 0.025); }
.grid .numeric { text-align: right; }
.grid tr.is-changed td { animation: row-flash 1s ease-out; }
@keyframes row-flash {
    from { background: rgba(0, 191, 166, 0.3); }
    to { background: transparent; }
}
.grid-empty { padding: 28px !important; text-align: center !important; color: var(--muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: rgba(102, 126, 234, 0.14); color: #aab8ff; font-size: 0.76rem; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper > span { min-width: 2ch; text-align: right; }
.stepper button, .row-delete {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    line-height: 1;
    cursor: pointer;
}
.stepper button:hover { border-color: var(--brand-strong); color: var(--text); }
.row-delete { border-color: transparent; }
.row-delete:hover { color: var(--danger); }
.low-stock { color: #ffc66b; font-weight: 600; }
.muted-cell { color: var(--muted); }

.grid-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; color: var(--muted); font-size: 0.86rem; }
.live-dot { margin-left: 12px; color: var(--brand); }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pager button {
    min-width: 30px;
    height: 30px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}
.pager button:hover:not(:disabled) { border-color: var(--brand-strong); }
.pager button:disabled { opacity: 0.35; cursor: default; }
.page-label { padding: 0 6px; color: var(--text); }

.activity {
    margin: 12px 0 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.25);
    list-style: none;
    font-family: var(--mono);
    font-size: 0.76rem;
    color: #c3cad8;
}
.activity li + li { margin-top: 4px; opacity: 0.7; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.local {
    margin-top: 40px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
}
.local h2 { margin: 0 0 8px; font-size: 1.2rem; }
.local p { color: var(--muted); line-height: 1.6; }
.local .code { padding: 14px 16px; border-radius: 8px; background: rgba(0, 0, 0, 0.25); white-space: pre; }
