/* Tokens ---------------------------------------------------------------- */
:root {
  --paper: #f5f6f8;      /* cool shop-floor white */
  --surface: #ffffff;
  --ink: #1b2b4b;        /* deep navy, all text */
  --ink-soft: #55627a;
  --line: #d5dae3;
  --label: #ffd60a;      /* shelf-label yellow: used once, for the result */
  --loss: #c8102e;
  --focus: #2f6bff;

  --display: "Bricolage Grotesque", "Arial Narrow", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* modular scale, ratio 1.25 from 17px */
  --s-1: 0.85rem;
  --s0: 1.0625rem;
  --s1: 1.33rem;
  --s2: 1.66rem;
  --s3: 2.07rem;
  --s4: 2.6rem;

  --gap: clamp(1rem, 3vw, 2rem);
  --radius: 6px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; animation: none !important; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--s0)/1.55 var(--body);
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; background: var(--surface); padding: .5rem .75rem; }

.wrap { width: min(100% - 2 * var(--gap), 1140px); margin-inline: auto; }

/* Header ---------------------------------------------------------------- */
.site-head { background: var(--surface); border-bottom: 1px solid var(--line); }
.site-head__inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 64px; }
.brand { display: inline-flex; align-items: center; gap: .55rem; color: var(--ink); text-decoration: none; font: 800 1.35rem/1 var(--display); letter-spacing: -0.02em; }
.brand__mark { width: 30px; height: 30px; }
.site-nav { display: flex; gap: 1.5rem; }
.site-nav a { color: var(--ink-soft); text-decoration: none; font-size: var(--s-1); }
.site-nav a:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 4px; }
@media (max-width: 640px) { .site-nav { display: none; } }

/* Layout ---------------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: calc(var(--gap) * 1.5);
  align-items: start;
  padding-bottom: 4rem;
}
.main { min-width: 0; }
.rail { position: sticky; top: 1.5rem; }
@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
}

/* Calculator ------------------------------------------------------------ */
.calc {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: clamp(1.25rem, 4vw, 2.5rem);
}

.calc__head h1 {
  font: 800 clamp(2.1rem, 5.5vw, 3.4rem)/0.95 var(--display);
  letter-spacing: -0.035em;
  margin: 0 0 .6rem;
}
.lede { margin: 0 0 2rem; color: var(--ink-soft); max-width: 46ch; }

.fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem 1.5rem;
}
@media (max-width: 520px) {
  .fields { gap: .9rem .75rem; }
  .field input { font-size: var(--s1); padding: .6rem .6rem .6rem .25rem; }
  .field__affix { font-size: var(--s0); padding-left: .6rem; }
  .field__hint { font-size: .78rem; line-height: 1.3; }
  .lede { margin-bottom: 1.4rem; }
  .tag { margin-top: 1.4rem; }
}
@media (max-width: 340px) { .fields { grid-template-columns: minmax(0, 1fr); } }

.field label {
  display: block;
  font: 600 var(--s0)/1.2 var(--display);
  margin-bottom: .4rem;
}
.field__box {
  display: flex;
  align-items: center;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .15s, background-color .15s;
}
.field__box:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.field__affix {
  font: 600 var(--s1)/1 var(--display);
  color: var(--ink-soft);
  padding-inline: .8rem .1rem;
  user-select: none;
}
.field__affix--post { padding-inline: .1rem .9rem; }
.field input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 600 var(--s2)/1 var(--display);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  padding: .7rem .8rem .7rem .35rem;
}
.field[data-key="margin"] input { padding-left: .8rem; text-align: left; }
.field input:focus { outline: none; }
.field input::placeholder { color: #b7bfcc; }
.field__hint { margin: .35rem 0 0; font-size: var(--s-1); color: var(--ink-soft); min-height: 1.3em; }

/* A field the calculator filled in: lighter frame, tinted fill */
.field[data-role="out"] .field__box { border-color: var(--line); background: #f0f3f8; }
.field[data-role="out"] .field__hint { color: var(--ink); }
.field[data-role="in"] .field__hint::before { content: ""; }
.field.is-bad .field__box { border-color: var(--loss); }

/* Shelf label: the one loud element on the page ------------------------- */
.tag {
  margin-top: 2rem;
  background: var(--label);
  color: var(--ink);
  border-radius: var(--radius);
  border-top: 10px solid var(--ink);
  padding: 1.25rem 1.5rem 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "main side" "foot foot";
  gap: .5rem 2rem;
  align-items: end;
}
.tag__main { grid-area: main; display: flex; flex-direction: column; }
.tag__label { font: 600 var(--s0)/1 var(--display); }
.tag__big {
  font: 800 clamp(3.6rem, 13vw, 6.5rem)/0.9 var(--display);
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
  margin-top: .35rem;
  white-space: nowrap;
}
.tag__side { grid-area: side; margin: 0; display: grid; gap: .8rem; text-align: right; padding-bottom: .4rem; }
.tag__side dt { font-size: var(--s-1); }
.tag__side dd { margin: 0; font: 600 var(--s2)/1.05 var(--display); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.tag__foot {
  grid-area: foot;
  margin: .6rem 0 0;
  padding-top: .6rem;
  border-top: 1.5px dashed rgba(27, 43, 75, .45);
  font-size: var(--s-1);
}
.tag[data-state="empty"] .tag__big,
.tag[data-state="empty"] dd { opacity: .35; }
.tag[data-state="loss"] .tag__big { color: var(--loss); }
.tag[data-state="error"] { background: #fff1f2; border-top-color: var(--loss); }
.tag[data-state="error"] .tag__big, .tag[data-state="error"] dd { opacity: .3; }
@media (max-width: 520px) {
  .tag { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "side" "foot"; }
  .tag__side { grid-auto-flow: column; justify-content: start; text-align: left; gap: 2rem; }
}

/* Breakdown bar --------------------------------------------------------- */
.split { margin: 1.25rem 0 0; }
.split__bar { display: flex; height: 14px; border-radius: 3px; overflow: hidden; background: var(--paper); }
.split__bar .seg { transition: width .35s cubic-bezier(.2,.7,.2,1); }
.seg--ink { background: var(--ink); }
.seg--mid { background: #5d6f93; }
.seg--light { background: #b7bfcc; }
.seg--profit { background: #e8b800; }
.seg--loss { background: repeating-linear-gradient(-45deg, var(--loss) 0 4px, #f6c3cb 4px 8px); }
.split__legend { display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; margin-top: .55rem; font-size: var(--s-1); color: var(--ink-soft); }
.split__legend b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .4rem; }
.sw.seg--loss { background: var(--loss); }

/* Full breakdown table ---------------------------------------------------- */
.breakdown { margin-top: 1.25rem; border-top: 1px solid var(--line); }
.breakdown summary {
  cursor: pointer;
  padding: .8rem 0;
  font: 600 var(--s0)/1.2 var(--display);
  list-style-position: inside;
}
.breakdown table { background: transparent; }
.breakdown th { font-weight: 400; text-align: left; color: var(--ink-soft); border-bottom: 1px solid var(--line); padding: .5rem 1rem .5rem 0; }
.breakdown td { font-weight: 700; }
.breakdown tr:last-child th, .breakdown tr:last-child td { border-bottom: 0; }

/* Tools row ------------------------------------------------------------- */
.calc__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.75rem;
}
.currency { display: grid; gap: .3rem; font-size: var(--s-1); color: var(--ink-soft); }
.currency select {
  font: 600 var(--s0)/1 var(--body);
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: .55rem 2rem .55rem .7rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%231b2b4b' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
}
.calc__actions { display: flex; gap: .6rem; }
.btn {
  font: 600 var(--s0)/1 var(--display);
  color: var(--surface);
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: .7rem 1.1rem;
  cursor: pointer;
}
.btn:hover { background: #2a3f69; }
.btn:active { transform: translateY(1px); }
.btn--quiet { background: transparent; color: var(--ink); }
.btn--quiet:hover { background: var(--paper); }
.toast { margin: .75rem 0 0; min-height: 1.4em; font-size: var(--s-1); color: var(--ink-soft); }

/* Ads ------------------------------------------------------------------- */
/* Reserved heights stop the page jumping when an ad loads. */
.ad { position: relative; display: block; margin-inline: auto; }
.ad--top { min-height: 100px; max-width: 728px; margin-block: 1.25rem; }
@media (min-width: 760px) { .ad--top { min-height: 90px; } }
.ad--inline { min-height: 280px; max-width: 336px; margin-block: 2.5rem; }
@media (min-width: 760px) { .ad--inline { max-width: 728px; min-height: 90px; } }
.ad--rail { width: 300px; min-height: 600px; }
.ad[data-filled]::before {
  content: "Advertisement";
  position: absolute;
  top: -1.2em;
  left: 0;
  font-size: .7rem;
  color: var(--ink-soft);
}
.ad[data-empty] { min-height: 0 !important; margin-block: 0; }
.ad__placeholder {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: inherit;
  border: 1.5px dashed #b7bfcc;
  border-radius: var(--radius);
  color: #8a94a6;
  font-size: var(--s-1);
  text-align: center;
}
.ad--top .ad__placeholder { min-height: 90px; }
.ad--inline .ad__placeholder { min-height: 90px; }
@media (max-width: 759px) { .ad--inline .ad__placeholder { min-height: 280px; } .ad--top .ad__placeholder { min-height: 100px; } }
.ad--rail .ad__placeholder { min-height: 600px; }

/* Article --------------------------------------------------------------- */
.prose { max-width: 68ch; }
.guide { margin-top: 3.5rem; }
.prose h2 {
  font: 800 var(--s3)/1.1 var(--display);
  letter-spacing: -0.025em;
  margin: 3rem 0 .8rem;
  scroll-margin-top: 1.5rem;
}
.prose h2:first-child { margin-top: 0; }
.prose h3 { font: 600 var(--s1)/1.2 var(--display); margin: 2rem 0 .5rem; }
.prose p { margin: 0 0 1rem; }
.prose code { font-size: .92em; background: #e8ecf2; padding: .1em .35em; border-radius: 3px; }
.formula {
  margin: 1.25rem 0;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-left: 4px solid var(--label);
  font: 600 var(--s1)/1.3 var(--display);
  white-space: pre-wrap;
  overflow-x: auto;
}
.formula span { color: var(--ink); text-decoration: underline; text-decoration-color: var(--label); text-decoration-thickness: 4px; text-underline-offset: 3px; }

.table-wrap { overflow-x: auto; margin: 1.25rem 0 1.25rem; }
table { border-collapse: collapse; width: 100%; background: var(--surface); font-variant-numeric: tabular-nums; }
caption { text-align: left; font-size: var(--s-1); color: var(--ink-soft); padding-bottom: .5rem; }
th, td { text-align: right; padding: .6rem 1rem; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
thead th { font: 600 var(--s-1)/1.2 var(--display); border-bottom: 2px solid var(--ink); }
tbody tr:last-child td { border-bottom: 0; }

/* FAQ ------------------------------------------------------------------- */
.faq { margin-top: 3rem; }
.faq details { border-top: 1px solid var(--line); }
.faq details:last-of-type { border-bottom: 1px solid var(--line); }
.faq summary {
  cursor: pointer;
  list-style: none;
  padding: 1rem 2rem 1rem 0;
  position: relative;
  font: 600 var(--s1)/1.25 var(--display);
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "";
  position: absolute;
  right: .25rem;
  top: 50%;
  width: 10px; height: 10px;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  transform: translateY(-70%) rotate(45deg);
  transition: transform .2s;
}
.faq details[open] summary::after { transform: translateY(-30%) rotate(225deg); }
.faq details p { margin: 0 0 1.2rem; color: var(--ink-soft); }

/* Footer ---------------------------------------------------------------- */
.site-foot { border-top: 1px solid var(--line); background: var(--surface); }
.site-foot__inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1rem; padding-block: 1.5rem; font-size: var(--s-1); color: var(--ink-soft); }
.site-foot p { margin: 0; }
.site-foot__inner nav { display: flex; gap: 1.25rem; }
.site-foot a { color: var(--ink); }

/* Calculate ------------------------------------------------------------- */
.btn--calc {
  grid-column: 1 / -1;
  justify-self: start;
  min-width: 14rem;
  padding: 1rem 2.25rem;
  font-size: var(--s1);
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-top: .25rem;
}
@media (max-width: 520px) { .btn--calc { justify-self: stretch; } }
.tag[data-state="stale"] .tag__big,
.tag[data-state="stale"] dd { opacity: .35; }
.tag[data-state="stale"] .tag__foot { font-weight: 700; }

/* Price ladder ---------------------------------------------------------- */
.ladder {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: clamp(1.25rem, 4vw, 2.5rem);
}
.ladder__head h2 { font: 800 var(--s3)/1.05 var(--display); letter-spacing: -0.025em; margin: 0 0 .4rem; }
.ladder__head p { margin: 0 0 1rem; color: var(--ink-soft); }
.ladder__body { position: relative; }
.ladder__body .table-wrap { margin: 0; }
.ladder__body[data-locked] .table-wrap {
  filter: blur(6px);
  user-select: none;
  pointer-events: none;
  max-height: 260px;
  overflow: hidden;
}
.ladder__lock {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1rem;
  padding: 1.5rem;
  text-align: center;
  background: rgba(255, 255, 255, .55);
}
.ladder__lock p { margin: 0; max-width: 36ch; font-weight: 700; }
.ladder tr.is-mine td { background: #fff6c2; font-weight: 700; }
.ladder tr.is-mine small { font-weight: 400; color: var(--ink-soft); margin-left: .35rem; }
.ladder__actions { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1.25rem; }
.ladder__actions[hidden], .ladder__lock[hidden] { display: none; }

/* Reward dialog --------------------------------------------------------- */
.reward {
  width: min(100% - 2rem, 440px);
  border: 0;
  border-top: 10px solid var(--ink);
  border-radius: var(--radius);
  padding: 1.75rem;
  color: var(--ink);
  background: var(--surface);
}
.reward::backdrop { background: rgba(27, 43, 75, .55); }
.reward h2 { font: 800 var(--s2)/1.1 var(--display); letter-spacing: -0.02em; margin: 0 0 .6rem; }
.reward p { margin: 0 0 1.25rem; }
.reward__actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.reward__step[hidden] { display: none; }
.reward__demo {
  display: flex;
  justify-content: space-between;
  align-items: end;
  height: 180px;
  padding: 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  background: repeating-linear-gradient(-45deg, #e8ecf2 0 10px, #f5f6f8 10px 20px);
  color: var(--ink-soft);
}
.reward__demo b { font: 800 var(--s4)/1 var(--display); color: var(--ink); }


/* Field extras ---------------------------------------------------------- */
.field label .opt { font: 400 var(--s-1)/1 var(--body); color: var(--ink-soft); margin-left: .35rem; }
.field__box--select { position: relative; }
.field__box--select select {
  width: 100%;
  appearance: none;
  border: 0;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%231b2b4b' stroke-width='2'/%3E%3C/svg%3E") no-repeat right .9rem center;
  color: var(--ink);
  font: 600 var(--s1)/1 var(--display);
  padding: .85rem 2.4rem .85rem .8rem;
}
.field__box--select select:focus { outline: none; }
.presets { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.presets button {
  font: 600 var(--s-1)/1 var(--body);
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: .35rem .7rem;
  cursor: pointer;
}
.presets button:hover { border-color: var(--ink); }
.fields--one { grid-template-columns: minmax(0, 1fr); max-width: 22rem; }
.btn--small { font-size: var(--s-1); padding: .6rem .9rem; }
.calc__actions { flex-wrap: wrap; }
.site-nav a[aria-current="page"] { color: var(--ink); font-weight: 700; }

/* Related + footer ------------------------------------------------------ */
.related { margin-top: 3.5rem; max-width: 68ch; }
.related h2 { font: 800 var(--s2)/1.1 var(--display); letter-spacing: -0.02em; margin: 0 0 1rem; }
.related ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .75rem; }
.related a {
  display: grid;
  gap: .25rem;
  height: 100%;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--label);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
}
.related a:hover { border-color: var(--ink); border-left-color: var(--label); }
.related b { font: 600 var(--s0)/1.25 var(--display); }
.related span { font-size: var(--s-1); color: var(--ink-soft); }

.foot-calcs { padding-top: 2rem; }
.foot-calcs h2 { font: 600 var(--s0)/1.2 var(--display); margin: 0 0 .75rem; }
.foot-calcs ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .45rem 1.5rem; }
.foot-calcs a { color: var(--ink); font-size: var(--s-1); text-decoration: none; }
.foot-calcs a:hover, .foot-calcs a[aria-current="page"] { text-decoration: underline; text-underline-offset: 3px; }
.site-foot .site-foot__inner { border-top: 1px solid var(--line); margin-top: 2rem; width: auto; }

.page-plain { padding-block: 1rem 3rem; }

/* Embed dialog ---------------------------------------------------------- */
.embed-dlg { width: min(100% - 2rem, 560px); }
.embed-dlg textarea {
  width: 100%;
  font: 400 .8rem/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: .75rem;
  resize: vertical;
}
.embed-dlg__status { min-height: 1.4em; margin: .5rem 0 1rem; font-size: var(--s-1); color: var(--ink-soft); }

/* Embedded widget (inside someone else's page) -------------------------- */
body.is-embed { background: transparent; padding: 2px; }
.is-embed .calc { padding: clamp(1rem, 4vw, 1.5rem); }
.is-embed .calc__head { margin-bottom: 1rem; }
.calc__title--embed { font: 800 var(--s2)/1.1 var(--display); letter-spacing: -0.02em; margin: 0; }
.is-embed .tag { margin-top: 1.25rem; }
.is-embed .tag__big { font-size: clamp(2.8rem, 11vw, 4.5rem); }
.embed-credit { margin: .5rem 0 0; font-size: .8rem; color: var(--ink-soft); text-align: right; }
.embed-credit a { color: var(--ink); }

@media (max-width: 520px) {
  .field__box--select select { font-size: var(--s0); padding: .75rem 2rem .75rem .6rem; background-position: right .6rem center; }
}

/* Legal pages ----------------------------------------------------------- */
.page-plain h1 { font: 800 var(--s4)/1 var(--display); letter-spacing: -0.035em; margin: 0 0 .5rem; }
.meta-line { color: var(--ink-soft); font-size: var(--s-1); }
.prose ul { padding-left: 1.2rem; margin: 0 0 1rem; }
.prose li { margin-bottom: .35rem; }
.company { margin: 1.5rem 0; display: grid; gap: 0; max-width: 40rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.company div { display: grid; grid-template-columns: 11rem 1fr; gap: 1rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.company div:last-child { border-bottom: 0; }
.company dt { color: var(--ink-soft); }
.company dd { margin: 0; font-weight: 700; }
@media (max-width: 520px) { .company div { grid-template-columns: 1fr; gap: .15rem; } }
.site-foot__about p { margin: 0 0 .35rem; }
.site-foot__about p:last-child { margin: 0; }
.prose a { color: var(--ink); text-decoration-thickness: 1.5px; text-underline-offset: 3px; text-decoration-color: #e8b800; }
.prose a:hover { text-decoration-color: var(--ink); }
.page-plain { padding-top: 2.5rem; }

/* No ads yet: single column, comfortable reading width */
.no-ads .layout { grid-template-columns: minmax(0, 1fr); max-width: 820px; padding-top: 1.75rem; }
.notfound-list { font: 600 var(--s1)/1.6 var(--display); }
/* Money in small text: use the display face (the body face slashes its zeros) */
.tag__foot, .split__legend, .tag__side dt, .breakdown td, .ladder td, .field__hint { font-family: var(--display); }
.tag__foot { font-weight: 400; }
