:root {
  /* Henric's palette, from the lecturer page. */
  --mint: #5CE0B8;
  --mint-light: #B8F0DF;
  --mint-faint: #E5F9F2;
  --lavender: #C4A6E8;
  --lavender-light: #E0D0F5;
  --lavender-faint: #F0EAF8;
  --paper: #FAFAF7;
  --cream: #F5F3EE;
  --ink: #1A1A2E;
  --ink-mid: #3D3D56;
  --ink-light: #5E5E73;
  --stage: #0B1D24;

  /* Chart marks, validated for CVD and 3:1 on --paper (dataviz validator). */
  --mark-net: #1E9C78;
  --mark-trip: #9B7BC7;
  --mark-ops: #5A4A8A;
  --mark-rest: #E4E1EA;

  /* Text-safe deep steps of the two brand hues. */
  --mint-text: #14705A;
  --lavender-text: #5A4A8A;

  --font-display: 'Outfit', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;

  --measure: 42rem;
  --wide: 82rem;
  --side: clamp(19rem, 29vw, 25rem);
  --gutter: clamp(1.25rem, 4vw, 3rem);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 106.25%; }

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--lavender-text); text-underline-offset: 0.18em; }
a:hover { color: var(--ink); }

:focus-visible {
  outline: 3px solid var(--lavender);
  outline-offset: 3px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.wrap { max-width: var(--wide); margin: 0 auto; padding: 0 var(--gutter); }

/* ---------- Top line ---------- */

.topline {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding-top: 1.5rem; padding-bottom: 1.5rem;
  font-size: 0.9rem; color: var(--ink-light);
}
.topline a { color: var(--ink); font-weight: 600; text-decoration: none; white-space: nowrap; }
.topline b { color: var(--ink); font-family: var(--font-display); font-weight: 700; }
@media (max-width: 34rem) { .topline-long { display: none; } }
.topline a:hover { color: var(--lavender-text); }

/* ---------- The question, as a sentence you complete ---------- */

/* ---------- Workspace: question, chart and steps, with the answer beside them ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: 'ask' 'side' 'flow' 'steps';
  padding-top: clamp(2rem, 8vh, 6rem);
}
.ask { grid-area: ask; padding-bottom: clamp(2.5rem, 7vh, 5rem); }
.result { grid-area: side; }
.flow { grid-area: flow; }
.steps { grid-area: steps; }

/* On a computer the answer stays in view while you change the numbers. */
@media (min-width: 64rem) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) var(--side);
    grid-template-rows: auto auto 1fr;
    grid-template-areas: 'ask side' 'flow side' 'steps side';
    column-gap: clamp(3rem, 5vw, 5rem);
  }
  .result { grid-row: 1 / span 3; align-self: start; position: sticky; top: 1.5rem; max-height: calc(100vh - 3rem); overflow-y: auto; }
  .ask h1 { font-size: clamp(2.1rem, 3.2vw, 3.3rem); max-width: none; }
  .ask { padding-bottom: 3rem; }
}

.ask h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.1rem, 5.6vw, 4.3rem);
  line-height: 1.22;
  letter-spacing: -0.02em;
  max-width: 17ch;
}
@media (min-width: 60rem) and (max-width: 63.99rem) { .ask h1 { max-width: 20ch; } }
.ask h1.is-list { font-size: clamp(1.7rem, 2.5vw, 2.5rem); line-height: 1.35; max-width: none; }

.slot {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  background: linear-gradient(to top, var(--mint-light) 0.28em, transparent 0.28em);
  border: 0;
  border-radius: 0;
  padding: 0 0.08em;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
input.slot:hover { background-image: linear-gradient(to top, var(--mint) 0.28em, transparent 0.28em); }

select.slot {
  padding-right: 0.55em;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%231A1A2E' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(to top, var(--mint-light) 0.28em, transparent 0.28em);
  background-repeat: no-repeat, no-repeat;
  background-position: right 0.08em center, 0 0;
  background-size: 0.42em auto, 100% 100%;
  max-width: 100%;
}
select.slot:hover {
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%231A1A2E' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(to top, var(--mint) 0.28em, transparent 0.28em);
}
/* The open list is read, not displayed: body type, not the headline's size. */
select.slot option { font: 400 1rem/1.4 var(--font-body); letter-spacing: 0; }
input.slot { cursor: text; -moz-appearance: textfield; }

.row-slot { white-space: nowrap; }
.row-remove {
  font: 400 0.45em/1 var(--font-body);
  vertical-align: 0.5em;
  margin-left: 0.15em;
  width: max(1.7em, 28px); height: max(1.7em, 28px);
  border-radius: 50%;
  border: 1.5px solid #C9C6D3;
  background: transparent;
  color: var(--ink-light);
  cursor: pointer;
}
.row-remove:hover { border-color: var(--ink); color: var(--ink); }

.add-row {
  margin-top: 1.1rem;
  font: 600 1rem var(--font-body);
  color: var(--lavender-text);
  background: none;
  border: 0;
  padding: 0.3rem 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}
.add-row::before { content: '+ '; }
.add-row:hover { color: var(--ink); }
.add-row[hidden] { display: none; }
input.slot::-webkit-inner-spin-button,
input.slot::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.ask-sub {
  margin-top: 1.5rem;
  max-width: var(--measure);
  font-size: 1.12rem;
  color: var(--ink-mid);
}

/* ---------- Result, on the dark stage ---------- */

.result {
  background: var(--stage);
  color: #F2F4F3;
  container-type: inline-size;
  /* Full bleed on small screens: out through the workspace gutter. */
  margin-inline: calc(-1 * var(--gutter));
}
.result-inner {
  padding: clamp(2.5rem, 7vh, 4.5rem) var(--gutter);
  display: grid;
  gap: 1.5rem 3rem;
}
@media (min-width: 44rem) and (max-width: 63.99rem) {
  .result-inner { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: end; }
}
@media (min-width: 64rem) {
  .result { margin-inline: 0; border-radius: 18px; }
  .result-inner { padding: 2rem 1.9rem 2.1rem; gap: 1.25rem; }
  .result .result-figure { font-size: min(4.2rem, 15cqi); }
  .result .result-caption { font-size: 1.08rem; }
  .result .result-actions { margin-top: 1rem; }
  .stickysum { display: none; }
}

.result-figure {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(3rem, 8vw, 6rem);
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--mint);
}
.result-figure .unit { font-size: 0.5em; letter-spacing: 0; }
.result-caption { margin-top: 0.75rem; font-size: 1.2rem; max-width: 30ch; }
.result-note { color: #B9C4C8; max-width: 44ch; }
.result-note strong { color: #F2F4F3; font-weight: 600; }

.result-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.25rem; }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  border: 1.5px solid currentColor;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.result .btn { color: var(--mint); }
.result .btn:hover { background: var(--mint); color: var(--stage); border-color: var(--mint); }

.negative-note {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--lavender);
  color: #F2F4F3;
  max-width: 44ch;
}

/* ---------- Chart ---------- */

.flow { padding-top: clamp(3rem, 8vh, 5rem); }
@media (min-width: 64rem) { .flow { padding-top: 0; } }
.flow h2, .steps h2, .sources h2, .method h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.flow-intro { margin-top: 0.5rem; max-width: var(--measure); color: var(--ink-mid); }

.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem; margin-top: 1.5rem; font-size: 0.92rem; color: var(--ink-mid); list-style: none; }
.legend li { display: inline-flex; align-items: center; gap: 0.45rem; }
.swatch { width: 0.85rem; height: 0.85rem; border-radius: 3px; display: inline-block; }

.bars { margin-top: 1.25rem; display: grid; gap: 1.4rem; }
.bar-row p { font-size: 0.98rem; margin-bottom: 0.35rem; }
.bar-row p b { font-weight: 600; }
.bar-row svg { display: block; width: 100%; height: 28px; overflow: visible; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--ink); color: var(--paper);
  font-size: 0.85rem; line-height: 1.35;
  padding: 0.45rem 0.65rem; border-radius: 6px;
  max-width: 16rem; opacity: 0; transition: opacity 120ms;
}
.tooltip.is-on { opacity: 1; }

/* ---------- Steps: the calculation, written out ---------- */

.steps { padding-top: clamp(3.5rem, 9vh, 6rem); }
.steps-head { display: grid; gap: 1rem; }
@media (min-width: 56rem) { .steps-head { grid-template-columns: 1fr auto; align-items: end; } }

.provenance { display: flex; flex-wrap: wrap; gap: 0.35rem 1.2rem; list-style: none; font-size: 0.88rem; color: var(--ink-light); }
.provenance li { display: inline-flex; align-items: center; gap: 0.4rem; }

.step-list { list-style: none; counter-reset: step; margin-top: 2rem; }
.step {
  counter-increment: step;
  display: grid;
  grid-template-columns: 2.6rem minmax(0, 1fr);
  gap: 0 1rem;
  padding: 1.75rem 0;
  border-top: 1px solid #E6E3EC;
}
.step::before {
  content: counter(step);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.9rem;
  line-height: 1;
  color: var(--lavender-text);
}
.step--total::before { content: '='; color: var(--mint-text); }
.step-body { max-width: var(--measure); }
.step h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.3rem; line-height: 1.3; }
.step p { margin-top: 0.5rem; color: var(--ink-mid); }

.equation {
  margin-top: 0.9rem;
  font-size: 1.12rem;
  line-height: 1.9;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.equation .res { font-weight: 700; white-space: nowrap; }
.equation .op { color: var(--ink-light); padding: 0 0.15em; }

.step.is-off .equation, .step.is-off .why { opacity: 0.45; }

.switch { display: inline-flex; align-items: center; gap: 0.6rem; margin-top: 0.75rem; font-size: 0.95rem; cursor: pointer; }
.switch input { width: 1.1rem; height: 1.1rem; accent-color: var(--mark-net); }

details.why { margin-top: 0.8rem; }
details.why summary { cursor: pointer; color: var(--lavender-text); font-weight: 600; font-size: 0.95rem; }
details.why p { margin-top: 0.5rem; }

/* Chips: every number in an equation is one of these. */
.chip {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0 0.5em;
  line-height: 1.6;
  border-radius: 6px;
  border: 1.5px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  vertical-align: baseline;
}
.chip::before, .mark {
  content: '';
  width: 0.55em; height: 0.55em;
  flex: none;
  display: inline-block;
}
.chip[data-kind='source'] { background: var(--mint-faint); }
.chip[data-kind='source']::before, .mark--source { border-radius: 50%; background: var(--mint-text); }
.chip[data-kind='assumption'] { background: var(--lavender-faint); }
.chip[data-kind='assumption']::before, .mark--assumption { border-radius: 50%; border: 2px solid var(--lavender-text); }
.chip[data-kind='example'] { background: transparent; border: 1.5px dashed #9A98A8; }
.chip[data-kind='example']::before, .mark--example { border-radius: 2px; border: 2px dashed var(--ink-light); }
.chip[data-kind='user'] { background: var(--paper); border-color: var(--ink); }
.chip[data-kind='user']::before, .mark--user { transform: rotate(45deg) scale(0.85); background: var(--ink); }
.chip:hover { border-color: var(--ink); }
.chip[aria-expanded='true'] { border-color: var(--ink); background: #fff; }

.editor {
  margin-top: 0.9rem;
  padding: 1.1rem 1.2rem;
  background: #fff;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  display: grid;
  gap: 0.8rem;
}
.editor[hidden] { display: none; }
.editor label { font-weight: 600; font-size: 0.95rem; }
.editor-fields { display: flex; flex-wrap: wrap; gap: 0.6rem 1.2rem; align-items: end; }
.editor-fields span { display: grid; gap: 0.25rem; font-size: 0.85rem; color: var(--ink-light); }
.editor input[type='number'] {
  font: inherit; font-size: 1.05rem; width: 8rem;
  padding: 0.4rem 0.55rem; border: 1.5px solid #C9C6D3; border-radius: 6px; background: var(--paper);
}
.editor input[type='number']:focus-visible { border-color: var(--ink); }
.editor-source { font-size: 0.92rem; color: var(--ink-mid); }
.editor-source .kind { font-weight: 600; color: var(--ink); }
.editor-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.editor .btn { font-size: 0.88rem; padding: 0.4rem 0.9rem; }
.editor .btn--solid { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- Sources and assumptions ---------- */

.sources, .method { padding-top: clamp(3.5rem, 9vh, 6rem); }
.sources p.lead, .method p { margin-top: 0.6rem; max-width: var(--measure); color: var(--ink-mid); }
.table-scroll { overflow-x: auto; margin-top: 1.5rem; }
table { border-collapse: collapse; width: 100%; min-width: 40rem; font-size: 0.95rem; }
th, td { text-align: left; vertical-align: top; padding: 0.7rem 1rem 0.7rem 0; border-bottom: 1px solid #E6E3EC; }
th { font-weight: 600; color: var(--ink-light); font-size: 0.88rem; }
td.num { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
td .kindtag { display: inline-flex; align-items: center; gap: 0.4rem; white-space: nowrap; }

.method h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; margin-top: 1.8rem; }
.method ul { margin-top: 0.6rem; padding-left: 1.2rem; max-width: var(--measure); color: var(--ink-mid); }
.method li { margin-top: 0.35rem; }

footer.site {
  margin-top: clamp(4rem, 10vh, 7rem);
  padding: 2.5rem 0 5.5rem;
  border-top: 1px solid #E6E3EC;
  font-size: 0.92rem;
  color: var(--ink-light);
}
footer.site p { max-width: var(--measure); }
footer.site p + p { margin-top: 0.5rem; }

/* ---------- Sticky net line, while you edit further down ---------- */

.stickysum {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--stage); color: #F2F4F3;
  transform: translateY(110%);
  transition: transform 200ms ease;
}
.stickysum.is-on { transform: none; }
.stickysum .wrap { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding-top: 0.8rem; padding-bottom: 0.8rem; }
.stickysum b { font-family: var(--font-display); font-size: 1.35rem; color: var(--mint); white-space: nowrap; }
.stickysum span { font-size: 0.9rem; color: #B9C4C8; }

.toast {
  position: fixed; left: 50%; bottom: 5rem; z-index: 30;
  transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  padding: 0.6rem 1.1rem; border-radius: 999px; font-size: 0.92rem;
  opacity: 0; transition: opacity 160ms; pointer-events: none;
}
.toast.is-on { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media (forced-colors: active) {
  .chip, .editor { border: 1px solid CanvasText; }
}
