:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --ink: #1f2421;
  --muted: #6b7280;
  --line: #e3e3de;
  --accent: #2f6f4f;
  --accent-soft: #e6f1ea;
  --gold: #b8860b;
  --danger: #a3372c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(31, 36, 33, 0.06), 0 4px 14px rgba(31, 36, 33, 0.05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.brand { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
.lede { color: var(--muted); margin: 0 0 22px; max-width: 62ch; }
.muted { color: var(--muted); }
.footnote { color: var(--muted); font-size: 13px; margin-top: 22px; max-width: 80ch; }

.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}
.back:hover { color: var(--accent); }

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

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 7px 12px;
  background: transparent;
  color: var(--ink);
  transition: background 0.12s, border-color 0.12s;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.primary { background: var(--accent); color: #fff; font-weight: 600; }
.primary:hover { background: #26593f; }
.secondary { background: var(--panel); border-color: var(--line); font-weight: 600; }
.secondary:hover { border-color: var(--accent); color: var(--accent); }
.ghost { border-color: var(--line); background: var(--panel); color: var(--muted); }
.ghost:hover { color: var(--ink); border-color: var(--muted); }
.danger { color: var(--danger); }
.danger:hover { border-color: var(--danger); background: #fdf3f2; color: var(--danger); }

.icon {
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
  border-color: transparent;
}
.icon:hover { background: var(--bg); color: var(--ink); }

/* --- inputs -------------------------------------------------------------- */

.text-input, .select {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  width: 100%;
  min-width: 0;
}
.text-input:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.text-input.small { padding: 5px 7px; font-size: 13px; }
.numeric { font-variant-numeric: tabular-nums; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin-bottom: 8px; }
.field.inline > span { flex: 0 0 72px; }

.title-input {
  font-family: inherit;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 4px 8px;
  margin: 6px -8px 2px;
  width: calc(100% + 16px);
}
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: none; background: var(--panel); border-color: var(--accent); }

/* --- decision list ------------------------------------------------------- */

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

.decision-card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px 10px 4px 4px;
}
.decision-card:hover { border-color: var(--accent); }

.decision-link {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
  min-width: 0;
}
.decision-name { font-weight: 600; }
.decision-meta { font-size: 13px; color: var(--muted); }

.empty {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 18px;
}
.empty p { margin: 0 0 6px; }

/* --- verdict ------------------------------------------------------------- */

.verdict {
  margin: 0 0 16px;
  font-weight: 600;
  color: var(--accent);
}
.verdict.muted { font-weight: 400; color: var(--muted); }

/* --- the grid ------------------------------------------------------------ */

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 230px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table.grid {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
}

table.grid th, table.grid td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  padding: 8px;
  background: var(--panel);
}

.corner, .option-head, .add-col {
  position: sticky;
  top: 0;
  z-index: 2;
}
/* The criteria column is resizable — --crit-w is set on .board-page from the
   stored preference, and the handle in the corner cell drags it. */
.board-page { --crit-w: 210px; }

.corner, .criterion-head {
  position: sticky;
  left: 0;
  z-index: 1;
  width: var(--crit-w);
  min-width: var(--crit-w);
  max-width: var(--crit-w);
}

.crit-resize {
  position: absolute;
  top: 0;
  right: 0;
  width: 16px;
  height: 100%;
  z-index: 4;
  cursor: col-resize;
  touch-action: none;      /* a drag here resizes; it must not scroll the table */
  display: flex;
  align-items: center;
  justify-content: center;
}
.crit-resize::before {
  content: '';
  width: 2px;
  height: 55%;
  min-height: 14px;
  border-radius: 2px;
  background: var(--line);
}
.crit-resize:hover::before, .crit-resize.dragging::before { background: var(--accent); }
.corner { z-index: 3; box-shadow: 1px 0 0 var(--line); }
/* sticky is already a positioned ancestor, so .crit-resize anchors to it */
th.corner { padding-right: 18px; }
.criterion-head { box-shadow: 1px 0 0 var(--line); }

.corner-label { display: block; font-size: 13px; color: var(--muted); }
.corner-sub { display: block; font-size: 11px; color: var(--muted); opacity: 0.8; }

.option-head { min-width: 180px; max-width: 240px; }
.option-head.is-leader { background: var(--accent-soft); }

.option-rank { font-size: 12px; font-weight: 700; color: var(--muted); min-height: 16px; }
.option-rank.winner { color: var(--gold); }

.option-name {
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 5px;
  margin: 2px -5px 6px;
  width: calc(100% + 10px);
}
.option-name:hover { border-color: var(--line); }
.option-name:focus { outline: none; background: var(--panel); border-color: var(--accent); }

.score { margin-bottom: 4px; }
.score-value { font-family: inherit; font-size: 20px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score-bar { height: 5px; border-radius: 3px; background: var(--line); margin: 4px 0 3px; overflow: hidden; }
.score-fill { height: 100%; width: 0; background: var(--muted); transition: width 0.18s ease; }
.score-fill.leading { background: var(--accent); }
.score-coverage { font-size: 11px; }

.row-tools { display: flex; gap: 2px; }

.criterion-name {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 5px;
  margin: 0 -5px 4px;
  width: calc(100% + 10px);
  display: block;
  resize: none;          /* height is set from scrollHeight as you type */
  overflow: hidden;
  overflow-wrap: break-word;
}
.criterion-name:hover { border-color: var(--line); }
.criterion-name:focus { outline: none; background: var(--panel); border-color: var(--accent); }

.criterion-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }

/* Narrow column: the name is all there's room for. The settings gear stays so
   type and weight are still one tap away. */
.board-page.narrow .criterion-meta .chip { display: none; }
/* Lift the gear out of the flow into the cell's top-right corner — on a phone
   a whole line per row for one button is a line the table can't spare. The
   name reserves room for it so long text never runs underneath. */
.board-page.narrow .criterion-meta { position: absolute; top: 3px; right: 2px; margin: 0; }
.board-page.narrow .criterion-name { padding-right: 22px; }
.board-page.narrow .corner-sub { display: none; }
.board-page.narrow th.criterion-head { padding: 6px; }
.board-page.narrow .criterion-name { font-size: 13px; }
.chip {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.weight { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.kind-text, .chip.muted-chip { opacity: 0.85; }

.settings {
  margin-top: 8px;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.settings .select, .settings .text-input { font-size: 13px; padding: 4px 6px; }
.settings-actions { display: flex; gap: 4px; align-items: center; margin-top: 6px; }

td.cell { min-width: 140px; }
td.cell.winner-cell { background: var(--accent-soft); }
.cell-input { background: transparent; border-color: transparent; }
td.cell:hover .cell-input { border-color: var(--line); }
.cell-input:focus { background: var(--panel); border-color: var(--accent); }

.empty-row { color: var(--muted); padding: 22px; text-align: center; }
.add-col { min-width: 120px; }

.board-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* --- modal --------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(31, 36, 33, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal {
  background: var(--panel);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 20px 50px rgba(31, 36, 33, 0.25);
}
.modal h2 { margin: 0 0 16px; font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.template-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.template-card:hover { border-color: var(--accent); }
.template-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.template-name { font-weight: 600; }
.template-blurb { font-size: 12px; color: var(--muted); }

/* --- toast --------------------------------------------------------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); }

/* --- test runner --------------------------------------------------------- */

.test-pass { color: var(--accent); }
.test-fail { color: var(--danger); font-weight: 600; }

@media (max-width: 640px) {
  .page { padding: 14px 10px 50px; }
  .table-wrap { max-height: calc(100vh - 260px); }
  th.corner { padding-right: 16px; }
  .option-head { min-width: 150px; }
  td.cell { min-width: 120px; }
  .title-input { font-size: 20px; }
}
