/* Page components for the UE interface guide. Everything here is built from
   the Organic tokens in design-system.css; nothing hard-codes a brand color.

   Layout note: the source design switched the sidebar between a column and a
   scrolling row with a JS matchMedia listener. Here it is a media query — the
   breakpoint (820px) is the same, but the page reflows before scripts run. */

:root {
  /* The highlight wash shared by chapter 04's hovered lines and chapter 05's
     stepped lines. One value so the two demos read as the same gesture. */
  --hl: color-mix(in srgb, var(--color-accent-500) 22%, transparent);
}

/* ── page shell ─────────────────────────────────────────────────────────── */

.page {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 100vh;
  overflow-y: auto;
  padding: 40px 26px 40px 34px;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.sidebar__brand { display: flex; flex-direction: column; gap: 6px; }
.sidebar__mark-row { display: flex; align-items: center; gap: 10px; }
.sidebar__mark {
  width: 30px; height: 30px; flex: none;
  border-radius: 999px;
  background: var(--color-accent);
}
.sidebar__title { font-family: var(--font-heading); font-size: 21px; line-height: 1.1; }
.sidebar__sub { font-size: 13px; color: var(--color-neutral-700); padding-left: 40px; }

.toc { display: flex; flex-direction: column; gap: 3px; }
.toc__item {
  display: flex;
  gap: 10px;
  align-items: baseline;
  flex: none;
  padding: 9px 12px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  color: var(--color-neutral-900);
  background: transparent;
}
.toc__item:hover { background: var(--color-neutral-200); color: var(--color-neutral-900); }
.toc__item.is-active { background: var(--color-accent-200); }
.toc__num { font-family: var(--font-mono); font-size: 11px; color: var(--color-neutral-600); }

.sidebar__foot {
  margin-top: auto;
  font-size: 12px;
  line-height: 1.7;
  color: var(--color-neutral-700);
  border-top: 1px solid var(--color-divider);
  padding-top: 18px;
}

.main {
  min-width: 0;
  padding: 40px 56px 140px 40px;
  display: flex;
  flex-direction: column;
  gap: 104px;
}

/* ── section furniture ──────────────────────────────────────────────────── */

.sec { display: flex; flex-direction: column; gap: 28px; scroll-margin-top: 32px; }
#ch1 { gap: 32px; }

.sec__head { display: flex; flex-direction: column; gap: 14px; max-width: 760px; }
#ch1 .sec__head { gap: 18px; }

.badge {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--color-accent-2-200);
  color: var(--color-accent-2-800);
  font-size: 13px;
  font-weight: 600;
}

.kicker {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 1.5px;
  font-weight: 600;
  color: var(--color-accent-700);
}

.hero__title {
  font-size: clamp(34px, 6.4vw, 60px);
  line-height: 1.1;
  margin: 0;
  letter-spacing: -0.5px;
  text-wrap: pretty;
}
.hero__lede {
  margin: 0;
  font-size: clamp(16px, 1.9vw, 19px);
  line-height: 1.85;
  color: var(--color-neutral-800);
  text-wrap: pretty;
}

.sec__title { font-size: clamp(26px, 4.4vw, 40px); line-height: 1.2; margin: 0; }
.sec__lede {
  margin: 0;
  font-size: clamp(15px, 1.7vw, 17px);
  line-height: 1.85;
  color: var(--color-neutral-800);
  text-wrap: pretty;
}

b, strong { font-weight: 600; }

/* Inline code that sits inside a lede, sized to the surrounding prose. */
.code-inline {
  font-size: 16px;
  background: var(--color-neutral-200);
  padding: 2px 7px;
  border-radius: 6px;
}

/* ── 01 — why cards ─────────────────────────────────────────────────────── */

.why {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 18px;
  max-width: 1000px;
}
.why__card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 26px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}
.why__num {
  width: 38px; height: 38px;
  border-radius: 999px;
  background: var(--color-accent-200);
  color: var(--color-accent-800);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14px;
}
.why__title { font-family: var(--font-heading); font-size: 19px; line-height: 1.3; }
.why__text { font-size: 14.5px; line-height: 1.75; color: var(--color-neutral-800); }

/* ── 02 — before / after ────────────────────────────────────────────────── */

.switch {
  display: inline-flex;
  align-self: flex-start;
  padding: 4px;
  border-radius: 999px;
  background: var(--color-neutral-200);
  gap: 4px;
}
.switch__opt {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: 999px;
  color: var(--color-neutral-700);
  background: transparent;
}
.switch__opt:hover { color: var(--color-accent-800); }
.switch__opt.is-on { background: var(--color-neutral-100); color: var(--color-accent-800); }

.ba {
  display: none;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr));
  gap: 24px;
  align-items: stretch;
}
.ba.is-on { display: grid; }

.ba__diagram {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 34px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.tree { display: flex; flex-direction: column; align-items: center; }
.tree--wide { gap: 18px; }
.tree__pair { display: flex; gap: 26px; align-items: center; }
.tree__branch { display: flex; flex-direction: column; align-items: center; }
.tree__row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.tree--wide .tree__row { gap: 10px; }
.tree__note { font-size: 13px; color: var(--color-neutral-700); text-align: center; }

/* The vertical rules between tree levels. */
.tick { width: 2px; height: 22px; background: var(--color-neutral-400); flex: none; }
.tick--sm { height: 18px; }
.tick--lg { height: 26px; }

.pill {
  padding: 12px 26px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.pill--sm { padding: 10px 20px; font-size: 13px; font-weight: 400; }
.pill--xs { padding: 9px 18px; font-size: 13px; font-weight: 400; }
.pill--neutral { background: var(--color-neutral-300); }
.pill--faint { background: var(--color-neutral-200); }
.pill--accent { background: var(--color-accent-200); color: var(--color-accent-800); }
.pill--iface {
  background: var(--color-accent-2-200);
  color: var(--color-accent-2-800);
  border: 2px dashed var(--color-accent-2-500);
}
.pill--off { opacity: .5; text-decoration: line-through; }

.callout {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  border-radius: var(--radius-md);
  padding: 18px 20px;
}
.callout__mark {
  width: 24px; height: 24px; flex: none;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  color: var(--color-neutral-100);
}
.callout__text { font-size: 14.5px; line-height: 1.8; }
.callout--warn { background: var(--color-accent-100); }
.callout--warn .callout__mark { background: var(--color-accent); }
.callout--warn .callout__text { color: var(--color-accent-900); }
.callout--ok { background: var(--color-accent-2-100); }
.callout--ok .callout__mark { background: var(--color-accent-2-600); font-size: 14px; }
.callout--ok .callout__text { color: var(--color-accent-2-900); }
.callout--dark { background: var(--color-neutral-800); padding: 20px 22px; }
.callout--dark .callout__mark { background: var(--color-accent); }
.callout--dark .callout__text { color: var(--color-neutral-200); line-height: 1.85; }

/* ── code blocks ────────────────────────────────────────────────────────── */

.code {
  background: var(--color-neutral-900);
  border-radius: var(--radius-lg);
  padding: 26px 24px;
  overflow: auto;
}
.code--panel { padding: clamp(20px, 3vw, 30px) clamp(16px, 2.4vw, 28px); box-shadow: var(--shadow-md); }
/* Line-addressable listings pad each row instead of the box, so a highlight
   can bleed to both edges. */
.code--lines { padding: 28px 4px; box-shadow: var(--shadow-md); overflow-x: auto; }
.code--tight { padding: 24px 4px; }

.code__body {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(11.5px, 2.4vw, 13.5px);
  line-height: 1.85;
  white-space: pre;
  color: var(--color-neutral-100);
}
.code__body--bare { font-size: clamp(11.5px, 2.4vw, 13.5px); line-height: 1.9; }

.code__file {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--color-neutral-500);
  padding: 0 24px 14px 24px;
}
.code--panel .code__file { padding-inline: 0; }

.code__lines {
  font-family: var(--font-mono);
  font-size: clamp(11.5px, 2.4vw, 13.5px);
  line-height: 1.9;
  color: var(--color-neutral-100);
  /* Without this the rows are only as wide as the visible box, so a highlight
     stops mid-line as soon as the listing is scrolled sideways. */
  min-width: max-content;
}
.code__line {
  padding: 0 24px;
  white-space: pre;
  background: transparent;
  transition: background .12s ease;
}
.code__line[data-hl] { cursor: default; }
.code__line.is-hot { background: var(--hl); }

/* Syntax roles. The ramp steps are chosen for contrast on neutral-900. */
.code .k { color: var(--color-accent-300); }
.code .s { color: var(--color-accent-2-300); }
.code .c { color: var(--color-neutral-500); }

/* Panes inside a .code--panel: one visible at a time. */
[data-pane] { display: none; }
[data-pane].is-on { display: block; }
.steps-doc.is-on,
.pane-stack.is-on { display: flex; flex-direction: column; gap: 22px; }

/* ── 03 — class map ─────────────────────────────────────────────────────── */

.map {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr));
  gap: 26px;
  align-items: start;
}
.map__diagram {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 40px 34px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.map__label { font-size: 12px; color: var(--color-neutral-700); margin-bottom: 8px; text-align: center; }
.map__row { display: flex; gap: 18px; align-items: stretch; flex-wrap: wrap; justify-content: center; }

.mapnode {
  cursor: pointer;
  font-family: var(--font-mono);
  border: 2px solid transparent;
  background: var(--color-neutral-200);
  color: var(--color-neutral-900);
}
.mapnode.is-on { border-color: var(--color-accent-600); box-shadow: var(--shadow-md); }
.mapnode--box { font-size: 14px; font-weight: 600; padding: 14px 26px; border-radius: var(--radius-md); }
.mapnode__role { font-family: var(--font-body); font-weight: 400; color: var(--color-neutral-700); }
.mapnode--card {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 22px;
  border-radius: var(--radius-md);
}
.mapnode--u { background: var(--color-accent-2-200); }
.mapnode--u .mapnode__name { color: var(--color-accent-2-900); }
.mapnode--u .mapnode__desc { color: var(--color-accent-2-800); }
.mapnode--i { background: var(--color-accent-200); }
.mapnode--i .mapnode__name { color: var(--color-accent-900); }
.mapnode--i .mapnode__desc { color: var(--color-accent-800); }
.mapnode__name { font-size: 14px; font-weight: 600; }
.mapnode__desc { font-family: var(--font-body); font-size: 12.5px; }
.mapnode--pill { font-size: 13px; padding: 12px 20px; border-radius: 999px; }

.detail {
  background: var(--color-neutral-100);
  border-radius: var(--radius-lg);
  padding: 30px 28px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 260px;
}
.detail__title { font-family: var(--font-heading); font-size: 22px; line-height: 1.25; }
.detail__body {
  display: none;
  font-size: 15px;
  line-height: 1.9;
  color: var(--color-neutral-800);
}
.detail__body.is-on { display: block; }

/* ── 04 — header anatomy ────────────────────────────────────────────────── */

.anatomy {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: 24px;
  align-items: start;
}
.notes { display: flex; flex-direction: column; gap: 12px; }
.note {
  background: var(--color-neutral-100);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  border-left: 5px solid var(--color-neutral-300);
  box-shadow: var(--shadow-sm);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.note.is-hot { border-left-color: var(--color-accent); box-shadow: var(--shadow-md); }
.note__term {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--color-accent-800);
}
.note__text { font-size: 14.5px; line-height: 1.8; color: var(--color-neutral-800); }

/* ── 05 — call flow ─────────────────────────────────────────────────────── */

.flow {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 3vw, 34px);
  display: flex;
  flex-direction: column;
  gap: 26px;
}
.flow__bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.flow__count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--color-neutral-700);
}

.btn-pill {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 24px;
  border-radius: 999px;
  background: var(--color-accent);
  color: var(--color-neutral-100);
}
.btn-pill:hover { background: var(--color-accent-600); }
.btn-pill:active { background: var(--color-accent-700); }
.btn-pill--ghost {
  padding: 11px 20px;
  background: transparent;
  color: var(--color-accent-700);
  border: 2px solid var(--color-accent-400);
}
.btn-pill--ghost:hover { background: var(--color-accent-100); color: var(--color-accent-800); }
.btn-pill--ghost:active { background: var(--color-accent-200); }

.steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(46%, 132px), 1fr));
  gap: 10px;
}
.step {
  cursor: pointer;
  text-align: left;
  border-radius: var(--radius-md);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--color-neutral-200);
  color: var(--color-neutral-800);
}
.step:hover { background: var(--color-neutral-300); }
.step.is-on {
  background: var(--color-accent);
  color: var(--color-neutral-100);
  box-shadow: var(--shadow-md);
}
.step__no { font-family: var(--font-mono); font-size: 11px; opacity: .7; }
.step__name { font-size: 13.5px; font-weight: 600; line-height: 1.5; }

.flow__panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}
.flow__desc {
  background: var(--color-neutral-100);
  border-radius: var(--radius-md);
  padding: 26px;
  min-height: 190px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.flow__title { font-family: var(--font-heading); font-size: 21px; line-height: 1.3; }
.flow__text {
  display: none;
  font-size: 15px;
  line-height: 1.9;
  color: var(--color-neutral-800);
}
.flow__text.is-on { display: block; }
.flow__panes .code--lines .code__line { padding-inline: 22px; }
.flow__panes .code--lines .code__file { padding: 0 22px 12px 22px; }

/* ── 06/07 — Blueprint step documents ───────────────────────────────────── */

.steps-doc__title { font-family: var(--font-heading); font-size: 20px; color: var(--color-neutral-100); }
.steps-doc__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 16px;
}
.steps-doc__card {
  background: var(--color-neutral-800);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.steps-doc__no { font-family: var(--font-mono); font-size: 11px; color: var(--color-accent-300); }
.steps-doc__no--alt { color: var(--color-accent-2-300); }
.steps-doc__no--mute { color: var(--color-neutral-400); }
.steps-doc__text { font-size: 14.5px; line-height: 1.8; color: var(--color-neutral-200); }
.steps-doc__foot {
  font-size: 14px;
  line-height: 1.8;
  color: var(--color-neutral-400);
  border-top: 1px solid var(--color-neutral-700);
  padding-top: 18px;
}
.steps-doc__text code,
.steps-doc__foot code,
.callout--dark code { color: inherit; }

/* ── 08 — inventory filter ──────────────────────────────────────────────── */

.filter {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: clamp(20px, 3vw, 34px);
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.filter__head { display: flex; flex-direction: column; gap: 6px; }
.filter__title { font-family: var(--font-heading); font-size: 20px; line-height: 1.3; }
.filter__sub { font-size: 14px; line-height: 1.7; color: var(--color-neutral-700); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--color-neutral-200);
  color: var(--color-neutral-800);
}
.chip:hover { background: var(--color-neutral-300); }
.chip.is-on { background: var(--color-accent); color: var(--color-neutral-100); }

.items {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: 14px;
}
.item {
  background: var(--color-neutral-100);
  border-radius: var(--radius-md);
  padding: 18px 18px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 2px solid transparent;
  box-shadow: var(--shadow-sm);
  opacity: 1;
  transition: opacity .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.item.is-dim { opacity: .28; }
.item.is-hit { border-color: var(--color-accent-600); box-shadow: var(--shadow-md); }
.item__cls {
  font-family: var(--font-mono);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--color-neutral-900);
}
.item__jp { font-size: 12.5px; color: var(--color-neutral-700); }
.item__tags { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 2px; }
.itag {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--color-accent-2-200);
  color: var(--color-accent-2-900);
}
.itag.is-on { background: var(--color-accent-2-600); color: var(--color-neutral-100); }

/* ── 09 — quiz ──────────────────────────────────────────────────────────── */

.quiz {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 318px), 1fr));
  gap: 20px;
  max-width: 1120px;
}
.qcard {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.qcard__head { display: flex; gap: 12px; align-items: baseline; }
.qcard__no {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--color-accent-700);
  flex: none;
}
.qcard__q { font-size: 16.5px; font-weight: 600; line-height: 1.6; }

.qopts { display: flex; flex-direction: column; gap: 8px; }
.qopt {
  cursor: pointer;
  text-align: left;
  border: 2px solid transparent;
  background: var(--color-neutral-100);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--color-neutral-900);
}
.qopt--mono { font-family: var(--font-mono); font-size: 13px; }
.qopt:hover { background: var(--color-neutral-200); }
/* Once answered the whole card is settled: the right answer greens, the
   picked-and-wrong one oranges, the rest fade back. */
.qcard.is-answered .qopt { background: var(--color-neutral-200); cursor: default; }
.qcard.is-answered .qopt.is-correct {
  background: var(--color-accent-2-200);
  border-color: var(--color-accent-2-600);
}
.qcard.is-answered .qopt.is-chosen {
  background: var(--color-accent-200);
  border-color: var(--color-accent-600);
}

.qfb {
  display: none;
  gap: 12px;
  align-items: flex-start;
  background: var(--color-neutral-100);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}
.qcard.is-answered .qfb { display: flex; }
.qfb__mark { font-weight: 800; font-size: 16px; color: var(--color-accent-700); flex: none; }
.qfb__text { font-size: 14px; line-height: 1.8; color: var(--color-neutral-800); }

.quiz__foot { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding-top: 8px; }
.quiz__next { font-size: 14px; color: var(--color-neutral-700); }

/* ── narrow ─────────────────────────────────────────────────────────────── */

@media (max-width: 820px) {
  .page { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    height: auto;
    padding: 16px 16px 12px 16px;
    gap: 12px;
  }
  /* The chapter list becomes a scrolling strip under the brand. */
  .toc { flex-direction: row; overflow-x: auto; padding-bottom: 6px; }
  .sidebar__foot { display: none; }

  .main { padding: 24px 18px 90px 18px; gap: 72px; }

  /* Two panes side by side leave ~150px each on a phone. Stack them. */
  .flow__panes { grid-template-columns: minmax(0, 1fr); }

  .ba__diagram, .map__diagram { padding: 24px 18px; }
  .tree__pair { flex-direction: column; gap: 18px; }
  .code { padding: 22px 18px; }
  .code--lines, .code--tight { padding: 22px 0; }
  .code__line, .flow__panes .code--lines .code__line { padding-inline: 18px; }
  .code__file, .flow__panes .code--lines .code__file { padding: 0 18px 12px 18px; }
  .qcard { padding: 22px 20px; }
}
