:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d2420;
  --muted: #66706a;
  --line: #e2e0d9;
  --accent: #1f5d3a;
  --accent-soft: #e3efe7;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --danger: #a3282b;
  --admin: #5b3f8c;
  --admin-soft: #efe9f8;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151916; --surface: #1e2420; --text: #e8ebe8; --muted: #9aa39d; --line: #313a34;
    --accent: #6cc28f; --accent-soft: #23392b; --warn: #e3b35a; --warn-soft: #3a2f1a;
    --danger: #f08a8c; --admin: #b9a2e6; --admin-soft: #2c2540;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 1.75rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }

/* Top bar */
.topbar { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .topbar { background: #173f28; } }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: .6rem 16px; display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.brand { font-weight: 700; color: #fff; text-decoration: none; margin-right: auto; }
.topbar nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.topbar nav a, .topbar button.link { color: #fff; text-decoration: none; padding: .35rem .65rem; border-radius: 6px; opacity: .85; font: inherit; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.16); opacity: 1; }
.topbar form { margin: 0; }
button.link { background: none; border: 0; cursor: pointer; }

main { max-width: 1200px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* Messages */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .65rem .9rem; border-radius: var(--radius); background: var(--accent-soft); margin-bottom: .4rem; }
.messages li.error { background: #fbe4e4; color: var(--danger); }

/* Cards and tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.card + .card { margin-top: 1rem; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.default { font-weight: 700; background: var(--accent-soft); }
td a { text-decoration: none; font-weight: 600; }

/* Tabs and search */
.toolbar { display: flex; gap: .75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: .75rem; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; }
.tabs a { padding: .4rem .75rem; border-radius: 999px; text-decoration: none; color: var(--text); border: 1px solid var(--line); background: var(--surface); }
.tabs a.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.tabs .count { opacity: .7; margin-left: .2rem; }
input[type=search] { min-width: 14rem; }

/* Badges */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .45rem; border-radius: 999px; margin-right: .2rem; background: var(--accent-soft); color: var(--accent); }
.badge.admin { background: var(--admin-soft); color: var(--admin); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.off { background: var(--line); color: var(--muted); }

/* Forms */
input[type=text], input[type=email], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .45rem .6rem; width: 100%;
}
textarea { resize: vertical; }
.field { margin-bottom: .85rem; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.field .help { color: var(--muted); font-size: .82rem; margin-top: .2rem; }
.field .errorlist, .errorlist { color: var(--danger); list-style: none; padding: 0; margin: .25rem 0 0; font-size: .87rem; }
.field.check label { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.checklist { max-height: 14rem; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; columns: 2 12rem; }
.checklist > div > div, .checklist label { display: block; font-weight: 400 !important; font-size: .9rem; margin: .15rem 0; }
.btn { display: inline-block; font: inherit; font-weight: 600; border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: .5rem 1rem; border-radius: 8px; cursor: pointer; text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--accent); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }

/* Admin-only panel */
.admin-panel { border: 1px solid var(--admin); border-radius: var(--radius); padding: 1rem 1.1rem; background: var(--admin-soft); margin-top: 1rem; }
.admin-panel h2 { margin-top: 0; color: var(--admin); }

/* Two-column layout for detail pages */
.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 800px) { .columns { grid-template-columns: 1fr; } }

.stats { display: flex; gap: .75rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .9rem; min-width: 7rem; }
.stat b { display: block; font-size: 1.4rem; }
ul.plain { margin: .25rem 0; padding-left: 1.2rem; }
.auth { max-width: 420px; margin: 3rem auto; }

/* Team builder */
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .75rem; align-items: start; }
.team-card { padding: .75rem; }
.team-card.short { border-color: var(--warn); }
.team-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .4rem; }
.team-total { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.slot { display: flex; width: 100%; align-items: center; gap: .5rem; font: inherit; color: inherit; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .55rem; margin-bottom: .3rem; cursor: pointer; }
.slot:hover { border-color: var(--accent); }
.slot.selected { outline: 2px solid var(--accent); background: var(--accent-soft); }
.slot.over { border-color: var(--accent); border-style: dashed; }
.slot.empty { border-style: dashed; }
.slot .tier { font-weight: 700; color: var(--muted); width: 1rem; }
.slot .who { flex: 1; }
.slot .hcp { font-variant-numeric: tabular-nums; font-weight: 600; }
.slot .hcp small { color: var(--muted); font-weight: 400; margin-left: .15rem; }
.blind { margin-top: .5rem; display: grid; gap: .35rem; }
.small-btn { padding: .3rem .7rem; font-size: .87rem; }
.team-grid .card + .card { margin-top: 0; }

/* Review list */
li.fix { color: var(--danger); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* Printable game sheet (always black on white, like paper) */
.sheet { background: #fff; color: #000; border: 1px solid var(--line); border-radius: 4px; padding: .35in; max-width: 11in; margin: 0 auto;
  font-family: Arial, Helvetica, sans-serif; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.sheet-table { border-collapse: collapse; width: 100%; font-size: 11pt; }
.sheet-table th, .sheet-table td { border: 1px solid #000; padding: 1px 6px; white-space: normal; background: #fff; position: static; }
.sheet-table th { text-align: right; font-weight: 400; font-size: 11pt; text-transform: none; letter-spacing: 0; color: #000; }
.sheet-table tbody tr:hover { background: none; }
.sheet-table tr:last-child th, .sheet-table tr:last-child td { border-bottom: 1px solid #000; }
.sheet-table .c-label { width: 1.45in; }
.sheet-table .c-tee { width: .35in; }
.sheet-table .center { text-align: center; }
.sheet-table .bold { font-weight: 700; }
.sheet-table .tiny { font-size: 8.5pt; }
.sheet-table .red-text { color: #e21b1b; font-weight: 700; font-size: 12pt; }
.s-date { font-size: 13pt; font-weight: 700; }
.box { text-align: center; font-weight: 700; padding: .12in 0; }
.box.red { color: #e21b1b; font-size: 28pt; }
.box.green { color: #1fa34a; font-size: 40pt; }
.s-game th, .s-cond th { vertical-align: bottom; }
.s-time th { font-size: 13pt; white-space: nowrap; }
.s-time td { font-size: 13pt; padding: 3px 6px; }

@media print {
  @page { size: letter landscape; margin: .35in; }
  body { background: #fff; }
  .no-print { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheet { border: 0; padding: 0; max-width: none; }
}

/* Outbox */
.count-pill { background: #fff; color: var(--accent); border-radius: 999px; padding: 0 .4rem; font-size: .75rem; font-weight: 700; margin-left: .2rem; }
.email-body { white-space: pre-wrap; font-family: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .8rem; }
details summary { cursor: pointer; color: var(--accent); }
.fix { color: var(--danger); }
