/* Reusable components. Nothing here knows about a particular screen. */

/* Buttons ------------------------------------------------------------ */
.btn {
  --btn-bg: var(--primary);
  --btn-fg: var(--on-primary);
  --btn-border: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: var(--space-3) var(--space-5);
  border: 2px solid var(--btn-border);
  border-radius: var(--radius-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--step-0);
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: transform var(--motion), background var(--motion), box-shadow var(--motion);
  box-shadow: var(--shadow-1);
}
.btn:hover:not(:disabled) { --btn-bg: var(--primary-press); --btn-border: var(--primary-press); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

.btn--secondary {
  --btn-bg: var(--surface);
  --btn-fg: var(--primary);
  --btn-border: var(--line-strong);
  box-shadow: none;
}
.btn--secondary:hover:not(:disabled) { --btn-bg: var(--primary-tint); --btn-border: var(--primary); }

.btn--quiet {
  --btn-bg: transparent;
  --btn-fg: var(--ink-soft);
  --btn-border: transparent;
  box-shadow: none;
  padding: var(--space-2) var(--space-3);
}
.btn--quiet:hover:not(:disabled) { --btn-bg: var(--surface-sunken); --btn-fg: var(--ink); --btn-border: transparent; }

.btn--danger { --btn-bg: var(--notyet); --btn-border: var(--notyet); --btn-fg: #fff; }
.btn--block { width: 100%; }
.btn--large { font-size: var(--step-1); padding: var(--space-4) var(--space-6); }
.btn .icon { flex: none; }

.btn[data-busy='true'] { pointer-events: none; opacity: .7; }

/* Cards -------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow-1);
}
.card--flush { padding: 0; overflow: hidden; }
.card--accent { border-left: 5px solid var(--accent, var(--primary)); }
.card__title { margin-bottom: var(--space-2); }

/* Chips and tags ----------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--surface);
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
}
.chip--accent { border-color: color-mix(in srgb, var(--accent, var(--primary)) 40%, var(--line)); color: var(--accent, var(--primary)); }
.chip--correct { border-color: var(--correct); color: var(--correct); background: var(--correct-tint); }
.chip--locked { color: var(--ink-faint); }
.chip--indicative { border-style: dashed; }

.tag-list { display: flex; flex-wrap: wrap; gap: var(--space-2); }
/* A chip holding a syllabus reference is a sentence, not a label, so it has to
   be allowed to wrap or it pushes the page sideways on a phone. */
.tag-list .chip { white-space: normal; max-width: 100%; text-align: left; }

/* Progress ----------------------------------------------------------- */
.meter {
  height: 12px;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken);
  border: 1.5px solid var(--line);
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  border-radius: inherit;
  background: var(--meter-colour, var(--primary));
  transition: width var(--motion);
}
.meter--thin { height: 8px; }

/* Step indicator at the top of every flow (a global convention). ------ */
.steps { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-5); }
.steps__dot {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--line);
}
.steps__dot[data-state='done'] { background: var(--primary); }
.steps__dot[data-state='current'] { background: var(--primary); opacity: .55; }
.steps__label { font-size: var(--step--1); font-weight: 700; color: var(--ink-soft); white-space: nowrap; }

/* Top bar ------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  padding-top: max(var(--space-3), env(safe-area-inset-top));
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1.5px solid var(--line);
}
.topbar__brand {
  display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: var(--tap);
  padding: var(--space-2) var(--space-3);
  margin-left: calc(var(--space-3) * -1);
  border: 0; border-radius: var(--radius-sm);
  background: none; cursor: pointer;
  font-family: var(--font-display); font-weight: 800; font-size: var(--step-1);
  color: var(--ink); text-decoration: none;
}
.topbar__brand:hover { background: var(--surface-sunken); }
.topbar__right { display: flex; align-items: center; gap: var(--space-2); }

.xp-chip { display: inline-flex; align-items: center; gap: 6px; }
.xp-chip__ring {
  width: 30px; height: 30px; flex: none;
  border-radius: 50%;
  background: conic-gradient(var(--primary) calc(var(--pct, 0) * 1%), var(--line) 0);
  display: grid; place-items: center;
}
.xp-chip__ring span {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 800; color: var(--primary);
}

/* Bottom tab bar ----------------------------------------------------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 6px var(--space-2);
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1.5px solid var(--line);
}
.tabbar__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: var(--tap);
  padding: 4px;
  border: 0; background: none; cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--ink-faint);
  font-size: 11px; font-weight: 700;
  text-decoration: none;
}
.tabbar__item[aria-current='page'] { color: var(--primary); background: var(--primary-tint); }
@media (min-width: 900px) {
  .tabbar {
    position: sticky; top: 0; bottom: auto;
    max-width: var(--shell-max); margin: 0 auto var(--space-5);
    grid-auto-columns: auto; justify-content: center; gap: var(--space-2);
    background: none; border: 0; backdrop-filter: none;
  }
  .tabbar__item { flex-direction: row; gap: var(--space-2); padding: var(--space-2) var(--space-4); font-size: var(--step--1); }
}

/* Feedback panels ---------------------------------------------------- */
.feedback {
  border-radius: var(--radius);
  border: 2px solid var(--fb-border);
  background: var(--fb-bg);
  padding: var(--space-4) var(--space-5);
  color: var(--ink);
}
.feedback[data-tone='correct'] { --fb-border: var(--correct); --fb-bg: var(--correct-tint); }
.feedback[data-tone='partial'] { --fb-border: var(--nearly); --fb-bg: var(--nearly-tint); }
.feedback[data-tone='incorrect'],
.feedback[data-tone='skipped'] { --fb-border: var(--notyet); --fb-bg: var(--notyet-tint); }
.feedback__title { font-family: var(--font-display); font-weight: 800; font-size: var(--step-1); margin: 0 0 var(--space-2); }
.feedback__title[data-tone='correct'] { color: var(--correct); }
.feedback p { margin-bottom: var(--space-3); }

/* Options ------------------------------------------------------------ */
.option {
  display: flex; align-items: flex-start; gap: var(--space-3);
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-4);
  text-align: left;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  transition: border-color var(--motion), background var(--motion);
}
.option:hover:not(:disabled) { border-color: var(--line-strong); background: var(--surface-sunken); }
.option[aria-pressed='true'], .option[data-selected='true'] { border-color: var(--primary); background: var(--primary-tint); }
.option[data-mark='correct'] { border-color: var(--correct); background: var(--correct-tint); }
.option[data-mark='wrong'] { border-color: var(--notyet); background: var(--notyet-tint); }
.option:disabled { cursor: default; }
.option__key {
  flex: none;
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 2px solid currentColor;
  font-size: var(--step--1); font-weight: 800;
  color: var(--ink-faint);
}
.option[data-selected='true'] .option__key { color: var(--primary); }
.option[data-mark='correct'] .option__key { color: var(--correct); }
.option[data-mark='wrong'] .option__key { color: var(--notyet); }

/* Text inputs -------------------------------------------------------- */
.field { display: block; margin-bottom: var(--space-4); }
.field__label { display: block; font-weight: 700; margin-bottom: var(--space-2); }
.field__hint { display: block; font-size: var(--step--1); color: var(--ink-soft); margin-bottom: var(--space-2); }
.input, .textarea, .select {
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-3) var(--space-4);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--font-read);
}
.textarea { min-height: 110px; resize: vertical; }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible { border-color: var(--primary); }
.input[aria-invalid='true'] { border-color: var(--notyet); }

.blank {
  display: inline-block;
  width: 8ch; min-width: 6ch;
  min-height: 38px;
  padding: 2px var(--space-2);
  margin: 0 2px;
  border: 0; border-bottom: 3px solid var(--primary);
  border-radius: 4px 4px 0 0;
  background: var(--primary-tint);
  font: inherit; font-weight: 700; text-align: center;
}
.blank[data-mark='correct'] { border-bottom-color: var(--correct); background: var(--correct-tint); }
.blank[data-mark='wrong'] { border-bottom-color: var(--notyet); background: var(--notyet-tint); }

/* Diagram ------------------------------------------------------------ */
.figure { margin: 0; }
.figure__frame {
  position: relative;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-4);
}
.figure__frame svg { display: block; width: 100%; height: auto; }
.figure figcaption { margin-top: var(--space-3); font-size: var(--step--1); color: var(--ink-soft); max-width: 62ch; }

/* Body-map hotspots sit at anatomically correct positions, and the heart is
   genuinely a few millimetres from a lung. Enlarging these to 44px would make
   neighbouring organs overlap and become un-tappable, so their presentation is
   essential in the sense of WCAG 2.2 SC 2.5.8. They are 32px (comfortably above
   the 24px AA floor), spaced apart, and every one of them is duplicated as a
   full-size row in the topic list directly below the map. The layout gate
   honours the data-target-exception attribute they carry. */
.hotspot {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 32px; min-height: 32px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 2.5px solid var(--surface);
  background: var(--primary);
  color: var(--on-primary);
  cursor: pointer;
  padding: 0;
  box-shadow: var(--shadow-2);
  transition: transform var(--motion);
}
.hotspot:hover, .hotspot:focus-visible { transform: translate(-50%, -50%) scale(1.15); }
.hotspot__dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; }

.droptarget {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 78px; min-height: var(--tap);
  max-width: 46%;
  display: grid; place-items: center;
  padding: 4px 10px;
  border: 2.5px dashed var(--line-strong);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  font-size: var(--step--1); font-weight: 700; color: var(--ink-faint);
  cursor: pointer;
  text-align: center;
}
.droptarget[data-filled='true'] { border-style: solid; border-color: var(--primary); color: var(--primary); background: var(--primary-tint); }
.droptarget[data-armed='true'] { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-tint); }
.droptarget[data-mark='correct'] { border-color: var(--correct); color: var(--correct); background: var(--correct-tint); }
.droptarget[data-mark='wrong'] { border-color: var(--notyet); color: var(--notyet); background: var(--notyet-tint); }

.label-bank { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }
.label-token {
  min-height: 40px;
  padding: var(--space-2) var(--space-4);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  font-weight: 700; cursor: pointer;
}
.label-token[data-armed='true'] { border-color: var(--primary); background: var(--primary-tint); color: var(--primary); }
.label-token[data-used='true'] { opacity: .35; }

/* Modal -------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  padding: var(--space-4);
  background: rgba(38, 36, 74, .45);
}
.modal {
  width: min(480px, 100%);
  max-height: 86dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-3);
}

/* Toast -------------------------------------------------------------- */
.toast-stack {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tap) + var(--space-5));
  z-index: 60;
  display: flex; flex-direction: column; gap: var(--space-2);
  width: min(420px, calc(100vw - var(--space-5)));
}
.toast {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 2px solid var(--primary);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  font-weight: 700;
}
.toast[data-tone='reward'] { border-color: var(--correct); color: var(--correct); }
.toast[data-tone='warn'] { border-color: var(--nearly); color: var(--nearly); }

/* Icon --------------------------------------------------------------- */
.icon { width: 1.25em; height: 1.25em; display: inline-block; vertical-align: -0.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon--lg { width: 1.75em; height: 1.75em; }

/* Disclaimer --------------------------------------------------------- */
.disclaimer {
  display: flex; gap: var(--space-3);
  padding: var(--space-4);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-sunken);
  font-size: var(--step--1);
  color: var(--ink-soft);
}
.disclaimer .icon { flex: none; color: var(--ink-faint); }

/* Label leader lines: drawn under the labels, linking each to its true point. */
.leaders {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.leaders line { stroke: var(--line-strong); stroke-width: 1.5; stroke-dasharray: 4 4; }
.leaders circle { fill: var(--primary); }
