:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e2e8f0;
  --brand: #2c3e50;
  --brand-ink: #ffffff;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }

.container {
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 1rem;
}

/* ---- Top bar / nav ---- */
.topbar {
  background: var(--brand);
  color: var(--brand-ink);
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.brand { color: var(--brand-ink); font-weight: 700; font-size: 1.1rem; }
.brand:hover { text-decoration: none; }

.nav-toggle { display: none; }
.nav-toggle-label {
  margin-left: auto;
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.nav-toggle-label span,
.nav-toggle-label span::before,
.nav-toggle-label span::after {
  content: "";
  display: block;
  width: 22px; height: 2px;
  background: var(--brand-ink);
  position: relative;
  transition: transform .2s ease;
}
.nav-toggle-label span::before { position: absolute; top: -7px; }
.nav-toggle-label span::after { position: absolute; top: 7px; }

.nav {
  display: none;
  flex-basis: 100%;
  flex-direction: column;
  gap: .25rem;
  padding-top: .5rem;
}
.nav-toggle:checked ~ .nav { display: flex; }
.nav a, .nav .link-btn {
  color: var(--brand-ink);
  padding: .55rem .25rem;
  display: block;
  border-radius: 6px;
}
.nav a:hover { text-decoration: none; opacity: .85; }
.link-btn {
  background: none; border: 0; color: var(--brand-ink);
  font: inherit; cursor: pointer; text-align: left; padding: .55rem .25rem;
}
.inline { display: inline; margin: 0; }

@media (min-width: 720px) {
  .nav-toggle-label { display: none; }
  .nav {
    display: flex;
    flex-direction: row;
    flex-basis: auto;
    margin-left: auto;
    align-items: center;
    gap: .25rem;
    padding-top: 0;
  }
  .nav a, .nav .link-btn { padding: .4rem .7rem; }
}

/* ---- Layout helpers ---- */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---- Sub-navigation (section tabs) ---- */
.subnav {
  display: flex; gap: .25rem; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1.25rem;
}
.subnav-link {
  padding: .5rem .85rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: .9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.subnav-link:hover { color: var(--ink); }
.subnav-link.is-active { color: var(--primary); border-bottom-color: var(--primary); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 720px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { text-align: center; }
.stat-num { display: block; font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .85rem; }

/* ---- Lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list.ordered { list-style: decimal; padding-left: 1.5rem; }
.list.ordered li { border-bottom: 0; padding: .25rem 0; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table th a.th-sort { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: .15rem; white-space: nowrap; }
.table th a.th-sort:hover { color: var(--ink); text-decoration: underline; }
.table .num { text-align: right; white-space: nowrap; }
.row-actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.reg-cell { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

/* ---- Definition meta ---- */
.meta { display: grid; grid-template-columns: 1fr; gap: .4rem; margin: 0 0 .75rem; }
@media (min-width: 520px) { .meta { grid-template-columns: 1fr 1fr; } }
.meta div { display: flex; gap: .5rem; }
.meta dt { color: var(--muted); min-width: 5.5rem; margin: 0; }
.meta dd { margin: 0; font-weight: 500; }

/* ---- Forms ---- */
label { display: block; margin-bottom: .75rem; font-weight: 500; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
input[type=text], input[type=email], input[type=tel], input[type=number],
input[type=datetime-local], select, textarea {
  width: 100%;
  padding: .55rem .6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: #fff;
  margin-top: .25rem;
}
input.tiny, .tiny { width: auto; max-width: 4.5rem; margin-top: 0; }
label.check input { width: auto; margin: 0; }
textarea { resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr; gap: .75rem; }
@media (min-width: 520px) { .form-row { grid-template-columns: 1fr 1fr; } }
.actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.filters { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filters label { margin: 0; }

.grants { border: 1px solid var(--line); border-radius: 8px; padding: .75rem; margin-bottom: .75rem; }
.grants legend { padding: 0 .4rem; color: var(--muted); font-size: .85rem; }
.grant-row { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; }
.grant-name { flex: 1; }
.grant-row select { width: auto; margin: 0; }
.access-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; }
.access-form label { margin: 0; }
.captain-reg { display: inline-flex; gap: .35rem; align-items: center; margin-left: .5rem; }
.captain-reg select { width: auto; margin: 0; padding: .25rem .4rem; }
.link-field { font-size: .8rem; min-width: 12rem; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .55rem .9rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit; font-weight: 600;
  cursor: pointer;
  background: #e5e7eb; color: var(--ink);
  min-height: 40px;
}
.btn:hover { text-decoration: none; filter: brightness(.97); }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-tiny { padding: .3rem .55rem; min-height: 0; font-size: .8rem; }
.btn-small { padding: .35rem .65rem; min-height: 0; font-size: .85rem; }
.btn-light { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-link { background: none; border: none; padding: .2rem 0; min-height: 0; color: var(--primary); font-weight: 600; }
.btn-link:hover { text-decoration: underline; filter: none; }
.btn-link.btn-danger { background: none; color: var(--danger); }
.btn-row, .btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Feature 5 — admin impersonation banner */
.impersonation-banner { background: #fde68a; color: #5b4708; border-bottom: 1px solid #f0c33c; }
.impersonation-inner {
  max-width: 960px; margin: 0 auto; padding: .5rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
  font-size: .9rem;
}

/* Feature 4 — linked sign-ins (account page) */
.linked-list { list-style: none; padding: 0; margin: .5rem 0; }
.linked-list li {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .5rem 0; border-bottom: 1px solid var(--line);
}
.link-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.auth-providers { display: flex; flex-direction: column; gap: .5rem; margin: 1rem 0; }
.btn-provider { width: 100%; }
.btn-microsoft { background: #2f2f2f; color: #fff; }
.btn-google { background: #fff; color: #3c4043; border-color: var(--line); }
.btn-apple { background: #000; color: #fff; }
.btn:disabled, .btn.is-busy { cursor: progress; opacity: .85; }
.btn.is-busy::before {
  content: "";
  width: 1em; height: 1em;
  margin-right: .5rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: btn-spin .6s linear infinite;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .btn.is-busy::before { animation: none; } }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: .12rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  background: #e5e7eb; color: #374151;
  vertical-align: middle;
  margin: .1rem .15rem .1rem 0;
}
.badge-registered, .badge-accepted, .badge-captain { background: #dcfce7; color: #166534; }
.badge-waitlist, .badge-pending, .badge-view { background: #fef3c7; color: #92400e; }
.badge-withdrawn, .badge-revoked, .badge-expired { background: #fee2e2; color: #991b1b; }
.badge-admin { background: #ede9fe; color: #5b21b6; }
.badge-player { background: #e0f2fe; color: #075985; }
.badge-win { background: #dcfce7; color: #166534; }
.badge-draw { background: #fef3c7; color: #92400e; }
.badge-loss { background: #fee2e2; color: #991b1b; }
.your-result { margin: .25rem 0 .5rem; font-weight: 600; }

/* ---- Next match ---- */
.next-match { border-left: 4px solid var(--primary); }
.next-match-title { margin: 0 0 .5rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.next-match-body { display: flex; flex-wrap: wrap; gap: .5rem 1rem; justify-content: space-between; align-items: flex-start; }
.next-match-teams { font-size: 1.15rem; font-weight: 600; }
.next-match-meta { text-align: right; }

/* ---- Flash ---- */
.flash { padding: .65rem .85rem; border-radius: 8px; margin-bottom: .75rem; border: 1px solid transparent; }
.flash-error { background: #fee2e2; border-color: #fecaca; color: #991b1b; }
.flash-success { background: #dcfce7; border-color: #bbf7d0; color: #166534; }
.flash-info { background: #e0f2fe; border-color: #bae6fd; color: #075985; }

/* ---- Misc ---- */
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.auth-card { max-width: 460px; margin: 1.5rem auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
code { background: #eef2f7; padding: .1rem .35rem; border-radius: 4px; font-size: .85em; }

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 1rem;
  margin-top: 2rem;
}
.site-footer .container { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; padding: 0 1rem; }
