:root {
    --canvas: #f1f4f8;
    --background: #f7f9fc;
    --surface: #fff;
    --ink: #17243a;
    --muted: #52657d;
    --line: #d6e0eb;
    --navy: #172338;
    --accent: #234d84;
    --selection: #eaf2fc;
    --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
    --workspace-inset: clamp(12px, 1.75vw, 24px);
    --panel-gap: clamp(10px, 1.3vw, 18px);
    --detail-inset: clamp(16px, 2vw, 28px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    overflow: hidden;
    color: var(--ink);
    background: var(--canvas);
    font: 15px/1.5 system-ui, sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid #457bc3; outline-offset: 2px; }
code { font-family: var(--mono); }

.topbar {
    position: relative;
    display: grid;
    flex: none;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 4px 12px;
    min-height: 60px;
    padding-block: 8px;
    padding-inline: var(--workspace-inset);
    border-bottom: 1px solid #36506c;
    background: linear-gradient(105deg, #213952, #0d1c30 65%);
    color: white;
}
.topbar-leading { display: flex; align-items: center; gap: clamp(8px, 1.3vw, 16px); min-width: 0; }
.brand { flex: none; color: inherit; text-decoration: none; font-size: 26px; font-weight: 700; letter-spacing: -.04em; white-space: nowrap; }
.workspace-search { display: flex; flex: 1; justify-content: center; min-width: 0; }
.workspace-search-field { width: min(100%, 420px); }
.workspace-search input {
    width: 100%;
    min-width: 0;
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
}
.workspace-search-toggle {
    display: none;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid #59667c;
    border-radius: 6px;
    background: transparent;
}
.workspace-search-toggle:hover, .workspace-search-toggle[aria-expanded="true"] { background: #2b3c55; }
.search-icon { position: relative; width: 11px; height: 11px; border: 1.5px solid currentColor; border-radius: 50%; }
.search-icon::after { position: absolute; inset: 8px auto auto 8px; width: 5px; height: 1.5px; border-radius: 1px; background: currentColor; transform: rotate(45deg); transform-origin: left center; content: ''; }
body.offline .workspace-search { display: none; }
.topbar nav { display: flex; justify-self: center; gap: 3px; padding: 3px; border: 1px solid #405770; border-radius: 10px; background: #0d1c30; }
.topbar #server-controls { justify-self: end; }
.topbar-link { display: inline-flex; align-items: center; justify-content: center; min-height: 34px; padding: 4px 12px; border: 1px solid transparent; border-radius: 7px; color: #e3edf9; font-size: 13px; font-weight: 620; text-decoration: none; white-space: nowrap; }
.topbar-link:hover { background: #253b54; }
.topbar-link[aria-current="page"] { border-color: #8bb4e1; background: #e7f1ff; color: #17477f; }
body.interpreter-focus:not(.offline) .topbar { display: none; }
.python-workspace { display: flex; flex: 1; min-width: 0; min-height: 0; }
.python-workspace iframe { min-width: 0; width: 100%; border: 0; }
.workspace {
    --workspace-sidebar: clamp(244px, 18vw, 252px);
    display: grid;
    flex: 1;
    min-width: 0;
    min-height: 0;
    grid-template-columns: var(--workspace-sidebar) minmax(0, 1fr);
    gap: var(--panel-gap);
    padding: var(--workspace-inset);
}
body[data-workspace="reference"] #syntax-workspace { --workspace-sidebar: clamp(258px, 21vw, 320px); }
#syntax-workspace.reference-sidebar-collapsed { grid-template-columns: minmax(0, 1fr); }
.sidebar, .detail {
    min-width: 0;
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface);
}
.sidebar {
    display: flex;
    flex-direction: column;
    padding: 15px 10px;
    overflow: auto;
}
.sidebar h1 { margin: 0 0 12px; font-size: 20px; font-weight: 680; }
.collections {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3px;
    padding: 3px;
    border-radius: 7px;
    background: #edf1f6;
}
.collections button { min-height: 36px; padding: 4px 3px; border: 1px solid transparent; border-radius: 5px; background: transparent; color: var(--muted); font-size: clamp(12px, 1vw, 13px); font-weight: 620; }
.collections button[aria-pressed="true"] { border-color: var(--line); background: var(--surface); color: var(--accent); }
.collection-summary { margin: 12px 0 4px; color: var(--muted); font-size: 12px; }
#catalog-status { margin-block: 0 4px; }
#library-sidebar:has(.reference-tools:not([hidden])) { overflow: visible; }
.reference-tools { display: grid; gap: 8px; margin-bottom: 7px; }
.reference-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; align-items: center; }
.reference-hide {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 34px;
    padding: 4px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
}
.reference-hide:hover { background: var(--selection); color: var(--accent); }
.sidebar-icon { width: 13px; height: 12px; border: 1px solid currentColor; border-radius: 2px; display: inline-flex; flex: none; }
.sidebar-icon::before { content: ''; display: block; width: 4px; border-inline-end: 1px solid currentColor; }
.reference-show { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
#empty-detail .reference-show { align-self: end; margin-bottom: 8px; }
.reference-tools [role="status"] { margin: 0; }
.reference-tools [role="status"]:empty { display: none; }
.reference-pages, .reference-branch-pages { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 6px; }
.reference-pages button:disabled, .reference-branch-pages button:disabled { opacity: .45; cursor: default; }
.reference-page-jump { display: flex; align-items: center; min-width: 0; gap: 5px; }
.reference-page-jump input {
    width: 3.65em;
    min-height: 34px;
    padding: 4px 5px;
    appearance: textfield;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-variant-numeric: tabular-nums;
    text-align: center;
}
.reference-page-jump input::-webkit-inner-spin-button { appearance: none; }
.reference-page-jump span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.reference-page-step { min-width: 32px; padding-inline: 6px; font-size: 18px; }
.reference-page-jump .action-button { padding-inline: 7px; }
.reference-branch-button {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
    min-height: 36px;
    padding: 5px 6px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    text-align: start;
    font-size: 13px;
    font-weight: 650;
}
.reference-branch-button:hover { background: var(--selection); }
.reference-branch-arrow { color: var(--muted); }
.reference-branch-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.reference-branch-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 0 0 0 10px; margin: 0; list-style: none; }
.reference-branch-pages { padding-inline: 6px; }
#record-navigation, .workspace-list { flex: 1; min-height: 42px; overflow-y: auto; }
.record-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px; margin: 0; padding: 3px; list-style: none; }
.entry {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    min-height: 42px;
    gap: 2px;
    padding: 8px 5px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: inherit;
    text-align: start;
    text-decoration: none;
}
.entry:hover { background: #edf1f6; }
.entry[aria-current="true"] { border-color: #bed1e9; background: var(--selection); color: var(--accent); }
.entry-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; font-weight: 650; }
.entry span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.entry .entry-name { overflow: hidden; overflow-wrap: normal; text-overflow: ellipsis; }

.detail { display: flex; flex-direction: column; overflow: hidden; }
.entry-header {
    display: flex;
    flex: none;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 18px;
    padding: 13px var(--detail-inset);
    border-bottom: 1px solid var(--line);
}
.entry-header h2 { min-width: 0; margin: 0; font-size: clamp(23px, 3vw, 29px); font-weight: 650; letter-spacing: -.025em; overflow-wrap: anywhere; }
.entry-header h2:focus { outline: none; }
.entry-title { min-width: 0; }
.entry-source { margin: 0 0 2px; color: var(--muted); font-size: 13px; }
.pager { display: flex; flex: none; gap: 4px; align-items: center; }
.page-arrow, .page-choice { display: inline-flex; align-items: center; justify-content: center; height: 40px; gap: 7px; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--muted); font-size: 13px; white-space: nowrap; }
.page-arrow { width: 38px; padding: 0 0 3px; font-size: 26px; line-height: 1; }
.page-choice { padding: 0 8px; }
.page-choice[aria-current] { background: var(--selection); color: var(--accent); font-weight: 650; }
.page-arrow:disabled { opacity: .35; cursor: default; }
.page-arrow:hover:not(:disabled), .page-choice:hover { background: var(--selection); }
.dot { width: 8px; height: 8px; border: 1.5px solid #6c83a1; border-radius: 50%; background: var(--surface); }
.page-choice[aria-current] .dot { border-color: var(--accent); background: var(--accent); }

.page { flex: 1; min-width: 0; min-height: 0; overflow: auto; }
.page[data-direction="forward"] { animation: enter-right .16s ease-out; }
.page[data-direction="backward"] { animation: enter-left .16s ease-out; }
@keyframes enter-right { from { transform: translateX(10px); opacity: .6; } }
@keyframes enter-left { from { transform: translateX(-10px); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .page[data-direction] { animation: none; } }

.overview-page, .empty-detail { padding: 20px var(--detail-inset); }
.overview-section + .overview-section { margin-top: 18px; }
.overview-page h3, .example-page h3 { margin: 0 0 8px; font-size: 15px; font-weight: 670; }
.definition-copy { margin: 0; line-height: 1.65; white-space: pre-line; overflow-wrap: anywhere; }
.syntax-signature { display: inline-block; max-width: 100%; margin: 0; padding: 7px 10px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--background); color: var(--accent); font-family: var(--mono); white-space: pre-wrap; }
.components { margin: 0; border: 1px solid var(--line); border-radius: 8px; }
.components > div { display: grid; grid-template-columns: minmax(90px, 16%) minmax(0, 1fr); align-items: baseline; gap: 14px; padding: 10px 13px; }
.components > div + div { border-top: 1px solid var(--line); }
.components dt code { color: var(--accent); font-size: 14px; font-weight: 650; overflow-wrap: anywhere; }
.components dd { margin: 0; color: #394f69; }
.overview-page .syntax-table { margin: 0; }
.overview-page .syntax-table thead th:first-child { width: clamp(104px, 18%, 220px); }
.reference-links { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.reference-links li { min-width: 0; max-width: 100%; }
.reference-link, .action-button { min-height: 36px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--accent); text-align: start; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.reference-link { display: inline-flex; align-items: center; text-decoration: none; }
.reference-link:hover, .action-button:hover { background: var(--selection); }
.empty-detail h2 { margin: 0; font-size: 21px; }
.empty-detail p, .muted { color: var(--muted); }
.empty-detail { overflow: auto; }

.example-page { display: flex; flex-direction: column; padding: 12px var(--detail-inset); }
.example-page > * + * { margin-block-start: 14px; }
.catalog-example { padding-block: 8px; }
.catalog-example > .lesson-code + p, .catalog-example > .overview-section, .catalog-example > a { margin-top: 12px; }
.catalog-example .lesson-code { overflow-wrap: normal; }
.reference-example-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.example-actions { display:inline-flex; align-items:center; gap:6px; flex-wrap:nowrap; }
.example-actions > button { white-space:nowrap; }
.example-actions svg { display:none; }
@media (pointer:coarse) { .example-actions > button { min-height:44px; } }
.reference-example-heading h3 { margin: 0; }
.reference-worked-example {
    flex: none;
    padding: 12px clamp(12px, 1.5vw, 20px);
    border: 1px solid var(--line);
    border-inline-start: 3px solid var(--accent);
    border-radius: 8px;
    background: var(--background);
}
.reference-worked-example + .overview-section { margin-block-start: 18px; }
.reference-example-takeaway {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 680;
    overflow-wrap: anywhere;
}
.reference-example-detail { color: var(--muted); }
.reference-example-takeaway code, .reference-example-detail code { color: var(--accent); font-size: .95em; }
.reference-worked-example > .lesson-code { margin-block-start: 12px; }
.reference-example-output { margin-block-start: 12px; }
.reference-example-output h4 { margin: 0 0 6px; font-size: 13px; font-weight: 670; }
.reference-example-status { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.written-walkthrough { padding: 8px 0; }
.written-walkthrough summary { color: var(--accent); cursor: pointer; font-weight: 600; }
.written-walkthrough p { margin-block-start: 8px; white-space: pre-wrap; }
.lesson-code {
    grid-column: 1 / -1;
    margin: 0;
    padding: 12px 14px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--background);
    color: var(--ink);
    font: 13px/1.55 var(--mono);
    tab-size: 4;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.coverage-panel { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.coverage-panel h3 { margin: 0; }
.coverage-list { grid-column: 1 / -1; margin: 0; padding: 0; border-top: 1px solid var(--line); list-style: none; }
.coverage-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 2px 0; border-bottom: 1px solid var(--line); }
.coverage-list .reference-link { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; width: fit-content; max-width: 100%; padding-inline: 4px; border-color: transparent; }
.coverage-name { color: var(--ink); }
.coverage-label { padding-inline-end: 4px; color: var(--muted); font-size: 12px; }
.coverage-form { margin: 18px 0 0; }
.coverage-form fieldset { display: grid; min-width: 0; gap: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; }
.coverage-form legend { padding-inline: 4px; font-weight: 650; }
.coverage-form p { margin: 0; font-size: 13px; }
.coverage-option { display: flex; align-items: center; min-height: 34px; gap: 8px; cursor: pointer; }
.coverage-option code { overflow-wrap: anywhere; }
.coverage-option input { min-width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.primary-action { border-color: var(--accent); background: var(--accent); color: white; }
.primary-action:hover { background: var(--navy); }
.outside-list { margin: 0; padding-inline-start: 20px; color: var(--muted); font-size: 13px; }
.outside-list .reference-link { min-height: 32px; margin-block: 3px; }
#practice-entry { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.practice-entry-tools, .practice-entry-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.practice-entry-tools { flex: none; justify-content: space-between; padding: 6px var(--detail-inset); border-bottom: 1px solid var(--line); }
#language-content:has(> .practice-entry-tools) { padding: 0; }
.practice-statement { white-space: pre-wrap; }
.practice-notes { margin-block: 16px; }
.practice-notes summary { color: var(--accent); font-weight: 650; cursor: pointer; }
.practice-related .practice-source { background: #edf6ee; border-left: 3px solid #487957; }
.practice-source { overflow-wrap: normal; }
.practice-source :is(.python-keyword, .python-function) { font-weight: 650; }
.practice-lines { margin: 10px 0 5px; color: var(--muted); font-size: 12px; }
#practice-list .entry { align-content: center; font-weight: 650; overflow-wrap: anywhere; }

#terminal-draft-library {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding: clamp(16px, 4vw, 52px) var(--workspace-inset);
}
.draft-library-content {
    width: min(100%, 52rem);
    margin-inline: auto;
    padding: var(--detail-inset);
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface);
}
.draft-library-content h1 { margin: 0; font-size: clamp(22px, 3.2vw, 30px); line-height: 1.2; letter-spacing: -.025em; }
.draft-library-content p { margin: 6px 0 0; color: var(--muted); }
.draft-library-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.draft-library-actions button { min-height: 44px; }
#draft-library-new { border-color: var(--accent); color: white; background: var(--accent); }
#draft-library-new:hover { background: var(--navy); }
.draft-library-status:empty { display: none; }
.draft-library-content .draft-library-status:not(:empty) {
    margin-top: 22px;
    padding: 14px 16px;
    border-radius: 6px;
    background: var(--background);
}
.draft-library-content table { width: 100%; margin-top: 22px; border-collapse: collapse; table-layout: fixed; }
.draft-library-content th { padding: 8px 10px; background: var(--background); color: var(--muted); font-size: 13px; font-weight: 650; text-align: start; }
.draft-library-content th:first-child { width: 42%; }
.draft-library-content th:last-child { width: 11rem; }
.draft-library-content .draft-destinations { padding: 4px 8px; }
.draft-library-content tr > :last-child { text-align: end; }
.draft-library-content td { border-top: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
.draft-library-content td:nth-child(2) { padding: 6px 10px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.draft-library-content td:first-child button {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 8px 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--accent);
    text-align: start;
    font-family: var(--mono);
    font-size: 14px;
    font-weight: 600;
    overflow-wrap: anywhere;
}
.draft-library-content td:first-child button:is(:hover, :focus-visible) { background: var(--selection); text-decoration: underline; text-underline-offset: .18em; }
.draft-library-content td:first-child button:focus-visible { outline-offset: -2px; }

@media (max-width: 560px) {
    .draft-library-content thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
    .draft-library-content tbody, .draft-library-content tr { display: block; }
    .draft-library-content tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(5.5rem, 35%); align-items: center; border-top: 1px solid var(--line); }
    .draft-library-content td { border: 0; }
    .draft-library-content td:nth-child(2) { text-align: end; }
    .draft-library-content td.draft-destinations { grid-column: 1 / -1; padding-bottom: 8px; text-align: start; }
}

@media (max-width: 820px) {
    .workspace-search { flex: none; }
    .workspace-search-toggle { display: grid; }
    .workspace-search-field {
        display: none;
        position: absolute;
        z-index: 3;
        inset-block-start: calc(100% + 6px);
        inset-inline-start: 12px;
        width: min(360px, calc(100% - 24px));
        padding: 8px;
        border: 1px solid var(--line);
        border-radius: 8px;
        background: var(--surface);
        box-shadow: 0 8px 24px #17243a26;
    }
    .workspace-search-toggle[aria-expanded="true"] + .workspace-search-field { display: block; }
    .workspace-search input { font-size: 16px; }
}

@media (max-width: 620px) {
    .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 6px; padding-inline: 10px; }
    .topbar-leading { gap: 8px; }
    .brand { font-size: 22px; }
    .topbar nav { grid-area: 2 / 1 / auto / -1; width: 100%; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .topbar nav:has(#open-drafts:not([hidden])) { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .topbar-link { padding-inline: 3px; font-size: 12px; }
    .topbar #stop { padding-inline: 8px; font-size: 12px; }
}

@media (max-width: 420px) {
    .topbar nav { display: flex; gap: 1px; }
    .topbar-link { flex: 1 0 auto; padding-inline: 2px; font-size: clamp(11px, 3.1vw, 12px); }
    .topbar .stop-label { display: none; }
    .topbar .stop-short { display: inline; }
    #practice-detail .page-choice { padding-inline: 5px; }
}

@media (max-width: 359px) {
    .topbar nav:has(#open-drafts:not([hidden])) { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
    body { height: auto; min-height: 100vh; min-height: 100dvh; overflow: auto; }
    body:is([data-workspace="python"], [data-workspace="terminal"]) { height: 100vh; height: 100dvh; overflow: hidden; }
    .workspace { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .sidebar { padding: 10px 12px; }
    .sidebar h1 { margin-bottom: 6px; }
    #record-navigation, .workspace-list { max-height: min(26dvh, 200px); }
    .entry-header { padding: 10px 12px; }
    .overview-page, .empty-detail { padding: 14px 12px 20px; }
    .components > div { grid-template-columns: minmax(55px, 1fr) minmax(0, 2fr); padding: 10px; }
    .overview-page .syntax-table thead th:first-child { width: 34%; }
    .example-page { padding: 8px; }
}
