:root {
  color-scheme: light;
  /* Theme tokens: add future skins by overriding these under body[data-theme="..."]. */
  --font-display: Georgia, "Times New Roman", serif;
  --font-sans: "Avenir Next", Avenir, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --color-text: #15171a;
  --color-text-muted: #60656f;
  --color-border: #ded8cc;
  --color-border-strong: #9d9689;
  --color-panel: #fffdfa;
  --color-page: #f4f0e8;
  --color-chart-surface: #111720;
  --color-chart-grid: rgba(236, 226, 204, 0.12);
  --color-chart-axis: rgba(236, 226, 204, 0.46);
  --color-chart-text: #f2e8d8;
  --color-chart-text-muted: #c4baa9;
  --color-stack-shadow: rgba(0, 0, 0, 0.58);
  --color-stack-coin-edge: rgba(137, 83, 10, 0.72);
  --color-stack-coin-edge-highlight: rgba(255, 221, 121, 0.58);
  --color-control-border: #bbb1a1;
  --color-table-head: #f1eadf;
  --color-heading-soft: #3f4147;
  --color-accent: #006b5f;
  --color-accent-warm: #a56a13;
  --color-tooltip-shadow: rgba(21, 23, 26, 0.14);
  --color-panel-shadow: rgba(55, 47, 36, 0.09);
  --color-error-border: #d8b4a0;
  --color-error-surface: #fff7ed;
  --color-error-text: #7c2d12;
  --color-error-heading: #431407;
  --radius-panel: 6px;
  --radius-control: 6px;
  --chart-coin-shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--color-page);
  color: var(--color-text);
}

.page-shell {
  width: min(1180px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 48px 0;
}

.chart-panel {
  background: var(--color-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-panel);
  box-shadow: 0 24px 60px var(--color-panel-shadow);
  padding: 42px;
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 42px;
  margin-bottom: 30px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--color-accent-warm);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  max-width: 820px;
  font-family: var(--font-display);
  font-size: clamp(2.15rem, 5vw, 4.65rem);
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: 0;
}

.metric {
  min-width: 260px;
  max-width: 320px;
  padding-top: 4px;
  text-align: right;
}

.metric p {
  margin: 0;
}

.metric-kicker {
  color: var(--color-heading-soft);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.25;
  text-transform: uppercase;
}

.metric-context {
  margin-top: 14px;
  color: var(--color-accent-warm);
  font-size: 0.86rem;
  font-weight: 800;
}

.metric-value {
  margin-top: 8px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 3.2vw, 3.05rem);
  font-weight: 700;
  line-height: 1;
  color: var(--color-accent);
}

.market-strip {
  display: grid;
  grid-template-columns: minmax(180px, 0.72fr) minmax(0, 2.3fr);
  align-items: stretch;
  gap: 0;
  margin-bottom: 26px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-panel);
  background: rgba(255, 253, 250, 0.82);
  overflow: hidden;
}

.market-strip-meta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 16px 18px;
  border-right: 1px solid var(--color-border);
}

.market-strip-meta p {
  margin: 0;
}

.market-strip-meta p:not(.section-eyebrow) {
  margin-top: 6px;
  color: var(--color-text-muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
}

.market-strip-items {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.market-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  min-height: 92px;
  padding: 16px 18px;
}

.market-item + .market-item {
  border-left: 1px solid var(--color-border);
}

.market-item h2 {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 850;
  line-height: 1.15;
}

.market-item p {
  margin: 5px 0 0;
  color: var(--color-text-muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.market-item-values {
  display: grid;
  justify-items: end;
  gap: 6px;
  text-align: right;
}

.market-item-values strong {
  color: var(--color-text);
  font-family: var(--font-display);
  font-size: clamp(1.28rem, 2vw, 1.74rem);
  line-height: 1;
}

.market-item-values small {
  color: var(--color-text-muted);
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1;
  text-transform: uppercase;
}

.market-item-values span {
  padding: 3px 7px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 850;
  line-height: 1.1;
  white-space: nowrap;
}

.market-item-values span.is-positive {
  border-color: rgba(0, 107, 95, 0.22);
  color: var(--color-accent);
  background: rgba(0, 107, 95, 0.06);
}

.market-item-values span.is-negative {
  border-color: rgba(165, 106, 19, 0.24);
  color: var(--color-accent-warm);
  background: rgba(165, 106, 19, 0.07);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.controls-row label {
  color: var(--color-heading-soft);
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
}

select {
  min-width: 240px;
  min-height: 44px;
  padding: 0 42px 0 14px;
  border: 1px solid var(--color-control-border);
  border-radius: var(--radius-control);
  background: var(--color-panel);
  color: var(--color-text);
  font: inherit;
  font-weight: 700;
}

.chart-wrap {
  position: relative;
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-panel);
  overflow: hidden;
  background: var(--color-chart-surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.gold-stack-chart {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 320px;
}

.chart-title {
  position: relative;
  z-index: 1;
  padding: 22px 24px 10px;
  color: var(--color-chart-text);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
}

.chart-body {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  min-height: 420px;
}

.chart-y-axis {
  position: relative;
  z-index: 1;
  display: block;
  background: var(--color-chart-surface);
  box-shadow: 12px 0 22px rgba(17, 23, 32, 0.46);
}

.chart-plot-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-color: rgba(236, 226, 204, 0.36) transparent;
  scrollbar-width: thin;
}

.chart-plot-scroll:focus {
  outline: 2px solid rgba(242, 232, 216, 0.28);
  outline-offset: -2px;
}

.chart-plot-scroll::-webkit-scrollbar {
  height: 10px;
}

.chart-plot-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
}

.chart-plot-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(236, 226, 204, 0.32);
}

.gold-stack-chart svg,
.chart-plot-scroll svg {
  display: block;
  width: auto;
  max-width: none;
  height: auto;
}

.axis-label,
.year-label,
.chart-title {
  fill: var(--color-chart-text-muted);
  font-family: var(--font-sans);
}

.axis-label,
.year-label {
  font-size: 11.5px;
  font-weight: 700;
}

.year-label {
  font-size: 10.5px;
}

.grid-line {
  stroke: var(--color-chart-grid);
  stroke-width: 1;
  stroke-dasharray: 2 6;
}

.axis-line {
  stroke: var(--color-chart-axis);
  stroke-width: 1.2;
}

.stack-group {
  cursor: pointer;
  outline: none;
}

.stack-coin {
  filter: drop-shadow(0 2px 1.8px var(--chart-coin-shadow));
}

.stack-coin-edge {
  fill: var(--color-stack-coin-edge);
  stroke: var(--color-stack-coin-edge-highlight);
  stroke-width: 0.55;
  opacity: 0.86;
}

.gold-coin-image {
  opacity: 0.98;
}

.stack-group:hover .gold-coin-image,
.stack-group:focus .gold-coin-image {
  filter: brightness(1.06) contrast(1.03);
}

.stack-shadow {
  fill: var(--color-stack-shadow);
  opacity: 0.68;
}

.stack-hit-area {
  fill: transparent;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  display: none;
  min-width: 230px;
  max-width: min(290px, calc(100% - 28px));
  padding: 10px 12px;
  border: 1px solid var(--color-control-border);
  border-radius: var(--radius-control);
  background: var(--color-panel);
  box-shadow: 0 12px 28px var(--color-tooltip-shadow);
  color: var(--color-text);
  font-size: 0.86rem;
  line-height: 1.35;
  pointer-events: none;
}

.chart-tooltip.is-visible {
  display: block;
}

.chart-tooltip strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.92rem;
}

.chart-tooltip span {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--color-text-muted);
}

.chart-tooltip b {
  color: var(--color-text);
  font-weight: 750;
  text-align: right;
}

.methodology-note {
  max-width: 760px;
  margin: 12px 0 0;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.calculator-section {
  margin-top: 30px;
  padding: 26px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-panel);
  background: rgba(255, 253, 250, 0.74);
}

.calculator-header {
  margin-bottom: 20px;
}

.section-eyebrow {
  margin: 0 0 8px;
  color: var(--color-accent-warm);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.55rem, 3vw, 2.35rem);
  line-height: 1.05;
}

.calculator-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.calculator-grid label {
  display: grid;
  gap: 8px;
  color: var(--color-heading-soft);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.calculator-grid input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid var(--color-control-border);
  border-radius: var(--radius-control);
  background: var(--color-panel);
  color: var(--color-text);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
}

.currency-input {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 46px;
  border: 1px solid var(--color-control-border);
  border-radius: var(--radius-control);
  background: var(--color-panel);
  overflow: hidden;
}

.currency-input span {
  padding-left: 14px;
  color: var(--color-accent-warm);
  font-size: 1rem;
}

.currency-input input {
  min-height: 44px;
  padding-left: 8px;
  border: 0;
  background: transparent;
}

.currency-input input:focus {
  outline: none;
}

.currency-input:focus-within {
  outline: 2px solid rgba(0, 107, 95, 0.16);
  outline-offset: 2px;
}

.calculator-button {
  min-height: 42px;
  margin-top: 16px;
  padding: 0 20px;
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-control);
  background: var(--color-accent);
  color: var(--color-panel);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

.calculator-button:hover,
.calculator-button:focus {
  background: #005c52;
}

.calculator-button:focus {
  outline: 2px solid rgba(0, 107, 95, 0.22);
  outline-offset: 2px;
}

.calculator-feedback {
  min-height: 22px;
  margin-top: 14px;
  color: var(--color-text-muted);
  font-size: 0.86rem;
}

.calculator-feedback.is-error {
  color: var(--color-error-text);
  font-weight: 700;
}

.calculator-results {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1.2fr);
  align-items: stretch;
  gap: 12px;
  margin-top: 18px;
}

.calculator-results[hidden] {
  display: none;
}

.calculator-step {
  padding: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-panel);
  background: var(--color-panel);
}

.calculator-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-accent-warm);
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 1;
}

.calculator-results span {
  display: block;
  margin-bottom: 8px;
  color: var(--color-text-muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.calculator-results strong {
  display: block;
  color: var(--color-text);
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  line-height: 1.05;
}

.calculator-step small {
  display: block;
  margin-top: 10px;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
}

.calculator-step-final {
  border-color: rgba(165, 106, 19, 0.34);
  background: #15171a;
  box-shadow: 0 18px 36px rgba(55, 47, 36, 0.12);
}

.calculator-step-final span,
.calculator-step-final small {
  color: #d9caa8;
}

.calculator-step-final strong {
  color: #f1d384;
  font-size: clamp(1.65rem, 3vw, 2.35rem);
}

.calculator-step-final b {
  color: #f4df9d;
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.load-error {
  margin: 24px;
  max-width: 640px;
  padding: 16px 18px;
  border: 1px solid var(--color-error-border);
  border-radius: var(--radius-control);
  background: var(--color-error-surface);
  color: var(--color-error-text);
}

.load-error strong {
  display: block;
  margin-bottom: 6px;
  color: var(--color-error-heading);
}

.load-error p {
  margin: 6px 0 0;
}

.load-error code {
  color: var(--color-error-heading);
  font-weight: 750;
}

.table-wrap {
  margin-top: 30px;
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  text-align: right;
  white-space: nowrap;
}

th {
  background: var(--color-table-head);
  color: var(--color-heading-soft);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

tbody tr:last-child td {
  border-bottom: 0;
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100vw - 20px, 1120px);
    padding: 10px 0;
  }

  .chart-panel {
    padding: 22px;
  }

  .header-row {
    display: block;
  }

  .metric {
    margin-top: 20px;
    text-align: left;
  }

  .market-strip {
    grid-template-columns: 1fr;
  }

  .market-strip-meta {
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
  }

  .market-strip-items {
    grid-template-columns: 1fr;
  }

  .market-item {
    min-height: 76px;
  }

  .market-item + .market-item {
    border-left: 0;
    border-top: 1px solid var(--color-border);
  }

  .controls-row {
    align-items: flex-start;
    flex-direction: column;
  }

  select {
    width: 100%;
  }

  .calculator-section {
    padding: 18px;
  }

  .calculator-grid,
  .calculator-results {
    grid-template-columns: 1fr;
  }

  .chart-title {
    padding: 18px 18px 8px;
    font-size: 15px;
  }

  .chart-body {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .chart-y-axis {
    width: 72px;
  }

  .chart-plot-scroll svg {
    min-width: 820px;
  }
}
