:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --text: #1c1b19;
  --muted: #6b6860;
  --border: #e3e0d8;
  --accent: #8a6d1d;
  --row-alt: #faf9f6;
  --error: #b3261e;
  --gold: #c9a227;
  --silver: #9aa0a6;
  --platinum: #7d8ea3;
  --palladium: #a39276;
  --copper: #b8693d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1d1c1a;
    --text: #ece9e2;
    --muted: #9c988e;
    --border: #2f2d29;
    --accent: #d9b44a;
    --row-alt: #222120;
    --error: #f2857b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap { max-width: 1000px; margin: 0 auto; padding: 0 16px; }

header { padding-top: 28px; }
h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }

.status { color: var(--muted); margin: 4px 0 20px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.status.error { color: var(--error); }

button {
  font: inherit; font-size: 0.85rem;
  padding: 3px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); cursor: pointer;
}
button:hover { border-color: var(--accent); }

.spots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.spot {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--metal, var(--border));
  border-radius: 8px;
  padding: 12px 14px;
}
.spot .name { color: var(--muted); font-size: 0.85rem; }
.spot .price { font-size: 1.45rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.spot .unit { color: var(--muted); font-size: 0.8rem; }
.spot .sub { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.swatch { width: 10px; height: 10px; border-radius: 50%; background: var(--metal); display: inline-block; }

.controls {
  display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center;
  margin-bottom: 24px;
}
.controls label { font-weight: 600; }
.controls .hint { color: var(--muted); font-size: 0.8rem; flex-basis: 100%; }

input, select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text);
}
#premiums { width: 180px; max-width: 100%; }

.tabs {
  position: relative; /* offset parent for scrolling the active tab into view */
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  scrollbar-width: thin;
}
.tabs button {
  flex: none;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 6px 6px 0 0;
  background: none;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 0.9rem;
  display: flex; align-items: center; gap: 6px;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--metal);
}

/* Phones get a dropdown instead of the tab row. */
.tab-select { display: none; }

.group { margin-bottom: 28px; }
.group .note { color: var(--muted); font-size: 0.85rem; margin: -4px 0 10px; }

.table-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 12px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; white-space: normal; min-width: 180px; }
thead th { font-size: 0.8rem; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border); }
tbody tr:nth-child(even) { background: var(--row-alt); }
td .desc { display: block; color: var(--muted); font-size: 0.78rem; }
td.content { color: var(--muted); }
td.melt { font-weight: 600; }

.calc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 28px;
}
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr)); gap: 12px; }
.calc-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.calc-result { font-size: 1.05rem; margin: 14px 0 0; font-variant-numeric: tabular-nums; }

footer { color: var(--muted); font-size: 0.8rem; padding-bottom: 32px; }
footer a { color: var(--accent); }

/* Only shown in the mobile card layout. */
td .content-inline, td .melt-inline { display: none; }

@media (max-width: 600px) {
  header { padding-top: 18px; }
  h1 { font-size: 1.35rem; }

  /* iOS zooms in on focused inputs smaller than 16px. */
  input, select { font-size: 16px; }

  button { min-height: 36px; padding: 6px 14px; }
  .tabs { display: none; }
  .tab-select { display: block; width: 100%; min-height: 44px; margin-bottom: 16px; font-weight: 600; }

  .spots { grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr)); gap: 8px; margin-bottom: 18px; }
  .spot { padding: 8px 10px; }
  .spot:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .spot .price { font-size: 1.15rem; }

  /* Tables become one card per item, so nothing scrolls sideways. */
  .table-scroll { overflow: visible; background: none; border: none; }
  table, tbody, td { display: block; }
  thead { display: none; }
  tbody tr {
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--metal);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
  }
  tbody tr:nth-child(even) { background: var(--surface); }
  td, td:first-child { padding: 0; text-align: left; min-width: 0; white-space: normal; }
  td.content, td.melt, td .desc-full { display: none; }

  /* Header row: name and details on the left, melt on the right. */
  td:first-child {
    grid-column: 1 / -1;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
  }
  .item { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
  .item > div:first-child { font-weight: 600; overflow-wrap: anywhere; }
  .item .desc { font-weight: 400; }
  td .content-inline { display: block; }
  td .melt-inline { display: block; text-align: right; font-size: 1.1rem; font-weight: 600; white-space: nowrap; }
  .melt-inline .desc { font-size: 0.72rem; line-height: 1.2; }

  /* Premium row: label above value, evenly spaced. */
  td[data-label] { font-size: 0.9rem; }
  td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.72rem;
    color: var(--muted);
  }
}
