/* ==========================================================================
   Components: controls, cards, prose blocks, tables, diagrams
   ========================================================================== */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 16px;
  border-radius: 99px; border: 1px solid transparent;
  font-size: var(--fs-small); font-weight: 550; letter-spacing: -0.005em;
  color: var(--ink); background: var(--surface-2);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease), opacity var(--t-fast) var(--ease);
  white-space: nowrap;
}
.btn:hover { text-decoration: none; background: var(--surface-sunk); }
.btn:active { transform: scale(.972); }
.btn svg { width: 15px; height: 15px; flex: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line-2); color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-lg { height: 44px; padding: 0 22px; font-size: var(--fs-body); }
.btn-sm { height: 28px; padding: 0 11px; font-size: var(--fs-fine); }
.btn[disabled] { opacity: .4; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

/* segmented control (Apple-style) */
.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--surface-sunk); border-radius: 9px; border: 1px solid var(--line); }
.seg button {
  padding: 5px 12px; border-radius: 7px; font-size: var(--fs-fine); font-weight: 500;
  color: var(--ink-3); transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
  white-space: nowrap;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--lift-1); }

/* switch */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: var(--fs-small); color: var(--ink-2); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 42px; height: 25px; border-radius: 99px; background: var(--surface-sunk); border: 1px solid var(--line-2); position: relative; transition: background var(--t-mid) var(--ease), border-color var(--t-mid) var(--ease); flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 99px; background: var(--surface); box-shadow: var(--lift-1); transition: transform var(--t-mid) var(--ease); }
.switch input:checked + .track { background: var(--good); border-color: transparent; }
.switch input:checked + .track::after { transform: translateX(17px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* range */
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: none; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 99px; background: var(--surface-sunk); border: 1px solid var(--line); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -8px; border-radius: 99px; background: var(--surface); box-shadow: var(--lift-2); border: .5px solid var(--line-2); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 99px; background: var(--surface-sunk); border: 1px solid var(--line); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 99px; background: var(--surface); box-shadow: var(--lift-2); border: .5px solid var(--line-2); }

/* text inputs */
.field {
  width: 100%; height: 36px; padding: 0 12px;
  border: 1px solid var(--line-2); border-radius: 9px;
  background: var(--surface); color: var(--ink); outline: none;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  font-size: var(--fs-small);
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.field { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.55; }

/* ---------- pills & chips ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-micro); font-weight: 600; letter-spacing: .02em;
  padding: 3px 9px; border-radius: 99px;
  background: var(--surface-2); color: var(--ink-3); border: 1px solid var(--line);
  white-space: nowrap;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.pill-dot { width: 6px; height: 6px; border-radius: 99px; background: currentColor; flex: none; }
.pill-hue { color: var(--hue); color: oklch(from var(--hue) min(l, var(--text-lmax)) c h); }
.pill-good { color: var(--good-text); background: var(--good-soft); border-color: transparent; }
.pill-warn { color: var(--warn-text); background: var(--warn-soft); border-color: transparent; }
.pill-bad  { color: var(--bad-text); background: var(--bad-soft);  border-color: transparent; }
.pill-accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

.lv { font-size: var(--fs-micro); font-weight: 600; color: var(--ink-4); letter-spacing: .05em; text-transform: uppercase; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px;
  display: flex; flex-direction: column; gap: 8px;
  transition: transform var(--t-mid) var(--ease), border-color var(--t-mid) var(--ease), box-shadow var(--t-mid) var(--ease);
}
a.card { color: inherit; }
a.card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--line-2); box-shadow: var(--lift-2); }
.card h3, .card .card-t { font-size: var(--fs-read); letter-spacing: -0.015em; }
.card p { color: var(--ink-3); font-size: var(--fs-small); }
.card-foot { margin-top: auto; padding-top: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.card-foot > * { min-width: 0; }

/* topic card gets a hue rail keyed to its track */
.tcard { position: relative; padding-left: 20px; }
.tcard::before {
  content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px;
  border-radius: 99px; background: var(--hue, var(--accent)); opacity: .65;
  transition: opacity var(--t-mid) var(--ease), top var(--t-mid) var(--ease), bottom var(--t-mid) var(--ease);
}
a.tcard:hover::before { opacity: 1; top: 8px; bottom: 8px; }
.tcard .tcard-top { display: flex; align-items: center; gap: 8px; }
.tcard .tcard-track { font-size: var(--fs-micro); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--hue, var(--accent)); color: oklch(from var(--hue, var(--accent)) min(l, var(--text-lmax)) c h); }
.tcard .tcard-mins { margin-left: auto; font-size: var(--fs-micro); color: var(--ink-4); font-variant-numeric: tabular-nums; }

/* status tick */
.tick { width: 16px; height: 16px; border-radius: 99px; border: 1.5px solid var(--line-2); flex: none; display: grid; place-items: center; }
.tick[data-s="done"] { background: var(--good); border-color: var(--good); }
.tick[data-s="done"]::after { content: ""; width: 8px; height: 4.5px; border-left: 1.7px solid #fff; border-bottom: 1.7px solid #fff; transform: rotate(-45deg) translate(.5px, -1px); }
.tick[data-s="doing"] { border-color: var(--warn); box-shadow: inset 0 0 0 3px var(--warn-soft); }

/* ---------- prose ---------- */
.prose { max-width: var(--measure); font-size: var(--fs-read); line-height: 1.62; color: var(--ink-2); }
.prose > * + * { margin-top: 1.1em; }
.prose h2 { color: var(--ink); margin-top: 2em; font-size: var(--fs-h2); }
.prose h3 { color: var(--ink); margin-top: 1.7em; font-size: var(--fs-h3); }
.prose h4 { color: var(--ink); margin-top: 1.5em; font-size: var(--fs-read); font-weight: 600; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose em { font-style: italic; }
.prose a { text-decoration: underline; text-decoration-color: var(--accent-line); text-underline-offset: 2.5px; }
.prose code { background: var(--surface-2); padding: .12em .38em; border-radius: 5px; border: 1px solid var(--line); color: var(--ink); }
.prose ul, .prose ol { margin-left: 0; padding-left: 1.25em; display: flex; flex-direction: column; gap: .5em; }
.prose li::marker { color: var(--ink-4); }
.prose li > strong:first-child { color: var(--ink); }

/* key-value definition rows */
.kv { display: grid; gap: 0; border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; background: var(--surface); max-width: var(--measure); }
.kv-row { display: grid; grid-template-columns: minmax(120px, 26%) 1fr; gap: 14px; padding: 12px 15px; border-top: 1px solid var(--line); font-size: var(--fs-body); }
.kv-row:first-child { border-top: 0; }
.kv-row dt { color: var(--ink); font-weight: 600; margin: 0; }
.kv-row dd { color: var(--ink-3); margin: 0; }
@media (max-width: 560px) { .kv-row { grid-template-columns: 1fr; gap: 3px; } }

/* callouts */
.note {
  max-width: var(--measure);
  border-radius: var(--r-md);
  padding: 15px 17px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink-4);
  font-size: var(--fs-body);
  color: var(--ink-2);
  display: flex; flex-direction: column; gap: 5px;
}
.note-t { font-size: var(--fs-micro); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4); }
.note-insight { border-left-color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.note-insight .note-t { color: var(--accent); }
.note-pitfall { border-left-color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.note-pitfall .note-t { color: var(--bad-text); }
.note-warn { border-left-color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.note-warn .note-t { color: var(--warn-text); }
.note-principle {
  border: 1px solid var(--line); border-left: 3px solid var(--ink);
  background: var(--surface);
  font-family: var(--serif); font-size: 1.12rem; line-height: 1.5; color: var(--ink);
  letter-spacing: -0.008em;
}
.note-principle .note-t { font-family: var(--sans); color: var(--ink-4); }

/* tables */
.table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
table.t { width: 100%; border-collapse: collapse; font-size: var(--fs-small); min-width: 460px; }
table.t th, table.t td { text-align: left; padding: 11px 14px; border-top: 1px solid var(--line); vertical-align: top; }
table.t thead th, table.t thead td { border-top: 0; background: var(--surface-2); color: var(--ink-3); font-weight: 600; font-size: var(--fs-fine); letter-spacing: .015em; position: sticky; top: 0; }
table.t td { color: var(--ink-2); }
table.t td:first-child { color: var(--ink); font-weight: 550; }
table.t tbody tr:hover td { background: var(--surface-2); }
table.t td code { font-size: .86em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }

/* code */
.code {
  max-width: 100%; overflow-x: auto;
  background: var(--surface-sunk);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 15px 17px;
  font-size: var(--fs-small); line-height: 1.62;
  color: var(--ink-2);
  -webkit-overflow-scrolling: touch;
}
.code pre { margin: 0; white-space: pre; font-family: var(--mono); }
.code-head { display: flex; align-items: center; gap: 8px; margin: 0 0 -6px; }
.code-lang { font-size: var(--fs-micro); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-4); font-weight: 600; }
.tok-k { color: var(--code-k); font-weight: 550; }
.tok-s { color: var(--code-s); }
.tok-c { color: var(--code-c); font-style: italic; }
.tok-n { color: var(--code-n); }
.tok-f { color: var(--accent); }

/* steps */
.steps { max-width: var(--measure); counter-reset: st; display: flex; flex-direction: column; gap: 0; border-left: 1px solid var(--line); padding-left: 0; }
.step { position: relative; padding: 0 0 20px 34px; counter-increment: st; }
.step:last-child { padding-bottom: 0; }
.step::before {
  content: counter(st);
  position: absolute; left: -12px; top: 0;
  width: 23px; height: 23px; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line-2);
  color: var(--ink-3); font-size: var(--fs-micro); font-weight: 650;
  display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.step .step-t { font-size: var(--fs-body); color: var(--ink); margin-bottom: 3px; }
.step p { color: var(--ink-3); font-size: var(--fs-body); }

/* trade-off blocks */
.tradeoff { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.to-card { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); padding: 15px 16px; display: flex; flex-direction: column; gap: 9px; }
.to-card .to-t { font-size: var(--fs-body); }
.to-list { display: flex; flex-direction: column; gap: 5px; font-size: var(--fs-small); }
.to-line { display: flex; gap: 8px; color: var(--ink-2); }
.to-line::before { content: "+"; color: var(--good-text); font-weight: 700; flex: none; width: 10px; font-family: var(--mono); }
.to-line[data-neg]::before { content: "−"; color: var(--bad); }
.to-use { margin-top: auto; padding-top: 9px; border-top: 1px solid var(--line); font-size: var(--fs-fine); color: var(--ink-3); }
.to-use b { color: var(--ink); font-weight: 600; }

/* number strip */
.numbers { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.num { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); padding: 14px 15px; display: flex; flex-direction: column; gap: 2px; }
.num-v { font-size: 1.45rem; font-weight: 600; letter-spacing: -0.03em; color: var(--ink); font-variant-numeric: tabular-nums; font-family: var(--mono); }
.num-l { font-size: var(--fs-fine); color: var(--ink-3); }
.num-n { font-size: var(--fs-micro); color: var(--ink-4); margin-top: 3px; }

/* figure / diagram */
.fig { max-width: 100%; margin: 0; display: flex; flex-direction: column; gap: 9px; }
.fig-box {
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); padding: 20px 16px;
  overflow-x: auto;
}
.fig-box svg { display: block; margin: 0 auto; height: auto; max-width: 100%; }
.fig figcaption { font-size: var(--fs-fine); color: var(--ink-3); max-width: var(--measure); }
.fig figcaption b { color: var(--ink-2); font-weight: 600; }
/* diagram primitives used by inline svg */
.d-fill { fill: var(--surface-2); }
.d-fill-2 { fill: var(--surface-sunk); }
.d-stroke { stroke: var(--line-strong); fill: none; }
.d-line { stroke: var(--ink-4); fill: none; }
.d-text { fill: var(--ink); font-family: var(--sans); font-size: 12px; font-weight: 550; }
.d-sub { fill: var(--ink-3); font-family: var(--sans); font-size: 10.5px; }
.d-mono { fill: var(--ink-3); font-family: var(--mono); font-size: 10px; }
.d-accent { fill: var(--accent); }
.d-accent-s { stroke: var(--accent); fill: none; }
.d-good { fill: var(--good); } .d-good-s { stroke: var(--good); fill: none; }
.d-bad { fill: var(--bad); } .d-bad-s { stroke: var(--bad); fill: none; }
.d-warn { fill: var(--warn); } .d-warn-s { stroke: var(--warn); fill: none; }

/* quiz */
.quiz { max-width: var(--measure); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); padding: 17px; display: flex; flex-direction: column; gap: 11px; }
.quiz-q { font-size: var(--fs-body); color: var(--ink); font-weight: 550; }
.quiz-opts { display: flex; flex-direction: column; gap: 7px; }
.quiz-opt {
  text-align: left; padding: 10px 13px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
  font-size: var(--fs-small);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.quiz-opt:hover { border-color: var(--line-2); }
.quiz-opt:active { transform: scale(.99); }
.quiz-opt[data-r="ok"] { border-color: var(--good); background: var(--good-soft); color: var(--ink); }
.quiz-opt[data-r="no"] { border-color: var(--bad); background: var(--bad-soft); color: var(--ink); }
.quiz-why { font-size: var(--fs-small); color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 11px; }

/* progress ring */
.ring { --p: 0; width: 34px; height: 34px; flex: none; display: grid; place-items: center; position: relative; }
.ring::before {
  content: ""; position: absolute; inset: 0; border-radius: 99px;
  background: conic-gradient(var(--hue, var(--accent)) calc(var(--p) * 1%), var(--surface-sunk) 0);
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 61%);
  mask: radial-gradient(circle, transparent 60%, #000 61%);
  transition: background var(--t-slow) var(--ease);
}
.ring span { font-size: var(--fs-micro); font-weight: 650; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* bar meter */
.meter { height: 5px; border-radius: 99px; background: var(--surface-sunk); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--hue, var(--accent)); border-radius: 99px; transition: width var(--t-slow) var(--ease); }

/* empty states */
.empty { text-align: center; padding: clamp(36px, 7vw, 72px) 20px; color: var(--ink-3); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty h1, .empty h2 { color: var(--ink); font-size: var(--fs-h3); letter-spacing: -0.01em; }
.empty p { max-width: 42ch; font-size: var(--fs-body); }
