/* /css/components.css: buttons, chips, callouts, recap, reconcile, next card, worked examples, deep dives,
   toast, overlay lock, inline confirm (§4.5). Callout icons are injected by main.js from /img/shared/icons.svg. */

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45em;
  min-height: 40px;
  min-width: 24px;
  padding: .45em 1em;
  border: 1px solid var(--rule);
  border-radius: var(--r-s);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 1px 0 color-mix(in srgb, var(--ink) 6%, transparent);
  transition: background-color var(--t-ui) var(--ease), border-color var(--t-ui) var(--ease), color var(--t-ui) var(--ease), transform 120ms var(--ease);
}
.btn:hover { border-color: color-mix(in srgb, var(--ink) 35%, var(--rule)); background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; transform: none; }
.btn .icon { width: 1.1em; height: 1.1em; }
.btn.primary {
  min-height: 44px;
  background: var(--c-lab);
  border-color: var(--c-lab);
  color: var(--on-accent);
  box-shadow: 0 1px 0 rgba(0,0,0,.12), inset 0 1px 0 rgba(255,255,255,.12);
}
.btn.primary:hover { background: color-mix(in srgb, var(--c-lab) 88%, var(--ink)); border-color: color-mix(in srgb, var(--c-lab) 88%, var(--ink)); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--ink); }
.btn.ghost:hover { background: var(--surface-2); border-color: transparent; }
.linklike {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--c-lab);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .18em;
  cursor: pointer;
  min-height: 24px;
}
.linklike:hover { text-decoration-thickness: 2px; }

/* ---------------------------------------------------------------- chips and pills */

.chip {
  display: inline-flex;
  align-items: center;
  gap: .4em;
  min-height: 26px;
  padding: .15em .7em;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  font-family: var(--font-sans);
  font-size: .74rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
  text-decoration: none;
  vertical-align: middle;
}
.chip .icon { width: 1.05em; height: 1.05em; }
.chip code { background: none; padding: 0; font-size: .95em; }
a.chip:hover { border-color: var(--ink-muted); }
.chip.toolkit { color: var(--c-lab); border-color: color-mix(in srgb, var(--c-lab) 35%, var(--rule)); background: var(--tint-lab); }
.chip.toolkit::before { content: "\2192"; font-weight: 700; }
.chip.you { color: var(--c-you); border-color: color-mix(in srgb, var(--c-you) 45%, var(--rule)); background: var(--tint-you); }
.chip.you.wrong { border-style: dashed; }
.chip.warn { color: var(--c-bad); border-color: color-mix(in srgb, var(--c-bad) 45%, var(--rule)); background: var(--tint-bad); }
.chip-toggle {
  margin-left: .3em;
  border: 0;
  border-left: 1px solid currentColor;
  background: none;
  padding: 0 0 0 .6em;
  font: inherit;
  font-weight: 500;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: .15em;
  cursor: pointer;
  min-height: 24px;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: .3em;
  padding: .05em .6em;
  border-radius: 999px;
  font-family: var(--font-sans);
  font-size: .72rem;
  font-weight: 650;
  font-style: normal;
  letter-spacing: .02em;
  vertical-align: .1em;
}
.pill .icon { width: 1em; height: 1em; stroke-width: 2.4; }
.pill.ok { color: var(--c-ok); background: var(--tint-ok); }
.pill.bad { color: var(--c-bad); background: var(--tint-bad); }

/* ---------------------------------------------------------------- callouts */

.callout {
  position: relative;
  margin: var(--s-6) 0;
  padding: var(--s-4) var(--s-5) var(--s-4) var(--s-5);
  background: var(--surface-2);
  border-left: 4px solid var(--rule);
  border-radius: 0 var(--r-m) var(--r-m) 0;
  --flow: .75em;
}
.callout-title {
  display: flex;
  align-items: center;
  gap: .5em;
  font-family: var(--font-sans);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent, var(--ink-muted));
}
.callout-title .icon { width: 1.35em; height: 1.35em; stroke-width: 1.7; }
.callout.try { border-left-color: var(--c-lab); --accent: var(--c-lab); }
.callout.predict { border-left-color: var(--c-light); --accent: var(--c-light-text); }
.callout.pitfall { border-left-color: var(--c-bad); --accent: var(--c-bad); }
.callout.why { border-left-color: var(--c-inv); --accent: var(--c-inv); }
.callout.nature { border-left-color: var(--c-light); --accent: var(--c-light-text); }
.callout.realnums { border-left-color: var(--ink-muted); --accent: var(--ink-muted); font-variant-numeric: tabular-nums; }
.callout.strange { border-left-color: var(--c-you); --accent: var(--c-you); }
.callout.code-primer { border-left-color: var(--c-you); --accent: var(--c-you); }
.callout.code-primer pre {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-s);
  padding: var(--s-3) var(--s-4);
  font-size: .82rem;
  line-height: 1.55;
}
.callout cite { display: block; font-family: var(--font-sans); font-size: .78rem; }

/* Field notes recap: the double teal rule and the invariant gem. */
.recap {
  margin: var(--s-6) 0;
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 7px double var(--c-inv);
  border-radius: 0 var(--r-m) var(--r-m) 0;
  box-shadow: var(--shadow);
  --accent: var(--c-inv);
  --flow: .75em;
}
.recap .callout-title { color: var(--c-inv); }
.recap .callout-title::after {
  content: "\2261";
  margin-left: auto;
  font-size: 1.3rem;
  line-height: 1;
  letter-spacing: 0;
}
.recap ul { padding-left: 1.2em; }
.recap li::marker { content: "\25C6  "; color: var(--c-inv); font-size: .7em; }

/* ---------------------------------------------------------------- reconcile card */

.reconcile {
  margin: var(--s-6) 0;
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
  --flow: .8em;
}
.reconcile-you {
  margin: calc(-1 * var(--s-5)) calc(-1 * var(--s-5)) var(--s-4);
  padding: var(--s-4) var(--s-5);
  background: var(--tint-light);
  border-bottom: 1px dashed color-mix(in srgb, var(--c-light) 50%, var(--rule));
  border-radius: var(--r-l) var(--r-l) 0 0;
  font-family: var(--font-sans);
  font-size: .85rem;
}
.reconcile-you > * + * { margin-top: .4em; }
.reconcile-label { font-weight: 700; color: var(--c-light-text); }
.reconcile-text { font-family: var(--font-serif); font-size: 1.05rem; font-style: italic; color: var(--ink); white-space: pre-wrap; }
.reconcile-meta { color: var(--ink); font-style: italic; }
.reconcile-observed { font-weight: 600; }
/* .reconcile[data-hold] (exercise.js) */
.reconcile-veil { display: grid; gap: var(--s-3); justify-items: start; font-family: var(--font-sans); font-size: .88rem; color: var(--ink-muted); }
@media print {
  [data-veiled][hidden] { display: block !important; }
  .reconcile-veil { display: none; }
}
.reconcile-observed::before {
  content: "What happened: ";
  font-family: var(--font-sans);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--c-inv);
}

/* ---------------------------------------------------------------- next-chapter card */

.next-card {
  display: grid;
  gap: var(--s-1);
  padding: var(--s-5) var(--s-6);
  border: 1px solid var(--rule);
  border-radius: var(--r-l);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  text-decoration: none;
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--t-ui) var(--ease), transform var(--t-ui) var(--ease), border-color var(--t-ui) var(--ease);
}
.next-card::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -30px;
  width: 140px;
  height: 140px;
  background:
    linear-gradient(45deg, transparent calc(50% - 1px), color-mix(in srgb, var(--c-light) 55%, transparent) calc(50% - 1px), color-mix(in srgb, var(--c-light) 55%, transparent) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(-45deg, transparent calc(50% - 1px), color-mix(in srgb, var(--c-light) 55%, transparent) calc(50% - 1px), color-mix(in srgb, var(--c-light) 55%, transparent) calc(50% + 1px), transparent calc(50% + 1px));
  opacity: .5;
  pointer-events: none;
}
.next-card:hover { box-shadow: var(--shadow-lift); transform: translateY(-2px); text-decoration: none; border-color: var(--ink-muted); }
.next-title { font-size: 1.56rem; font-weight: 700; line-height: 1.2; }
.next-title::after { content: " \2192"; color: var(--c-lab); }

/* ---------------------------------------------------------------- worked example */

.worked-example {
  list-style: none;
  counter-reset: we;
  padding: 0;
  margin: var(--s-5) 0;
  border: 1px solid var(--rule);
  border-radius: var(--r-m);
  background: var(--surface);
  overflow: hidden;
}
.worked-example > li {
  counter-increment: we;
  position: relative;
  padding: var(--s-4) var(--s-5) var(--s-4) calc(var(--s-5) + 2.2em);
  margin: 0;
  outline: none;
}
.worked-example > li + li { border-top: 1px dashed var(--rule); }
.worked-example > li::before {
  content: counter(we);
  position: absolute;
  left: var(--s-4);
  top: var(--s-4);
  width: 1.7em;
  height: 1.7em;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1.5px solid var(--ink-muted);
  font-family: var(--font-sans);
  font-size: .78rem;
  font-weight: 700;
  color: var(--ink-muted);
  background: var(--surface);
}
.worked-example > li:focus-visible { background: var(--tint-light); }
.worked-example > li.we-new { animation: we-in var(--t-morph) var(--ease); }
@keyframes we-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.worked-example .why {
  display: block;
  margin-top: .4em;
  padding-left: var(--s-3);
  border-left: 2px solid var(--c-inv);
  font-family: var(--font-sans);
  font-size: .8rem;
  color: var(--ink-muted);
}
.we-bar { display: flex; align-items: center; gap: var(--s-3); margin: calc(-1 * var(--s-3)) 0 var(--s-5); flex-wrap: wrap; }
.we-count { font-family: var(--font-sans); font-size: .78rem; color: var(--ink-muted); }
.we-all { font-family: var(--font-sans); font-size: .78rem; margin-left: auto; }

/* ---------------------------------------------------------------- deep dive and other details */

details { --flow: .8em; }
summary { cursor: pointer; }
summary::-webkit-details-marker { display: none; }
.deep-dive {
  margin: var(--s-6) 0;
  border: 1px solid var(--rule);
  border-radius: var(--r-m);
  background: var(--surface);
  padding: 0 var(--s-5);
}
.deep-dive > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: .6em;
  padding: var(--s-4) 0;
  font-family: var(--font-sans);
  font-size: .9rem;
  font-weight: 650;
  min-height: 44px;
}
.deep-dive > summary::before {
  content: "";
  width: .55em;
  height: .55em;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform var(--t-ui) var(--ease);
  flex: none;
}
.deep-dive[open] > summary::before { transform: rotate(45deg); }
.deep-dive > summary::after {
  content: "Optional";
  margin-left: auto;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-muted);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: .1em .6em;
}
.deep-dive[open] { padding-bottom: var(--s-5); }

details.long-desc { margin-top: var(--s-3); font-family: var(--font-sans); font-size: .8rem; color: var(--ink-muted); }
details.long-desc > summary { display: inline-flex; align-items: center; gap: .4em; min-height: 24px; color: var(--ink-muted); text-decoration: underline; text-underline-offset: .18em; }
details.long-desc > summary::before { content: "\25B8"; display: inline-block; text-decoration: none; transition: transform var(--t-ui) var(--ease); }
details.long-desc[open] > summary::before { transform: rotate(90deg); }

/* ---------------------------------------------------------------- toast */

.toast-region {
  position: fixed;
  left: 50%;
  bottom: var(--s-5);
  transform: translateX(-50%);
  z-index: 60;
  display: grid;
  gap: var(--s-2);
  width: min(92vw, 460px);
  pointer-events: none;
}
/* wide screens: bottom left, clear of the lab being read */
@media (min-width: 1200px) {
  .toast-region { left: var(--s-4); transform: none; width: min(300px, 92vw); }
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-lift);
  font-family: var(--font-sans);
  font-size: .85rem;
  animation: toast-in 240ms var(--ease);
}
.toast code { background: color-mix(in srgb, var(--bg) 16%, transparent); color: inherit; }
.toast-icon { width: 1.5em; height: 1.5em; color: var(--c-light); }
.toast-text { flex: 1; }
.toast-close { background: none; border: 0; color: inherit; width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--r-s); opacity: .75; }
.toast-close:hover { opacity: 1; background: color-mix(in srgb, var(--bg) 14%, transparent); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity 200ms var(--ease), transform 200ms var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- lab lock overlay and inline confirm */

.lab-lock {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(5px) saturate(.6);
  backdrop-filter: blur(5px) saturate(.6);
  border-radius: inherit;
}
.lab-lock-card {
  max-width: 34ch;
  text-align: center;
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-m);
  box-shadow: var(--shadow-lift);
  font-family: var(--font-sans);
  font-size: .9rem;
  display: grid;
  gap: var(--s-3);
  justify-items: center;
}
.lab-lock-icon { width: 2em; height: 2em; color: var(--c-light-text); }
.lab-lock-skip { font-size: .8rem; }

.confirm-inline {
  display: grid;
  gap: var(--s-2);
  margin: var(--s-2) 0;
  padding: var(--s-3) var(--s-4);
  border: 1px solid color-mix(in srgb, var(--c-light) 45%, var(--rule));
  background: var(--tint-light);
  border-radius: var(--r-m);
  font-family: var(--font-sans);
  font-size: .84rem;
  animation: toast-in 180ms var(--ease);
}
.confirm-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }

/* ---------------------------------------------------------------- generic cards */

.card {
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
}

/* The orientation card (docs/redesign/PATTERNS.md) */
.card.orient { margin: var(--s-6) 0; max-width: 40rem; }
.card.orient ol { margin: var(--s-3) 0 0; padding-left: 1.5em; }
.card.orient li + li { margin-top: var(--s-2); }
.card.orient > :is(p, ol, ul) + :is(p, ol, ul) { margin-top: var(--s-3); }
.card.orient > :last-child { margin-bottom: 0; }

/* Try-it Done pill (exercise.js markTry) */
[data-goal] .try-done { margin-left: auto; font-size: .72rem; }
[data-goal].is-done { border-left-color: var(--c-ok); }
@media (prefers-reduced-motion: no-preference) {
  html:not([data-motion="reduced"]) [data-goal] .try-done { animation: try-done-in 300ms var(--ease) 1; }
}
@keyframes try-done-in { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
