/* BONKulator — "Terminal" theme. Gruvbox dark where it was born: monospace TUI, sharp corners,
   hairline boxes, shell/markdown cues ($, //, ##, ›, [ ], #), aqua + green prompt accents.
   Corruption elements are purple. */
:root {
  --bg: #1d2021;          /* terminal black (bg0 hard) */
  --panel: #282828;       /* raised panel (bg0) */
  --line: #504945;        /* box border (bg2) */
  --line2: #3c3836;       /* faint divider (bg1) */
  --fg: #ebdbb2;          /* foreground */
  --dim: #a89984;         /* muted */
  --faint: #7c6f64;       /* faintest / comments */

  --green: #b8bb26;       /* primary prompt accent */
  --aqua: #8ec07c;        /* secondary accent */
  --yellow: #fabd2f;      /* labels / warnings */
  --orange: #fe8019;
  --blue: #83a598;        /* computed values */
  --purple: #d3869b;      /* corruption (bright) */
  --purple-dim: #b16286;  /* corruption (neutral) */
  --corrupt-track: #45303f; /* corruption slider track (dark purple) */
  --green-bonus: #b8bb26; /* the green +bonus accent */
  --red: #fb4934;         /* destructive / over-budget */

  --space: 8px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---- Top bar: tabs on the left, brand on the right (one row — no separate header) ---- */
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  padding: calc(var(--space) * 0.6) calc(var(--space) * 2);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.tab-bar { display: flex; gap: 0; flex-wrap: wrap; }
.brand {
  flex: none;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--green);
  white-space: nowrap;
}
.brand::before { content: "$ "; color: var(--aqua); }
/* Tabs + the export button grouped on the left; the brand stays on the right. */
.topbar-left { display: flex; align-items: center; flex-wrap: wrap; gap: calc(var(--space) * 1.25); min-width: 0; }
/* Debug export: copies the full app state (inputs + computed results) as JSON. */
.export-btn {
  padding: calc(var(--space) * 0.35) calc(var(--space) * 0.9);
  background: transparent; color: var(--dim);
  border: 1px solid var(--line); border-radius: 0;
  cursor: pointer; font-size: 0.74rem; font-family: var(--mono);
  white-space: nowrap;
  transition: color 120ms ease, border-color 120ms ease;
}
.export-btn:hover { color: var(--aqua); border-color: var(--aqua); }
.tab {
  display: flex;
  align-items: center;
  padding: calc(var(--space) * 0.85) calc(var(--space) * 1.5);
  color: var(--dim);
  cursor: pointer;
  font-size: 0.85rem;
  transition: color 120ms ease, background 120ms ease;
}
.tab:hover { color: var(--fg); }
.tab-name::before { content: "["; color: var(--faint); margin-right: 5px; }
.tab-name::after  { content: "]"; color: var(--faint); margin-left: 5px; }
.tab.active { color: var(--bg); background: var(--green); }
.tab.active:hover { color: var(--bg); }
.tab.active .tab-name::before, .tab.active .tab-name::after { color: var(--bg); }
.tab-name { outline: none; }
.tab-name[contenteditable="true"] { color: var(--green); background: var(--panel); padding: 0 4px; }

/* ---- Panels ---- */
.main-container { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.panel { overflow-y: auto; padding: calc(var(--space) * 2) calc(var(--space) * 2.5); }
/* Inputs get 2/3, the computed stats 1/3. */
.panel-left { width: 66.6667%; background: var(--panel); border-right: 1px solid var(--line); }
.panel-right { width: 33.3333%; background: var(--bg); }

/* ---- Sections & labels ---- */
.section { margin-bottom: calc(var(--space) * 3); }
.section h2 {
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--aqua);
  padding-bottom: calc(var(--space) * 0.75);
  margin-bottom: calc(var(--space) * 1.5);
  border-bottom: 1px dashed var(--line);
}
.section h2::before { content: "## "; color: var(--green); }
.section h2 span { color: var(--faint); font-weight: 400; text-transform: none; letter-spacing: 0; }
/* ---- Inputs (NPC data fields) ---- */
.input-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--space); }
.input-grid-2 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.input-grid-3 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.input-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.input-group { display: flex; flex-direction: column; gap: 3px; }
.input-group label { font-size: 0.72rem; letter-spacing: 0.02em; color: var(--dim); text-transform: uppercase; }
.input-group input, .input-group select {
  padding: calc(var(--space) * 0.6) calc(var(--space) * 0.85);
  background: var(--bg);
  border: 1px solid var(--line2);
  border-radius: 0;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 0.85rem;
  transition: border-color 120ms ease, background 120ms ease;
}
.input-group select { cursor: pointer; }
.input-group input:hover, .input-group select:hover { border-color: var(--line); }
.input-group input:focus, .input-group select:focus { outline: none; border-color: var(--green); background: var(--panel); }
.bonus-input input { color: var(--green-bonus); box-shadow: inset 2px 0 0 var(--green-bonus); }
.input-group input:disabled, .input-group select:disabled { color: var(--faint); background: var(--panel); cursor: not-allowed; }

/* Player attribute gear/buff bonus: a compact field under the slider + a live "= effective" readout. */
.bonus-row { display: flex; align-items: center; gap: calc(var(--space) * 0.75); margin-top: calc(var(--space) * 0.75); }
.bonus-label { flex: none; font-size: 0.7rem; letter-spacing: 0.02em; color: var(--dim); text-transform: uppercase; }
.bonus-field {
  flex: none; width: 5em; text-align: right;
  padding: calc(var(--space) * 0.35) calc(var(--space) * 0.6);
  background: var(--bg); border: 1px solid var(--line2); border-radius: 0;
  color: var(--green-bonus); font-family: var(--mono); font-size: 0.82rem;
  box-shadow: inset 2px 0 0 var(--green-bonus);
  transition: border-color 120ms ease, background 120ms ease;
}
.bonus-field:focus { outline: none; border-color: var(--green); background: var(--panel); }
.bonus-eff { font-family: var(--mono); font-size: 0.8rem; color: var(--green-bonus); font-variant-numeric: tabular-nums; }

/* Marker on values we haven't fully verified (hover for the reason). */
.uncertain-marker {
  display: inline-grid; place-items: center;
  width: 13px; height: 13px; margin-left: 4px;
  border: 1px solid var(--yellow);
  color: var(--yellow); font-size: 0.6rem; font-weight: 700; line-height: 1;
  cursor: help; vertical-align: middle;
}

/* A short caveat note for a gap, unknown, or easily-misread value (placed throughout the UI). */
.ui-note { font-size: 0.74rem; line-height: 1.5; color: var(--dim); margin-top: calc(var(--space) * 0.75); }
.ui-note::before { content: "\24D8"; color: var(--blue); font-weight: 700; margin-right: 0.45em; }
/* Amber variant — same footnote format, used for active-status notices (e.g. "Well-Trained is active"). */
.ui-note-amber, .ui-note-amber::before { color: var(--yellow); }

/* ---- Level / point budget ---- */
.level-block {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  padding: calc(var(--space) * 1.5);
}
.level-header { display: flex; justify-content: flex-end; align-items: baseline; margin-bottom: var(--space); }
.level-title { font-size: 0.85rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--fg); }
.level-value { font-family: var(--mono); font-size: 1.2rem; font-weight: 700; color: var(--green); }
.points-display { display: flex; justify-content: space-between; margin-top: var(--space); font-size: 0.78rem; }
.points-spent { color: var(--blue); }
.points-remaining { color: var(--green); }
.points-remaining.over { color: var(--red); }

/* ---- Attribute blocks ---- */
.attribute-block {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  padding: calc(var(--space) * 1.5);
}
.attribute-header { display: flex; justify-content: flex-end; align-items: baseline; margin-bottom: var(--space); }
.attribute-name { font-size: 0.85rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--fg); }

/* Each card sits in a row with its name as a vertical label in the left gutter, vertically centered. */
.attribute-row, .level-row { display: flex; align-items: center; gap: calc(var(--space) * 0.75); }
.level-row { margin-bottom: calc(var(--space) * 2); }
.attribute-row { margin-bottom: calc(var(--space) * 1.75); }
.attribute-row:last-child { margin-bottom: 0; }
.attribute-name, .level-title { flex: none; writing-mode: vertical-rl; transform: rotate(180deg); }
.attribute-value { font-family: var(--mono); font-size: 0.95rem; font-weight: 700; color: var(--green); }
.attribute-value .max { color: var(--faint); font-weight: 400; }

/* ---- Sliders ---- */
.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; background: var(--line); outline: none; cursor: pointer; margin: calc(var(--space) * 0.5) 0; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 10px; height: 16px; border-radius: 0; background: var(--green); cursor: pointer; transition: transform 100ms ease; }
.slider::-webkit-slider-thumb:hover { transform: scaleY(1.1); }
.slider::-moz-range-thumb { width: 10px; height: 16px; border: none; border-radius: 0; background: var(--green); cursor: pointer; }
.slider.corruption { background: var(--corrupt-track); }
.slider.corruption::-webkit-slider-thumb { background: var(--purple); }
.slider.corruption::-moz-range-thumb { background: var(--purple); }
.slider.level { background: linear-gradient(to right, var(--line2), var(--aqua)); }

/* ---- Corruption ---- */
.corruption-row { margin-top: calc(var(--space) * 1.25); padding-top: calc(var(--space) * 1.25); border-top: 1px dashed var(--line); }
.corruption-label { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--purple); margin-bottom: calc(var(--space) * 0.75); letter-spacing: 0.02em; }
.corruption-label span:last-child { font-family: var(--mono); }

/* ---- Perks ---- */
.perk-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: calc(var(--space) * 0.75); margin-top: calc(var(--space) * 1.25); }
.perk-item {
  display: flex; align-items: center; gap: 4px;
  min-width: 0; overflow: hidden; white-space: nowrap;
  font-size: 0.78rem;
  color: var(--faint);
  padding: 3px calc(var(--space) * 0.75);
  border: 1px solid var(--line2);
}
.perk-thr { flex: none; color: var(--faint); font-variant-numeric: tabular-nums; }
.perk-item.disabled { color: var(--faint); border-color: var(--line2); }
.perk-item.unlocked { color: var(--green); border-color: var(--green); }
.perk-item.unlocked .perk-thr { color: var(--green); }
.perk-item.corrupted.unlocked { color: var(--purple); border-color: var(--purple); }
.perk-item.corrupted.unlocked .perk-thr { color: var(--purple); }
/* A normal perk whose threshold corruption has covered: the corrupted perk overrides it. */
.perk-item.overridden { color: var(--purple-dim); border-color: var(--purple-dim); text-decoration: line-through; }
.perk-item.overridden .perk-thr, .perk-item.overridden select { color: var(--purple-dim); text-decoration: line-through; }
.perk-item select {
  flex: 1; min-width: 0;
  background: transparent; color: inherit; border: none;
  font-family: var(--mono); font-size: 0.78rem; cursor: pointer; padding: 0;
  text-overflow: ellipsis;
}
.perk-item select:focus { outline: none; }
.perk-item select option { background: var(--panel); color: var(--fg); }

/* Always-visible perk-effect list under each attribute's pills — compact "man-page" rows. */
.pd-list { margin-top: calc(var(--space) * 1.25); display: flex; flex-direction: column; gap: 2px; }
/* Inactive (locked) perks read slightly dimmer; unlocked ones brighten up. */
.pd-row { display: flex; gap: 10px; padding: 2px 0; font-size: 0.76rem; line-height: 1.5; opacity: 0.62; transition: opacity 0.12s ease; }
.pd-row.active { opacity: 1; }
.pd-thr { flex: none; min-width: 1.8em; text-align: right; color: var(--faint); font-variant-numeric: tabular-nums; }
.pd-text { flex: 1 1 auto; min-width: 0; }
.pd-name { color: var(--aqua); font-weight: 700; }
.pd-desc { color: var(--dim); }
.pd-list-corrupt .pd-name { color: var(--purple); }

/* "How to enter a follower" reference block at the bottom of the follower pane. */
.help-blob {
  margin-top: calc(var(--space) * 2.5);
  padding: calc(var(--space) * 1.25);
  border: 1px dashed var(--line);
  font-size: 0.74rem;
  line-height: 1.55;
  color: var(--dim);
}
.help-blob h3 {
  font-size: 0.8rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--aqua); margin-bottom: calc(var(--space) * 0.75);
}
.help-blob p { margin-bottom: calc(var(--space) * 0.5); }
.help-blob p:last-child { margin-bottom: 0; }
.help-blob strong { color: var(--fg); font-weight: 700; }

/* Reference spreadsheet links */
.sheet-links { display: flex; flex-wrap: wrap; gap: calc(var(--space) * 2); margin-bottom: calc(var(--space) * 1.5); padding-bottom: var(--space); border-bottom: 1px dashed var(--line); }
.sheet-link { color: var(--blue); font-size: 0.78rem; text-decoration: none; transition: color 120ms ease; }
.sheet-link:hover { color: var(--aqua); text-decoration: underline; }

/* Reset / Copy buttons */
.pane-tools { display: flex; justify-content: flex-end; margin-bottom: var(--space); }
.reset-btn {
  background: transparent; border: 1px solid var(--line); color: var(--dim);
  padding: calc(var(--space) * 0.45) calc(var(--space) * 1);
  font-family: var(--mono); font-size: 0.78rem; cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}
.reset-btn:hover { color: var(--red); border-color: var(--red); }

/* ---- Results ---- */
.stat-row { display: flex; justify-content: space-between; align-items: baseline; gap: calc(var(--space) * 1.5); padding: calc(var(--space) * 1.1) 0; border-bottom: 1px dashed var(--line2); }
.stat-info { min-width: 0; }
.stat-name { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--yellow); }
.stat-generic { font-family: var(--mono); font-size: 0.78rem; color: var(--faint); margin-top: 4px; overflow-wrap: anywhere; }
.stat-math { font-family: var(--mono); font-size: 0.82rem; color: var(--blue); margin-top: 3px; overflow-wrap: anywhere; }
.stat-result { flex: none; font-family: var(--mono); font-size: 1.1rem; font-weight: 700; color: var(--green); white-space: nowrap; }
/* Headline stats (key=true): solid brighter divider + a larger result so they stand out. */
.stat-row.key { border-bottom: 1px solid var(--line); }
.stat-row.key .stat-result { font-size: 1.3rem; }

.copy-btn {
  margin-top: var(--space);
  padding: calc(var(--space) * 0.6) calc(var(--space) * 1.1);
  background: transparent; color: var(--dim);
  border: 1px solid var(--line); border-radius: 0;
  cursor: pointer; font-size: 0.78rem; font-family: var(--mono);
  transition: color 120ms ease, border-color 120ms ease;
}
.copy-btn:hover { color: var(--aqua); border-color: var(--aqua); }
.copy-success { margin-left: var(--space); font-size: 0.78rem; color: var(--green); opacity: 0; transition: opacity 0.3s; }
.copy-success.show { opacity: 1; }

/* ---- Scrollbars ---- */
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb { background: var(--line); border: 2px solid var(--bg); }
.panel::-webkit-scrollbar-thumb:hover { background: var(--dim); }

/* ---- Responsive ---- */
@media (max-width: 720px) {
  .main-container { flex-direction: column; overflow-y: auto; }
  .panel { width: 100%; overflow-y: visible; }
  .panel-left { border-right: none; border-bottom: 1px solid var(--line); }
  .tab-bar { flex-wrap: wrap; }
}
@media (max-width: 480px) {
  .input-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
