/* ==========================================================================
   Components
   ========================================================================== */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 15px; border-radius: 9px; border: 1px solid transparent;
  font-size: var(--fs-small); font-weight: 560; letter-spacing: -0.004em;
  color: var(--ink); background: var(--surface-2); white-space: nowrap;
  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);
}
.btn:hover { text-decoration: none; background: var(--surface-sunk); }
.btn:active { transform: scale(.97); }
.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: 42px; padding: 0 20px; font-size: var(--fs-body); }
.btn-sm { height: 27px; padding: 0 10px; font-size: var(--fs-fine); }
.btn[disabled] { opacity: .4; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--surface-sunk); border-radius: 9px; border: 1px solid var(--line); max-width: 100%; overflow-x: auto; }
.seg button { padding: 5px 11px; border-radius: 7px; font-size: var(--fs-fine); font-weight: 520; color: var(--ink-3); white-space: nowrap; transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--lift-1); }

.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: 40px; height: 24px; 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: 18px; height: 18px; border-radius: 99px; background: var(--surface); box-shadow: var(--lift-1); transition: transform var(--t-mid) var(--ease); }
.switch input:checked + .track { background: var(--accent); border-color: transparent; }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; 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: 16px; height: 16px; margin-top: -7px; 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: 16px; height: 16px; border-radius: 99px; background: var(--surface); box-shadow: var(--lift-2); border: .5px solid var(--line-2); }

.field {
  width: 100%; height: 34px; padding: 0 11px;
  border: 1px solid var(--line-2); border-radius: 9px;
  background: var(--surface); color: var(--ink); outline: none; font-size: var(--fs-small);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.mono { font-family: var(--mono); }
textarea.field { height: auto; min-height: 90px; padding: 9px 11px; resize: vertical; line-height: 1.55; }

/* ---------- pills, badges ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--fs-micro); font-weight: 650; letter-spacing: .015em;
  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; }

/* complexity badge — colour grades difficulty consistently everywhere */
.cx {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: var(--mono); font-size: var(--fs-micro); font-weight: 650;
  padding: 2px 7px; border-radius: 5px; white-space: nowrap;
  border: 1px solid currentColor; background: transparent;
}
.cx[data-g="1"]  { color: var(--cx-1); }
.cx[data-g="lg"] { color: var(--cx-lg); }
.cx[data-g="n"]  { color: var(--cx-n); }
.cx[data-g="nl"] { color: var(--cx-nl); }
.cx[data-g="n2"] { color: var(--cx-n2); }
.cx[data-g="ex"] { color: var(--cx-ex); }
.cx-pair { display: inline-flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.cx-lbl { font-size: var(--fs-micro); color: var(--ink-4); text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }

.diff { font-size: var(--fs-micro); font-weight: 680; letter-spacing: .05em; text-transform: uppercase; }
.diff[data-d="easy"] { color: var(--good-text); }
.diff[data-d="medium"] { color: var(--warn-text); }
.diff[data-d="hard"] { color: var(--bad-text); }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 16px; display: flex; flex-direction: column; gap: 8px; min-width: 0;
  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.014em; }
.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: 7px; flex-wrap: wrap; min-width: 0; }
.card-foot > * { min-width: 0; }

.tcard { position: relative; padding-left: 19px; }
.tcard::before {
  content: ""; position: absolute; left: 0; top: 13px; bottom: 13px; width: 3px;
  border-radius: 99px; background: var(--hue, var(--accent)); opacity: .7;
  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: 7px; bottom: 7px; }
.tcard .tcard-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tcard .tcard-track { font-size: var(--fs-micro); font-weight: 680; 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); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcard .tcard-mins { margin-left: auto; font-size: var(--fs-micro); color: var(--ink-4); font-variant-numeric: tabular-nums; flex: none; }

.tick { width: 15px; height: 15px; 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: 7px; height: 4px; 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 / blocks ---------- */
.prose { max-width: var(--measure); font-size: var(--fs-read); line-height: 1.62; color: var(--ink-2); }
.prose > * + * { margin-top: 1.05em; }
.prose strong { color: var(--ink); font-weight: 620; }
.prose code { background: var(--surface-2); padding: .12em .38em; border-radius: 5px; border: 1px solid var(--line); color: var(--ink); }

.kv { display: grid; 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(110px, 26%) 1fr; gap: 14px; padding: 11px 14px; 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: 620; margin: 0; }
.kv-row dd { color: var(--ink-3); margin: 0; min-width: 0; }
@media (max-width: 560px) { .kv-row { grid-template-columns: 1fr; gap: 3px; } }

.note {
  max-width: var(--measure); border-radius: var(--r-md); padding: 14px 16px;
  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: 720; 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-signal { border-left-color: var(--st-frontier); background: var(--st-frontier-soft); border-color: transparent; }
.note-signal .note-t { color: var(--st-frontier); color: oklch(from var(--st-frontier) min(l, calc(var(--text-lmax) - 0.04)) c h); }

.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: 440px; }
table.t th, table.t td { text-align: left; padding: 10px 13px; 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: 650; font-size: var(--fs-fine); position: sticky; top: 0; }
table.t td { color: var(--ink-2); }
table.t td:first-child { color: var(--ink); font-weight: 560; }
table.t tbody tr:hover td { background: var(--surface-2); }
table.t 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: 14px 16px; font-size: var(--fs-small); line-height: 1.6; 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: 650; }
.tok-k { color: var(--code-k); font-weight: 560; }
.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 { max-width: var(--measure); counter-reset: st; display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.step { position: relative; padding: 0 0 18px 32px; 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: 680; 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); }

.tradeoff { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr)); }
.to-card { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); padding: 14px 15px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.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 { position: relative; padding-left: 18px; color: var(--ink-2); min-width: 0; overflow-wrap: anywhere; }
.to-line::before { content: "+"; position: absolute; left: 0; top: 0; color: var(--good-text); font-weight: 700; font-family: var(--mono); }
.to-line[data-neg]::before { content: "−"; color: var(--bad); }
.to-use { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--line); font-size: var(--fs-fine); color: var(--ink-3); }
.to-use b { color: var(--ink); font-weight: 620; }

.quiz { max-width: var(--measure); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); padding: 16px; display: flex; flex-direction: column; gap: 11px; }
.quiz-q { font-size: var(--fs-body); color: var(--ink); font-weight: 560; }
.quiz-opts { display: flex; flex-direction: column; gap: 7px; }
.quiz-opt { text-align: left; padding: 10px 12px; 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; }

.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: 18px 14px; 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); }
.d-fill { fill: var(--surface-2); } .d-fill-2 { fill: var(--surface-sunk); }
.d-stroke { stroke: var(--line-strong); fill: none; }
.d-text { fill: var(--ink); font-family: var(--sans); font-size: 12px; font-weight: 560; }
.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; }

.ring { --p: 0; width: 32px; height: 32px; 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: 680; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.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 { text-align: center; padding: clamp(32px, 6vw, 64px) 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); }

.chip {
  padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-3); font-size: var(--fs-fine); font-weight: 520;
  transition: all var(--t-fast) var(--ease); white-space: nowrap;
}
.chip:hover { color: var(--ink); border-color: var(--line-2); }
.chip[aria-pressed="true"] { background: var(--hue, var(--ink)); color: var(--ground); border-color: transparent; }
