/* ==========================================================================
   Family medicine exam prep: components
   Requires tokens.css. Every class is prefixed .ds- so it can be dropped into
   an existing site without overriding existing styles. Nothing here styles
   bare elements (no resets), so adopt it page by page.

   Icons: use inline SVG with class="ds-icon" (stroke-based, 24px viewBox).
   ========================================================================== */

.ds-icon { width: 1em; height: 1em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ds-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:where([class^="ds-"], [class*=" ds-"]):focus-visible { outline: 2px solid var(--ds-brand); outline-offset: 2px; }

/* Page helpers ------------------------------------------------------------ */
.ds-page { background: var(--ds-bg); color: var(--ds-ink); font: 400 var(--ds-text-md)/var(--ds-leading-ui) var(--ds-font-sans); }
.ds-wrap { max-width: var(--ds-page-max); margin: 0 auto; padding: 0 var(--ds-space-5); }
.ds-h1 { font-size: var(--ds-text-2xl); line-height: var(--ds-leading-tight); letter-spacing: -0.02em; font-weight: 700; margin: 0; }
.ds-h2 { font-size: var(--ds-text-xl); line-height: 1.2; letter-spacing: -0.015em; font-weight: 700; margin: 0; }
.ds-h3 { font-size: 1.15rem; letter-spacing: -0.01em; font-weight: 700; margin: 0; }
.ds-muted { color: var(--ds-ink-2); }

/* Buttons ----------------------------------------------------------------- */
.ds-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--ds-tap); padding: 0 18px; border-radius: var(--ds-r-control); border: 1px solid transparent; font: 600 var(--ds-text-md)/1 var(--ds-font-sans); background: var(--ds-brand); color: var(--ds-on-brand); cursor: pointer; text-decoration: none; transition: background var(--ds-fast); }
.ds-btn:hover { background: var(--ds-brand-hover); }
.ds-btn--secondary { background: var(--ds-surface); color: var(--ds-ink); border-color: var(--ds-line); }
.ds-btn--secondary:hover { background: var(--ds-surface-2); }
.ds-btn--quiet { background: transparent; color: var(--ds-brand); }
.ds-btn--quiet:hover { background: var(--ds-brand-tint); }
.ds-btn--danger { background: var(--ds-bad-tint); color: var(--ds-bad); }
.ds-btn--danger:hover { background: var(--ds-bad-tint); filter: brightness(0.96); }
.ds-btn--sm { min-height: 36px; padding: 0 12px; font-size: var(--ds-text-sm); border-radius: var(--ds-r-small); }
.ds-btn[disabled], .ds-btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.ds-btn.is-loading::before { content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: ds-spin 0.8s linear infinite; }
@keyframes ds-spin { to { transform: rotate(360deg); } }
.ds-icon-btn { width: var(--ds-tap); height: var(--ds-tap); display: inline-grid; place-items: center; border-radius: var(--ds-r-control); border: 1px solid var(--ds-line); background: var(--ds-surface); color: var(--ds-ink); font-size: 1.1rem; cursor: pointer; }
.ds-icon-btn:hover { background: var(--ds-surface-2); }

/* Badges, chips, segmented control ---------------------------------------- */
.ds-badge { display: inline-flex; align-items: center; gap: 6px; font-size: var(--ds-text-xs); font-weight: 600; padding: 3px 9px; border-radius: 6px; background: var(--ds-surface-2); color: var(--ds-ink-2); }
.ds-badge--brand { background: var(--ds-brand-tint); color: var(--ds-brand); }
.ds-badge--ok { background: var(--ds-ok-tint); color: var(--ds-ok); }
.ds-badge--warn { background: var(--ds-warn-tint); color: var(--ds-warn); }
.ds-badge--bad { background: var(--ds-bad-tint); color: var(--ds-bad); }

.ds-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: var(--ds-r-pill); border: 1px solid var(--ds-line); background: var(--ds-surface); color: var(--ds-ink); font: 500 0.92rem/1 var(--ds-font-sans); cursor: pointer; }
.ds-chip[aria-pressed="true"] { background: var(--ds-brand-tint); border-color: var(--ds-brand); color: var(--ds-brand); }

.ds-seg { display: inline-flex; gap: 2px; padding: 3px; max-width: 100%; border-radius: var(--ds-r-option); background: var(--ds-surface-2); }
.ds-seg button { border: 0; background: transparent; min-height: 36px; padding: 6px 14px; border-radius: 9px; font: 600 0.92rem/1.2 var(--ds-font-sans); color: var(--ds-ink-2); cursor: pointer; }
.ds-seg button[aria-pressed="true"] { background: var(--ds-surface); color: var(--ds-ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14); }

/* Surfaces ---------------------------------------------------------------- */
.ds-panel { background: var(--ds-surface); border: 1px solid var(--ds-line); border-radius: var(--ds-r-panel); padding: var(--ds-space-6); }
.ds-panel--tinted { background: var(--ds-brand-tint); border-color: transparent; border-radius: var(--ds-r-card); padding: var(--ds-space-5); }
.ds-panel--inverse { background: var(--ds-ink); color: var(--ds-bg); border-color: transparent; }
.ds-progress { height: 8px; border-radius: var(--ds-r-pill); background: color-mix(in srgb, var(--ds-brand) 18%, transparent); overflow: hidden; }
.ds-progress > span { display: block; height: 100%; background: var(--ds-brand); border-radius: inherit; }

/* Form controls ----------------------------------------------------------- */
.ds-field { display: grid; gap: 6px; }
.ds-label { font-weight: 600; font-size: 0.95rem; }
.ds-hint { color: var(--ds-ink-2); font-size: 0.86rem; }
.ds-input, .ds-select, .ds-textarea { width: 100%; min-height: var(--ds-tap); padding: 0 12px; border-radius: var(--ds-r-control); border: 1.5px solid var(--ds-line); background: var(--ds-surface); color: var(--ds-ink); font: inherit; }
.ds-textarea { padding: 14px 16px; min-height: 140px; resize: vertical; background: var(--ds-bg); border-radius: var(--ds-r-option); }
.ds-textarea--serif { font-family: var(--ds-font-serif); font-size: 1.02rem; line-height: 1.6; }
.ds-input:focus, .ds-select:focus, .ds-textarea:focus { outline: none; border-color: var(--ds-brand); box-shadow: 0 0 0 3px var(--ds-brand-tint); }
.ds-range { width: 100%; accent-color: var(--ds-brand); height: 28px; }
.ds-switch { width: 50px; height: 30px; border-radius: var(--ds-r-pill); border: 0; background: var(--ds-line); position: relative; flex: none; cursor: pointer; transition: background var(--ds-fast); }
.ds-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transition: transform var(--ds-fast); }
.ds-switch[aria-checked="true"] { background: var(--ds-brand); }
.ds-switch[aria-checked="true"]::after { transform: translateX(20px); }

/* Question bank ----------------------------------------------------------- */
.ds-question { background: var(--ds-surface); border: 1px solid var(--ds-line); border-radius: var(--ds-r-panel); overflow: hidden; }
.ds-question__bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--ds-space-3); padding: 12px 16px 12px 22px; border-bottom: 1px solid var(--ds-line); }
.ds-question__progress { height: 3px; background: var(--ds-surface-2); }
.ds-question__progress > span { display: block; height: 100%; background: var(--ds-brand); }
.ds-question__body { padding: 24px 22px 8px; }
.ds-question__foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 14px; padding: 18px 22px 22px; }

.ds-stem { font-family: var(--ds-font-serif); font-size: var(--ds-text-lg); line-height: var(--ds-leading-reading); max-width: var(--ds-measure); margin: 0; }
.ds-ask { font-family: var(--ds-font-serif); font-weight: 600; font-size: var(--ds-text-lg); margin: 0 0 16px; }

/* Vitals and lab results: <dl class="ds-labs"><div><dt>..</dt><dd>..</dd></div></dl> */
.ds-labs { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); background: var(--ds-surface); outline: 1px solid var(--ds-line); outline-offset: -1px; border-radius: var(--ds-r-option); overflow: hidden; margin: 18px 0; }
.ds-labs > div { padding: 10px 14px; box-shadow: inset -1px -1px 0 var(--ds-line); }
.ds-labs dt { font-size: var(--ds-text-xs); color: var(--ds-ink-2); }
.ds-labs dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.ds-labs dd small { font-weight: 400; color: var(--ds-ink-2); }
.ds-labs > .is-abnormal dd { color: var(--ds-bad); }

/* Answer option */
.ds-options { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ds-option { display: grid; grid-template-columns: 1fr auto; border: 1.5px solid var(--ds-line); border-radius: var(--ds-r-option); background: var(--ds-surface); transition: border-color var(--ds-fast), background var(--ds-fast); }
.ds-option__main { display: grid; grid-template-columns: 30px 1fr auto; gap: 12px; align-items: center; text-align: left; border: 0; background: transparent; color: inherit; font: inherit; padding: 12px 8px 12px 14px; border-radius: var(--ds-r-option); min-height: 52px; cursor: pointer; }
.ds-option__letter { width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--ds-line); display: grid; place-items: center; font-weight: 600; font-size: 0.88rem; color: var(--ds-ink-2); }
.ds-option__text { font-size: 0.98rem; }
.ds-option__mark { display: none; font-size: 1.2rem; }
.ds-option__strike { border: 0; background: transparent; color: var(--ds-ink-2); width: var(--ds-tap); border-radius: 0 var(--ds-r-option) var(--ds-r-option) 0; display: grid; place-items: center; cursor: pointer; }
.ds-option__strike:hover { color: var(--ds-ink); }
.ds-option:hover:not(.is-locked) { border-color: var(--ds-ink-2); }
.ds-option.is-selected { border-color: var(--ds-brand); background: var(--ds-brand-tint); }
.ds-option.is-selected .ds-option__letter { background: var(--ds-brand); border-color: var(--ds-brand); color: var(--ds-on-brand); }
.ds-option.is-struck { opacity: 0.6; }
.ds-option.is-struck .ds-option__text { text-decoration: line-through; color: var(--ds-ink-2); }
.ds-option.is-correct { border-color: var(--ds-ok); background: var(--ds-ok-tint); }
.ds-option.is-correct .ds-option__letter { background: var(--ds-ok); border-color: var(--ds-ok); color: #fff; }
.ds-option.is-correct .ds-option__mark { display: block; color: var(--ds-ok); }
.ds-option.is-incorrect { border-color: var(--ds-bad); background: var(--ds-bad-tint); }
.ds-option.is-incorrect .ds-option__letter { background: var(--ds-bad); border-color: var(--ds-bad); color: #fff; }
.ds-option.is-incorrect .ds-option__mark { display: block; color: var(--ds-bad); }
.ds-option.is-locked .ds-option__strike { visibility: hidden; }

.ds-explain { border-top: 1px solid var(--ds-line); padding: 22px; background: var(--ds-surface-2); }
.ds-explain__verdict { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 1.05rem; font-weight: 700; }
.ds-explain__verdict.is-correct { color: var(--ds-ok); }
.ds-explain__verdict.is-incorrect { color: var(--ds-bad); }
.ds-explain p { margin: 10px 0 0; max-width: var(--ds-measure); font-size: 0.97rem; }
.ds-pearl { margin-top: 16px; border-left: 3px solid var(--ds-brand); padding: 2px 0 2px 14px; font-size: 0.95rem; }
.ds-pearl b { display: block; font-size: 0.85rem; color: var(--ds-brand); margin-bottom: 2px; }

/* Key-feature checklist (short-answer self scoring) */
.ds-checklist { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.ds-checklist label { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: var(--ds-r-control); background: var(--ds-surface-2); font-size: 0.94rem; cursor: pointer; }
.ds-checklist input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--ds-brand); flex: none; }

/* Timer ring */
.ds-ring { position: relative; width: 148px; height: 148px; margin: 18px auto 14px; }
.ds-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ds-ring circle { fill: none; stroke-width: 9; }
.ds-ring__track { stroke: var(--ds-surface-2); }
.ds-ring__prog { stroke: var(--ds-brand); stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear; }
.ds-ring__time { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.9rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.ds-timer { display: inline-flex; align-items: center; gap: 6px; color: var(--ds-ink-2); font-weight: 500; font-variant-numeric: tabular-nums; }

/* Mastery map */
.ds-mosaic { display: grid; grid-template-columns: repeat(15, 1fr); gap: 4px; }
.ds-mosaic button { aspect-ratio: 1; border: 0; padding: 0; min-width: 0; border-radius: var(--ds-r-cell); cursor: pointer; }
.ds-mosaic button[data-level="0"] { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ds-line); }
.ds-mosaic button[data-level="1"] { background: var(--ds-m1); }
.ds-mosaic button[data-level="2"] { background: var(--ds-m2); }
.ds-mosaic button[data-level="3"] { background: var(--ds-m3); }
.ds-mosaic button[data-level="4"] { background: var(--ds-m4); }
.ds-mosaic button[aria-current="true"] { outline: 2px solid var(--ds-ink); outline-offset: 1px; }
.ds-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.82rem; color: var(--ds-ink-2); }
.ds-legend span { display: inline-flex; align-items: center; gap: 6px; }
.ds-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* Domain bars */
.ds-bars { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 16px; }
.ds-bars li > div:first-child { display: flex; justify-content: space-between; gap: 10px; font-size: 0.92rem; margin-bottom: 6px; }
.ds-bars b { font-variant-numeric: tabular-nums; }
.ds-bars__track { height: 8px; border-radius: var(--ds-r-pill); background: var(--ds-surface-2); overflow: hidden; }
.ds-bars__track > span { display: block; height: 100%; border-radius: var(--ds-r-pill); }

/* Chart (inline SVG) */
.ds-chart { width: 100%; height: auto; display: block; }
.ds-chart text { font: 500 11px var(--ds-font-sans); fill: var(--ds-ink-2); }
.ds-chart .ds-chart__grid { stroke: var(--ds-line); stroke-width: 1; }
.ds-chart .ds-chart__target { stroke: var(--ds-warn); stroke-width: 1.5; stroke-dasharray: 5 4; }
.ds-chart .ds-chart__line { fill: none; stroke: var(--ds-brand); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.ds-chart .ds-chart__target-label { fill: var(--ds-warn); font-weight: 600; }
.ds-chart .ds-chart__area { fill: var(--ds-brand); opacity: 0.09; }
.ds-chart .ds-chart__pt { fill: var(--ds-surface); stroke: var(--ds-brand); stroke-width: 2; }

/* Feedback */
.ds-alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--ds-r-option); font-size: 0.94rem; background: var(--ds-brand-tint); color: var(--ds-brand); }
.ds-alert > .ds-icon { font-size: 1.2rem; margin-top: 2px; }
.ds-alert b { display: block; }
.ds-alert p { margin: 0; color: var(--ds-ink); opacity: 0.85; }
.ds-alert--warn { background: var(--ds-warn-tint); color: var(--ds-warn); }
.ds-alert--bad { background: var(--ds-bad-tint); color: var(--ds-bad); }
.ds-alert--ok { background: var(--ds-ok-tint); color: var(--ds-ok); }

.ds-empty { border: 1.5px dashed var(--ds-line); border-radius: var(--ds-r-card); padding: 28px 22px; text-align: center; }
.ds-empty__icon { width: 52px; height: 52px; border-radius: 14px; background: var(--ds-surface-2); display: grid; place-items: center; margin: 0 auto 14px; font-size: 1.5rem; color: var(--ds-ink-2); }
.ds-empty p { color: var(--ds-ink-2); font-size: 0.92rem; margin: 6px auto 16px; max-width: 32ch; }

.ds-toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); transform: translate(-50%, 24px); opacity: 0; pointer-events: none; background: var(--ds-ink); color: var(--ds-bg); padding: 12px 16px; border-radius: var(--ds-r-option); display: flex; gap: 10px; align-items: center; font-weight: 500; font-size: 0.94rem; transition: transform var(--ds-base), opacity var(--ds-base); z-index: 50; max-width: calc(100% - 32px); }
.ds-toast.is-visible { transform: translate(-50%, 0); opacity: 1; }

/* Responsive and motion */
@media (max-width: 520px) {
  .ds-wrap { padding: 0 14px; }
  .ds-panel { padding: 18px; border-radius: var(--ds-r-card); }
  .ds-question__body { padding: 20px 16px 6px; }
  .ds-question__bar { padding-left: 16px; }
  .ds-question__foot, .ds-explain { padding-left: 16px; padding-right: 16px; }
  .ds-mosaic { gap: 3px; }
}
@media (prefers-reduced-motion: reduce) {
  .ds-btn, .ds-option, .ds-switch, .ds-switch::after, .ds-toast, .ds-ring__prog { transition: none; }
  .ds-btn.is-loading::before { animation: none; }
}
