@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/assets/fonts/jbm-var.woff2') format('woff2');
}
:root {
  --bg: #1a1418; --bg-2: #221a20; --bg-3: #2b2128;
  --fg: #e8ddd9; --fg-dim: #b5a8a5; --fg-muted: #9b8f91;
  --hl: #d8992f; --accent: #e0705f; --link: #efe4d9;
  --rule: #352e39; --ok: #61c554; --selection: #d8992f44;
  --field: var(--bg);
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #e8e4dc; --bg-2: #faf8f3; --bg-3: #f1eee7;
  --fg: #1a1a1a; --fg-dim: #4a4a4a; --fg-muted: #5e5a54;
  --hl: #8b2e1f; --accent: #b0261c; --link: #1a1a1a;
  --rule: #cdc7bc; --ok: #2a6b22; --selection: #8b2e1f2e;
  --field: #ffffff;
}
html[data-theme="light"] :is(.calc, .cards a, .related a) { box-shadow: 0 1px 2px #1a1a1a12, 0 2px 6px #1a1a1a0a; }
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--fg);
  font-family: 'JetBrains Mono', 'Menlo', monospace;
  font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; min-height: 100%;
}
::selection { background: var(--selection); color: var(--fg); }
a { color: var(--link); text-decoration: none; border-bottom: 1px dotted var(--link); }
a:hover { color: var(--hl); border-color: var(--hl); }
.wrap { max-width: 820px; margin: 0 auto; padding: 0 20px 80px; }
header { border-bottom: 1px solid var(--rule); background: linear-gradient(180deg, var(--bg-3), var(--bg-2)); }
header .bar { max-width: 820px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 10px; }
header a.brand { display: inline-flex; align-items: center; flex: none; color: var(--fg); border: none; text-decoration: none; line-height: 0; }
header a.brand .kb-mark { height: 18px; width: auto; display: block; fill: currentColor; }
header a.brand .kb-dot { fill: var(--hl); }
header .crumb { color: var(--fg-muted); font-size: 12px; }
header .crumb .sep { margin: 0 6px; opacity: 0.5; }
header .theme-toggle { margin-left: auto; flex: none; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 26px; padding: 0; cursor: pointer; color: var(--fg-dim); background: var(--bg-2); border: 1px solid var(--rule); border-radius: 4px; }
header .theme-toggle svg { width: 15px; height: 15px; display: block; }
header .theme-toggle:hover { color: var(--hl); border-color: var(--hl); }
header .theme-toggle[hidden] { display: none; }
header .theme-toggle .sun, html[data-theme="light"] header .theme-toggle .moon { display: none; }
html[data-theme="light"] header .theme-toggle .sun { display: block; }
header .kofi { font-size: 12px; color: var(--hl); white-space: nowrap; margin-left: auto; }
header .theme-toggle:not([hidden]) + .kofi { margin-left: 4px; }
header .kofi img { vertical-align: -2px; }
@media (max-width: 520px) { header .kofi-label { display: none; } }
@media (max-width: 420px) { header a.brand .kb-mark { height: 15px; } }

h1 { font-size: 26px; font-weight: 700; margin: 32px 0 8px; letter-spacing: -0.01em; }
h1 .pipe { color: var(--hl); }
.sub { color: var(--fg-dim); font-size: 14px; margin: 0 0 6px; max-width: 660px; text-wrap: pretty; }
.privacy {
  display: inline-flex; align-items: center; gap: 7px; color: var(--ok); font-size: 12px; margin: 14px 0 24px;
  border: 1px solid var(--rule); border-left: 2px solid var(--ok); background: var(--bg-2); padding: 6px 12px; border-radius: 3px;
}
.privacy::before { content: '●'; }

.calc { border: 1px solid var(--rule); border-radius: 6px; background: var(--bg-2); padding: 20px; margin-bottom: 8px; }
.modes { display: inline-flex; border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; margin-bottom: 18px; flex-wrap: wrap; }
.modes button { background: var(--field); color: var(--fg-dim); border: none; font: inherit; font-size: 12px; padding: 8px 14px; cursor: pointer; border-right: 1px solid var(--rule); }
.modes button:last-child { border-right: none; }
.modes button.active { background: var(--hl); color: var(--bg); font-weight: 600; }

.fields { display: grid; gap: 12px; }
.field { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
.field label { color: var(--fg-dim); font-size: 13px; }
.field .help { display: block; color: var(--fg-muted); font-size: 11px; margin-top: 2px; }
.inputwrap { position: relative; display: inline-flex; align-items: center; }
.inputwrap .pre, .inputwrap .suf { color: var(--fg-muted); font-size: 13px; position: absolute; pointer-events: none; }
.inputwrap .pre { left: 10px; }
.inputwrap .suf { right: 10px; }
.field input {
  background: var(--field); border: 1px solid var(--rule); border-radius: 4px; color: var(--fg);
  font-family: inherit; font-size: 14px; padding: 9px 12px; outline: none; width: 170px; text-align: right;
}
.field input.has-pre { padding-left: 24px; }
.field input.has-suf { padding-right: 26px; }
.field input:focus { border-color: var(--hl); }
.field input::-webkit-outer-spin-button, .field input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.field input[type=number] { -moz-appearance: textfield; }

.results { margin-top: 20px; border-top: 1px solid var(--rule); padding-top: 18px; }
.result-primary { border: 1px solid var(--hl); border-left: 3px solid var(--hl); border-radius: 5px; background: var(--bg-3); padding: 16px 18px; margin-bottom: 12px; }
.result-primary .rlabel { color: var(--fg-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.result-primary .rvalue { color: var(--hl); font-size: 30px; font-weight: 700; letter-spacing: -0.01em; margin-top: 2px; word-break: break-word; }
.result-primary .rhint { color: var(--fg-dim); font-size: 12px; margin-top: 6px; }
.rrow { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 2px; border-bottom: 1px dotted var(--rule); }
.rrow:last-child { border-bottom: none; }
.rrow .rlabel { color: var(--fg-dim); font-size: 13px; }
.rrow .rvalue { color: var(--fg); font-size: 15px; font-weight: 600; }
.rrow .rhint { color: var(--fg-muted); font-size: 11px; }
.result-note { color: var(--fg-muted); font-size: 12px; margin-top: 12px; text-wrap: pretty; }
.result-note.warn { color: var(--accent); }
.result-note.good { color: var(--ok); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 14px 0 0; }
.btn { background: var(--hl); color: var(--bg); border: 1px solid var(--hl); font: inherit; font-size: 12px; font-weight: 600; padding: 7px 13px; border-radius: 4px; cursor: pointer; }
.btn:hover { background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--fg-dim); border-color: var(--rule); }
.btn.ghost:hover { color: var(--hl); border-color: var(--hl); background: transparent; }

.prose { margin-top: 52px; border-top: 1px solid var(--rule); padding-top: 30px; }
.prose h2 { font-size: 18px; margin: 28px 0 10px; color: var(--fg); }
.prose h3 { font-size: 14px; margin: 20px 0 6px; color: var(--hl); }
.prose p { color: var(--fg-dim); margin: 0 0 12px; max-width: 680px; text-wrap: pretty; }
.prose ol, .prose ul { color: var(--fg-dim); max-width: 680px; padding-left: 22px; }
.prose li { margin-bottom: 6px; }
.prose code { background: var(--bg-3); padding: 1px 5px; border-radius: 3px; font-size: 13px; color: var(--fg); }
.formula { background: var(--bg-2); border: 1px solid var(--rule); border-left: 2px solid var(--hl); border-radius: 4px; padding: 12px 14px; color: var(--fg); font-size: 13px; margin: 0 0 12px; max-width: 680px; overflow-x: auto; }

.affiliate { margin-top: 28px; border: 1px solid var(--rule); border-left: 2px solid var(--fg-muted); border-radius: 4px; background: var(--bg-2); padding: 14px 16px; }
.affiliate .atitle { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-muted); margin-bottom: 8px; }
.affiliate .disc { color: var(--fg-muted); font-size: 11px; margin-top: 10px; }
.affiliate ul { margin: 0; padding-left: 18px; }

.related { margin-top: 40px; }
.related h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-muted); margin-bottom: 12px; }
.related .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.related a { display: block; border: 1px solid var(--rule); border-left: 2px solid var(--hl); border-radius: 3px; background: var(--bg-2); padding: 10px 12px; color: var(--fg); font-size: 12px; }
.related a:hover { background: var(--bg-3); border-color: var(--hl); }
.related a .t { font-weight: 600; }
.related a .d { color: var(--fg-muted); font-size: 11px; }

footer { border-top: 1px solid var(--rule); margin-top: 48px; padding-top: 20px; color: var(--fg-muted); font-size: 12px; }
footer a { color: var(--fg-dim); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin: 8px 0 0; }
.cards a { display: block; border: 1px solid var(--rule); border-left: 2px solid var(--hl); border-radius: 4px; background: var(--bg-2); padding: 14px 16px; color: var(--fg); }
.cards a:hover { background: var(--bg-3); border-color: var(--hl); }
.cards a .ct { font-weight: 700; font-size: 14px; }
.cards a .cd { color: var(--fg-dim); font-size: 12px; margin-top: 4px; }
.group-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-muted); margin: 30px 0 4px; }

@media (max-width: 560px) {
  .field { grid-template-columns: 1fr; align-items: start; gap: 5px; }
  .field .inputwrap, .field input { width: 100%; }
  .field input { text-align: left; }
}
footer .dot { opacity: .6; }
.nf { max-width: 640px; margin: 0 auto; padding: 80px 20px; text-align: center; }
.nf .code { color: var(--hl); font-size: 56px; font-weight: 700; letter-spacing: -0.02em; }
.nf p { color: var(--fg-dim); margin: 10px 0 24px; }
.nf .cards { text-align: left; }
:root { --cell: var(--bg-2); --cell-head: var(--bg-3); --input-cell: #d8992f1f; --target: #d8992f; --grid: #3a3138; }
html[data-theme="light"] { --cell: #ffffff; --cell-head: #f1eee7; --input-cell: #f6e7b8; --target: #8b2e1f; --grid: #ddd7cc; }

@media (max-width: 480px) { .wrap { padding: 0 16px 64px; } header .bar { padding: 12px 16px; } }
header .sep { color: var(--fg-muted); font-size: 12px; }
header a.crumb { border: none; color: var(--fg-dim); font-size: 12px; }
header a.crumb:hover { color: var(--hl); }
.group-label a { color: inherit; border: none; }
.group-label { font-weight: 400; }
.cards a .cm { color: var(--fg-muted); font-size: 11px; margin-top: 6px; }

.lesson h1 { margin-bottom: 14px; }
.answer { border-left: 3px solid var(--hl); background: var(--bg-2); border-radius: 0 5px 5px 0; padding: 12px 16px; max-width: 680px; }
.answer p { margin: 0; color: var(--fg); text-wrap: pretty; }
.answer code, .args code, .tp code, .status code, .finished code { background: var(--bg-3); padding: 1px 5px; border-radius: 3px; font-size: 13px; color: var(--fg); }
.syntax { margin: 22px 0 0; max-width: 680px; }
.syntax .formula { white-space: pre-wrap; word-break: break-word; }
.args { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.args dt { margin: 0; }
.args dd { margin: 0; color: var(--fg-dim); text-wrap: pretty; }
@media (max-width: 560px) { .args { grid-template-columns: 1fr; gap: 2px; } .args dd { margin-bottom: 8px; } }
.prose pre.formula { white-space: pre-wrap; word-break: break-word; }
.prose.explain { margin-top: 36px; }

.practice { margin-top: 44px; border-top: 1px solid var(--rule); padding-top: 26px; }
.practice h2 { font-size: 18px; margin: 0 0 8px; }
.practice .hint { color: var(--fg-dim); font-size: 13px; margin: 0 0 16px; max-width: 680px; text-wrap: pretty; }

.ws { border: 1px solid var(--rule); border-radius: 6px; background: var(--bg-2); overflow: hidden; }
html[data-theme="light"] .ws { box-shadow: 0 1px 2px #1a1a1a12, 0 2px 6px #1a1a1a0a; }
.fbar { display: flex; align-items: stretch; border-bottom: 1px solid var(--rule); background: var(--bg-3); }
.namebox { flex: none; width: 58px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--fg-dim); border-right: 1px solid var(--rule); }
.fxl { flex: none; display: flex; align-items: center; padding: 0 10px; font-style: italic; color: var(--hl); font-size: 13px; border-right: 1px solid var(--rule); }
.fin { flex: 1; min-width: 0; font: inherit; font-size: 14px; color: var(--fg); background: var(--field); border: none; padding: 9px 10px; outline: none; }
.fin:focus { box-shadow: inset 0 -2px 0 var(--hl); }
.fin:disabled { color: var(--fg-muted); }
.ws[data-state="failed"] .fin::placeholder { color: var(--accent); }
.gridwrap { overflow-x: auto; overscroll-behavior-x: contain; outline: none; background: var(--cell); }
.gridwrap:focus-visible { box-shadow: inset 0 0 0 2px var(--hl); }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: 13px; line-height: 1.2; }
table.sheet.live { table-layout: fixed; width: max-content; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
table.sheet th { background: var(--cell-head); color: var(--fg-muted); font-weight: 400; font-size: 11px; padding: 4px 6px; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); text-align: center; position: sticky; z-index: 1; }
table.sheet thead th { top: 0; }
table.sheet tbody th { left: 0; min-width: 34px; }
table.sheet th.corner { left: 0; z-index: 2; }
table.sheet td { height: 28px; padding: 0 6px; min-width: 64px; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); color: var(--fg); position: relative; cursor: cell; }
table.sheet.live td { max-width: none; }
table.sheet td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.sheet td.bool { text-align: center; }
table.sheet td.err { color: var(--accent); text-align: center; }
table.sheet td.head { font-weight: 700; background: var(--cell-head); }
table.sheet td.input { background: var(--input-cell); }
table.sheet td.target { box-shadow: inset 0 0 0 1px var(--target); }
table.sheet td.target::before { content: attr(data-badge); position: absolute; top: 1px; left: 2px; font-size: 9px; line-height: 1; color: var(--target); font-weight: 700; }
table.sheet td.target.done { box-shadow: inset 0 0 0 1px var(--ok); }
table.sheet td.target.done::before { color: var(--ok); }
table.sheet td.fillout { background: var(--cell-head); color: var(--fg-dim); }
table.sheet td.pick { background: var(--selection); }
table.sheet td.sel { box-shadow: inset 0 0 0 2px var(--hl); }
.ws.editing table.sheet td.sel { box-shadow: inset 0 0 0 2px var(--hl), inset 0 0 0 4px var(--selection); }
.wsbar { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-top: 1px solid var(--rule); font-size: 12px; color: var(--fg-dim); flex-wrap: wrap; }
.wsbar .note { flex: 1; color: var(--fg-muted); min-width: 0; }
.wsbar .reset { margin-left: auto; }

.tasks { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 10px; }
.task { border: 1px solid var(--rule); border-left: 3px solid var(--rule); border-radius: 4px; background: var(--bg-2); padding: 12px 14px; }
.task.current { border-left-color: var(--hl); }
.task.solved { border-left-color: var(--ok); }
.tq { display: flex; gap: 12px; align-items: flex-start; }
.tn { flex: none; width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: var(--bg); background: var(--fg-muted); margin-top: 1px; }
.task.current .tn { background: var(--hl); }
.task.solved .tn { background: var(--ok); }
.tp { color: var(--fg); font-size: 13px; text-wrap: pretty; }
.status { font-size: 13px; margin: 8px 0 0 34px; text-wrap: pretty; }
.status:empty { display: none; }
.task.pass .status { color: var(--ok); }
.task.wrong .status { color: var(--accent); }
.task.almost .status { color: var(--hl); }
.tactions { display: flex; align-items: baseline; gap: 14px; margin: 10px 0 0 34px; flex-wrap: wrap; }
.tactions .btn { font-size: 11px; padding: 4px 9px; }
.reveal { font-size: 12px; color: var(--fg-muted); }
.reveal summary { cursor: pointer; }
.reveal summary:hover { color: var(--hl); }
.reveal code { display: inline-block; margin-top: 6px; background: var(--bg-3); padding: 3px 7px; border-radius: 3px; color: var(--fg); font-size: 13px; word-break: break-all; }
.finished { margin-top: 16px; border: 1px solid var(--ok); border-left: 3px solid var(--ok); border-radius: 4px; padding: 12px 14px; color: var(--ok); background: var(--bg-2); }
.finished a { color: var(--ok); border-color: var(--ok); }
.prose.errors, .prose.faq { margin-top: 44px; }
.faq h3 { color: var(--fg); }
footer { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between; }
@media (prefers-reduced-motion: no-preference) { .task.just { animation: pop .5s ease-out; } @keyframes pop { from { background: var(--input-cell); } to { background: var(--bg-2); } } }
