/* Melt Ledger. An assay slip on a dealer's counter: cream paper, ink rules, a double-ruled slip for every
   result, mono figures in ledger rows and small stamped labels for metal and fineness.
   One accent, verdigris, for actions and state only. Old gold, silver grey and copper appear only as the
   metal stamps and the chart lines. Serif headings, sans body, mono numbers.
   Every dark value lives in BOTH dark blocks below; components use variables only. */

:root {
  --paper: #f5f0e3;
  --paper-2: #ece5d2;
  --card: #fbf8f0;
  --ink: #1f1c16;
  --muted: #59533f;
  --line: #cdc4ab;
  --rule: #1f1c16;
  --field: #7a7260;
  --accent: #1d6a5b;
  --accent-hover: #17574a;
  --accent-ink: #ffffff;
  --accent-soft: #d9e9e2;
  --link: #1d6a5b;
  --warn: #9a3412;
  --warn-soft: #f6e3d3;
  --ok: #1d6a5b;
  --gold: #775a0b;
  --silver: #565e66;
  --copper: #8a4524;
  --nickel: #4f5a4a;
  --zinc: #4d5a6b;
  --grid: #e1d9c4;
  --sel: #efe3b8;
  --serif: "Iowan Old Style", Charter, Georgia, "Times New Roman", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r: 2px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16140f;
    --paper-2: #1d1a14;
    --card: #221f18;
    --ink: #efe8d6;
    --muted: #b6ad96;
    --line: #433d30;
    --rule: #efe8d6;
    --field: #8a8270;
    --accent: #6cc3ae;
    --accent-hover: #8ad3c1;
    --accent-ink: #0f201b;
    --accent-soft: #1d332d;
    --link: #7fcfbb;
    --warn: #f4a27a;
    --warn-soft: #3a2418;
    --ok: #7fcfbb;
    --gold: #dcb75c;
    --silver: #bcc4cb;
    --copper: #e39a72;
    --nickel: #b5c2a9;
    --zinc: #a9b9cf;
    --grid: #2f2b22;
    --sel: #3a3320;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #16140f;
  --paper-2: #1d1a14;
  --card: #221f18;
  --ink: #efe8d6;
  --muted: #b6ad96;
  --line: #433d30;
  --rule: #efe8d6;
  --field: #8a8270;
  --accent: #6cc3ae;
  --accent-hover: #8ad3c1;
  --accent-ink: #0f201b;
  --accent-soft: #1d332d;
  --link: #7fcfbb;
  --warn: #f4a27a;
  --warn-soft: #3a2418;
  --ok: #7fcfbb;
  --gold: #dcb75c;
  --silver: #bcc4cb;
  --copper: #e39a72;
  --nickel: #b5c2a9;
  --zinc: #a9b9cf;
  --grid: #2f2b22;
  --sel: #3a3320;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 12px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 17px/1.55 var(--sans);
  overflow-wrap: break-word;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 700; line-height: 1.2; margin: 1.4em 0 .5em; }
h1 { font-size: clamp(1.75rem, 1.3rem + 2vw, 2.5rem); margin-top: .6em; letter-spacing: -.005em; }
h2 { font-size: clamp(1.35rem, 1.15rem + .9vw, 1.7rem); }
h3 { font-size: 1.15rem; }
p, ul, ol, dl { margin: 0 0 1em; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--ink); color: var(--paper); padding: 10px 14px; z-index: 10; min-height: 44px; }
.skip:focus { top: 8px; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.num, td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: .9rem; }
[hidden] { display: none !important; }

/* Header: a ledger head with a double rule under it */
.site-header { border-bottom: 3px double var(--rule); background: var(--paper); }
.header-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding-top: 8px; padding-bottom: 8px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; min-height: 44px; margin-right: auto; }
.logo { flex: none; color: var(--ink); }
.logo .logo-mark { fill: none; stroke: var(--accent); }
.wordmark { font-family: var(--serif); font-size: 1.35rem; font-weight: 700; letter-spacing: .01em; }
.wordmark em { font-style: italic; font-weight: 400; }
.nav { list-style: none; display: flex; flex-wrap: wrap; gap: 0 2px; margin: 0; padding: 0; }
.nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px; color: var(--ink); text-decoration: none; font-size: .95rem; border-bottom: 2px solid transparent; }
.nav a:hover { border-bottom-color: var(--accent); }
.nav a[aria-current="page"] { border-bottom-color: var(--ink); font-weight: 600; }
.theme-toggle { min-height: 44px; min-width: 64px; padding: 0 12px; background: transparent; color: var(--ink); border: 1px solid var(--line); border-radius: var(--r); font: inherit; font-size: .9rem; cursor: pointer; }
.theme-toggle:hover { border-color: var(--ink); }
@media (max-width: 560px) {
  .header-row { gap: 0 6px; }
  .nav { width: 100%; order: 3; justify-content: space-between; border-top: 1px solid var(--line); }
  .nav a { padding: 0 6px; font-size: .9rem; }
}

/* Page */
main { padding-bottom: 40px; }
.crumb { font-size: .9rem; color: var(--muted); margin: 16px 0 0; }
.crumb a { display: inline-block; padding: 12px 0; }
.lede { font-size: 1.12rem; max-width: 46em; }
.lede strong, .answer strong { font-family: var(--mono); font-weight: 700; font-variant-numeric: tabular-nums; }
.meta { color: var(--muted); font-size: .92rem; }
.section { padding: 8px 0 24px; border-top: 1px solid var(--line); margin-top: 24px; }
.section-lede { max-width: 46em; }
.prose { max-width: 760px; }
.wrap.prose { max-width: 1100px; }
.wrap.prose > * { max-width: 760px; }
.spot-row .affix input { min-width: 6.5em; }
.prose li { margin-bottom: .35em; }
.formula { font-family: var(--mono); font-variant-numeric: tabular-nums; background: var(--card); border-left: 3px solid var(--accent); padding: 10px 14px; overflow-x: auto; font-size: .95rem; }
noscript p, .noscript { border: 1px solid var(--line); padding: 10px 14px; background: var(--card); }

/* Buttons and fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border: 1px solid var(--ink); border-radius: var(--r); background: var(--card); color: var(--ink); font: inherit; font-size: .95rem; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--paper-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.quiet { border-color: var(--line); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 14px; min-width: 0; }
.field > label, .field-label { font-weight: 600; font-size: .95rem; }
input[type="number"], input[type="text"], select {
  min-height: 44px; width: 100%; padding: 8px 10px; font: inherit; color: var(--ink);
  background: var(--card); border: 1px solid var(--field); border-radius: var(--r);
}
input[type="number"] { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
input[aria-invalid="true"] { border-color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.hint { color: var(--muted); font-size: .88rem; }
.error { color: var(--warn); font-size: .9rem; min-height: 0; }
.error:empty { display: none; }
.affix { display: flex; align-items: stretch; }
.affix > span { display: inline-flex; align-items: center; padding: 0 10px; border: 1px solid var(--field); border-right: 0; background: var(--paper-2); font-family: var(--mono); border-radius: var(--r) 0 0 var(--r); }
.affix > span.after { border-right: 1px solid var(--field); border-left: 0; border-radius: 0 var(--r) var(--r) 0; font-family: var(--sans); font-size: .88rem; white-space: nowrap; }
.affix input { border-radius: 0; min-width: 0; }
.affix input:first-child { border-radius: var(--r) 0 0 var(--r); }
.seg { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
.seg legend { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: 4px; }
.seg-row { display: flex; flex-wrap: wrap; border: 1px solid var(--field); border-radius: var(--r); }
.seg-row label { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 6px 12px; cursor: pointer; text-align: center; font-size: .95rem; position: relative; }
.seg-row label + label { border-left: 1px solid var(--field); }
.seg-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg-row label:has(input:checked) { background: var(--ink); color: var(--paper); font-weight: 600; }
.seg-row label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; z-index: 1; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
input[type="range"] { width: 100%; min-height: 44px; accent-color: var(--accent); }

/* Stamps: a struck label for metal and fineness. Information, not decoration. */
.stamp { display: inline-block; font-family: var(--mono); font-size: .78rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 1px 6px; border: 1.5px solid currentColor; outline: 1px solid currentColor; outline-offset: 1.5px; margin: 0 4px 0 2px; vertical-align: .1em; line-height: 1.4; white-space: nowrap; }
.stamp-gold { color: var(--gold); }
.stamp-silver { color: var(--silver); }
.stamp-copper { color: var(--copper); }
.stamp-nickel { color: var(--nickel); }
.stamp-zinc { color: var(--zinc); }

/* The slip: the double-ruled box used for results and the spot prices */
.slip { background: var(--card); border: 3px double var(--rule); padding: 14px 16px 12px; margin: 0 0 20px; }
.slip-title { font-family: var(--serif); font-size: 1.05rem; font-variant: small-caps; letter-spacing: .06em; margin: 0 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.slip h2.slip-title, .slip h3.slip-title { margin-top: 0; }

/* Spot prices slip */
.spot-rows { margin: 0; }
.spot-row { display: grid; grid-template-columns: 7.5rem minmax(0, 16rem) minmax(0, 1fr); gap: 4px 14px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.spot-row:last-child { border-bottom: 0; }
.spot-name { font-weight: 600; display: flex; align-items: center; gap: 4px; }
.spot-src { font-size: .88rem; color: var(--muted); }
.spot-src .live { color: var(--ok); font-weight: 600; }
.spot-src .stale, .warn-text { color: var(--warn); font-weight: 600; }
.spot-actions { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 6px; font-size: .9rem; }
.spot-actions a { display: inline-flex; align-items: center; min-height: 44px; }
.spot-status { margin: 0 0 6px; font-size: .92rem; }
@media (max-width: 640px) {
  .spot-row { grid-template-columns: minmax(0, 1fr) minmax(0, 15rem); }
  .spot-src { grid-column: 1 / -1; }
}

/* Calculator layout */
.tool { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 28px; }
@media (min-width: 900px) { .tool { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); } }
.calc-form { padding-top: 4px; }
.row-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 14px; }
@media (min-width: 520px) { .row-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }

/* Result slip */
.result-figure { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin: 4px 0 2px; }
.big { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: clamp(2rem, 1.5rem + 2.5vw, 2.8rem); font-weight: 700; line-height: 1.1; min-width: 6ch; }
.result-sub { color: var(--muted); font-size: .95rem; margin: 0 0 10px; }
.floor-note { font-size: .9rem; border-top: 1px dashed var(--line); padding-top: 8px; margin: 10px 0 0; }

/* Ledger tables */
.table-scroll { overflow-x: auto; margin: 0 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: .95rem; }
caption { text-align: left; font-family: var(--serif); font-weight: 700; padding: 0 0 6px; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; text-align: left; }
thead th { border-bottom: 2px solid var(--rule); font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; vertical-align: bottom; }
tfoot td, tfoot th { border-top: 2px solid var(--rule); border-bottom: 3px double var(--rule); font-weight: 700; }
td.num, th.num { white-space: nowrap; }
.ledger { margin: 4px 0 0; }
.ledger td, .ledger th { padding: 7px 4px; }
.ledger th[scope="row"] { font-weight: 400; }
tr.total th, tr.total td { border-top: 2px solid var(--rule); border-bottom: 3px double var(--rule); font-weight: 700; }
.spec th[scope="row"] { width: 42%; font-weight: 600; }
.coin-table th a { display: inline-flex; align-items: center; min-height: 44px; }
.coin-table th, .coin-table td { vertical-align: middle; }
@media (max-width: 640px) {
  .stack thead { display: none; }
  .stack tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  .stack td, .stack th { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 0; text-align: right; }
  .stack td::before, .stack th[scope="row"]::before { content: attr(data-label); font-family: var(--sans); font-weight: 600; text-align: left; color: var(--muted); font-size: .88rem; }
  .stack th[scope="row"] { text-align: left; font-weight: 700; }
  .stack th[scope="row"]::before { content: none; }
  .stack tfoot tr { border-top: 2px solid var(--rule); }
}

/* Offer checker */
.verdict { font-size: 1.05rem; margin: 8px 0; }
.scale { position: relative; height: 44px; margin: 10px 0 4px; }
.scale svg { width: 100%; height: 44px; display: block; }
.scale-key { display: flex; justify-content: space-between; font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.band-table td:first-child { font-family: var(--mono); white-space: nowrap; }

/* Stash */
.stash-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.file-btn { position: relative; }
.file-btn input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.file-btn:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.qty-input { width: 7.5rem; }
.row-del { min-width: 44px; }
.shared-banner { border: 3px double var(--accent); background: var(--accent-soft); padding: 12px 14px; margin: 12px 0; }
.empty { border: 1px dashed var(--line); padding: 16px; color: var(--muted); background: var(--card); }
.toast { min-height: 1.5em; font-size: .95rem; }
.toast .btn { min-height: 44px; margin-left: 6px; }
.change-up { color: var(--ok); }
.change-down { color: var(--warn); }
.spark { width: 100%; max-width: 320px; height: 60px; display: block; }

/* Charts */
.chart-fig { margin: 0 0 28px; }
.chart-fig svg { width: 100%; height: auto; display: block; background: var(--card); border: 1px solid var(--line); }
.chart-fig figcaption { font-size: .92rem; color: var(--muted); margin-top: 6px; }
.chart-fig .axis text, .chart-fig .lbl { font-family: var(--mono); font-size: 13px; fill: var(--muted); }
.chart-fig .lbl-end { font-family: var(--mono); font-size: 14px; font-weight: 700; }
.chart-fig .gridline { stroke: var(--grid); stroke-width: 1; }
.chart-fig .baseline { stroke: var(--rule); stroke-width: 1.5; }
.line-gold { stroke: var(--gold); fill: var(--gold); }
.line-silver { stroke: var(--silver); fill: var(--silver); }
.line-copper { stroke: var(--copper); fill: var(--copper); }
.line-nickel { stroke: var(--nickel); fill: var(--nickel); }
.line-zinc { stroke: var(--zinc); fill: var(--zinc); }
.chart-fig path.series { fill: none; stroke-width: 2.25; }
details { margin: 0 0 16px; }
details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
details.faq { border-bottom: 1px solid var(--line); margin: 0; }
details.faq > summary { font-family: var(--serif); font-size: 1.08rem; padding: 6px 0; }
details.faq > p { margin-top: 4px; }

/* Coin drawing: a plain struck blank with reeded edge, our own drawing */
.coin-head { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 24px; align-items: start; }
@media (min-width: 760px) { .coin-head { grid-template-columns: minmax(0, 1fr) 150px; } }
.coin-art { width: 150px; height: 150px; color: var(--ink); justify-self: start; }
@media (max-width: 759px) { .coin-art { display: none; } }

/* Lists of links */
.link-list { list-style: none; padding: 0; columns: 2 16rem; column-gap: 24px; }
.link-list li { break-inside: avoid; margin: 0; }
.link-list a { display: inline-flex; align-items: center; min-height: 44px; }
.guide-list a { display: inline-flex; align-items: center; min-height: 44px; padding: 4px 0; }
.sources { font-size: .9rem; }
.sources li { margin-bottom: .4em; }

/* Ads: hidden until switched on; reserved space so nothing jumps */
.ad-slot { margin: 24px 0; }
.ad-label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 4px; }
.ad-box { min-height: 280px; border: 1px dashed var(--line); }
@media (min-width: 600px) { .ad-box { min-height: 120px; } }

/* Footer */
.site-footer { border-top: 3px double var(--rule); padding: 18px 0 28px; font-size: .92rem; background: var(--paper-2); }
.footer-brand { font-family: var(--serif); font-size: 1.15rem; font-weight: 700; margin-bottom: 6px; }
.footer-brand em { font-weight: 400; }
.footer-nav { list-style: none; display: flex; flex-wrap: wrap; gap: 0 16px; padding: 0; margin: 8px 0; }
.footer-nav a { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 44px; }
.copyright { color: var(--muted); margin: 0; }

@media print {
  .site-header nav, .theme-toggle, .ad-slot, .actions, .stash-tools, .spot-actions { display: none !important; }
  body { background: #fff; color: #000; }
}
@media (max-width: 420px) {
  .spot-row { grid-template-columns: minmax(0, 1fr); gap: 4px; }
}
@media (max-width: 640px) {
  .stack, .stack tbody, .stack tfoot { display: block; width: 100%; }
  .stack td, .stack th { white-space: normal; flex-wrap: wrap; }
  .stack td > *:last-child { margin-left: auto; }
}
@media (max-width: 480px) {
  .ledger .col-spot { display: none; }
  .ledger td, .ledger th { font-size: .9rem; }
}
@media (max-width: 640px) { .stack caption { display: block; } }
