/* Mobile first, and built around the chart: the whole page exists to put two
   lines beside each other, so everything above it is kept to the size it needs
   and nothing below it competes. */

:root {
  /* Hands the native select and the number spinners to the same theme as the
     rest of the page, and keeps scrollbars from arriving white on the dark
     card. */
  color-scheme: light dark;

  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16181d;
  --ink-soft: #5c6270;
  --ink-faint: #868c99;
  --line: #e2e5ea;
  --accent: #1f6feb;
  --radius: 12px;

  /* The two futures. Slots one and two of a categorical palette, validated for
     colour-vision deficiency against both surfaces before being used here:
     worst-pair separation 24.7 on light, 26.8 on dark, against a floor of 8.

     Warm for the south and cool for the north is a memory aid, not decoration.
     Neither line ever carries meaning by colour alone -- both are labelled at
     their own end, and both appear in the legend and the table. */
  --series-south: #eb6834;
  --series-north: #2a78d6;

  --grid: #eceef2;
  --gain: #0a7d55;
  --loss: #b6482c;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1c1f25;
    --ink: #e8eaee;
    --ink-soft: #9aa1ae;
    --ink-faint: #767d8b;
    --line: #2b2f37;
    --accent: #4a9eff;

    /* Re-stepped for the dark surface, not dimmed: the same two hues chosen
       again against a dark background and validated there separately. */
    --series-south: #d95926;
    --series-north: #3987e5;

    --grid: #262a32;
    --gain: #3fb98a;
    --loss: #e58063;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1rem;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.page { max-width: 58rem; margin: 0 auto; }

.page-head h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.01em; }

.standfirst {
  margin: 0.4rem 0 0;
  max-width: 44rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* -------------------------------------------------------------------------- */
/* The form                                                                    */
/* -------------------------------------------------------------------------- */

.inputs { margin: 1.2rem 0 0; }

fieldset {
  margin: 0 0 0.8rem;
  padding: 0.9rem 1rem 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

legend, summary {
  padding: 0 0.35rem;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.assumptions {
  margin: 0 0 0.8rem;
  padding: 0.9rem 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

summary { cursor: pointer; padding-left: 0; }
.assumptions[open] summary { margin-bottom: 0.9rem; }

/* One column on a phone. Two is the most this fits before a label starts
   wrapping mid-word, so the jump to three waits for a real desktop. */
.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem 1.1rem;
}

/* Four across, not three: every fieldset above is pairs -- a salary and its
   raises, a value and what was paid for it -- and an odd number of columns
   splits each pair across two rows. */
@media (min-width: 30rem) { .grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 52rem) { .grid { grid-template-columns: repeat(4, 1fr); } }

/* Except where the control is a sentence rather than a number. */
@media (min-width: 52rem) { .grid-roomy { grid-template-columns: repeat(3, 1fr); } }

.field { min-width: 0; }
.field[hidden] { display: none; }

.field label {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

/* The unit sits in the border with the field rather than beside it, so a row of
   money boxes lines up on the digits and not on the dollar signs. */
.entry {
  display: flex;
  align-items: stretch;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.entry:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

.affix {
  display: flex;
  align-items: center;
  padding: 0 0.15rem 0 0.55rem;
  color: var(--ink-faint);
  font-size: 0.85rem;
  white-space: nowrap;
}

.affix:last-child { padding: 0 0.55rem 0 0.3rem; }

.entry input,
.entry select {
  /* 16px keeps iOS from zooming the page when a field is tapped, and inheriting
     the family stops Safari giving form controls one of their own. */
  font: inherit;
  font-size: 16px;

  /* Both of these are drawn natively by default, and a natively drawn control
     is sized from the platform's metrics rather than from the box it was handed
     -- so width reads as a suggestion and the field lands at some other size.
     Dropping the appearance is what makes the rules below authoritative. */
  -webkit-appearance: none;
  appearance: none;

  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  color: var(--ink);
  background: none;
  border: 0;
  border-radius: 8px;
}

.entry input:focus, .entry select:focus { outline: none; }

/* The spinners are half the width of a salary field and nobody nudges a salary
   by one dollar. */
.entry input::-webkit-outer-spin-button,
.entry input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.entry input[type="number"] { -moz-appearance: textfield; }

.entry select { padding-right: 1.6rem; cursor: pointer; }

/* The arrow the select lost with its appearance, drawn back on. */
.field .entry:has(select) {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-faint) 50%),
                    linear-gradient(135deg, var(--ink-faint) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.hint {
  margin: 0.3rem 0 0;
  color: var(--ink-faint);
  font-size: 0.75rem;
  line-height: 1.35;
}

/* -------------------------------------------------------------------------- */
/* The salary schedule                                                         */
/* -------------------------------------------------------------------------- */

.schedule {
  margin: 1rem 0 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.schedule summary { padding-left: 0; cursor: pointer; }

/* Says whether the path is the growth rate's or the reader's own, and lights up
   only in the second case -- so a page carrying a hand-built schedule cannot be
   mistaken for one that is still on its defaults. */
.schedule-note {
  margin-left: 0.5rem;
  color: var(--ink-faint);
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

.schedule-note.on { color: var(--accent); }

.schedule .hint { margin: 0.8rem 0; max-width: 40rem; font-size: 0.78rem; }

.salary-grid { width: 100%; border-collapse: collapse; }

.salary-grid th[scope="col"] {
  padding: 0 0.5rem 0.35rem;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 600;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.salary-grid tbody th {
  width: 2rem;
  padding-right: 0.5rem;
  color: var(--ink-faint);
  font-size: 0.8rem;
  font-weight: 400;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.salary-grid td { padding: 0.12rem 0.25rem 0.12rem 0; }
.salary-grid tr > *:last-child { padding-right: 0; }

/* Past a phone the row has far more width than a six-figure salary needs. The
   cells stop growing and the table shrinks to them, so the two columns stay
   beside each other for comparison instead of drifting to opposite edges of a
   wide card. */
@media (min-width: 34rem) {
  .salary-grid { width: auto; }
  .salary-grid .entry-tight { width: 11rem; }
}

/* Tighter than a form field: there are up to forty rows of these, and the row
   height is what decides whether the whole path can be seen at once. */
.entry-tight { border-radius: 6px; }
.entry-tight .affix { padding-left: 0.4rem; font-size: 0.75rem; }
.entry-tight input { padding: 0.3rem 0.4rem; font-size: 16px; }

/* A pinned year, marked by its border rather than its fill: a filled cell in a
   column of forty reads as a warning, and this is only a note. */
.entry-tight.pinned {
  border-color: var(--accent);
  background: var(--card);
}

.entry-tight.pinned input { font-weight: 600; }

#reset-schedule {
  font: inherit;
  font-size: 0.8rem;
  margin-top: 0.9rem;
  padding: 0.4rem 0.7rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

#reset-schedule:disabled { opacity: 0.45; cursor: default; }

/* -------------------------------------------------------------------------- */
/* The verdict                                                                 */
/* -------------------------------------------------------------------------- */

.verdict {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin: 1.2rem 0 0;
}

@media (min-width: 46rem) { .verdict { grid-template-columns: repeat(4, 1fr); } }

.tile {
  padding: 0.8rem 0.9rem 0.9rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tile-label {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tile-value {
  margin: 0.3rem 0 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.1;
  /* Equal-width digits, so a figure that changes as a field is typed does not
     shove the tile beside it sideways. */
  font-variant-numeric: tabular-nums;
}

.tile-note {
  margin: 0.25rem 0 0;
  color: var(--ink-faint);
  font-size: 0.75rem;
  line-height: 1.3;
}

/* -------------------------------------------------------------------------- */
/* Panels                                                                      */
/* -------------------------------------------------------------------------- */

.panel {
  margin: 0.8rem 0 0;
  padding: 1rem 1.1rem 1.2rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.panel h2 { margin: 0 0 0.5rem; font-size: 1rem; letter-spacing: -0.01em; }

.panel h3 {
  margin: 1.4rem 0 0.4rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
  letter-spacing: -0.01em;
}

.panel-note, .axis-caption {
  margin: 0 0 0.8rem;
  max-width: 42rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.axis-caption { margin: 0.4rem 0 0; text-align: center; font-size: 0.75rem; }

/* -------------------------------------------------------------------------- */
/* The chart                                                                   */
/* -------------------------------------------------------------------------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-bottom: 0.6rem;
  font-size: 0.82rem;
}

.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }

.swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  flex: none;
}

.plot { position: relative; margin: 0; touch-action: pan-y; }

#chart { display: block; width: 100%; height: auto; overflow: visible; }

/* Recessive by design. The grid is there to be measured against when a reader
   goes looking for it, not to be read on the way past. */
.gridline { stroke: var(--grid); stroke-width: 1; }

.axis-label {
  fill: var(--ink-faint);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.line {
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

/* The crossing, marked on the surface rather than drawn as a third line: it is
   a fact about the two series, not a series of its own. */
.crossing { stroke: var(--ink-faint); stroke-width: 1; stroke-dasharray: 3 3; }

.crossing-label {
  fill: var(--ink-faint);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.series-label { font-size: 11px; font-weight: 600; }

.crosshair { stroke: var(--ink-faint); stroke-width: 1; }

/* Ringed in the surface colour so a dot stays legible where the two lines
   cross and the markers land on top of each other. */
.dot { stroke: var(--card); stroke-width: 2; }

.tip {
  position: absolute;
  top: 0;
  z-index: 2;
  min-width: 11rem;
  padding: 0.5rem 0.6rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  font-size: 0.78rem;
  pointer-events: none;
}

.tip-head {
  margin: 0 0 0.35rem;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* The swatch carries the identity; the text stays in the page's own ink, so a
   value is never a colour a reader has to decode. */
.tip-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.15rem 0;
}

.tip-name { color: var(--ink-soft); }
.tip-value { margin-left: auto; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------------------- */
/* The gap chart                                                               */
/* -------------------------------------------------------------------------- */

.bar { transition: opacity 0.1s ease; }

/* Picked out by lifting one column rather than by dimming the fourteen others,
   which would repaint the whole chart every time the pointer moved. */
.bar-on { stroke: var(--ink); stroke-width: 1.5; }

/* The line the columns are measured from, and the one the reader is looking for
   them to cross. Firmer than a gridline, quieter than the data. */
.zero { stroke: var(--ink-soft); stroke-width: 1; }

.tip-gap {
  margin: 0.4rem 0 0;
  padding-top: 0.35rem;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------------------- */
/* The border, and the table                                                   */
/* -------------------------------------------------------------------------- */

.facts {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.15rem 0.9rem;
  font-size: 0.88rem;
}

@media (min-width: 34rem) { .facts { grid-template-columns: auto 1fr; gap: 0.6rem 1rem; } }

.facts dt {
  color: var(--ink-soft);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  /* The labels are small caps and the values are not, so their baselines are
     aligned by hand rather than by letting the grid row centre them. */
  padding-top: 0.15rem;
}

.facts dd { margin: 0 0 0.6rem; }

@media (min-width: 34rem) { .facts dd { margin-bottom: 0; } }

.fact-value { display: block; font-variant-numeric: tabular-nums; }

.fact-detail {
  display: block;
  margin-top: 0.1rem;
  color: var(--ink-faint);
  font-size: 0.78rem;
  line-height: 1.35;
}

/* A wide table on a narrow phone scrolls sideways rather than squeezing six
   columns of money into thirty characters. */
.scroller { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.years {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.years th, .years td {
  padding: 0.35rem 0.5rem;
  text-align: right;
  white-space: nowrap;
}

.years thead th {
  position: sticky;
  top: 0;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
}

.years tbody th { text-align: left; color: var(--ink-faint); font-weight: 400; }
.years tbody tr + tr td, .years tbody tr + tr th { border-top: 1px solid var(--line); }

/* The year the holding is sold is the hinge of the whole table. */
.sale-year td, .sale-year th { background: var(--bg); font-weight: 600; }

.gap-north { color: var(--gain); }
.gap-south { color: var(--loss); }

/* Take-home pay is context, not the answer, so it is the first thing to go when
   the screen runs out of room. */
@media (max-width: 36rem) { .years .pay { display: none; } }

/* -------------------------------------------------------------------------- */
/* The small print                                                             */
/* -------------------------------------------------------------------------- */

.caveats { font-size: 0.85rem; color: var(--ink-soft); }
.caveats p { margin: 0 0 0.7rem; max-width: 44rem; }
.caveats ul { margin: 0 0 0.7rem; padding-left: 1.1rem; max-width: 44rem; }
.caveats li { margin-bottom: 0.5rem; line-height: 1.45; }
.caveats strong { color: var(--ink); font-weight: 600; }

.disclaimer { color: var(--ink-faint); font-size: 0.8rem; }

.prompt { margin: 1rem 0 0; color: var(--ink-soft); }
