:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --surface: #ffffff;
  --sunk: #efe9df;
  --ink: #1d2a25;
  --muted: #5b6862;
  --line: rgba(29, 42, 37, 0.1);
  --field: #8a948f;
  --terra: #a8481f;
  --terra-deep: #873818;
  --terra-soft: #f6e6dd;
  --green: #244b3c;
  --green-soft: #e1ebe5;
  --amber: #e3a857;
  --amber-soft: #f8ecd6;
  --danger: #a3261b;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(29, 42, 37, 0.05), 0 6px 20px rgba(29, 42, 37, 0.06);
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --tabs-h: calc(64px + env(safe-area-inset-bottom));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body.has-tabs { padding-bottom: var(--tabs-h); }
a { color: var(--terra-deep); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--terra-deep); outline-offset: 2px; border-radius: 8px; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 50; background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px; }
.skip:focus { left: 8px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* top bar */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(246, 243, 238, 0.86);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
}
.brand { display: grid; place-items: center; width: 36px; height: 36px; flex: none; }
.brand svg { width: 30px; height: 30px; }
.top h1 { flex: 1; min-width: 0; font: 600 1.15rem/1.2 var(--serif); letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: grid; place-items: center; text-decoration: none;
  background: var(--green); color: #fff; font-weight: 600; font-size: 0.9rem;
}

main { display: block; width: min(640px, 100%); margin: 0 auto; padding: 8px 16px 32px; }
main.wide { width: min(1080px, 100%); }
main:focus { outline: none; }
.loading { color: var(--muted); padding: 32px 0; text-align: center; }

/* bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: var(--tabs-h); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 -1px 0 var(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 500; min-height: 48px;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current='page'] { color: var(--terra); }
.tabs a[aria-current='page'] svg { stroke-width: 2.2; }

/* type */
.hello { font: 600 1.6rem/1.15 var(--serif); letter-spacing: -0.015em; margin: 12px 0 4px; }
.sub { color: var(--muted); }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-head h2 { font: 600 1.15rem/1.2 var(--serif); letter-spacing: -0.01em; }
.section-head a, .link { font-weight: 600; color: var(--terra-deep); text-decoration: none; font-size: 0.95rem; }
.empty { color: var(--muted); padding: 16px; background: var(--surface); border-radius: var(--radius); text-align: center; }
.small { font-size: 0.875rem; }
.muted { color: var(--muted); }

/* the three big actions */
.quick { display: grid; gap: 10px; margin-top: 18px; }
.quick a {
  display: flex; align-items: center; gap: 14px; min-height: 68px; padding: 12px 16px;
  border-radius: var(--radius); text-decoration: none; color: #fff; font-weight: 600; font-size: 1.08rem;
  box-shadow: var(--shadow); transition: transform 0.12s ease;
}
.quick a:active { transform: scale(0.985); }
.quick .ico { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: rgba(255, 255, 255, 0.18); flex: none; }
.quick svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.quick .go { margin-left: auto; opacity: 0.8; }
.q-ref { background: var(--terra); }
.q-ty { background: var(--green); }
.q-121 { background: var(--amber); color: var(--ink) !important; }
.q-121 .ico { background: rgba(29, 42, 37, 0.1); }
@media (min-width: 560px) {
  .quick { grid-template-columns: repeat(3, 1fr); }
  .quick a { flex-direction: column; align-items: flex-start; min-height: 116px; }
  .quick .go { display: none; }
}
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 16px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--green-soft); color: var(--green); font-weight: 600; text-decoration: none;
}

/* cards and lists */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 10px; }
.stack { display: grid; gap: 10px; }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list > a, .list > div { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: inherit; text-decoration: none; min-height: 56px; }
.list > * + * { border-top: 1px solid var(--line); }
.list > a:active { background: var(--sunk); }
.title { font-weight: 600; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 0.875rem; }
.chev { color: var(--muted); flex: none; }
.num { font-variant-numeric: tabular-nums; font-weight: 600; }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(3, 1fr); } .stats.four { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat b { display: block; font: 600 1.7rem/1.1 var(--serif); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat span { display: block; margin-top: 4px; color: var(--muted); font-size: 0.85rem; line-height: 1.3; }

/* segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--sunk); }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 0.9rem;
  padding: 7px 14px; border-radius: 999px; min-height: 36px; cursor: pointer;
}
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(29, 42, 37, 0.12); }

/* status chips */
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; background: var(--sunk); color: var(--ink); }
.st-new { background: var(--amber-soft); color: #7a4b0c; }
.st-contacted { background: #e5ecf3; color: #28476b; }
.st-meeting_set { background: var(--green-soft); color: var(--green); }
.st-closed_won, .st-confirmed, .st-joined { background: var(--green); color: #fff; }
.st-closed_lost, .st-not_a_fit, .st-declined, .st-expired, .st-void { background: #ecebea; color: #55605b; }
.st-pending, .st-registered, .st-follow_up { background: var(--amber-soft); color: #7a4b0c; }
.st-visited, .st-applied { background: #e5ecf3; color: #28476b; }
.hot { color: var(--danger); font-weight: 600; }

/* inline status buttons on a referral */
.status-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.status-row button {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: 0.85rem; font-weight: 600;
  padding: 7px 12px; border-radius: 999px; min-height: 36px; cursor: pointer;
}
.status-row button[aria-pressed='true'] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* forms */
form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span, .field > legend { font-weight: 600; font-size: 0.95rem; padding: 0; }
.field .opt { font-weight: 400; color: var(--muted); }
.hint { font-size: 0.85rem; color: var(--muted); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
input:not([type='checkbox']):not([type='radio']), select, textarea {
  width: 100%; min-height: 48px; padding: 11px 13px; border: 1px solid var(--field); border-radius: 12px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--terra-deep); outline-offset: 1px; border-color: transparent; }
.invalid input, .invalid select, .invalid textarea, input.invalid { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.err { color: var(--danger); font-size: 0.875rem; font-weight: 600; }
.choice { display: flex; flex-wrap: wrap; gap: 8px; }
.choice label { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.choice span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--field); background: var(--surface); font-weight: 600; font-size: 0.95rem;
}
.choice input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }
.choice input:focus-visible + span { outline: 3px solid var(--terra-deep); outline-offset: 2px; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--green); flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

/* member picker */
.picker .selected {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 8px 8px 8px 14px;
  border-radius: 12px; background: var(--green-soft); color: var(--green); font-weight: 600;
}
.picker .selected button { margin-left: auto; border: 0; background: transparent; color: var(--green); font: inherit; font-weight: 600; min-height: 36px; padding: 0 10px; cursor: pointer; }
.picker .options { margin-top: 8px; max-height: 264px; overflow-y: auto; background: var(--surface); border-radius: 12px; border: 1px solid var(--line); }
.picker .options button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; font: inherit; color: inherit;
  padding: 11px 14px; min-height: 52px; cursor: pointer;
}
.picker .options button + button { border-top: 1px solid var(--line); }
.picker .options button:hover, .picker .options button:focus-visible { background: var(--sunk); }
.picker .options small { display: block; color: var(--muted); font-size: 0.85rem; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 20px;
  border: 0; border-radius: 999px; background: var(--terra); color: #fff; font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; transition: background 0.15s;
}
.btn:hover { background: var(--terra-deep); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.green { background: var(--green); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px var(--field); }
.btn.ghost:hover { background: var(--sunk); }
.btn.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px rgba(163, 38, 27, 0.4); }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: 0.9rem; }
.btn.block { width: 100%; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.sticky-save { position: sticky; bottom: calc(var(--tabs-h) + 8px); z-index: 5; }

/* detail page */
.hero-card h2 { font: 600 1.45rem/1.2 var(--serif); letter-spacing: -0.015em; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 12px 0 0; }
.kv dt { color: var(--muted); font-size: 0.9rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before { content: ''; position: absolute; left: 4px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--terra); }
.timeline li::after { content: ''; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.note { margin-top: 4px; padding: 8px 12px; background: var(--sunk); border-radius: 10px; white-space: pre-wrap; }

/* leaderboard bars */
.bar { height: 6px; border-radius: 999px; background: var(--sunk); margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: inherit; background: var(--terra); }
.rank { width: 28px; text-align: center; font: 600 1.05rem var(--serif); color: var(--muted); flex: none; }

/* roster: name and the four marks on one line, even on a small phone */
.roster > div { padding: 8px 10px 8px 14px; gap: 8px; }
.roster .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster .seg { flex: none; }
.roster .seg button { padding: 6px 8px; font-size: 0.8rem; min-height: 36px; }

/* tables (leadership) */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { padding: 10px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
th button { border: 0; background: none; font: inherit; color: inherit; cursor: pointer; padding: 4px 0; }
th button[aria-sort] { color: var(--ink); }
tr:last-child td { border-bottom: 0; }
td.left { text-align: left; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + 12px); z-index: 60; transform: translate(-50%, 16px);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px; background: var(--ink); color: #fff;
  font-weight: 600; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); }

/* sign in / public pages */
.gate { min-height: calc(100vh - 40px); min-height: calc(100dvh - 40px); display: grid; place-items: center; padding: 8px 0; }
.gate .card { width: min(420px, 100%); padding: 28px 24px; }
.gate .logo { width: 56px; height: 56px; margin-bottom: 16px; }
.gate h2 { font: 600 1.6rem/1.15 var(--serif); letter-spacing: -0.015em; margin-bottom: 8px; }
.code { letter-spacing: 0.35em; font-size: 1.4rem !important; text-align: center; font-variant-numeric: tabular-nums; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
