/* Shared chrome for the Calc II geometry apps.
 * Tokens + site header/footer + hub card grid + the two-column app shell
 * (sidebar of controls on the left, figures on the right).
 * Every app under /apps/<topic>/ links this file and reuses the shell classes.
 */

:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #d9dee5;
  --border-soft: #e8ecf1;
  /* Text colours are held at 7:1 against every background they land on — the
     WCAG AAA bar, not the AA 4.5:1. --muted is bound by the badge's #eef1f5
     and --accent by the accent tint below, so neither can be lightened to suit
     white alone. The curve colours further down are graphics, not text: 3:1 is
     what WCAG asks of them, and darkening them would pull the three together. */
  --ink: #1f2733;
  --muted: #48515d;
  --accent: #1b49ae;
  --accent-soft: #e8f0ff;
  --warn-bg: #fff7e6;
  --warn-border: #f0c36d;
  --err-bg: #fdecea;
  --err-border: #e0857f;
  --err-ink: #8a1c14;

  --curve-1: #2d70b3;
  --curve-2: #388c46;
  --curve-3: #c74440;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 4px 12px rgba(16, 24, 40, .08);
  --sidebar-w: 340px;
  --header-h: 46px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* the hidden attribute must win over any display rule a class sets */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---------------------------------------------------------------- header */

.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.site-header .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  font-size: 14px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.site-header .brand svg { display: block; }
.site-header .crumb {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.site-header .crumb::before { content: "/"; margin-right: 8px; color: var(--border); }
.site-header .spacer { flex: 1; }

/* ---------------------------------------------------------------- footer */

/* content pages stretch to the viewport so the footer sits at the bottom even
   when the page is short (the app shell sizes itself and opts out) */
body.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body.page > main { flex: 1 0 auto; }

.site-footer {
  flex: 0 0 auto;
  padding: 18px;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
}
.site-footer a { color: var(--muted); }

/* the app shell fills the viewport, so its credit sits at the foot of the sidebar */
.sidebar-credit {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-top: 1px solid var(--border-soft);
  font-size: 10px;
  color: var(--muted);
}
.sidebar-credit a { color: var(--muted); }

/* back to top — only reachable once the page actually scrolls, i.e. when the
   shell has stacked on a narrow screen */
.to-top {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel);
  color: var(--accent);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
}
.to-top.show { display: block; }

/* ------------------------------------------------------------- hub page */

.hub {
  max-width: 980px;
  margin: 0 auto;
  padding: 40px 20px 8px;
}
.hub h1 {
  font-size: 28px;
  margin: 0 0 8px;
  letter-spacing: -.01em;
}
.hub .lede {
  margin: 0 0 32px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  max-width: 60ch;
}
.hub h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 32px 0 12px;
}
.hub h2:first-of-type { margin-top: 0; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(272px, 1fr));
  gap: 14px;
}
.card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
a.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: #b9c6d8;
}
.card .card-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.card h3 {
  font-size: 15px;
  margin: 0 0 5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}
/* No opacity here: fading the whole card dropped its text to an effective
   2.97:1. The greyed icon and the "Coming soon" badge already say these are not
   built yet, so the wording stays at full strength. */
.card.soon {
  background: #fbfcfd;
  box-shadow: none;
}
.card.soon .card-icon { background: #eef1f5; color: var(--muted); }
.badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eef1f5;
  color: var(--muted);
  white-space: nowrap;
}
.badge.live { background: var(--accent-soft); color: var(--accent); }

/* ----------------------------------------------------------- app shell */

.app-shell {
  display: flex;
  align-items: stretch;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 14px 6px;
}
.app-shell.collapsed .sidebar { display: none; }

/* collapse handle sits on the divider between the panes */
.collapse-btn {
  position: absolute;
  top: 50%;
  left: calc(var(--sidebar-w) - 11px);
  transform: translateY(-50%);
  z-index: 5;
  width: 22px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.collapse-btn:hover { color: var(--accent); border-color: var(--accent); }
.app-shell.collapsed .collapse-btn { left: 6px; }

.graph-col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
}
.graph-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.graph-panel.top { flex: 42 1 0; }
/* the two 3D views sit side by side under the region plot */
.graph-row {
  display: flex;
  gap: 10px;
  flex: 58 1 0;
  min-height: 0;
}
.graph-row > .graph-panel { flex: 1 1 0; min-width: 0; }
.panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px;
  min-height: 33px;              /* keeps side-by-side panels' plots aligned */
  border-bottom: 1px solid var(--border-soft);
}
.panel-head h2 {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 0;
}
.panel-head .spacer { flex: 1; }
.panel-body { flex: 1 1 auto; min-height: 0; position: relative; }
.plot { position: absolute; inset: 0; }
.plot.hidden { display: none; }

/* ------------------------------------------------- a figure, put in words */
/* Every plot carries a description that tracks the model, so the apps can be
   read without seeing them. It stays in the DOM when collapsed rather than
   taking the hidden attribute: aria-describedby cannot resolve to a hidden
   element, and the whole point is that a screen reader reaches the text
   without anyone having to find the button first. Collapsed it is clipped to
   a pixel — the same idiom as a visually-hidden label. */
.figure-desc {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow-y: auto;
  padding: 12px 16px;
  background: var(--panel);
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
}
.figure-desc.is-collapsed {
  inset: auto;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------- sidebar controls */

.group { margin-bottom: 16px; }
.group .title {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 7px;
}
/* a group heading with a "?" that reveals its help text */
.title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}
.title-row > .title { margin-bottom: 0; }
.help-btn {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}
.help-btn:hover, .help-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }

.hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.45;
  margin-top: 6px;
}
.hint[hidden] { display: none; }

/* text input with its typeset form alongside, rather than stacked below */
.field-row { display: flex; align-items: center; gap: 10px; }
.field-row input[type="text"] { flex: 1 1 auto; min-width: 0; }
.field-row .preview { flex: 0 0 auto; margin-top: 0; max-width: 45%; }
.hint code {
  font-family: var(--mono);
  background: #f1f4f8;
  padding: 1px 4px;
  border-radius: 4px;
}

input[type="text"],
input[type="number"] {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 13px;
  font-family: var(--mono);
  background: #fff;
  color: var(--ink);
}
input[type="text"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(27, 73, 174, .12);
}
input[type="number"] { width: 72px; }
input[type="text"].wide { width: 100%; }
/* a short text field standing in for a number, so expressions like pi/2 fit */
input[type="text"].num-in { width: 88px; }

/* expression rows (Desmos-style list) */
.expr-list { display: flex; flex-direction: column; gap: 8px; }
.expr-row {
  display: grid;
  grid-template-columns: 12px 1fr 20px;
  align-items: start;
  gap: 8px;
}
.expr-row.hidden { display: none; }
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-top: 8px;
}
.swatch.c1 { background: var(--curve-1); }
.swatch.c2 { background: var(--curve-2); }
.swatch.c3 { background: var(--curve-3); }
.expr-main { min-width: 0; }
.expr-main .expr-label {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-family: var(--mono);
  margin-bottom: 3px;
}
.expr-main input[type="text"] { width: 100%; }
.preview {
  min-height: 18px;
  margin-top: 4px;
  padding-left: 2px;
  font-size: 13px;
  color: var(--ink);
  overflow-x: auto;
  overflow-y: hidden;
}
.preview.raw { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.preview:empty { display: none; }
.row-x {
  border: none;
  background: none;
  color: var(--border);
  font-size: 15px;
  line-height: 1;
  padding: 6px 0 0;
  cursor: pointer;
}
.row-x:hover { color: var(--err-ink); }
.add-curve {
  margin-top: 8px;
  border: 1px dashed var(--border);
  background: none;
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
}
.add-curve:hover { border-color: var(--accent); color: var(--accent); }
.add-curve.hidden { display: none; }

/* segmented controls — labels wrapping hidden radios */
.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #f3f5f8;
}
.segmented label {
  flex: 1 1 0;
  text-align: center;
  font-size: 12px;
  padding: 6px 4px;
  cursor: pointer;
  color: var(--muted);
  white-space: nowrap;
  border-right: 1px solid var(--border);
}
.segmented label:last-child { border-right: none; }
/* visually hidden but still focusable and exposed to assistive tech */
.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.segmented label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.segmented label:has(input:checked) {
  background: var(--panel);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* a segmented control with more options than fit one row */
.segmented.wrap { flex-wrap: wrap; }
.segmented.wrap label { flex: 1 0 45%; }

.inline { display: flex; align-items: center; gap: 7px; margin-top: 8px; }
.inline label { font-size: 12px; color: var(--muted); }
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  cursor: pointer;
}
.check input { accent-color: var(--accent); }

button.primary {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
}
button.secondary {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
button.secondary:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }

/* compact button in a panel head */
.panel-head button.secondary { padding: 3px 10px; font-size: 11px; }

/* banner */
.banner {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.45;
  display: none;
  margin-bottom: 14px;
}
.banner.info { display: block; background: var(--accent-soft); border: 1px solid #bcd2ff; }
.banner.warn { display: block; background: var(--warn-bg); border: 1px solid var(--warn-border); }
.banner.err  { display: block; background: var(--err-bg); border: 1px solid var(--err-border); color: var(--err-ink); }

/* sweep control living in a panel head, beside the title */
.panel-sweep {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}
.panel-sweep .val { font-family: var(--mono); color: var(--ink); white-space: nowrap; }
.panel-sweep input[type="range"] { width: 170px; accent-color: var(--accent); }

/* the unit a field is measured in, sitting after the input */
.unit { font-size: 11px; color: var(--muted); font-family: var(--mono); }

/* computed figures listed in the sidebar: label on the left, value on the right */
.readout {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
  margin: 0;
  font-size: 12px;
}
.readout dt { color: var(--muted); }
.readout dd {
  margin: 0;
  text-align: right;
  font-family: var(--mono);
  color: var(--ink);
  overflow-x: auto;
}
.readout dd.strong { font-weight: 600; color: var(--accent); }

/* a panel that carries the picture gets more of the row than its neighbour */
.graph-panel.wide { flex: 1.55 1 0; }

/* a panel of steps to work through rather than a plot: each step names what to
   find, and folds its answer away until it is asked for */
/* the body scrolls as a whole, so opening every step never clips the last one */
.panel-body.scroll { overflow-y: auto; }
.steps {
  margin: 0;
  padding: 4px 16px 4px 36px;
}
.steps li { margin-bottom: 10px; }
.steps li::marker { color: var(--muted); font-size: 13px; }
.step-toggle {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 2px 0;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.step-toggle::after {
  content: "▸";
  margin-left: 7px;
  font-size: 11px;
  font-weight: 400;
  color: var(--accent);
}
.step-toggle[aria-expanded="true"]::after { content: "▾"; }
.step-toggle:hover { color: var(--accent); }
.step-math {
  display: block;
  margin: 4px 0 2px;
  font-size: 15px;
  color: var(--ink);
  overflow-x: auto;
  overflow-y: hidden;
}
.step-math.raw { font-family: var(--mono); font-size: 12px; }
.steps-note {
  margin: 0;
  padding: 0 16px 14px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}
.steps-note.top { padding: 12px 16px 10px; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
  .sidebar {
    width: auto;
    flex: 0 0 auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-scroll { overflow-y: visible; }
  .collapse-btn { display: none; }
  /* the head stacks rather than squeezing the slider off the edge */
  .panel-head { flex-wrap: wrap; }
  .panel-sweep input[type="range"] { width: 120px; }
  .app-shell.collapsed .sidebar { display: flex; }
  .graph-col { height: auto; }
  .graph-panel.top { flex: 0 0 auto; height: 320px; }
  .graph-row { flex-direction: column; flex: 0 0 auto; }
  .graph-row > .graph-panel { flex: 0 0 auto; height: 380px; }
  .hub { padding-top: 26px; }
}
