:root {
  --ink: #15231e; --ink-soft: #55645d; --ink-faint: #818d86;
  --brand: #1b4a3b; --brand-hover: #163d31; --brand-deep: #13302a;
  --accent: #d7f56b; --surface: #ffffff; --page: #f4f5f0; --line: #dfe3dc; --line-strong: #c8cfc7;
  --danger: #a3262b; --danger-bg: #fbeceb; --ok: #1d6b3f; --ok-bg: #e6f4ea;
  --radius: 14px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(19,48,42,.06), 0 4px 16px rgba(19,48,42,.05);
  --focus: 0 0 0 3px rgba(27,74,59,.28);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e7efe9; --ink-soft: #aab9b1; --ink-faint: #7f8e86;
    --brand: #2e6b57; --brand-hover: #3a7d67; --brand-deep: #0c1e19;
    --surface: #17241f; --page: #0f1915; --line: #2a3a34; --line-strong: #3b4f47;
    --danger: #ff8d8f; --danger-bg: #3a1d1e; --ok: #8fe0ab; --ok-bg: #173026;
    --shadow: none; --focus: 0 0 0 3px rgba(215,245,107,.35);
  }
}
:root[data-theme="dark"] {
  --ink: #e7efe9; --ink-soft: #aab9b1; --ink-faint: #7f8e86;
  --brand: #2e6b57; --brand-hover: #3a7d67; --brand-deep: #0c1e19;
  --surface: #17241f; --page: #0f1915; --line: #2a3a34; --line-strong: #3b4f47;
  --danger: #ff8d8f; --danger-bg: #3a1d1e; --ok: #8fe0ab; --ok-bg: #173026;
  --shadow: none; --focus: 0 0 0 3px rgba(215,245,107,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--page); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; display: flex; flex-direction: column; min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
:focus-visible { outline: none; box-shadow: var(--focus); }
[hidden] { display: none !important; }

/* top bar */
.topbar {
  background: var(--brand-deep); color: #fff; padding: 12px 24px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #fff; }
.brand-mark { width: 12px; height: 12px; border: 2px solid var(--accent); transform: rotate(45deg); margin-left: 4px; }
.brand-name { font-weight: 800; letter-spacing: .22em; font-size: 15px; }
.nav { display: flex; gap: 6px; margin-left: 8px; }
.nav a { color: #cfe0d6; text-decoration: none; padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.nav a[aria-current="page"], .nav a:hover { background: rgba(215,245,107,.16); color: var(--accent); }
.who { margin-left: auto; display: flex; gap: 10px; align-items: center; font-size: 14px; color: #cfe0d6; }
.role-pill { background: rgba(215,245,107,.16); color: var(--accent); border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 700; text-transform: capitalize; }

/* layout */
.root { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 20px 56px; }
.center-wrap { display: grid; place-items: start center; padding-top: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; width: 100%; }
.card.narrow { max-width: 440px; }
.card.wide { max-width: 760px; }
.card + .card { margin-top: 16px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--brand); margin: 0 0 6px; }
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 10px; }
p { margin: 0 0 14px; color: var(--ink-soft); }
.muted { color: var(--ink-faint); font-size: 13px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 16px; }
.divider { height: 1px; background: var(--line); margin: 22px 0; border: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.page-head .actions select { min-width: 0; }

/* forms */
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: var(--focus); }
input.code { letter-spacing: .3em; font-size: 20px; text-align: center; font-variant-numeric: tabular-nums; }
input.narrow-input { max-width: 180px; }
.hint { font-size: 12px; color: var(--ink-faint); margin-top: 6px; }
.field { min-width: 0; }
.field + .field { margin-top: 16px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 500; color: var(--ink); margin: 0; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }

.btn {
  appearance: none; border: 1px solid transparent; border-radius: var(--radius-sm); padding: 10px 16px;
  font-weight: 700; cursor: pointer; background: var(--brand); color: #fff; text-decoration: none; display: inline-block; text-align: center;
  transition: background .15s ease;
}
.btn:hover { background: var(--brand-hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn.secondary:hover { background: var(--page); }
.btn.danger { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.btn.small { padding: 6px 11px; font-size: 13px; }
.link { color: var(--brand); font-weight: 600; background: none; border: 0; padding: 0; cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }

.alert { border-radius: var(--radius-sm); padding: 11px 13px; font-size: 14px; margin: 0 0 16px; background: var(--danger-bg); color: var(--danger); }
.alert.info { background: var(--ok-bg); color: var(--ok); }

/* enrollment and codes */
.qr-wrap { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; }
.qr { width: 220px; height: 220px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; padding: 6px; }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; background: var(--page); border: 1px dashed var(--line-strong); padding: 8px 10px; border-radius: 8px; word-break: break-all; user-select: all; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 16px; }
.codes div { background: var(--page); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; text-align: center; letter-spacing: .06em; }
.invite-code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 22px; text-align: center; letter-spacing: .1em; padding: 14px; background: var(--page); border-radius: var(--radius-sm); border: 1px solid var(--line); user-select: all; }

/* lists and tiles */
.player-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.player-card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.player-card:hover { border-color: var(--brand); }
.player-card .name { font-weight: 700; font-size: 16px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; background: var(--page); color: var(--ink-faint); border: 1px solid var(--line); }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.hero { background: var(--brand-deep); color: #fff; border-radius: var(--radius); padding: 22px 26px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.hero .eyebrow { color: var(--accent); }
.hero h1 { color: #fff; margin: 0; }
.hero .sub { color: #c9d9d0; font-size: 14px; margin-top: 4px; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 20px 0 16px; }
.tab { background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink); padding: 8px 16px; border-radius: 999px; cursor: pointer; font-weight: 600; text-decoration: none; }
.tab[aria-selected="true"] { background: var(--brand); color: #fff; border-color: var(--brand); }

.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.tile .label { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); }
.tile .big { font-size: 30px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 13px; color: var(--ink-soft); }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 10px; text-align: center; }
.stat-row .n { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-row .l { font-size: 12px; color: var(--ink-faint); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; overscroll-behavior-x: contain; }
.table-wrap td:first-child, .table-wrap th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.table-wrap th:first-child { background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); font-weight: 700; padding: 8px 8px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 11px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
td a { color: var(--brand); font-weight: 600; }

.bars { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding: 12px 4px 0; border-bottom: 1px solid var(--line-strong); overflow-x: auto; }
.bar-col { flex: 0 0 56px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-col .bar-wrap { flex: 1; }
.bar-wrap { width: 100%; flex: 1; min-height: 0; display: flex; align-items: flex-end; }
.bar { width: 100%; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar-val { font-size: 12px; font-weight: 700; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.bar-lbl { font-size: 11px; color: var(--ink-faint); margin-top: 6px; text-align: center; }

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

/* at-bat editor */
.pa-list { display: grid; gap: 12px; }
.pa-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; background: var(--page); }
.pa-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pa-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px 12px; }
.pa-grid label { font-size: 12px; }
.totals-line { font-size: 15px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.rating-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--brand-deep); color: #fff; padding: 11px 18px; border-radius: 999px; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: 14px; z-index: 10; max-width: calc(100% - 32px); text-align: center; }

.steps { margin: 0 0 18px; padding-left: 22px; color: var(--ink-soft); font-size: 15px; }
.steps li { margin: 6px 0; padding-left: 4px; }

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .nav { order: 3; width: 100%; margin: 0; }
  .who { font-size: 13px; }
  .root { padding: 20px 14px 48px; }
  .card { padding: 20px 16px; }
  h1 { font-size: 22px; }
  .qr { width: 180px; height: 180px; }
  .hero { padding: 20px; }
  .codes { grid-template-columns: 1fr; }
  .card .table-wrap { margin: 0 -16px; padding: 0 16px; }
  th, td { padding: 9px 6px; font-size: 13px; }
  th { font-size: 10px; }
}
@media (min-width: 641px) {
  .page-head .actions select { width: auto; min-width: 180px; }
}
@media print { .topbar, .btn, .toast, .nav { display: none !important; } .card { box-shadow: none; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
