:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --surface-sunk: #f1eee8;
  --ink: #1c1a17;
  --ink-soft: #5b564e;
  --ink-faint: #8b857b;
  --line: #e2ddd4;
  --line-strong: #cfc8bc;
  --accent: #1f5f52;
  --accent-soft: #e3efeb;
  --uncertain: #9a6a12;
  --uncertain-soft: #fbf0dc;
  --positive: #2f6b3f;
  --negative: #a33a2c;
  --radius: 6px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body { padding-bottom: env(safe-area-inset-bottom); }

a { color: var(--accent); }

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

.shell { max-width: 720px; margin: 0 auto; padding: 0 16px 96px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 12px 0 10px;
  margin-bottom: 20px;
}

.topbar-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.wordmark {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.wordmark span { color: var(--ink-faint); font-weight: 400; }

.who { font-size: 13px; color: var(--ink-soft); }

h1 { font-size: 26px; line-height: 1.2; letter-spacing: -0.02em; margin: 0 0 4px; }
h2 { font-size: 18px; letter-spacing: -0.01em; margin: 28px 0 10px; }
h3 { font-size: 15px; margin: 20px 0 8px; }

.lede { color: var(--ink-soft); margin: 0 0 20px; font-size: 15px; }

/* ---------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
  /* A fade on the right edge signals there is more to scroll to. */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
  flex: 0 0 auto;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  display: block;
  color: inherit;
  text-decoration: none;
}

.card:active { background: var(--surface-sunk); }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-title { font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.card-sub { color: var(--ink-soft); font-size: 14px; margin-top: 2px; }

.row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: none; }
.row-label { color: var(--ink-soft); font-size: 14px; }
.row-value { font-family: var(--mono); font-size: 14px; text-align: right; font-variant-numeric: tabular-nums; }

.figure { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 3px;
  background: var(--surface-sunk);
  color: var(--ink-soft);
  white-space: nowrap;
}
.badge.benchmark { background: var(--accent-soft); color: var(--accent); }
.badge.uncertain { background: var(--uncertain-soft); color: var(--uncertain); }
.badge.positive { background: #e6f0e8; color: var(--positive); }
.badge.negative { background: #f8e8e5; color: var(--negative); }

/* ---------------------------------------------------------------- honesty rules */

.uncertainty {
  background: var(--uncertain-soft);
  border-left: 3px solid var(--uncertain);
  color: #6b4c0e;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 10px 0;
}

.empty { color: var(--ink-faint); font-size: 14px; padding: 24px 0; text-align: center; }

/* ---------------------------------------------------------------- forms */

label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 4px; }

input, select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  min-height: 44px;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

.field { margin-bottom: 14px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: 12px; color: var(--ink-faint); margin-top: 4px; }

button.primary, button.ghost, button.danger {
  appearance: none;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  padding: 11px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 44px;
  width: 100%;
}
button.primary { background: var(--accent); color: #fff; border: 1px solid var(--accent); }
button.primary:disabled { background: var(--line-strong); border-color: var(--line-strong); cursor: not-allowed; }
button.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); }
button.danger { background: var(--surface); color: var(--negative); border: 1px solid var(--negative); }

.btn-row { display: flex; gap: 8px; margin-top: 18px; }
.btn-row button { flex: 1; }

.checkline { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.checkline input[type="checkbox"] { width: 20px; min-height: 20px; margin-top: 2px; flex: none; }
.checkline label { margin: 0; color: var(--ink); font-size: 15px; }

/* ---------------------------------------------------------------- money table */

.money { width: 100%; border-collapse: collapse; }
.money td { padding: 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.money tr:last-child td { border-bottom: none; }
.money .name { font-size: 14px; }
.money .name small { display: block; color: var(--ink-faint); font-size: 12px; }
.money .amt { font-family: var(--mono); text-align: right; font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.money .amt.missing { color: var(--uncertain); font-family: var(--font); font-size: 13px; }

.totals { background: var(--surface-sunk); border-radius: var(--radius); padding: 14px 16px; margin-top: 14px; }
.totals .big { font-family: var(--mono); font-size: 26px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.totals .label { font-size: 13px; color: var(--ink-soft); }
.totals .awaiting { font-size: 15px; color: var(--uncertain); font-weight: 600; }

/* ---------------------------------------------------------------- compare */

.compare-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
.compare { border-collapse: collapse; width: 100%; min-width: 520px; }
.compare th, .compare td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 13px;
  text-align: left;
  vertical-align: top;
  min-width: 116px;
}
.compare thead th {
  background: var(--surface-sunk);
  font-size: 12px;
  position: sticky;
  top: 0;
  /* The label column stays put so a row never loses its meaning mid-scroll. */
  left: 0;
  z-index: 2;
}
.compare tbody th {
  font-weight: 500;
  color: var(--ink-soft);
  white-space: nowrap;
  background: var(--surface);
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 96px;
}

/* Tell the reader the table continues, instead of letting it look cut off. */
.scroll-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-faint);
  margin: 8px 0 4px;
}
.scroll-hint::after {
  content: "";
  width: 16px;
  height: 8px;
  border-right: 1.5px solid var(--line-strong);
  border-bottom: 1.5px solid var(--line-strong);
  transform: rotate(-45deg);
}

/* ---------------------------------------------------------------- gallery */

.shots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 10px; }
.shot { position: relative; aspect-ratio: 4 / 3; background: var(--surface-sunk); border-radius: 3px; overflow: hidden; }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot .tag {
  position: absolute; left: 4px; bottom: 4px;
  background: rgba(0,0,0,0.65); color: #fff; font-size: 10px;
  padding: 1px 5px; border-radius: 2px; letter-spacing: 0.03em;
}

/* ---------------------------------------------------------------- events */

.event { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.event-when {
  font-family: var(--mono); font-size: 12px; color: var(--ink-soft);
  min-width: 88px; padding-top: 2px;
}
.event-body { flex: 1; }
.event-kind { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-faint); }

/* ---------------------------------------------------------------- misc */

.stack > * + * { margin-top: 8px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.mt { margin-top: 16px; }
.mb0 { margin-bottom: 0; }

.banner {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}
.banner.err { border-left-color: var(--negative); color: var(--negative); }

.spinner { color: var(--ink-faint); padding: 40px 0; text-align: center; }

@media (min-width: 640px) {
  .shell { padding-bottom: 48px; }
  h1 { font-size: 30px; }
  .shots { grid-template-columns: repeat(4, 1fr); }
}

/* ---------------------------------------------------------------- additions */

.linklike {
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  padding: 0;
  text-align: left;
}
.linklike.faint { color: var(--ink-faint); font-size: 13px; text-decoration: underline; }

button.compact {
  padding: 7px 12px;
  font-size: 13px;
  min-height: 34px;
  width: auto;
}

.card.linklike { display: block; width: 100%; text-align: left; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 26, 23, 0.45);
  z-index: 60;
  overflow: auto;
  padding: 16px;
  -webkit-backdrop-filter: blur(2px);
}

.sheet {
  background: var(--surface);
  border-radius: 8px;
  padding: 18px;
  max-width: 560px;
  margin: 0 auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  padding: 11px 16px;
  border-radius: var(--radius);
  z-index: 90;
  max-width: calc(100vw - 32px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}
.toast.err { background: var(--negative); }

@media (min-width: 640px) {
  .sheet { margin: 4vh auto; }
}

/* ------------------------------------------------- compare tray and chip */

.chip {
  appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 5px 12px;
  min-height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
}
.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.compare-tray {
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(28, 26, 23, 0.12);
  z-index: 30;
}
.compare-tray .btn-row { flex: 1; max-width: 62%; }
.compare-tray button.primary { padding: 8px 14px; min-height: 36px; }
.compare-tray button.ghost { padding: 8px 14px; min-height: 36px; }
