/* Geometry Lab: a small observatory in deep space. Starlight for text, the shapes are the
   colour, and gold only for "the thing being measured" (in the model, the results, the formula). */
:root {
    --tt-topnav-h: 64px;
    --void: #04061a;
    --bg: #060920;
    --surface: #0a0f2e;
    --surface-2: #131a49;
    --surface-3: #1e2768;
    --line: rgba(150, 165, 255, 0.13);
    --line-strong: rgba(150, 165, 255, 0.27);
    --ink: #eef0ff;
    --ink-2: rgba(226, 230, 255, 0.76);
    --ink-3: rgba(226, 230, 255, 0.58);
    --gold: #ffd23f;
    --gold-ink: #221800;
    --cyan: #6be9ff;
    --violet: #9d7bff;
    --coral: #ff7f93;
    --radius: 10px;
    --font: 'Lexend', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --display: 'Exo 2', 'Lexend', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--void); }
body {
    margin: 0;
    background: transparent;
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
/* the night sky behind everything: two tiles of stars (prime sizes, so the repeat hides)
   and three faint nebulae */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(1px 1px at 23px 41px, rgba(255, 255, 255, 0.85), transparent 70%),
        radial-gradient(1px 1px at 141px 97px, rgba(200, 214, 255, 0.75), transparent 70%),
        radial-gradient(1.6px 1.6px at 67px 163px, rgba(255, 255, 255, 0.95), transparent 70%),
        radial-gradient(1px 1px at 189px 201px, rgba(255, 238, 214, 0.7), transparent 70%),
        radial-gradient(1.2px 1.2px at 211px 29px, rgba(255, 255, 255, 0.7), transparent 70%),
        radial-gradient(1px 1px at 61px 341px, rgba(190, 205, 255, 0.65), transparent 70%),
        radial-gradient(1.4px 1.4px at 331px 151px, rgba(255, 220, 236, 0.8), transparent 70%),
        radial-gradient(1px 1px at 383px 287px, rgba(255, 255, 255, 0.6), transparent 70%),
        radial-gradient(70vw 60vh at 88% 6%, rgba(109, 60, 255, 0.2), transparent 70%),
        radial-gradient(60vw 55vh at 4% 96%, rgba(18, 181, 201, 0.13), transparent 70%),
        radial-gradient(45vw 40vh at 50% 60%, rgba(214, 53, 155, 0.07), transparent 70%),
        var(--void);
    background-size: 293px 307px, 293px 307px, 293px 307px, 293px 307px, 293px 307px,
        419px 383px, 419px 383px, 419px 383px, auto, auto, auto;
}
.page { overflow-x: clip; }
a { color: var(--cyan); }
a:hover { color: #b5f3ff; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }
.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;
}
button, input, select { font: inherit; color: inherit; }
select option { background-color: #1a1a24; color: #ffffff; }

/* ------------------------------------------------------------------ the lab grid */
.lab {
    display: grid;
    grid-template-columns: 252px minmax(0, 1fr) 404px;
    height: calc(100vh - var(--tt-topnav-h));
    height: calc(100dvh - var(--tt-topnav-h));
    min-height: 600px;
    border-bottom: 1px solid var(--line);
}

/* ------------------------------------------------------------------ picker */
.picker {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(10, 15, 46, 0.94), rgba(6, 9, 32, 0.94));
}
.picker-head { padding: 18px 16px 8px; }
.lab-title {
    margin: 0;
    font-family: var(--display);
    font-size: 1.55rem;
    font-weight: 800;
    letter-spacing: 0.005em;
    line-height: 1.1;
}
.lab-title a { color: inherit; text-decoration: none; }
.lab-title a:hover { color: var(--cyan); }
.lab-title-sub, .shape-name-sub {
    display: block;
    margin-top: 4px;
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0;
    line-height: 1.35;
    color: var(--violet);
}
.shape-name-sub:empty { display: none; }
.lab-sub { margin: 6px 0 12px; color: var(--ink-2); font-size: 0.86rem; line-height: 1.45; }
.picker-filter { display: flex; flex-direction: column; gap: 8px; }
.picker-search {
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--line-strong);
    background: rgba(19, 26, 73, 0.6);
}
.picker-search:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(107, 233, 255, 0.15); }
.picker-search::placeholder { color: var(--ink-3); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; align-self: flex-start; }
.seg-btn {
    min-height: 36px;
    min-width: 48px;
    padding: 4px 12px;
    border: 0;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    font-size: 0.86rem;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line-strong); }
.seg-btn.is-on { background: var(--surface-3); color: var(--ink); }

.picker-list { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px 18px; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
.picker-group-title { margin: 14px 6px 6px; font-size: 0.78rem; font-weight: 500; color: var(--ink-3); }
.picker-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.shape-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 44px;
    padding: 6px 4px 8px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink-2);
    font-size: 0.74rem;
    line-height: 1.25;
    text-align: center;
    cursor: pointer;
}
.shape-tile img, .shape-tile .thumb-ph { width: 64px; height: 64px; display: block; }
.shape-tile span:last-child { max-width: 100%; overflow-wrap: break-word; hyphens: auto; }
.thumb-ph { border-radius: 50%; background: radial-gradient(circle, var(--surface-2) 0 40%, transparent 42%); }
/* every thumbnail floats on a faint orbit */
.shape-tile img, .shape-tile .thumb-ph { background: radial-gradient(closest-side, rgba(107, 233, 255, 0.09), transparent 70%), radial-gradient(50% 18% at 50% 78%, rgba(157, 123, 255, 0.22), transparent 100%); border-radius: 50%; }
.shape-tile:hover { background: rgba(19, 26, 73, 0.55); color: var(--ink); }
.shape-tile.is-on { border-color: rgba(255, 210, 63, 0.75); background: rgba(255, 210, 63, 0.07); color: var(--ink); box-shadow: 0 0 18px rgba(255, 210, 63, 0.14), inset 0 0 12px rgba(255, 210, 63, 0.06); }
.picker-empty { padding: 12px 6px; color: var(--ink-3); font-size: 0.86rem; }

/* ------------------------------------------------------------------ stage */
.stage-wrap {
    position: relative;
    min-width: 0;
    min-height: 0;
    background: var(--void);
    overflow: hidden;
}
.stage { position: absolute; inset: 0; }
.stage canvas { display: block; touch-action: none; }
.stage-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.stage-label {
    position: absolute;
    left: 0;
    top: 0;
    padding: 3px 9px;
    border-radius: 7px;
    background: rgba(6, 9, 32, 0.78);
    border: 1px solid rgba(107, 233, 255, 0.32);
    box-shadow: 0 0 12px rgba(107, 233, 255, 0.12);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.3;
    white-space: nowrap;
    will-change: transform;
}
.stage-label.is-hl { background: var(--gold); color: var(--gold-ink); border-color: rgba(34, 24, 0, 0.55); font-size: 16px; box-shadow: 0 0 18px rgba(255, 210, 63, 0.55); }
.stage-label .katex { font-size: 1em; }
.stage-hint {
    position: absolute;
    left: 16px;
    top: 14px;
    margin: 0;
    max-width: min(420px, calc(100% - 260px));
    color: var(--ink-3);
    font-size: 0.8rem;
    pointer-events: none;
    transition: opacity 0.6s ease;
}
.stage-hint.is-gone { opacity: 0; }
.stage-tools { position: absolute; right: 12px; top: 12px; display: flex; gap: 6px; }
.tool-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--line-strong);
    background: rgba(6, 9, 32, 0.7);
    color: var(--ink-2);
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 0.95rem;
}
.tool-btn:hover { color: var(--cyan); border-color: rgba(107, 233, 255, 0.55); box-shadow: 0 0 14px rgba(107, 233, 255, 0.22); }
.tool-btn.is-on { color: var(--gold); border-color: rgba(255, 210, 63, 0.6); box-shadow: 0 0 14px rgba(255, 210, 63, 0.2); }
.stage-scale {
    position: absolute;
    left: 16px;
    bottom: 12px;
    margin: 0;
    color: var(--ink-3);
    font-size: 0.78rem;
    pointer-events: none;
}
.stage-warning {
    position: absolute;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    margin: 0;
    max-width: calc(100% - 32px);
    padding: 8px 14px;
    border-radius: var(--radius);
    background: rgba(46, 8, 26, 0.9);
    border: 1px solid rgba(255, 127, 147, 0.5);
    color: var(--coral);
    font-size: 0.88rem;
    text-align: center;
}
.stage-fallback { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--ink-2); }

/* ------------------------------------------------------------------ panel */
.panel {
    min-height: 0;
    overflow-y: auto;
    padding: 18px 20px 32px;
    border-left: 1px solid var(--line);
    background: linear-gradient(180deg, rgba(14, 20, 60, 0.95), rgba(9, 13, 42, 0.95) 320px);
    scrollbar-width: thin;
    scrollbar-color: var(--surface-3) transparent;
}
.shape-name { margin: 0 0 10px; font-family: var(--display); font-size: 1.6rem; font-weight: 700; letter-spacing: 0.005em; line-height: 1.15; }
.hero {
    display: block;
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--line-strong);
    background: radial-gradient(120% 140% at 100% 0%, rgba(157, 123, 255, 0.16), transparent 60%), rgba(4, 6, 26, 0.75);
    text-align: left;
    cursor: pointer;
}
.hero:hover { border-color: rgba(255, 210, 63, 0.55); }
.hero.is-on { border-color: var(--gold); box-shadow: 0 0 22px rgba(255, 210, 63, 0.16); }
.hero-formula { display: block; font-size: 1.32rem; min-height: 1.6em; overflow-x: auto; overflow-y: hidden; }
.hero-value { display: block; margin-top: 2px; color: var(--gold); font-family: var(--display); font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hero-value small { color: var(--ink-3); font-weight: 400; font-size: 0.82rem; margin-left: 6px; }

.panel-h { margin: 0; font-family: var(--display); font-size: 1rem; font-weight: 700; letter-spacing: 0.01em; }
.panel-note { margin: 0 0 12px; color: var(--ink-2); font-size: 0.88rem; }

.sizes { margin: 18px 0 6px; }
.sizes-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.sizes-opts { display: flex; gap: 10px; }
.opt { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-3); font-size: 0.8rem; }
.opt select, .field select {
    min-height: 36px;
    padding: 4px 8px;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: var(--bg);
    color: var(--ink);
}

.param { padding: 10px 0 4px; border-top: 1px solid var(--line); }
.param:first-child { border-top: 0; }
.param-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.param-label { display: flex; align-items: baseline; gap: 8px; min-width: 0; font-size: 0.92rem; color: var(--ink-2); }
.param-label .sym { color: var(--ink); font-size: 1.05rem; min-width: 1.2em; }
.param-num { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); }
.param-num input {
    width: 92px;
    min-height: 38px;
    padding: 4px 8px;
    border: 0;
    background: transparent;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.param-num input:focus { outline: none; }
.param-num:focus-within { border-color: var(--gold); }
.param-num .unit, .input-unit .unit { padding: 0 10px 0 2px; color: var(--ink-3); font-size: 0.85rem; }
.param.is-invalid .param-num { border-color: var(--coral); }

/* the slider is a ruler: ticks every tenth of its range */
.ruler {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 44px;
    margin: 0;
    background: transparent;
    cursor: pointer;
}
.ruler::-webkit-slider-runnable-track {
    height: 14px;
    border-radius: 3px;
    background:
        linear-gradient(var(--gold), var(--gold)) 0 100% / var(--fill, 50%) 3px no-repeat,
        repeating-linear-gradient(90deg, rgba(226, 230, 255, 0.38) 0 1px, transparent 1px calc(10% - 0.1px)) 0 100% / 100% 8px no-repeat,
        linear-gradient(rgba(226, 230, 255, 0.16), rgba(226, 230, 255, 0.16)) 0 100% / 100% 1px no-repeat;
}
.ruler::-moz-range-track {
    height: 14px;
    background:
        linear-gradient(var(--gold), var(--gold)) 0 100% / var(--fill, 50%) 3px no-repeat,
        repeating-linear-gradient(90deg, rgba(226, 230, 255, 0.38) 0 1px, transparent 1px calc(10% - 0.1px)) 0 100% / 100% 8px no-repeat,
        linear-gradient(rgba(226, 230, 255, 0.16), rgba(226, 230, 255, 0.16)) 0 100% / 100% 1px no-repeat;
}
.ruler::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    margin-top: 1px;
    border-radius: 50%;
    border: 3px solid var(--surface);
    background: var(--gold);
    box-shadow: 0 0 0 1px rgba(255, 210, 63, 0.6), 0 0 14px rgba(255, 210, 63, 0.55);
}
.ruler::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 3px solid var(--bg);
    background: var(--gold);
}
.param-error { margin: 6px 0 0; color: var(--coral); font-size: 0.86rem; }

/* ------------------------------------------------------------------ tabs */
.tabs { display: flex; gap: 2px; margin: 16px 0 12px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tab {
    min-height: 44px;
    padding: 6px 12px;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.92rem;
}
.tab:hover { color: var(--ink); }
.tab.is-on { color: var(--ink); border-bottom-color: var(--gold); text-shadow: 0 0 14px rgba(255, 210, 63, 0.35); }

/* ------------------------------------------------------------------ results */
.results { list-style: none; margin: 0; padding: 0; }
.result { border-bottom: 1px solid var(--line); }
.result-row {
    display: grid;
    grid-template-columns: 3.4em minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    padding: 8px 6px 8px 10px;
    border: 0;
    border-left: 3px solid transparent;
    background: transparent;
    text-align: left;
    cursor: pointer;
}
.result-row:hover { background: rgba(226, 230, 255, 0.03); }
.result.is-on .result-row { border-left-color: var(--gold); background: rgba(255, 210, 63, 0.05); }
.result-sym { font-size: 1.05rem; color: var(--ink); overflow: hidden; }
.result-name { color: var(--ink-2); font-size: 0.9rem; line-height: 1.3; }
.result-name .approx { color: var(--ink-3); font-size: 0.78rem; }
.result-val { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.result.is-on .result-val { color: var(--gold); }
.result-val .u { color: var(--ink-3); margin-left: 3px; font-size: 0.86rem; }
.result.is-on .result-val .u { color: rgba(255, 210, 63, 0.75); }
.result-detail { padding: 2px 10px 14px 13px; }
.result-detail[hidden] { display: none; }
.work { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.work-line { font-size: 1.04rem; }
.work-line + .work-line { margin-top: 4px; color: var(--ink-2); }
.result-extra { margin: 6px 0 0; color: var(--ink-3); font-size: 0.84rem; }
.result-aux .result-name { color: var(--ink-3); }

/* ------------------------------------------------------------------ solve */
.solve { display: grid; gap: 10px; }
.field { display: grid; gap: 4px; color: var(--ink-3); font-size: 0.82rem; }
.field select { width: 100%; min-height: 42px; font-size: 0.95rem; }
.input-unit { display: flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bg); }
.input-unit:focus-within { border-color: var(--gold); }
.input-unit input { flex: 1; min-width: 0; min-height: 42px; padding: 6px 10px; border: 0; background: transparent; font-size: 1rem; }
.input-unit input:focus { outline: none; }
.btn-primary {
    min-height: 46px;
    padding: 8px 16px;
    border: 0;
    border-radius: var(--radius);
    background: var(--gold);
    color: var(--gold-ink);
    font-weight: 600;
    cursor: pointer;
}
.btn-primary:hover { background: #ffe073; box-shadow: 0 0 20px rgba(255, 210, 63, 0.35); }
.btn-ghost {
    min-height: 40px;
    padding: 6px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    font-size: 0.86rem;
}
.btn-ghost:hover { color: var(--ink); border-color: rgba(226, 230, 255, 0.4); }
.solve-out { margin-top: 14px; }
.solve-result { padding: 12px 14px; border-left: 3px solid var(--gold); background: rgba(255, 210, 63, 0.05); }
.solve-found { font-family: var(--display); font-weight: 700; font-size: 1.35rem; color: var(--gold); font-variant-numeric: tabular-nums; }
.solve-check { margin: 4px 0 10px; color: var(--ink-2); font-size: 0.9rem; }
.solve-error { padding: 10px 12px; border-left: 3px solid var(--coral); color: var(--coral); background: rgba(255, 127, 147, 0.07); font-size: 0.92rem; }

/* ------------------------------------------------------------------ calculator */
.calc-screen { padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg); }
.calc-screen:focus-within { border-color: var(--gold); }
.calc-input { width: 100%; min-height: 40px; border: 0; background: transparent; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.calc-input:focus { outline: none; }
.calc-input::placeholder { color: var(--ink-3); }
.calc-result { display: block; min-height: 1.6em; text-align: right; font-family: var(--display); font-weight: 600; font-size: 1.45rem; color: var(--gold); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.calc-result.is-error { color: var(--coral); font-size: 0.9rem; }
.calc-mode { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 10px 0 6px; }
.calc-hint { color: var(--ink-3); font-size: 0.8rem; }
.calc-vars { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.var-chip {
    min-height: 36px;
    padding: 4px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 18px;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    font-size: 0.84rem;
    font-variant-numeric: tabular-nums;
}
.var-chip b { color: var(--ink); font-weight: 500; }
.var-chip:hover { border-color: rgba(226, 230, 255, 0.45); color: var(--ink); }
.keypad { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.key {
    min-height: 46px;
    border: 0;
    border-radius: 8px;
    background: linear-gradient(180deg, #18205a, #11174a);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    color: var(--ink);
    cursor: pointer;
    font-size: 1rem;
}
.key:hover { background: var(--surface-3); }
.key:active { transform: translateY(1px); }
.key.op { color: var(--cyan); }
.key.fn { font-size: 0.86rem; color: var(--ink-2); }
.key.eq { background: var(--gold); color: var(--gold-ink); font-weight: 600; grid-column: span 2; }
.key.eq:hover { background: #ffe073; }
.calc-history { list-style: none; margin: 12px 0 0; padding: 0; }
.calc-history li { border-top: 1px solid var(--line); }
.calc-history button {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 40px;
    padding: 6px 4px;
    border: 0;
    background: transparent;
    color: var(--ink-2);
    cursor: pointer;
    font-size: 0.88rem;
    text-align: left;
    font-variant-numeric: tabular-nums;
}
.calc-history button span:last-child { color: var(--ink); white-space: nowrap; }

/* ------------------------------------------------------------------ explain */
.explain-text { margin: 0 0 16px; color: var(--ink); font-size: 0.95rem; line-height: 1.6; }
.formula-list { margin: 8px 0 16px; padding: 0; list-style: none; }
.formula-list li { display: grid; gap: 2px; padding: 8px 0; border-top: 1px solid var(--line); }
.formula-list .fname { color: var(--ink-3); font-size: 0.8rem; }
.formula-list .ftex { overflow-x: auto; overflow-y: hidden; font-size: 1.02rem; }
.rules { margin: 0 0 16px; padding-left: 18px; color: var(--ink-2); font-size: 0.88rem; }
.code {
    margin: 8px 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: #050821;
    border: 1px solid var(--line);
    color: #cfdcff;
    font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    font-size: 0.8rem;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.code-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    z-index: calc(var(--tt-z-modal, 1000) + 20);
    padding: 10px 16px;
    border-radius: var(--radius);
    background: var(--ink);
    color: #0a0f2e;
    font-size: 0.9rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* ------------------------------------------------------------------ learn (below the lab) */
/* a shape's own guide: the math behind it, every formula, a worked example, questions */
.guide-lead { margin: 0 0 22px; max-width: 72ch; color: var(--ink); font-size: 1.02rem; line-height: 1.65; }
.guide h3 { margin: 26px 0 10px; font-family: var(--display); font-size: 1.12rem; font-weight: 700; }
.guide-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 44px; }
.guide-cols h3 { margin-top: 0; }
.guide-formulas { margin: 0; }
.guide-formulas > div { display: grid; gap: 2px; padding: 9px 0; border-top: 1px solid var(--line); }
.guide-formulas dt { color: var(--ink-3); font-size: 0.82rem; }
.guide-formulas dd { margin: 0; overflow-x: auto; overflow-y: hidden; font-size: 1.04rem; }
.guide-formulas small, .guide-steps small { display: block; margin-top: 2px; color: var(--ink-3); font-size: 0.8rem; }
.guide-given { margin: 0 0 8px; color: var(--ink-2); }
.guide-steps { margin: 0; padding: 0; list-style: none; counter-reset: step; }
.guide-steps li { display: grid; gap: 2px; padding: 9px 0 9px 34px; border-top: 1px solid var(--line); position: relative; counter-increment: step; }
.guide-steps li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 10px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--surface-2);
    color: var(--cyan);
    font-size: 0.74rem;
    font-weight: 600;
}
.guide-step-name { color: var(--ink-3); font-size: 0.82rem; }
.guide-steps .tex { font-size: 1.02rem; }
.guide-faq { border-bottom: 1px solid var(--line); }
.guide-related { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.guide-related a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 6px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 20px;
    background: rgba(19, 26, 73, 0.5);
    color: var(--ink-2);
    text-decoration: none;
    font-size: 0.9rem;
}
.guide-related a:hover { color: var(--cyan); border-color: rgba(107, 233, 255, 0.55); }
.guide .tex { display: block; overflow-x: auto; overflow-y: hidden; white-space: nowrap; padding: 2px 0; }
.learn { max-width: 1120px; margin: 0 auto; padding: 48px 24px 80px; }
.learn-sec + .learn-sec { margin-top: 56px; }
.learn h2 { margin: 0 0 8px; font-family: var(--display); font-size: 1.75rem; font-weight: 700; letter-spacing: 0.005em; line-height: 1.2; }
.learn-lead { margin: 0 0 20px; max-width: 68ch; color: var(--ink-2); }
.catalog-group + .catalog-group { margin-top: 28px; }
.catalog-group h3 { margin: 0 0 10px; font-family: var(--display); font-size: 1.05rem; font-weight: 700; color: var(--violet); }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 0 28px; }
.catalog-item {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
    color: var(--ink);
    text-decoration: none;
}
.catalog-item:hover .catalog-name { color: var(--gold); }
.catalog-item img, .catalog-item .thumb-ph { width: 56px; height: 56px; }
.catalog-name { display: block; font-size: 0.95rem; }
.catalog-tex { display: block; color: var(--ink-2); font-size: 0.92rem; overflow-x: auto; overflow-y: hidden; }
.how { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 40px; }
.how h3 { margin: 0 0 6px; font-family: var(--display); font-size: 1.12rem; font-weight: 700; }
.how p { margin: 0; color: var(--ink-2); max-width: 60ch; }
.faq { border-top: 1px solid var(--line); }
.faq:last-of-type { border-bottom: 1px solid var(--line); }
.faq summary { min-height: 48px; padding: 12px 0; cursor: pointer; font-weight: 500; }
.faq p { margin: 0 0 16px; color: var(--ink-2); max-width: 72ch; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1180px) {
    .lab {
        grid-template-columns: minmax(0, 1fr) 372px;
        grid-template-rows: auto minmax(0, 1fr);
    }
    .picker {
        grid-column: 1 / -1;
        flex-direction: row;
        align-items: stretch;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
    .picker-head { width: 250px; flex: none; padding: 12px 14px; border-right: 1px solid var(--line); }
    .lab-sub { display: none; }
    .lab-title { font-size: 1.2rem; margin-bottom: 8px; }
    /* the strip's height is known before the tiles arrive, so the stage below never jumps */
    .picker-list { display: flex; gap: 14px; overflow-x: auto; overflow-y: hidden; padding: 8px 12px; min-height: 151px; }
    .picker-group { display: flex; flex-direction: column; flex: none; }
    .picker-group-title { margin: 0 4px 4px; white-space: nowrap; }
    .picker-grid { display: flex; gap: 2px; }
    .shape-tile { width: 96px; flex: none; }
    .shape-tile img, .shape-tile .thumb-ph { width: 52px; height: 52px; }
}

@media (max-width: 820px) {
    .lab { display: block; height: auto; min-height: 0; }
    .picker { flex-direction: column; }
    .picker-head { width: auto; border-right: 0; padding: 12px 16px 6px; }
    .picker-filter { flex-direction: row; align-items: center; }
    .picker-search { flex: 1; min-width: 0; }
    .lab-title { margin-bottom: 8px; }
    .picker-list { padding: 4px 16px 10px; }
    .stage-wrap { height: 54vh; height: 54svh; min-height: 300px; max-height: 560px; }
    .stage-hint { display: none; }
    .stage-tools { right: 8px; top: 8px; gap: 4px; }
    .panel { border-left: 0; padding: 16px 16px 28px; overflow: visible; }
    .how, .guide-cols { grid-template-columns: minmax(0, 1fr); }
    .learn { padding: 36px 16px 64px; }
    .learn h2 { font-size: 1.35rem; }
}

@media (max-width: 420px) {
    .param-num input { width: 78px; }
    .sizes-opts { gap: 6px; }
    .result-row { grid-template-columns: 3em minmax(0, 1fr) auto; gap: 8px; }
    .key { min-height: 44px; font-size: 0.95rem; }
}

@media (prefers-reduced-motion: reduce) {
    .stage-hint { transition: none; }
}
