:root {
  color-scheme: light;
  --ink: #24150b;
  --muted: #7a6552;
  --line: #efd3b6;
  --paper: #fff7ed;
  --surface: #ffffff;
  --field: #fff0dc;
  --green: #f36c21;
  --green-dark: #b8420f;
  --red: #c44536;
  --gold: #f6b331;
  --blue: #174a8b;
  --shadow: 0 18px 48px rgba(72, 37, 11, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(243, 108, 33, 0.24), transparent 28rem),
    radial-gradient(circle at 82% 8%, rgba(23, 74, 139, 0.12), transparent 24rem),
    linear-gradient(135deg, #fff7ed 0%, #ffe8c7 52%, #fff3e0 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.import-label {
  align-items: center;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 750;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
}

button {
  background: var(--green);
  color: white;
}

button:hover,
.import-label:hover {
  filter: brightness(0.96);
}

.secondary {
  background: var(--field);
  color: var(--green-dark);
}

.ghost,
.import-label {
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.8);
  color: var(--green-dark);
}

.danger {
  background: #fff1ed;
  color: var(--red);
}

.topbar {
  align-items: center;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1180px;
  padding: 34px 24px 18px;
}

.topbar h1 {
  color: var(--green-dark);
  font-size: clamp(2.1rem, 5vw, 4rem);
  letter-spacing: 0;
  line-height: 0.95;
  margin: 0;
}

.top-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.role-switch {
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  display: flex;
  gap: 4px;
  padding: 4px;
}

.role-switch button {
  background: transparent;
  color: var(--muted);
  min-height: 34px;
  padding: 0 12px;
}

.role-switch button.active {
  background: var(--green-dark);
  color: white;
}

body[data-role="user"] .admin-only,
body[data-role="player"] .admin-only,
body[data-role="admin"] .user-only {
  display: none !important;
}

.user-badge {
  color: var(--green-dark);
  font-weight: 800;
}

#importFile {
  display: none;
}

.eyebrow {
  color: var(--green-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.app-shell {
  margin: 0 auto;
  max-width: 1180px;
  padding: 0 24px 48px;
}

.tabs {
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  padding: 6px;
  position: sticky;
  top: 10px;
  z-index: 5;
}

.tab {
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: var(--green-dark);
  color: white;
}

.stats-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, 1fr);
  margin: 18px 0;
}

.stats-grid article,
.panel,
.leader-row,
.match-card,
.person-card,
.rules-grid {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stats-grid article {
  padding: 18px;
}

.stats-grid span,
.meta,
.note {
  color: var(--muted);
}

.stats-grid strong {
  display: block;
  font-size: clamp(1.4rem, 3vw, 2.1rem);
  margin-top: 8px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-title {
  align-items: end;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin: 30px 0 16px;
}

.section-title h2,
.panel h3 {
  margin: 0;
}

.select-label {
  color: var(--muted);
  display: grid;
  font-size: 0.9rem;
  gap: 6px;
  min-width: 220px;
}

.login-panel {
  margin-bottom: 16px;
  padding: 18px;
}

.login-panel h3 {
  margin: 0 0 12px;
}

.login-grid {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 1fr) auto;
}

.login-grid label {
  color: var(--muted);
  display: grid;
  font-size: 0.85rem;
  gap: 5px;
}

.active-player {
  align-items: center;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px;
}

.active-player span {
  color: var(--muted);
}

input,
select,
textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  padding: 9px 11px;
  width: 100%;
}

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

.leaderboard,
.match-list,
.people-grid,
.compact-list {
  display: grid;
  gap: 12px;
}

.leader-row {
  align-items: center;
  display: grid;
  gap: 16px;
  grid-template-columns: 54px 1fr auto;
  padding: 15px;
}

.rank {
  align-items: center;
  background: var(--field);
  border-radius: 999px;
  color: var(--green-dark);
  display: inline-flex;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.leader-row:first-child .rank {
  background: var(--gold);
  color: #2b2109;
}

.score {
  color: var(--green-dark);
  font-size: 1.25rem;
  font-weight: 900;
}

.two-column {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 1fr;
  margin-top: 18px;
}

.panel {
  padding: 18px;
}

.compact-item {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px 0 0;
}

.match-card {
  border-left: 6px solid var(--green);
  padding: 16px;
}

.match-card.round-group {
  border-left-color: var(--green);
}

.match-card.round-last16 {
  border-left-color: var(--blue);
}

.match-card.round-quarter {
  border-left-color: #e85d04;
}

.match-card.round-semi {
  border-left-color: var(--gold);
}

.match-card.round-final {
  border-left-color: var(--red);
}

.match-card.round-other {
  border-left-color: var(--muted);
}

.match-head {
  align-items: center;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.teams {
  font-size: 1.1rem;
  font-weight: 850;
}

.round-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.74rem;
  font-weight: 850;
  margin-bottom: 8px;
  padding: 4px 9px;
}

.round-pill.round-group {
  background: #ffe2bd;
  color: var(--green-dark);
}

.round-pill.round-last16 {
  background: #e8f0fb;
  color: var(--blue);
}

.round-pill.round-quarter {
  background: #ffd4a3;
  color: #9a3412;
}

.round-pill.round-semi {
  background: #fff0b8;
  color: #6d4e00;
}

.round-pill.round-final {
  background: #ffddd3;
  color: #9d3025;
}

.round-pill.round-other {
  background: var(--field);
  color: var(--muted);
}

.filter-bar {
  align-items: end;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) minmax(150px, 1fr) auto;
  margin-bottom: 16px;
  padding: 12px;
}

.filter-bar label {
  color: var(--muted);
  display: grid;
  font-size: 0.85rem;
  gap: 5px;
}

.team-filter-control {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}

.team-filter-control.has-crest {
  grid-template-columns: 1fr 34px;
}

.team-filter-crest {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 34px;
  object-fit: contain;
  padding: 4px;
  width: 34px;
}

.team-filter-crest[hidden] {
  display: none;
}

.score-inputs {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(72px, 90px)) auto;
  margin-top: 14px;
}

.close-controls {
  align-items: end;
  background: rgba(255, 240, 220, 0.72);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  grid-template-columns: 150px 130px auto;
  margin-top: 14px;
  padding: 12px;
}

.score-inputs label,
.close-controls label {
  color: var(--muted);
  display: grid;
  font-size: 0.82rem;
  gap: 4px;
}

.score-inputs input {
  text-align: center;
}

.score-inputs button.has-score {
  background: var(--gold);
  color: #2b2109;
}

.lock-note {
  color: var(--green-dark);
  font-size: 0.85rem;
  font-weight: 750;
  margin-top: 10px;
}

.lock-note.closed {
  color: var(--red);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.inline-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: 150px 120px 1fr 1fr auto;
  margin-bottom: 16px;
}

.inline-form.short {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(180px, 1fr) auto;
}

.inline-form label,
.rules-grid label {
  color: var(--muted);
  display: grid;
  font-size: 0.85rem;
  gap: 5px;
}

.people-grid {
  grid-template-columns: repeat(3, 1fr);
}

.person-card {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 16px;
}

.pin-input {
  max-width: 120px;
}

.rules-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, 1fr);
  padding: 18px;
}

.api-panel {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
  padding: 18px;
}

.api-panel h3,
.selection-panel h3 {
  margin: 0 0 6px;
}

.api-grid {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: 180px minmax(220px, 1fr) auto auto;
}

.api-grid label {
  color: var(--muted);
  display: grid;
  font-size: 0.85rem;
  gap: 5px;
}

.api-status {
  margin: 0;
}

.notify-actions,
.waha-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.notify-actions label,
.notify-toggle {
  align-items: center;
  color: var(--muted);
  display: inline-flex;
  font-size: 0.88rem;
  gap: 8px;
}

.notify-actions input,
.notify-toggle input {
  min-height: 18px;
  width: 18px;
}

.waha-panel {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
  padding: 18px;
}

.waha-panel h3 {
  margin: 0 0 6px;
}

.waha-grid {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(160px, 1fr)) minmax(220px, 1.2fr);
}

.waha-grid label,
.manual-message label {
  color: var(--muted);
  display: grid;
  font-size: 0.85rem;
  gap: 5px;
}

.waha-grid label:has(input[type="checkbox"]) {
  align-items: center;
  background: var(--field);
  border-radius: 8px;
  color: var(--green-dark);
  font-weight: 850;
  grid-template-columns: 1fr 22px;
  min-height: 42px;
  padding: 9px 11px;
}

.waha-grid input[type="checkbox"] {
  min-height: 18px;
  width: 18px;
}

.manual-message {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(240px, 1fr) auto;
}

.notify-toggle {
  margin: -4px 0 16px;
}

.selection-panel {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
  padding: 18px;
}

.selection-toolbar {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 260px) auto auto auto;
  justify-content: start;
}

.selection-toolbar label {
  color: var(--muted);
  display: grid;
  font-size: 0.85rem;
  gap: 5px;
}

.selection-list {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  max-height: 280px;
  overflow: auto;
}

.checkbox-row {
  align-items: center;
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  display: grid;
  gap: 10px;
  grid-template-columns: 22px 1fr;
  padding: 10px 12px;
}

.checkbox-row:last-child {
  border-bottom: 0;
}

.checkbox-row input {
  min-height: 18px;
  width: 18px;
}

.checkbox-row span {
  display: grid;
  gap: 2px;
}

.checkbox-row small {
  color: var(--muted);
}

.inactive-match {
  opacity: 0.72;
}

.pool-toggle {
  align-items: center;
  background: #fff0dc;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--green-dark);
  display: inline-flex;
  font-size: 0.9rem;
  font-weight: 850;
  gap: 8px;
  margin-bottom: 12px;
  padding: 8px 10px;
}

.pool-toggle input {
  min-height: 18px;
  width: 18px;
}

.prediction-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  margin-top: 14px;
  overflow: hidden;
}

.prediction-row {
  align-items: center;
  background: rgba(255, 255, 255, 0.76);
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(120px, 1fr) 110px 90px;
  min-height: 42px;
  padding: 9px 12px;
}

.prediction-row:last-child {
  border-bottom: 0;
}

.prediction-row strong {
  color: var(--green-dark);
}

.prediction-head {
  background: var(--field);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
  min-height: 36px;
  text-transform: uppercase;
}

.empty-state {
  background: rgba(255, 255, 255, 0.62);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 20px;
  text-align: center;
}

@media (max-width: 820px) {
  .topbar,
  .section-title,
  .compact-item {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar,
  .top-actions,
  .section-title,
  .compact-item {
    display: flex;
  }

  .tabs {
    grid-template-columns: repeat(2, 1fr);
    position: static;
  }

  .stats-grid,
  .two-column,
  .people-grid,
  .rules-grid,
  .filter-bar,
  .waha-grid,
  .manual-message,
  .selection-toolbar,
  .login-grid,
  .api-grid,
  .inline-form,
  .inline-form.short {
    grid-template-columns: 1fr;
  }

  .leader-row {
    grid-template-columns: 44px 1fr;
  }

  .score {
    grid-column: 2;
  }

  .score-inputs {
    grid-template-columns: repeat(2, 1fr);
  }

  .prediction-row {
    grid-template-columns: 1fr 82px 72px;
  }

  .score-inputs button,
  .close-controls button {
    grid-column: 1 / -1;
  }

  .close-controls {
    grid-template-columns: 1fr;
  }
}
