:root {
  --bg: #0d0e11;
  --panel: #15171c;
  --panel-2: #1a1d23;
  --text: #e6e4dd;
  --muted: #8a8d96;
  --muted-2: #5f626a;
  --accent: #d4a259;
  --accent-2: #ecc488;
  --error: #c97a7a;
  --border: #24272e;
  --border-soft: #1d2026;

  --sans: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1060px;
  margin: 0 auto;
  padding: 56px 24px 80px;
}

/* Inputs on the left, reference tables on the right. */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}

/* Keep the footer at a comfortable reading width; results spans full width. */
.colophon {
  max-width: 760px;
}

/* ── Masthead ──────────────────────────────────────────── */
.masthead {
  margin-bottom: 32px;
}

.masthead-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

/* Keep the title and subtitle at a comfortable reading width. */
.masthead h1,
.subtitle {
  max-width: 760px;
}

.issue-link {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto; /* push to the far right edge of the masthead */
  margin-top: 4px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  transition: color 0.15s, border-color 0.15s;
}

.issue-link:hover {
  color: var(--accent-2);
  border-color: var(--accent);
}

h1 {
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.015em;
  margin: 0 0 8px;
  line-height: 1.15;
}

.subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 14px;
}

/* ── Form ──────────────────────────────────────────────── */
.form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
}

fieldset {
  border: 0;
  padding: 14px 22px;
  margin: 0;
}

fieldset:first-of-type {
  padding-top: 22px;
}

fieldset:last-of-type {
  padding-bottom: 20px;
}

.legend {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin: 0 0 12px;
}

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

.row + .row {
  margin-top: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 220px;
}

.field-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.field-label .hint {
  font-style: normal;
  color: var(--muted-2);
  letter-spacing: 0.04em;
}

/* ── Enhancement Mode slider ───────────────────────────── */
.slider-field {
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex: 1;
}

.slider {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  margin: 4px 0 0;
  border-radius: 2px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  cursor: pointer;
}

.slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
  transition: background 0.12s ease;
}

.slider::-webkit-slider-thumb:hover { background: var(--accent-2); }

.slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
}

.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
}

.slider::-moz-range-thumb:hover { background: var(--accent-2); }

.slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--panel-2);
}

.slider:focus-visible { outline: none; }
.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px rgba(212, 162, 89, 0.35); }
.slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 3px rgba(212, 162, 89, 0.35); }

.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--muted-2);
}

.slider-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}

input[type="number"],
select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 9px 11px;
  font: inherit;
  font-feature-settings: "tnum" 1;
  transition: border-color 120ms ease, background 120ms ease;
}

input[type="number"]:hover,
select:hover {
  border-color: #2f333c;
}

input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  background: #1c1f25;
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

/* Checkboxes */
.checks {
  gap: 22px;
}

.check {
  flex: 0 1 auto;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 13.5px;
}

.check em {
  font-style: normal;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
  margin-left: 2px;
}

.check input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 2px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.check input[type="checkbox"]:hover {
  border-color: #3a3e48;
}

.check.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.check.is-disabled input[type="checkbox"] {
  cursor: not-allowed;
}

.check input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.check input[type="checkbox"]:checked::after {
  content: "";
  width: 7px;
  height: 4px;
  border-left: 1.5px solid #1c1304;
  border-bottom: 1.5px solid #1c1304;
  transform: translateY(-1px) rotate(-45deg);
}

/* Actions */
.actions {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-top: 1px solid var(--border-soft);
  background: #131519;
  border-radius: 0 0 4px 4px;
}

button {
  background: var(--accent);
  color: #1c1304;
  border: 0;
  border-radius: 3px;
  padding: 9px 18px;
  font: 500 13px var(--sans);
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 120ms ease;
}

button:hover { background: var(--accent-2); }
button:active { transform: translateY(0.5px); }
button:disabled,
button.is-running {
  cursor: progress;
  background: var(--panel-2);
  color: var(--muted);
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.error {
  color: var(--error);
  font-size: 13px;
}

.event-note {
  margin: -4px 0 0;
  padding: 9px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
}

.event-note p {
  margin: 0;
}

.event-note p + p {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.event-note strong {
  color: var(--accent-2);
  font-weight: 600;
}

.event-note.hidden { display: none; }

/* Keep the gap before the next row constant whether or not the note is shown —
   the note's presence in the DOM breaks the .row + .row spacing chain. */
.event-note + .row {
  margin-top: 14px;
}

.check-note {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted-2);
}

/* ── Results ───────────────────────────────────────────── */
.results {
  margin-top: 40px;
}

.results.hidden { display: none; }

.section-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.section-head .rule {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.section-title {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 14px 16px;
}

.card-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  margin-top: 6px;
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.01em;
}

/* Stat panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-bottom: 18px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: #13151a;
}

.panel-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

.panel-unit {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--muted-2);
}

.panel-body {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(0, 2fr);
  gap: 0;
}

/* ── Enhancement Mode cost reference ───────────────────── */
.reference {
  margin-top: 0;
}

.reference .panel:last-child {
  margin-bottom: 0;
}

.reference .panel-body {
  display: block;
}

.mode-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 13px;
}

.mode-table th,
.mode-table td {
  text-align: right;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

.mode-table th:first-child,
.mode-table td:first-child {
  text-align: left;
}

.mode-table thead th {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
  font-weight: 500;
}

.mode-table tbody td {
  color: var(--text);
}

.mode-table tbody td:first-child {
  color: var(--muted);
}

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

.mode-table .num {
  color: var(--accent);
}

.mode-table .num.zero {
  color: var(--muted-2);
}

.mode-table .t-note {
  margin-left: 6px;
  font-size: 11px;
  color: var(--muted-2);
}

.table-foot {
  margin: 0;
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border-soft);
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

.stat-list {
  margin: 0;
  padding: 14px 0;
  border-right: 1px solid var(--border-soft);
}

.stat-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 5px 18px;
  gap: 12px;
}

.stat-line dt {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0;
}

.stat-line dd {
  font-family: var(--mono);
  font-size: 13.5px;
  font-feature-settings: "tnum" 1;
  color: var(--text);
  margin: 0;
  text-align: right;
}

.stat-line--accent dt {
  color: var(--accent);
}

.stat-line--accent dd {
  color: var(--accent-2);
  font-weight: 500;
}

.stat-line--divider {
  border-bottom: 1px solid var(--border-soft);
  padding-bottom: 11px;
  margin-bottom: 6px;
}

/* Chart */
.chart {
  padding: 12px 16px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#histogram,
#histogram-booms {
  width: 100%;
  max-width: 100%;
  height: 180px;
  display: block;
}

@media (max-width: 880px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 22px;
  }
  .reference {
    margin-top: 4px;
  }
}

@media (max-width: 600px) {
  .panel-body {
    grid-template-columns: 1fr;
  }
  .stat-list {
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
    padding: 10px 0;
  }
}

/* ── Colophon ──────────────────────────────────────────── */
.colophon {
  margin-top: 56px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.sources {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.source {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 16px;
  align-items: baseline;
}

.source dt {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted-2);
  margin: 0;
}

.source dd {
  margin: 0;
  color: var(--text);
  font-size: 13px;
}

.colophon a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 120ms ease, color 120ms ease;
}

.colophon a:hover {
  color: var(--accent-2);
  border-bottom-color: var(--accent-2);
}

.src-sep {
  color: var(--muted-2);
  margin: 0 6px;
}

@media (max-width: 540px) {
  .source {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

/* ── Small screens ─────────────────────────────────────── */
@media (max-width: 540px) {
  .container { padding: 36px 18px 56px; }
  h1 { font-size: 24px; }
  fieldset { padding: 16px 16px; }
  .actions { padding: 14px 16px; flex-wrap: wrap; }
}
