:root {
  color-scheme: light;
  --bg: #f4f7ef;
  --surface: #ffffff;
  --ink: #162018;
  --muted: #627064;
  --line: #dce6dc;
  --brand: #147a3d;
  --brand-strong: #0d5f2e;
  --brand-soft: #dff1e4;
  --danger: #b73535;
  --shadow: 0 10px 30px rgba(24, 45, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(20, 122, 61, 0.16), transparent 30rem),
    linear-gradient(180deg, #f7faf4 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 2px 18px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-actions[hidden],
.tabbar[hidden],
.panel[hidden],
.tab-panel[hidden] {
  display: none;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(1.85rem, 4vw, 2.75rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.35rem;
}

h3 {
  margin-bottom: 8px;
  font-size: 1.05rem;
}

code {
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf4;
  padding: 10px;
  overflow-wrap: anywhere;
}

.subline,
.muted,
.empty-state {
  color: var(--muted);
}

.subline {
  margin-bottom: 0;
}

.tabbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.tab-button,
.ghost-button,
.primary-button,
.secondary-button,
.danger-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

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

.tab-button.is-active,
.primary-button {
  background: var(--brand);
  color: #ffffff;
}

.tab-button.is-active:hover,
.primary-button:hover {
  background: var(--brand-strong);
}

.ghost-button,
.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.danger-button {
  border: 1px solid rgba(183, 53, 53, 0.25);
  background: #fff5f5;
  color: var(--danger);
}

main,
.tab-panel,
.match-list,
.leaderboard-list,
.rule-list,
.player-list {
  display: grid;
  gap: 12px;
}

main {
  padding-top: 14px;
}

.panel,
.match-card,
.leaderboard-row,
.rule-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.auth-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.auth-card {
  display: grid;
  align-content: start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdf9;
  padding: 14px;
}

.auth-mode-switch {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  padding: 6px;
}

.account-auth-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-grid,
.dashboard-tournaments {
  display: grid;
  gap: 12px;
}

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

.dashboard-tournaments {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
}

.dashboard-hero,
.recovery-notice,
.tournament-dashboard-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tournament-dashboard-card {
  margin-bottom: 0;
}

.recovery-notice {
  border-color: #e2c35b;
  background: #fffbe8;
}

.recovery-notice code {
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.compact-form {
  display: grid;
  gap: 10px;
}

.dashboard-search-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.dashboard-search-item div {
  display: grid;
  gap: 4px;
}

.search-results {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.search-result {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 11px;
  text-align: left;
}

.search-result.is-selected {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.search-result span {
  color: var(--muted);
  font-size: 0.85rem;
}

.toolbar,
.section-heading,
.result-line,
.readonly-prediction {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.section-heading {
  margin-bottom: 10px;
}

.section-heading h2,
.section-heading h3 {
  margin-bottom: 0;
}

.league-picker {
  min-width: 170px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

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

.match-card {
  padding: 14px;
}

.match-card.is-locked {
  background: rgba(255, 255, 255, 0.72);
}

.match-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.teams {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  font-size: 1.1rem;
  font-weight: 900;
}

.teams span:last-child {
  text-align: right;
}

.versus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 0.78rem;
}

.match-window {
  margin-bottom: 12px;
  font-size: 0.88rem;
}

.score-form {
  display: grid;
  grid-template-columns: minmax(72px, 96px) minmax(72px, 96px) auto;
  gap: 10px;
  align-items: end;
}

.result-line,
.readonly-prediction {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

.readonly-prediction {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdf9;
  padding: 10px 11px;
}

.points-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 900;
}

.status-pill {
  background: #fff7d5;
  color: #6d5510;
}

.summary-grid,
.session-grid {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 8px;
}

.session-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.summary-grid span,
.session-grid span {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdf9;
  padding: 9px 11px;
  color: var(--muted);
}

.leaderboard-row,
.rule-row,
.player-row {
  padding: 12px;
}

.leaderboard-row,
.player-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}

.player-row {
  grid-template-columns: 1fr auto auto;
}

.rank {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand);
  color: #ffffff;
  font-weight: 900;
}

.leaderboard-points {
  font-size: 1.25rem;
  font-weight: 900;
}

.standings-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.standings-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}

.standings-table th,
.standings-table td {
  padding: 11px 9px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

.standings-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.standings-table tr:last-child td {
  border-bottom: 0;
}

.standings-table th:nth-child(2),
.standings-table td:nth-child(2) {
  text-align: left;
}

.team-name {
  font-weight: 900;
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

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

.empty-state.compact {
  padding: 10px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 10;
  width: min(340px, calc(100% - 32px));
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

@media (max-width: 720px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .topbar-actions,
  .toolbar,
  .section-heading,
  .readonly-prediction,
  .result-line {
    display: grid;
    justify-content: stretch;
  }

  .auth-grid,
  .dashboard-grid,
  .dashboard-tournaments,
  .summary-grid,
  .session-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-hero,
  .recovery-notice,
  .tournament-dashboard-card {
    display: grid;
  }

  .score-form {
    grid-template-columns: 1fr 1fr;
  }

  .score-form button {
    grid-column: 1 / -1;
  }

  .teams {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .teams span,
  .teams span:last-child {
    text-align: left;
  }

  .versus {
    width: fit-content;
    height: auto;
    border-radius: 8px;
    padding: 4px 8px;
  }

  .player-row,
  .leaderboard-row {
    grid-template-columns: 1fr;
  }
}
