:root {
  --bg: #fafafa;
  --bg-card: #ffffff;
  --ink: #0a0a0a;
  --muted: #737373;
  --muted-light: #a3a3a3;
  --border: #e5e5e5;
  --border-light: #f0f0f0;
  --brand: #0f766e;
  --brand-hover: #0d6b63;
  --brand-soft: rgba(15, 118, 110, 0.08);
  --good: #16a34a;
  --good-soft: rgba(22, 163, 74, 0.1);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.1);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.08);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; }

html, body {
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: -webkit-fill-available;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ── Topbar ── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 1.5rem 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.logo {
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.logo-q { color: var(--brand); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8125rem;
}

.topbar-user .user-name {
  font-weight: 600;
  color: var(--ink);
}

.topbar-user .user-role {
  color: var(--muted);
}

/* ── Flash ── */
.flash {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  max-width: 960px;
  width: calc(100% - 2rem);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--brand-soft);
  border: 1px solid rgba(15, 118, 110, 0.15);
  color: var(--brand);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  text-align: center;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.flash.flash-hiding {
  opacity: 0;
}

.flash.flash-error {
  background: var(--danger-soft);
  border-color: rgba(220, 38, 38, 0.15);
  color: var(--danger);
}

.hidden { display: none !important; }

/* ── Layout ── */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

.layout {
  display: grid;
  gap: 1.5rem;
}

.layout-auth {
  max-width: 400px;
  margin: 4rem auto;
}

.layout-main {
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .layout-main {
    grid-template-columns: 1fr 340px;
  }
}

/* ── Card ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--ink);
}

.card-desc {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 0.125rem;
}

.card-body { padding: 1.25rem; }
.card-body-flush { padding: 0; }

/* ── Tabs ── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow-x: auto;
}

.tab {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--ink); }

.tab.active {
  color: var(--ink);
  border-bottom-color: var(--brand);
  font-weight: 600;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--border-light);
  color: var(--muted);
  white-space: nowrap;
}

.badge-ready {
  background: var(--good-soft);
  color: var(--good);
}

.badge-waiting {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge-brand {
  background: var(--brand-soft);
  color: var(--brand);
}

/* ── Match card ── */
.match-item {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}

.match-item:last-child { border-bottom: none; }

.match-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.match-title {
  font-size: 0.9375rem;
  font-weight: 600;
}

.match-date {
  font-size: 0.8125rem;
  color: var(--muted);
}

.match-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}

.match-location {
  font-size: 0.8125rem;
  color: var(--muted);
}

.match-location a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 500;
}

.match-location a:hover { text-decoration: underline; }

.match-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.match-notes {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  font-style: italic;
}

/* ── Progress bar ── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.75rem;
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border-light);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width 0.3s ease;
}

.progress-fill.full { background: var(--good); }

.progress-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

/* ── People list ── */
.people-section {
  margin-top: 0.75rem;
}

.people-toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0;
}

.people-toggle:hover { color: var(--ink); }

.people-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 0.2s;
}

.people-toggle.open svg { transform: rotate(90deg); }

.people-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.5rem;
}

.person-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}

.person-row:hover { background: var(--border-light); }

.person-info { display: flex; flex-direction: column; }

.person-name { font-weight: 600; }

.person-detail {
  font-size: 0.75rem;
  color: var(--muted);
}

.guest-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.guest-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: rgba(217, 119, 6, 0.08);
  color: #92400e;
}

.guest-form {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
}

.guest-form-row {
  display: flex;
  gap: 0.5rem;
}

.guest-form-row input { flex: 1; }

/* ── Teams ── */
.teams-section {
  margin-top: 0.75rem;
  padding: 0.875rem;
  background: var(--brand-soft);
  border-radius: var(--radius-md);
}

.teams-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.teams-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.team-col-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.375rem;
}

.team-col .person-name {
  font-size: 0.8125rem;
  padding: 0.125rem 0;
}

.bench-section {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(15, 118, 110, 0.12);
}

/* ── Beer section ── */
.beer-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--warn);
  margin-bottom: 0.75rem;
}

.beer-icon { font-size: 1rem; }

.badge-beer {
  background: var(--warn-soft);
  color: #92400e;
}

.beer-toggle {
  display: flex !important;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  flex-direction: row;
}

.beer-toggle input { width: auto; margin: 0; }

.beer-section {
  margin-top: 0.75rem;
  padding: 0.625rem 0.75rem;
  background: var(--warn-soft);
  border-radius: var(--radius-md);
}

.beer-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #92400e;
  margin-bottom: 0.375rem;
}

.beer-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.beer-pill {
  display: inline-flex;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: rgba(217, 119, 6, 0.12);
  color: #92400e;
}

.btn-beer {
  background: var(--warn-soft) !important;
  color: #92400e !important;
  border: 1px solid rgba(217, 119, 6, 0.2) !important;
}

.btn-beer:hover { background: rgba(217, 119, 6, 0.15) !important; }

.btn-beer-leave {
  background: none !important;
  color: var(--muted) !important;
  border: 1px solid var(--border) !important;
}

/* ── Forms ── */
form { display: grid; gap: 0.75rem; }

label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink);
}

input, textarea, select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

/* ── Buttons ── */
button { font: inherit; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }

.btn-outline {
  background: var(--bg-card);
  color: var(--ink);
  border-color: var(--border);
}

.btn-outline:hover:not(:disabled) { background: var(--border-light); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0.375rem 0.625rem;
}

.btn-ghost:hover:not(:disabled) { color: var(--ink); background: var(--border-light); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: none;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn-cta {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
}

.btn-cta:hover:not(:disabled) { background: var(--brand-hover); }

.btn-leave {
  background: var(--bg-card);
  color: var(--danger);
  border-color: var(--border);
}

.btn-leave:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm {
  padding: 0.375rem 0.625rem;
  font-size: 0.75rem;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ── Stats row ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border-light);
  border-bottom: 1px solid var(--border-light);
}

.stat-cell {
  padding: 0.875rem 1.25rem;
  background: var(--bg-card);
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.125rem;
}

/* ── Role list ── */
.role-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.8125rem;
}

.role-item:last-child { border-bottom: none; }

/* ── Empty state ── */
.empty-state {
  padding: 2.5rem 1.25rem;
  text-align: center;
  color: var(--muted);
}

.empty-state p {
  font-size: 0.875rem;
}

/* ── Auth card ── */
.auth-card { text-align: center; }

.auth-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.auth-card p {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.auth-card form { text-align: left; }

.auth-card .help-text {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted-light);
  margin-top: 0.25rem;
}

.auth-card .preview-link {
  display: block;
  text-align: center;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-light);
}

.auth-card .preview-link a {
  color: var(--brand);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
}

.auth-card .preview-link a:hover { text-decoration: underline; }

/* ── Sidebar ── */
.sidebar { display: flex; flex-direction: column; gap: 1.5rem; }

/* ── Landing ── */
.landing {
  text-align: center;
  padding: 3rem 1rem 1rem;
  max-width: 600px;
  margin: 0 auto;
}

.landing-eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brand);
  margin-bottom: 0.75rem;
}

.landing-title {
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--ink);
  margin-bottom: 1rem;
}

.landing-desc {
  font-size: 1rem;
  color: var(--muted);
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto;
}

/* ── Person actions ── */
.person-actions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

/* ── Edit match form ── */
.edit-match-form {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-light);
}

.edit-match-form form { gap: 0.5rem; }

.form-hint {
  font-size: 0.75rem;
  color: var(--muted-light);
  margin-top: 0.125rem;
}

.empty-row {
  padding: 0.5rem 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

/* ── Ratings ── */
.rating-select {
  width: 60px;
  padding: 0.25rem 0.375rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  background: var(--bg-card);
  color: var(--ink);
  cursor: pointer;
}

.rating-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-soft);
}

.rating-avg {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--warn);
  margin-left: 0.375rem;
}

.rating-hint {
  font-size: 0.75rem;
  color: var(--muted-light);
  padding: 0.5rem 0;
  font-style: italic;
}

.rating-hint-active {
  color: var(--brand);
  font-style: normal;
  font-weight: 500;
}

/* ── Archived matches ── */
.match-archived {
  opacity: .5;
}

.archive-section {
  border-top: 1px solid rgba(15, 118, 110, .1);
}

.archive-toggle {
  display: block;
  width: 100%;
  padding: .75rem 1.25rem;
  background: none;
  border: none;
  color: #0f766e;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}

.archive-toggle:hover {
  background: rgba(15, 118, 110, .04);
}

.archived-list {
  border-top: 1px solid rgba(15, 118, 110, .08);
}

/* ── Responsive ── */
@media (max-width: 767px) {
  .container { padding: 1rem; }
  .topbar { padding: env(safe-area-inset-top) 1rem 0; }
  .stats-row { grid-template-columns: 1fr; }
  .teams-grid { grid-template-columns: 1fr; }
}
