:root {
  --bg: #f4f6f5; --panel: #ffffff; --ink: #14201e; --muted: #56635f; --line: #dde4e2;
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #e0f2ef; --focus: #0f766e;
  --warn: #8a5a00; --warn-soft: #fff4dc; --radius: 14px;
  --shadow: 0 1px 2px rgba(10, 30, 28, .06), 0 6px 24px rgba(10, 30, 28, .06);
  --code-bg: #fbfcfc; --code-ink: #1d2a28; --code-gutter: #9aa8a5; --code-line: #eef2f1; --chg: #fff2c4;
  --t-kw: #a3279b; --t-str: #1f7a3a; --t-doc: #6b7a76; --t-com: #7b8784; --t-num: #b45309; --t-fn: #1d4ed8; --t-bi: #0e7490; --t-const: #9a3412; --t-dec: #7c3aed;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
:root[data-theme="dark"] {
  --bg: #0d1413; --panel: #141e1c; --ink: #e5eeec; --muted: #9cb0ab; --line: #26332f;
  --accent: #2dd4bf; --accent-ink: #062a26; --accent-soft: #123430; --focus: #5eead4;
  --warn: #fcd34d; --warn-soft: #2f2610; --shadow: none;
  --code-bg: #0f1716; --code-ink: #dbe7e4; --code-gutter: #5f736e; --code-line: #1b2624; --chg: #3a3214;
  --t-kw: #f0abfc; --t-str: #86efac; --t-doc: #8fa39e; --t-com: #7f938e; --t-num: #fdba74; --t-fn: #93c5fd; --t-bi: #67e8f9; --t-const: #fca5a5; --t-dec: #c4b5fd;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .88em; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.topbar { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; padding: 12px 16px; max-width: 1400px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-name { font-weight: 750; font-size: 1.15rem; letter-spacing: -.01em; }
.pill { font-size: .78rem; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.top-link { font-size: .9rem; text-decoration: none; color: var(--muted); }
.icon-btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 10px; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 0 16px 32px; }
.hero { padding: 8px 0 4px; }
.hero h1 { font-size: clamp(1.5rem, 3.6vw, 2.2rem); line-height: 1.15; margin: 0 0 8px; letter-spacing: -.02em; }
.lede { margin: 0 0 14px; max-width: 52rem; color: var(--muted); font-size: 1.03rem; }
.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ex-label { font-weight: 650; font-size: .92rem; margin-right: 2px; }
.chip { font: inherit; font-size: .86rem; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 6px 12px; min-height: 36px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 44px; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-small { padding: 6px 12px; min-height: 38px; font-size: .9rem; }

.layout { display: grid; grid-template-columns: minmax(0, 430px) minmax(0, 1fr); gap: 16px; align-items: start; margin-top: 16px; }
@media (max-width: 960px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.config { padding: 6px 16px 14px; }
.group { border: 0; border-bottom: 1px solid var(--line); margin: 0; padding: 12px 0 14px; min-width: 0; }
.group:last-of-type { border-bottom: 0; }
legend { font-weight: 700; font-size: 1.02rem; display: flex; align-items: center; gap: 8px; padding: 0; margin-bottom: 8px; float: left; width: 100%; }
legend + * { clear: both; }
.step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: .82rem; }
.sub-label { margin: 12px 0 6px; font-size: .85rem; font-weight: 650; color: var(--muted); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span { display: inline-flex; align-items: center; min-height: 38px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: .9rem; cursor: pointer; background: var(--panel); }
.seg span:hover { border-color: var(--accent); }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.f { display: flex; flex-direction: column; gap: 4px; font-size: .84rem; color: var(--muted); font-weight: 600; min-width: 0; }
.f-wide { grid-column: 1 / -1; }
.f input, .f select { font: inherit; font-size: .95rem; font-weight: 400; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-height: 40px; width: 100%; min-width: 0; }
.f input:focus, .f select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.checks { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.aug .checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: .92rem; min-height: 32px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.layout-hint { margin-top: 12px; font-size: .88rem; }
.layout-hint summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.layout-hint pre { font-family: var(--mono); font-size: .8rem; background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; overflow-x: auto; margin: 8px 0 0; white-space: pre; }
.form-foot { display: flex; justify-content: flex-end; padding-top: 4px; }

.preview { position: sticky; top: 12px; display: flex; flex-direction: column; max-height: calc(100vh - 24px); overflow: hidden; }
@media (max-width: 960px) { .preview { position: static; max-height: none; } }
.pv-head { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: flex-start; padding: 14px 16px 8px; }
.pv-title h2 { margin: 0; font-size: 1.12rem; }
.pv-title p { margin: 2px 0 0; }
.pv-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.warns { margin: 0 16px 8px; padding: 8px 12px 8px 28px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; font-size: .88rem; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.tab { font: inherit; font-family: var(--mono); font-size: .85rem; border: 0; background: none; color: var(--muted); padding: 9px 12px; min-height: 40px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
.pv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.outline-pick { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.outline-pick select { font: inherit; font-size: .85rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); padding: 4px 6px; min-height: 34px; max-width: 220px; }
.chg-note { background: var(--chg); color: var(--ink); padding: 2px 8px; border-radius: 999px; font-weight: 600; }

.code-wrap { position: relative; background: var(--code-bg); overflow: auto; flex: 1 1 auto; min-height: 320px; }
@media (max-width: 960px) { .code-wrap { max-height: 70vh; } }
.code { margin: 0; padding: 10px 0 16px; font-family: var(--mono); font-size: .8rem; line-height: 1.55; color: var(--code-ink); counter-reset: none; tab-size: 4; }
.code .ln { display: block; padding: 0 16px 0 58px; position: relative; white-space: pre; min-height: 1.55em; }
.code .ln::before { content: attr(data-n); position: absolute; left: 0; width: 44px; text-align: right; color: var(--code-gutter); user-select: none; }
.code .ln.chg { background: var(--chg); }
.code .ln.chg::before { color: var(--warn); font-weight: 700; }
#code { width: max-content; min-width: 100%; }
.t-kw { color: var(--t-kw); } .t-str { color: var(--t-str); } .t-doc { color: var(--t-doc); } .t-com { color: var(--t-com); font-style: italic; }
.t-num { color: var(--t-num); } .t-fn { color: var(--t-fn); } .t-bi { color: var(--t-bi); } .t-const { color: var(--t-const); } .t-dec { color: var(--t-dec); }

.nb { padding: 10px 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.cell { border-radius: 10px; min-width: 0; }
.cell-markdown { padding: 2px 4px; }
.cell-markdown h3 { margin: 6px 0 4px; font-size: 1.1rem; }
.cell-markdown h4 { margin: 8px 0 2px; font-size: 1rem; }
.cell-markdown p { margin: 4px 0; font-size: .92rem; color: var(--muted); }
.cell-code { border: 1px solid var(--line); background: var(--panel); position: relative; overflow-x: auto; }
.cell-code .code { padding: 22px 12px 10px; white-space: pre; }
.cell-tag { position: absolute; top: 4px; left: 10px; font-family: var(--mono); font-size: .72rem; color: var(--code-gutter); }
.status-line { margin: 0; padding: 8px 16px 12px; font-size: .9rem; color: var(--muted); min-height: 1.5em; border-top: 1px solid var(--line); }

.explain { margin-top: 28px; }
.explain h2 { font-size: 1.25rem; margin: 0 0 10px; }
.explain-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.explain-grid > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.explain-grid h3 { margin: 4px 0 6px; font-size: 1rem; }
.explain-grid p { margin: 0; color: var(--muted); font-size: .93rem; }
.foot { max-width: 1400px; margin: 0 auto; padding: 18px 16px 36px; color: var(--muted); font-size: .86rem; border-top: 1px solid var(--line); }
.foot p { margin: 4px 0; }

@media (max-width: 520px) {
  .fields { grid-template-columns: minmax(0, 1fr); }
  .aug .checks { grid-template-columns: minmax(0, 1fr); }
  .pill { display: none; }
  .pv-actions .btn { flex: 1 1 auto; }
  .code { font-size: .74rem; }
  .code .ln { padding-left: 46px; }
  .code .ln::before { width: 34px; }
}
