@view-transition { navigation: auto; }

:root {
  color-scheme: dark;
  --bg: #0e0e0e;
  --pane: #141414;
  --pane-2: #1b1b1b;
  --hover: #232323;
  --line: #262626;
  --text: #d6d6d3;
  --dim: #8e8e8a;
  --yellow: #e5c07b;
  --green: #98c379;
  --blue: #6fb3f2;
  --purple: #c49be8;
  --orange: #e39a64;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --sans: "Inter", system-ui, sans-serif;
  --ease: cubic-bezier(.3, .7, .2, 1);
}

* { box-sizing: border-box; }
html { font-size: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 1.0625rem; line-height: 1.6; overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 1px solid var(--blue); outline-offset: 1px; }
.skip { position: absolute; left: -999px; background: var(--blue); color: #000; padding: .4rem .8rem; font-size: 1rem; z-index: 90; }
.skip:focus { left: .5rem; top: .5rem; }

/* Workspace frame */
.ide { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto auto; min-height: 100vh; }
.ide > *, .body > *, .split > *, .term > * { min-width: 0; }
@media (min-width: 60rem) { .ide { height: 100vh; } }
.titlebar { display: flex; align-items: center; gap: 1rem; padding: .45rem .9rem; background: var(--pane); border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 1rem; }
.lights { display: flex; gap: .4rem; }
.lights i { width: .75rem; height: .75rem; border-radius: 50%; background: #3a3a3a; transition: background .2s var(--ease); }
.titlebar:hover .lights i:nth-child(1) { background: #e0625a; }
.titlebar:hover .lights i:nth-child(2) { background: #e2b34a; }
.titlebar:hover .lights i:nth-child(3) { background: #5dbb63; }
.titlebar .ttl { color: var(--dim); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.titlebar .ttl b { color: var(--text); font-weight: 500; }
.files-btn { display: none; background: var(--pane-2); border: 1px solid var(--line); border-radius: 4px; padding: .15rem .6rem; font-family: var(--mono); font-size: 1rem; cursor: pointer; }
@media (max-width: 59.99rem) { .files-btn { display: inline-block; } }

.body { display: grid; grid-template-columns: 1fr; min-height: 0; }
@media (min-width: 60rem) { .body { grid-template-columns: 17.5rem minmax(0, 1fr); } }
.explorer { background: var(--pane); border-right: 1px solid var(--line); font-family: var(--mono); font-size: 1rem; overflow-y: auto; }
@media (max-width: 59.99rem) {
  .explorer { position: fixed; z-index: 70; inset: 0 auto 0 0; width: min(20rem, 88vw); transform: translateX(-102%); transition: transform .35s var(--ease); box-shadow: 20px 0 50px rgba(0, 0, 0, .6); }
  .explorer.open { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .35s var(--ease); }
  .scrim.open { opacity: 1; pointer-events: auto; }
}
@media (min-width: 60rem) { .scrim { display: none; } }
.ex-head { padding: .6rem .9rem; color: var(--dim); letter-spacing: .06em; }
.tree { list-style: none; margin: 0; padding: 0 0 1rem; }
.tree ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-rows: 1fr; transition: grid-template-rows .3s var(--ease); }
.tree ul > div { overflow: hidden; }
.tree li.closed > ul { grid-template-rows: 0fr; }
.tree a, .tree button { display: flex; align-items: center; gap: .45rem; width: 100%; text-align: left; background: none; border: 0; padding: .2rem .9rem; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background .15s var(--ease); }
.tree a:hover, .tree button:hover { background: var(--hover); }
.tree a[aria-current="page"] { background: #2a2d33; color: #fff; }
.tree .d1 { padding-left: 1.9rem; }
.tree .d2 { padding-left: 2.9rem; }
.chev { display: inline-block; width: .8rem; color: var(--dim); transition: transform .25s var(--ease); }
.tree li.closed > button .chev { transform: rotate(-90deg); }
.ic-md { color: var(--blue); }
.ic-dir { color: var(--yellow); }
.ic-live { color: var(--green); margin-left: auto; }

.editor { display: grid; grid-template-rows: auto auto 1fr; min-width: 0; min-height: 0; }
.tabs { display: flex; background: var(--pane); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { flex: none; display: flex; align-items: center; gap: .5rem; padding: .45rem .9rem; font-family: var(--mono); font-size: 1rem; color: var(--dim); border-right: 1px solid var(--line); border-top: 2px solid transparent; transition: background .2s var(--ease), color .2s var(--ease); }
.tab:hover { background: var(--pane-2); color: var(--text); }
.tab.active { background: var(--bg); color: var(--text); border-top-color: var(--blue); }
.crumbs { font-family: var(--mono); font-size: 1rem; color: var(--dim); padding: .35rem 1.1rem; border-bottom: 1px solid var(--line); white-space: nowrap; overflow-x: auto; }
.crumbs a:hover { color: var(--text); }
.split { display: grid; grid-template-columns: 1fr; min-height: 0; }
@media (min-width: 75rem) { .split.has-preview { grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); } }
.doc { overflow-y: auto; padding: 1.25rem 1.1rem 3rem; min-width: 0; }
@media (min-width: 48rem) { .doc { padding: 1.75rem 2.25rem 4rem; } }
.doc > * { max-width: 48rem; }
.preview { border-left: 1px solid var(--line); display: grid; grid-template-rows: auto 1fr; min-height: 32rem; background: var(--pane); }
.pv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .9rem; padding: .45rem .9rem; font-family: var(--mono); font-size: 1rem; border-bottom: 1px solid var(--line); }
.pv-bar .run { color: var(--green); }
.pv-bar select { background: var(--pane-2); border: 1px solid var(--line); border-radius: 4px; padding: .1rem .4rem; font-family: var(--mono); font-size: 1rem; max-width: 100%; }
.pv-bar a { margin-left: auto; color: var(--blue); }
.pv-bar a:hover { text-decoration: underline; }
.pv-stage { position: relative; background: #fff; min-height: 30rem; }
.pv-stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; transition: opacity .4s var(--ease); }
.pv-stage iframe.fading { opacity: 0; }
@media (max-width: 74.99rem) { .preview { border-left: 0; border-top: 1px solid var(--line); } .pv-stage { min-height: 70vh; } }

/* Markdown rendering */
.md h1, .md h2, .md h3 { font-family: var(--mono); font-weight: 600; line-height: 1.25; margin: 1.6rem 0 .6rem; }
.md h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); margin-top: 0; }
.md h2 { font-size: 1.35rem; }
.md h3 { font-size: 1.1rem; }
.md h1::before { content: "# "; color: var(--dim); }
.md h2::before { content: "## "; color: var(--dim); }
.md h3::before { content: "### "; color: var(--dim); }
.md p { margin: 0 0 .9rem; }
.md ul { list-style: none; padding: 0; margin: 0 0 .9rem; }
.md li { padding-left: 1.3rem; position: relative; margin-bottom: .3rem; }
.md li::before { content: "-"; position: absolute; left: .2rem; color: var(--orange); font-family: var(--mono); }
.md a.link { color: var(--blue); border-bottom: 1px solid transparent; transition: border-color .2s var(--ease); }
.md a.link:hover { border-bottom-color: var(--blue); }
.front { font-family: var(--mono); font-size: 1rem; background: var(--pane); border: 1px solid var(--line); border-radius: 6px; padding: .8rem 1rem; margin: 0 0 1.4rem; line-height: 1.7; overflow-x: auto; }
.front .k { color: var(--purple); }
.front .s { color: var(--green); }
.front .c { color: var(--dim); }
.lede { font-size: 1.2rem; color: #c3c3bf; }
.mtable { width: 100%; border-collapse: collapse; font-size: 1rem; margin: 0 0 1.2rem; }
.mtable th, .mtable td { border: 1px solid var(--line); padding: .45rem .7rem; text-align: left; vertical-align: top; }
.mtable th { font-family: var(--mono); font-weight: 500; color: var(--dim); background: var(--pane); }
.mtable td.v { font-family: var(--mono); color: var(--yellow); white-space: nowrap; font-size: 1.15rem; }
.fence { border: 1px solid var(--line); border-radius: 6px; margin: 1.2rem 0; background: var(--pane); overflow: hidden; }
.fence-head { font-family: var(--mono); font-size: 1rem; color: var(--dim); padding: .35rem .8rem; border-bottom: 1px solid var(--line); }
.fence .body-in { padding: 1rem; overflow-x: auto; }
.fence svg { min-width: 42rem; width: 100%; height: auto; display: block; }
.story-figure { margin: 0; }
.shot { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin: 1.2rem 0; }
.quote { border-left: 3px solid var(--orange); padding: .3rem 0 .3rem 1rem; color: #c3c3bf; margin: 1.2rem 0; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 1rem; }
.chips code { font-family: var(--mono); font-size: 1rem; background: var(--pane-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .4rem; color: var(--orange); }
.btn { display: inline-flex; gap: .4rem; align-items: center; font-family: var(--mono); font-size: 1rem; border: 1px solid var(--line); background: var(--pane-2); border-radius: 4px; padding: .35rem .8rem; cursor: pointer; transition: border-color .2s var(--ease), background .2s var(--ease); }
.btn:hover { border-color: var(--blue); background: var(--hover); }
.btn.primary { border-color: var(--blue); color: var(--blue); }
.lsl { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 1rem; }
.lsl td, .lsl th { padding: .35rem .6rem; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.lsl th { color: var(--dim); font-weight: 400; }
.lsl tr { transition: background .15s var(--ease); }
.lsl tbody tr:hover { background: var(--hover); }
.lsl .nm { color: var(--blue); }
.lsl .cat { color: var(--purple); }
.lsl .st { color: var(--green); white-space: normal; }
.lsl .sum { color: var(--dim); white-space: normal; font-family: var(--sans); }
@media (max-width: 48rem) { .lsl .hide-s { display: none; } }
.pager { display: flex; justify-content: space-between; gap: 1rem; margin-top: 2rem; font-family: var(--mono); font-size: 1rem; }
.pager a { color: var(--blue); }
.pager a:hover { text-decoration: underline; }
.form { display: grid; gap: .8rem; margin-top: 1rem; font-family: var(--mono); font-size: 1rem; }
.form label { display: grid; gap: .25rem; color: var(--dim); }
.form input, .form textarea { background: var(--pane); border: 1px solid var(--line); border-radius: 4px; padding: .55rem .7rem; font-family: var(--mono); font-size: 1rem; transition: border-color .2s var(--ease); }
.form input:focus, .form textarea:focus { outline: none; border-color: var(--blue); }
.form textarea { min-height: 10rem; resize: vertical; }
.form .btn { justify-self: start; }

/* Terminal */
.term { background: var(--bg); border-top: 1px solid var(--line); font-family: var(--mono); font-size: 1rem; display: grid; grid-template-rows: auto 1fr; }
.term-head { display: flex; align-items: center; gap: 1rem; padding: .3rem .9rem; background: var(--pane); border-bottom: 1px solid var(--line); color: var(--dim); }
.term-head b { color: var(--text); font-weight: 500; border-bottom: 1px solid var(--blue); }
.term-head button { margin-left: auto; background: none; border: 0; color: var(--dim); cursor: pointer; font-family: var(--mono); font-size: 1rem; transition: color .2s var(--ease); }
.term-head button:hover { color: var(--text); }
.term-body { height: 11rem; overflow-y: auto; padding: .5rem .9rem; transition: height .35s var(--ease), padding .35s var(--ease); }
.term.min .term-body { height: 0; padding-top: 0; padding-bottom: 0; }
.term-body p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.term-body .pr { color: var(--green); }
.term-body .er { color: var(--orange); }
.term-body .dm { color: var(--dim); }
.term-body a { color: var(--blue); }
.term-in { display: flex; gap: .5rem; align-items: center; }
.term-in span { color: var(--green); flex: none; }
.term-in input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; font-family: var(--mono); font-size: 1rem; color: var(--text); caret-color: var(--blue); }
.status { display: flex; flex-wrap: wrap; gap: .1rem 1.2rem; padding: .2rem .9rem; background: #1f2a38; color: #d7e3f2; font-family: var(--mono); font-size: 1rem; }
.status span:last-child { margin-left: auto; }

/* Figures drawn by figures.mjs */
.figure-svg text { font-family: var(--mono); fill: var(--text); }
.fig-label, .fig-node-title, .fig-hub-label, .fig-wheel-note { font-size: 26px; font-weight: 600; }
.fig-node-sub, .fig-axis, .fig-note, .fig-value, .fig-tag, .fig-lane { font-size: 24px; }
.fig-node-sub, .fig-axis, .fig-note { fill: var(--dim); }
.fig-lane { fill: var(--purple); transform: translateY(-12px); }
.fig-node rect, .fig-layer rect { fill: var(--bg); stroke: #3a3a3a; stroke-width: 2; }
.fig-node.is-hi rect, .fig-layer.is-hi rect { stroke: var(--blue); fill: #16202b; }
.fig-edge, .fig-spoke { stroke: var(--dim); stroke-width: 2; fill: none; }
.fig-arrowhead { fill: var(--dim); }
.fig-grid { stroke: var(--line); }
.fig-bar rect, .fig-tally-bar, .fig-dot, .fig-cell { fill: #5c5c59; }
.fig-bar.is-hi rect, .fig-tally-bar.is-hi, .fig-dot.is-after, .fig-hubdot.is-hi, .fig-cell.is-hi { fill: var(--blue); }
.fig-marker { stroke: var(--yellow); stroke-dasharray: 6 6; stroke-width: 2; }
.fig-tally-track { fill: var(--pane-2); }
.fig-track { stroke: #3a3a3a; stroke-width: 6; }
.fig-span { stroke: var(--blue); stroke-width: 6; }
.fig-ring, .fig-disk { fill: none; stroke: #3a3a3a; stroke-width: 2; }
.fig-hubdot { fill: var(--text); }
.fig-hub { fill: var(--pane-2); stroke: var(--blue); stroke-width: 2; }
.fig-orbit-node, .fig-triad-node { fill: var(--bg); stroke: #3a3a3a; stroke-width: 3; }
.fig-night { fill: #050505; }
.fig-star { fill: #f2f2ee; }
.fig-sky-arc { fill: none; stroke: #444; stroke-dasharray: 4 8; }
.fig-treeline { fill: #000; }
.fig-geodesic { fill: none; stroke: var(--text); stroke-width: 2; }
.fig-geodesic.is-fine { stroke: #3a3a3a; }
.fig-cellmark rect { fill: var(--pane-2); stroke: #3a3a3a; }
.fig-cellmark circle { fill: none; stroke-width: 3; }
.fig-trail { fill: none; stroke-width: 2.5; }
.fig-origin { fill: var(--yellow); }
.fig-wedge { stroke: var(--bg); stroke-width: 3; }
.fig-tag { fill: var(--green); }

/* Scroll reveal and page transitions */
.rv { opacity: 0; transform: translateX(-8px); transition: opacity .5s var(--ease), transform .5s var(--ease); }
.rv.in { opacity: 1; transform: none; }
::view-transition-old(root) { animation: none; }
::view-transition-new(root) { animation: none; }
.doc, .preview { view-transition-name: none; }
.editor { view-transition-name: editor; }
::view-transition-old(editor) { animation: .18s var(--ease) both d4-out; }
::view-transition-new(editor) { animation: .3s var(--ease) both d4-in; }
@keyframes d4-out { to { opacity: 0; } }
@keyframes d4-in { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after, ::view-transition-old(editor), ::view-transition-new(editor) { animation: none !important; transition: none !important; }
  .rv { opacity: 1; transform: none; }
}
