:root {
  --bg: #000000;
  --bg-panel: #0b0a0c;
  /* Rows drop back to pure black. The item renders ship on a black backdrop,
     so against a black row they lose their tile entirely and the objects read
     as if they were cut out. */
  --bg-row: #000000;
  --bg-row-hover: #17151a;

  --line: #38342e;
  --line-soft: #23211e;

  --text: #f1ece4;
  --text-dim: #a79c90;
  --text-faint: #7a6f65;

  --gold: #d8ab54;
  --gold-bright: #f2cb7d;

  --green: #7fc98a;
  --red: #e0716a;

  /* Lifted surfaces and accent washes, kept as tokens so no rule has to
     hardcode a colour that depends on the theme. Against black these lift
     rather than recess, which is why they are white-based. */
  --sunken: rgba(255, 255, 255, 0.04);
  --tint: rgba(255, 255, 255, 0.07);
  --hollow: rgba(255, 255, 255, 0.05);
  --gold-wash: rgba(216, 171, 84, 0.14);
  --gold-edge: rgba(216, 171, 84, 0.38);
  --green-wash: rgba(127, 201, 138, 0.15);

  --radius: 10px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 15% -10%, rgba(216, 171, 84, 0.11), transparent 55%),
    radial-gradient(ellipse at 90% 0%, rgba(150, 60, 40, 0.13), transparent 50%);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

.wrap {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- header ---------- */

.site-header {
  padding: 40px 0 28px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 32px;
}

.header-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.header-text { min-width: 0; }

.gh-link {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-top: 4px;
  border-radius: 9px;
  color: var(--text-dim);
  background: var(--tint);
  border: 1px solid var(--line-soft);
  transition: color 0.14s, background 0.14s, border-color 0.14s;
}

.gh-link:hover {
  color: var(--gold-bright);
  background: var(--gold-wash);
  border-color: var(--gold);
}

.gh-link:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.gh-link svg { display: block; }

.site-header h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 42px);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--gold-bright);
}

.site-header h1 span {
  color: var(--text);
  font-weight: 300;
}

.tagline {
  margin: 10px 0 0;
  color: var(--text-dim);
  /* Wide enough to hold the sentence on one line; it is short enough that the
     usual measure limit would only ever strand the last word or two. */
  max-width: 92ch;
}

/* ---------- layout ---------- */

/* Treasures | gemstones | the plan. The tools bar spans all three. */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 3.7fr) minmax(0, 5.3fr);
  gap: 24px;
  align-items: start;
}

.layout-tools {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: -6px;
}

.layout-tools h2 { margin: 0; font-size: 19px; font-weight: 600; }

/* Two columns of inventory with the plan beneath, then a single stack. */
@media (max-width: 1150px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .results { grid-column: 1 / -1; position: static; }
}

@media (max-width: 700px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 20px;
}

.results { position: sticky; top: 20px; }

.inventory .stack { margin-top: 12px; }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.panel-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
}

.preset-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- switch ---------- */

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  user-select: none;
}

.switch:hover { color: var(--text); }

/* The checkbox stays in the layout so it keeps its focus ring and hit target,
   but the track below is what you actually see. */
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-track {
  position: relative;
  width: 34px;
  height: 19px;
  flex: none;
  border-radius: 999px;
  background: var(--tint);
  border: 1px solid var(--line);
  transition: background 0.14s, border-color 0.14s;
}

.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.14s, background 0.14s;
}

.switch input:checked + .switch-track {
  background: var(--gold-wash);
  border-color: var(--gold);
}

.switch input:checked + .switch-track .switch-knob {
  background: var(--gold-bright);
  transform: translateX(15px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.switch-hint {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-faint);
}

.group-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-faint);
  margin: 22px 0 8px;
  font-weight: 600;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--bg-row);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn:hover { background: var(--bg-row-hover); border-color: var(--gold); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); }

/* ---------- inventory rows ---------- */

.stack { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  background: var(--bg-row);
  border: 1px solid transparent;
  border-radius: 8px;
}

.row:hover { background: var(--bg-row-hover); }

.row-lead {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.row-main { min-width: 0; }

.row-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
}

.row-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-faint);
}

.row-base { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.row-shape { text-transform: uppercase; letter-spacing: 0.06em; }

/* Hollow outlines rather than filled glyphs, and a gap between the round
   group and the square group so you never have to count across a mixed row. */
.sockets { display: inline-flex; align-items: center; gap: 8px; }

.socket-group { display: inline-flex; align-items: center; gap: 3px; }

.socket {
  flex: none;
  border: 1.5px solid var(--gold);
  background: var(--hollow);
}

.socket-round { width: 11px; height: 11px; border-radius: 50%; }
.socket-square { width: 8px; height: 12px; border-radius: 2px; }

.swatch {
  width: 12px;
  height: 12px;
  flex: none;
  background: var(--chip);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45) inset;
}

.swatch-round { border-radius: 50%; }
.swatch-square { border-radius: 2px; }

/* ---------- item icons ---------- */

/* The renders ship on a black backdrop, so each one reads as a little
   inventory slot rather than a floating cut-out. */
.icon {
  flex: none;
  display: block;
  object-fit: contain;
  background: #000;
  border-radius: 5px;
}

.icon-lg {
  width: 38px;
  height: 38px;
  border-radius: 7px;
}

/* Nothing outlines an icon at rest — it reads as the bare object. Hovering a
   row rings it in gold, which turns it back into a visible slot. */
.row:hover .icon-lg { box-shadow: 0 0 0 1px var(--gold); }

.icon-md { width: 34px; height: 34px; border-radius: 6px; }

.icon-sm { width: 22px; height: 22px; }

.icon-xs { width: 16px; height: 16px; border-radius: 4px; }

/* ---------- stepper ---------- */

.stepper {
  display: flex;
  align-items: center;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--sunken);
}

.stepper.has-some { border-color: var(--gold); }

.step {
  width: 30px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.step:hover:not(:disabled) { background: var(--gold-wash); color: var(--gold-bright); }
.step:disabled { opacity: 0.28; cursor: default; }
.step:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }

.step-value {
  width: 34px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: center;
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  padding: 0;
}

.step-value:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }

.has-some .step-value { color: var(--gold-bright); font-weight: 600; }

/* ---------- results ---------- */

.empty, .warn {
  color: var(--text-dim);
  font-size: 14px;
  margin: 18px 0 0;
}

.warn {
  background: var(--gold-wash);
  border: 1px solid var(--gold-edge);
  border-radius: 8px;
  padding: 10px 12px;
}

.total {
  margin-top: 16px;
  padding: 18px;
  border-radius: 10px;
  background: linear-gradient(150deg, rgba(216, 171, 84, 0.17), rgba(216, 171, 84, 0.04));
  border: 1px solid var(--gold-edge);
}

.total-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-dim);
}

.total-value {
  font-size: clamp(30px, 6vw, 42px);
  font-weight: 700;
  color: var(--gold-bright);
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.total-delta { font-size: 13px; color: var(--text-dim); }
.total-delta.positive { color: var(--green); }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.card {
  background: var(--bg-row);
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  padding: 12px 14px;
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-who {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.card-name { font-size: 15px; font-weight: 600; }

.card-value {
  font-size: 17px;
  font-weight: 700;
  color: var(--gold-bright);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 9px 0 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 4px;
  font-size: 12px;
  border-radius: 999px;
  background: var(--tint);
  border: 1px solid var(--chip);
  color: var(--text);
}

.chip-count { font-weight: 700; color: var(--text-dim); }

.card-math {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-faint);
}

.bonus {
  padding: 2px 8px;
  border-radius: 5px;
  font-weight: 600;
  background: var(--tint);
  color: var(--text-dim);
}

.bonus-mid { background: var(--green-wash); color: var(--green); }
.bonus-high { background: var(--gold-wash); color: var(--gold-bright); }

.sum { font-variant-numeric: tabular-nums; }

.card-note { margin-top: 7px; font-size: 12px; color: var(--text-faint); font-style: italic; }

.plain {
  display: grid;
  gap: 6px;
  background: var(--sunken);
  border-radius: 9px;
  padding: 12px 14px;
}

.plain-line {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 10px;
  align-items: baseline;
  font-size: 13px;
}

@media (max-width: 520px) {
  .plain-line { grid-template-columns: 1fr auto; }
  .plain-line .plain-items { grid-column: 1 / -1; }
}

.plain-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.plain-items { display: flex; flex-wrap: wrap; gap: 5px 10px; color: var(--text-dim); }
.plain-item { display: inline-flex; align-items: center; gap: 6px; }
.plain-sum { color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.plain-sum-muted { color: var(--text-faint); text-decoration: line-through; }

.plain-note {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--text-faint);
  font-style: italic;
}

/* ---------- reference ---------- */

.reference { margin: 36px auto 0; }

.reference details {
  background: var(--bg-panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 4px 20px;
}

.reference summary {
  cursor: pointer;
  padding: 14px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.reference summary::-webkit-details-marker { display: none; }

.reference summary::before {
  content: "\25B8";
  color: var(--gold);
  transition: transform 0.15s;
}

.reference details[open] summary::before { transform: rotate(90deg); }

.reference summary h2 { margin: 0; font-size: 17px; font-weight: 600; display: inline; }

.ref-body { padding-bottom: 24px; }

.ref-body h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  margin: 26px 0 8px;
}

.formula {
  background: var(--sunken);
  border-left: 3px solid var(--gold);
  border-radius: 0 6px 6px 0;
  padding: 12px 14px;
  margin: 6px 0 14px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 14px;
  color: var(--gold-bright);
}

.note { color: var(--text-dim); font-size: 14px; max-width: 78ch; }
.note strong { color: var(--text); }

.table-scroll { overflow-x: auto; }

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 420px;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 600;
}

td { color: var(--text-dim); }
td:first-child { color: var(--text); }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- self test ---------- */

.selftest-summary { font-weight: 600; margin: 14px 0 8px; }
.selftest-summary.good { color: var(--green); }
.selftest-summary.bad { color: var(--red); }

.selftest-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }

.selftest-list li {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 8px;
  font-size: 13px;
  padding: 3px 0;
  color: var(--text-dim);
}

.selftest-mark { color: var(--green); }
.selftest-list li.bad { color: var(--red); }
.selftest-list li.bad .selftest-mark { color: var(--red); }
.selftest-got { font-variant-numeric: tabular-nums; color: var(--text-faint); }

/* ---------- footer ---------- */

.site-footer {
  margin: 34px auto 40px;
  color: var(--text-faint);
  font-size: 13px;
}

.site-footer p { margin: 0; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
