/* "Coach" design system — controls: buttons, form fields, pills, progress, tables, tabs,
   callouts, dialogs and toasts. */

/* ---------- Chunky buttons: a solid face on a darker lip that presses down ---------- */
.btn {
  --face: var(--teal); --lipc: var(--teal-deep); --on: var(--surface);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 48px; padding: 0 var(--s5);
  border: 0; border-radius: 14px;
  background: var(--face); color: var(--on);
  box-shadow: var(--lip) var(--lipc);
  font-family: var(--display); font-size: var(--fs-l); font-weight: 700; line-height: 1.1;
  text-decoration: none; text-align: center; white-space: nowrap; user-select: none;
  transition: transform 120ms var(--ease-out), box-shadow 120ms var(--ease-out);
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: var(--lip-pressed) var(--lipc); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; }
.btn--sun { --face: var(--sun); --lipc: var(--sun-deep); --on: var(--on-sun); }
.btn--danger { --face: var(--coral-deep); --lipc: var(--coral-ink); --on: var(--on-fill); }
.btn--plain {
  --face: var(--surface); --lipc: var(--edge); --on: var(--ink);
  box-shadow: inset 0 0 0 2px var(--edge), var(--lip) var(--edge);
}
.btn--plain:active:not(:disabled) { box-shadow: inset 0 0 0 2px var(--edge), var(--lip-pressed) var(--edge); }
.btn--quiet {
  --face: transparent; --on: var(--ink); box-shadow: none; padding: 0 var(--s3);
  font-family: var(--text); font-size: var(--fs-base); border-radius: 12px;
}
.btn--quiet:active:not(:disabled) { transform: scale(0.97); box-shadow: none; }
.btn--s { min-height: 44px; padding: 0 var(--s4); font-size: var(--fs-base); border-radius: 12px; }
.btn--l { min-height: 56px; padding: 0 var(--s6); font-size: 1.1875rem; border-radius: var(--r-m); }
.btn--block { display: flex; width: 100%; }
.btn--icon { padding: 0; width: 44px; min-height: 44px; }
@media (hover: hover) and (pointer: fine) {
  .btn--quiet:hover:not(:disabled) { background: var(--line); }
  .btn--plain:hover:not(:disabled) { --face: var(--on-fill); }
}

/* Exam mode buttons are flat: ink and greys only. */
.btn--exam {
  --face: var(--ink); --on: var(--on-fill);
  min-height: 44px; padding: 0 var(--s5); border-radius: var(--r-s);
  box-shadow: none; font-size: var(--fs-base);
}
.btn--exam:active:not(:disabled) { transform: scale(0.97); box-shadow: none; }
.btn--exam.btn--l { min-height: 52px; padding: 0 var(--s6); font-size: var(--fs-l); }
.btn--exam-plain { --face: transparent; --on: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn--exam-plain:active:not(:disabled) { box-shadow: inset 0 0 0 1px var(--line-strong); }
@media (hover: hover) and (pointer: fine) {
  .btn--exam-plain:hover:not(:disabled) { --face: var(--exam-fill); }
}

.xp {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
}

/* ---------- Layout helpers ---------- */
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); }
.row--end { justify-content: flex-end; }
.row--center { justify-content: center; }
.row--between { justify-content: space-between; }
.row--loose { gap: var(--s4); }
.flow > * + * { margin-top: var(--s4); }
.flow-s > * + * { margin-top: var(--s2); }

/* ---------- Form fields ---------- */
.field { display: grid; gap: var(--s2); align-content: start; min-width: 0; }
.field > label, .field > .label { font-weight: 700; font-size: var(--fs-m); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: var(--s4); }
input[type="text"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; min-height: 48px; padding: 0 var(--s4);
  border: 0; border-radius: 12px; background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--edge);
  font-size: var(--fs-base);
}
textarea { padding: var(--s3) var(--s4); line-height: 1.6; resize: vertical; display: block; }
select {
  appearance: none; -webkit-appearance: none; padding-inline-end: 44px; cursor: pointer;
  background-image: var(--select-chevron);
  background-repeat: no-repeat; background-position: right 14px center; background-size: 20px;
}
input::placeholder, textarea::placeholder { color: var(--ink-2); opacity: 1; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 12px; }
input:disabled, select:disabled, textarea:disabled { background: var(--paper-2); color: var(--ink); opacity: 1; -webkit-text-fill-color: var(--ink); }

/* A tick box with a label. */
.check {
  display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: var(--s3); align-items: start;
  min-height: 44px; padding-block: 10px; cursor: pointer;
}
.check input {
  appearance: none; -webkit-appearance: none; width: 24px; height: 24px; margin: 0; border-radius: 7px;
  background: var(--surface); box-shadow: inset 0 0 0 2px var(--line-strong); cursor: pointer;
  display: grid; place-items: center;
}
.check input::after {
  content: ""; width: 12px; height: 7px; margin-top: -3px;
  border: solid var(--surface); border-width: 0 0 2.5px 2.5px; transform: rotate(-45deg); opacity: 0;
}
.check input:checked { background: var(--teal); box-shadow: none; }
.check input:checked::after { opacity: 1; }

/* A radio shown as a card. */
.choices { display: grid; gap: var(--s2); }
.choice {
  position: relative; display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: var(--s3); align-items: start;
  min-height: 52px; padding: var(--s3) var(--s4);
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-m); cursor: pointer;
  transition: border-color 150ms ease;
}
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice__dot {
  width: 24px; height: 24px; margin-top: 1px; border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--line-strong); display: grid; place-items: center;
}
.choice:has(input:checked) { background: var(--teal-tint); border-color: var(--teal); }
.choice:has(input:checked) .choice__dot { background: var(--teal); box-shadow: inset 0 0 0 6px var(--teal), inset 0 0 0 12px var(--surface); }
.choice:has(input:focus-visible) { outline: 3px solid var(--ink); outline-offset: 2px; }
.choice__title { font-family: var(--display); font-weight: 700; font-size: var(--fs-l); line-height: 1.3; }
.choice__text { display: block; margin-top: 2px; font-size: var(--fs-m); color: var(--ink-2); }
.choice:has(input:checked) .choice__text { color: var(--ink); }
@media (hover: hover) and (pointer: fine) { .choice:hover { border-color: var(--line-strong); } }

/* ---------- Pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 2px var(--s3);
  border-radius: 14px; background: var(--paper-2); color: var(--ink);
  font-size: var(--fs-s); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.pill--good { background: var(--teal-tint); color: var(--teal-deep); }
.pill--warn { background: var(--sun-tint); color: var(--sun-ink); }
.pill--bad { background: var(--coral-tint); color: var(--coral-deep); }
.pill--xp { background: var(--sun); color: var(--on-sun); }
.pill--line { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--ink-2); }
a.pill-link { text-decoration: none; display: inline-flex; align-items: center; min-height: 44px; }

/* ---------- Progress ---------- */
.bar { height: 14px; border-radius: 7px; background: var(--paper-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 7px; background: var(--teal); transition: width 300ms var(--ease-out); }
.bar--thin { height: 8px; border-radius: 4px; }
.bar--sun > span { background: var(--sun-deep); }
.bar--coral > span { background: var(--coral); }
.bar--ink > span { background: var(--ink); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* A table wider than the screen (learn.js: lessons and the exam guide): the side with more to see
   fades out and shows an arrow, so the cue is a shape as well as a shade, and it needs no hover. The
   arrow lets taps through to the table, and stays in sight half-way down the screen while a tall
   table scrolls by. */
.table-box.is-more-start, .table-box.is-more-end { position: relative; }
.table-cue {
  position: absolute; inset-block: 0; z-index: 1; display: none; align-items: flex-start; width: 48px;
  padding-block: var(--s2); pointer-events: none; color: var(--surface);
}
.table-cue--end { inset-inline-end: 0; justify-content: flex-end; background: linear-gradient(to right, transparent, var(--surface) 60%); }
.table-cue--start { inset-inline-start: 0; justify-content: flex-start; background: linear-gradient(to left, transparent, var(--surface) 60%); }
.table-box.is-more-end .table-cue--end, .table-box.is-more-start .table-cue--start { display: flex; }
.table-cue .i {
  position: sticky; top: calc(50dvh - 14px);
  width: 28px; height: 28px; padding: 4px; border-radius: 50%; background: var(--ink); stroke-width: 2.5;
}
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: start; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-2);
  padding: 0 var(--s4) var(--s2) 0; vertical-align: bottom;
}
.table td { padding: var(--s3) var(--s4) var(--s3) 0; border-top: 1px solid var(--line); vertical-align: middle; }
.table th:last-child, .table td:last-child { padding-inline-end: 0; text-align: end; }
.table .when { color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .task a { font-weight: 700; text-decoration: none; }
@media (hover: hover) and (pointer: fine) { .table .task a:hover { text-decoration: underline; } }
.table .task span { display: block; font-size: var(--fs-s); color: var(--ink-2); }
.table .result { font-family: var(--display); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table--left th:last-child, .table--left td:last-child { text-align: start; }
/* Reference tables (score tables, timetables inside a passage): every cell boxed, easy to scan. */
.table--grid { font-variant-numeric: tabular-nums; font-size: var(--fs-m); }
.table--grid th, .table--grid td { padding: var(--s2) var(--s3); border: 1px solid var(--line-2); text-align: start; vertical-align: top; }
.table--grid th:last-child, .table--grid td:last-child { padding-inline-end: var(--s3); text-align: start; }
.table--grid thead th { background: var(--paper-2); color: var(--ink); font-size: var(--fs-s); }
.table--grid tbody th { font-family: var(--display); font-size: var(--fs-base); color: var(--ink); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: var(--s1); padding: var(--s1); border-radius: 14px; background: var(--paper-2); overflow-x: auto; scrollbar-width: none; width: fit-content; max-width: 100%; }
.tab {
  display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s4);
  border: 0; border-radius: 10px; background: transparent; color: var(--ink-2);
  font-weight: 700; font-size: var(--fs-m); white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.tab small { font-weight: 400; font-size: var(--fs-s); font-variant-numeric: tabular-nums; }

/* ---------- Callouts and helpers ---------- */
.callout {
  display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: var(--s3);
  padding: var(--s4) var(--s5) var(--s4) var(--s4); border-radius: var(--r-m); background: var(--paper-2);
}
.callout > .i { margin-top: 2px; color: var(--ink-2); }
.callout__title { display: block; font-family: var(--display); font-weight: 700; }
.callout p + p { margin-top: var(--s2); }
.callout--tip { background: var(--teal-tint); }
.callout--tip > .i { color: var(--teal); }
.callout--warn { background: var(--coral-tint); }
.callout--warn > .i { color: var(--coral-deep); }
.callout--sun { background: var(--sun-tint); }
.callout--sun > .i { color: var(--sun-ink); }

details.helper { border-radius: var(--r-m); background: var(--paper-2); }
details.helper > summary {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  min-height: 48px; padding: var(--s2) var(--s4); cursor: pointer; font-weight: 700; list-style: none;
}
details.helper > summary::-webkit-details-marker { display: none; }
details.helper > summary::after {
  content: ""; width: 10px; height: 10px; margin-inline-end: 4px; flex: none;
  border: solid var(--ink-2); border-width: 0 2px 2px 0; transform: translateY(-3px) rotate(45deg);
  transition: transform 150ms ease;
}
details.helper[open] > summary::after { transform: translateY(2px) rotate(-135deg); }
details.helper > :not(summary) { margin: 0 var(--s4) var(--s4); }
details.helper > :not(summary) + :not(summary) { margin-top: var(--s3); }

.empty {
  display: grid; justify-items: center; gap: var(--s3); text-align: center;
  padding: var(--s7) var(--s5); border: 2px dashed var(--line-2); border-radius: var(--r-l);
}
.empty p { color: var(--ink-2); max-width: 44ch; }
.empty .i { color: var(--line-strong); }

.spinner {
  display: inline-block; width: 18px; height: 18px; border-radius: 50%; vertical-align: -3px; margin-inline-end: var(--s2);
  border: 2.5px solid var(--line-2); border-top-color: var(--teal); animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
pre.error { padding: var(--s3) var(--s4); border-radius: var(--r-s); background: var(--paper-2); font-size: var(--fs-s); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Dialog ---------- */
.dialog {
  width: min(480px, calc(100vw - 32px)); padding: var(--s6); border: 0; border-radius: var(--r-l);
  background: var(--surface); color: var(--ink); box-shadow: var(--float);
}
.dialog::backdrop { background: var(--scrim); }
.dialog h2 { font-size: 1.5rem; }
.dialog-body { margin-top: var(--s3); color: var(--ink-2); font-size: var(--fs-l); }
.dialog-body p + p { margin-top: var(--s2); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s3); margin-top: var(--s6); }
.dialog[open] { animation: pop 180ms var(--ease-out); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
/* During a test the dialog follows the exam's flat, colourless controls. */
body.running .dialog { border-radius: var(--r-m); background: var(--exam-bg); }
body.running .dialog .btn { --face: var(--ink); --on: var(--on-fill); box-shadow: none; border-radius: var(--r-s); min-height: 44px; font-size: var(--fs-base); }
body.running .dialog .btn--plain { --face: transparent; --on: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
body.running .dialog .btn:active { transform: scale(0.97); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; inset-inline: 0; bottom: var(--s5); z-index: 80; width: fit-content; max-width: calc(100vw - 32px);
  margin-inline: auto; padding: var(--s3) var(--s5); border-radius: var(--r-m);
  background: var(--ink); color: var(--surface); box-shadow: var(--float);
  font-weight: 500; text-align: center;
  opacity: 0; transform: translateY(12px); pointer-events: none;
  transition: opacity 200ms ease, transform 200ms var(--ease-out);
}
#toast.show { opacity: 1; transform: none; }

/* ---------- "Review later" (STORY-03.26, REVIEW-2 §3) ---------- */
/* Off: an outline bookmark and the words; on: a filled teal bookmark. 44 px tall; the dense one 44 × 44. */
.rl {
  display: inline-flex; align-items: center; gap: var(--s2); justify-self: start; align-self: start;
  min-height: 44px; margin-top: var(--s1); padding: 0 var(--s4) 0 var(--s3);
  border: 0; border-radius: var(--r-s); background: var(--surface); color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  font: inherit; font-weight: 500; font-size: var(--fs-base); line-height: 1.2; text-align: start;
  transition: background-color 120ms var(--ease-out), color 120ms var(--ease-out), transform 120ms var(--ease-out);
}
.rl:active { transform: scale(0.97); }
.rl .i, .rl-in .i { flex: none; transition: fill 120ms var(--ease-out); }
.rl.is-on { background: var(--teal-tint); color: var(--teal-deep); box-shadow: inset 0 0 0 1px var(--teal); }
.rl .is-filled, .rl-in .is-filled { fill: currentColor; }
.rl--dense { width: 44px; padding: 0; justify-content: center; }
.rl-in { display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; margin-top: var(--s1); color: var(--teal-deep); font-weight: 500; }
.q > .rl, .q > .rl-in { grid-column: 2; }
.callout .rl { display: flex; margin-top: var(--s3); }
.lp-step > .rl { margin-top: var(--s5); }
/* STORY-04.23: in a feedback card, the bookmark at the right of its first line; the explanation runs under it. */
.fb:has(> .rl) { grid-template-columns: 24px minmax(0, 1fr) 44px; row-gap: var(--s1); }
.fb:has(> .rl) > .fb__body { display: contents; }
.fb:has(> .rl) > .fb__body > * { grid-column: 2 / -1; margin-top: 0; }
.fb:has(> .rl) > .fb__body > .fb__head { grid-column: 2; grid-row: 1; align-self: center; }
.fb > .rl { grid-column: 3; grid-row: 1; margin: -10px -12px -10px 0; justify-self: end; }
/* The bar: above the bottom buttons (review-later.js sets `bottom`), never over them. */
.rl-bar { position: fixed; inset-inline: 0; bottom: var(--s5); z-index: 81; display: flex; justify-content: center; padding-inline: var(--s4); pointer-events: none; transition-property: none; }
.rl-bar__in {
  display: flex; flex-wrap: wrap; align-items: center; column-gap: var(--s2); max-width: 480px;
  padding: 0 var(--s2) 0 var(--s4); border-radius: var(--r-m); background: var(--ink); color: var(--surface);
  box-shadow: var(--float); font-weight: 500; pointer-events: auto; animation: rl-in 200ms var(--ease-out);
}
.rl-bar__undo { min-height: 44px; padding: 0 var(--s3); border: 0; border-radius: var(--r-s); background: none; color: var(--teal-soft); font: inherit; font-weight: 700; text-decoration: underline; }
.rl-bar__first { flex-basis: 100%; padding-bottom: var(--s3); font-size: var(--fs-m); font-weight: 400; }
@keyframes rl-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes rl-fade { from { opacity: 0; } }
/* With Reduce Motion the bar fades in and does not move. */
@media (prefers-reduced-motion: reduce) {
  .rl-bar__in { animation: rl-fade 200ms ease !important; }
  .rl:active { transform: none; }
}
/* At every width a practice set's question pane has room under its last control, so the bar never covers the
   control it confirms (review-later.js scrolls it clear; the coordinator's ruling, 2026-11-15). */
.steps .questions { padding-bottom: 128px; }
/* A kept card, drawn from its record alone. */
.rl-card { display: grid; gap: var(--s3); padding: var(--s5); border-radius: var(--r-m); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
.rl-card__front { font-weight: 700; font-size: var(--fs-l); }
.rl-card__back { color: var(--teal-deep); font-weight: 700; }
.rl-card__why { color: var(--ink-2); }
.rl-card p + p { margin-top: var(--s1); }

@media (max-width: 860px) {
  #toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
  body.running #toast, body.no-nav #toast { bottom: var(--s5); }
  .dialog { padding: var(--s5); }
  .dialog-actions .btn { flex: 1 1 auto; }
  .callout { padding: var(--s4); }
  .q > .rl, .q > .rl-in { grid-column: 1 / -1; }
  .table--stack thead { display: none; }
  .table--stack tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--s4); padding-block: var(--s3); border-top: 1px solid var(--line); }
  .table--stack tbody tr:first-child { border-top: 0; padding-top: 0; }
  .table--stack td { padding: 0; border: 0; }
  .table--stack .task { grid-column: 1; grid-row: 1; }
  .table--stack .result { grid-column: 2; grid-row: 1; text-align: end; }
  .table--stack .when { grid-column: 1; grid-row: 2; font-size: var(--fs-s); }
  .table--stack td:last-child { grid-column: 2; grid-row: 2; }
}

/* What a component is used for, its name and its licence: three columns, stacked on a phone. */
.uses { list-style: none; padding: 0; }
.uses li { display: grid; grid-template-columns: 1.1fr 1.3fr 1.6fr; gap: var(--s4); padding-block: var(--s3); border-top: 1px solid var(--line); }
.uses__what, .uses__licence { color: var(--ink-2); }
@media (max-width: 720px) {
  .uses li { grid-template-columns: 1fr; gap: 2px; }
}
