:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --text: #172033;
  --muted: #64748b;
  --line: #d9e1ec;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.68rem 0.75rem;
  color: var(--text);
  background: #fff;
}

textarea {
  resize: vertical;
}

label span {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.2rem;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--amber));
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.user-box small,
.eyebrow,
.game-card-header p,
.panel-header p {
  color: var(--muted);
}

.year-picker {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.year-picker label {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.main-nav {
  display: grid;
  gap: 0.35rem;
}

.main-nav a {
  padding: 0.78rem 0.85rem;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
}

.main-nav a:hover,
.main-nav a.active {
  color: var(--text);
  background: var(--surface-soft);
}

.user-box {
  margin-top: auto;
  display: grid;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.main-content {
  min-width: 0;
  padding: 2rem;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1;
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-weight: 800;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.62rem 0.9rem;
  cursor: pointer;
  font-weight: 850;
  white-space: nowrap;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button-primary {
  color: #fff;
  background: var(--primary);
}

.button-primary:hover {
  background: var(--primary-dark);
}

.button-ghost {
  color: var(--text);
  border-color: var(--line);
  background: #fff;
}

.button-ghost:hover {
  background: var(--surface-soft);
}

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

.panel {
  padding: 1.2rem;
}

.panel-header,
.game-card-header,
.match-card-header,
.team-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.panel-header h2,
.game-card h2,
.match-card h2,
.team-card h2 {
  margin: 0;
  font-size: 1.1rem;
}

.panel-header p,
.game-card-header p {
  margin: 0.2rem 0 0;
}

.dashboard-grid,
.detail-grid,
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.team-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.game-card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.game-card {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.game-card-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.8rem;
  align-items: start;
}

.game-bracket-area {
  min-width: 0;
}

.status-badge,
.pill,
.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0.2rem 0.58rem;
  font-size: 0.78rem;
  font-weight: 900;
}

.pill {
  color: #334155;
  background: #e2e8f0;
}

.status-not_started,
.status-pending {
  color: #475569;
  background: #e2e8f0;
}

.status-active,
.status-in_progress {
  color: #92400e;
  background: #fef3c7;
}

.status-completed {
  color: #166534;
  background: #dcfce7;
}

.result-win {
  color: #fff;
  background: var(--green);
}

.result-loss {
  color: #fff;
  background: #94a3b8;
}

.team-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--team-color, #64748b);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--team-color, #64748b) 20%, transparent);
}

.team-dot.large {
  width: 22px;
  height: 22px;
}

.ranking-list {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.ranking-list li,
.status-row,
.score-table div,
.admin-row,
.round-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.ranking-list strong,
.status-row span:first-child,
.score-table strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: #fff;
  background: var(--text);
  font-weight: 900;
}

.points,
.score-table span:last-child {
  margin-left: auto;
  font-weight: 900;
}

.status-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
}

.status-row {
  justify-content: space-between;
}

.bracket-mini,
.bracket-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
}

.bracket-mini-scored {
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
}

.bracket-mini-scored .final-column {
  align-self: stretch;
}

.bracket-column {
  display: grid;
  gap: 1rem;
}

.final-column,
.final-detail-column {
  align-self: center;
}

.bracket-match {
  position: relative;
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.match-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.bracket-team,
.match-team {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
  padding: 0.48rem 0.55rem;
  border-radius: 8px;
  background: #fff;
}

.bracket-team span:nth-child(2),
.match-team strong {
  min-width: 0;
}

.match-team strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bracket-team span:nth-child(2) {
  overflow: visible;
  white-space: normal;
  overflow-wrap: anywhere;
}

.bracket-team.winner,
.match-team.winner {
  outline: 2px solid color-mix(in srgb, var(--green) 35%, transparent);
}

.match-team.loser {
  color: var(--muted);
}

.vs {
  justify-self: center;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.score-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.score-strip span {
  border-radius: 999px;
  padding: 0.32rem 0.55rem;
  background: var(--surface-soft);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.bracket-score-form {
  display: grid;
  gap: 0.55rem;
}

.bracket-score-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.8fr) repeat(var(--round-count), minmax(52px, 0.45fr)) minmax(64px, 0.45fr);
  gap: 1px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.score-grid-head,
.score-team-name,
.score-cell,
.score-result-cell {
  min-width: 0;
  background: #fff;
}

.score-grid-head {
  display: grid;
  align-content: center;
  min-height: 34px;
  padding: 0.35rem 0.45rem;
  color: var(--text);
  text-align: center;
  font-size: 0.78rem;
}

.score-grid-head small {
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.2;
}

.score-team-name {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 42px;
  padding: 0.45rem 0.6rem;
  font-size: 0.92rem;
  font-weight: 800;
}

.score-team-name span:last-child {
  min-width: 0;
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

.score-team-name.winner {
  background: #dcfce7;
}

.score-team-name.loser {
  background: #fee2e2;
}

.score-cell,
.score-result-cell {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 0.3rem;
}

.score-input {
  width: 100%;
  min-width: 42px;
  height: 34px;
  padding: 0.25rem;
  text-align: center;
  font-weight: 900;
}

.score-input::-webkit-outer-spin-button,
.score-input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.score-input {
  appearance: textfield;
}

.button-small {
  min-height: 34px;
  padding: 0.42rem 0.7rem;
  font-size: 0.85rem;
}

.game-score-table {
  display: grid;
  gap: 0.55rem;
  min-width: 0;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.game-score-table h3 {
  margin: 0;
  font-size: 0.95rem;
}

.score-table-rows {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}

.score-table-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.45rem;
  min-height: 36px;
  padding: 0.45rem 0.55rem;
  border-radius: 8px;
  background: #fff;
}

.score-table-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: normal;
}

.score-table-row span:last-child {
  font-weight: 900;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
}

.section-heading {
  margin: 1.5rem 0 1rem;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.35rem;
}

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

.overview-panel {
  overflow: hidden;
}

.overview-table-wrap {
  margin-top: 1rem;
  overflow-x: auto;
}

.overview-table {
  width: 100%;
  min-width: 860px;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.overview-table th,
.overview-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0.72rem 0.75rem;
  text-align: center;
  white-space: nowrap;
}

.overview-table th:first-child,
.overview-table td:first-child {
  text-align: left;
}

.overview-table thead th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.82rem;
  font-weight: 900;
}

.overview-table tbody th {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 190px;
  font-weight: 900;
}

.overview-table tbody tr:last-child th,
.overview-table tbody tr:last-child td {
  border-bottom: 0;
}

.overview-table tr > *:last-child {
  border-right: 0;
  background: #ecfdf5;
}

.overview-table tbody td:last-child {
  color: #065f46;
  font-size: 1rem;
}

.bracket-config {
  display: grid;
  gap: 0.8rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.bracket-config h3 {
  margin: 0;
}

.bracket-config-grid,
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.inline-fields strong {
  grid-column: 1 / -1;
}

.score-panel {
  align-self: start;
}

.score-table {
  display: grid;
  gap: 0.5rem;
  margin-top: 1rem;
}

.bracket-detail {
  align-items: center;
  margin-top: 1rem;
}

.match-card {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.match-teams {
  display: grid;
  gap: 0.4rem;
}

.round-form,
.round-list,
.stack {
  display: grid;
  gap: 0.8rem;
}

.round-row {
  justify-content: space-between;
}

.round-row small {
  display: block;
  color: var(--muted);
}

.round-row select {
  max-width: 240px;
}

.inline-score-editor {
  display: grid;
  gap: 0.65rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
}

.inline-score-editor h3 {
  margin: 0;
  font-size: 0.95rem;
}

.inline-match-editor {
  display: grid;
  gap: 0.55rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.inline-match-editor header,
.inline-score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
}

.inline-score-form {
  display: grid;
  gap: 0.55rem;
}

.inline-score-row span {
  min-width: 0;
}

.inline-score-row small,
.muted {
  display: block;
  color: var(--muted);
}

.inline-score-row select {
  max-width: 240px;
}

.team-card {
  padding: 1rem;
}

.team-card-header {
  align-items: center;
}

.member-list {
  display: grid;
  gap: 0.45rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.member-list li {
  padding: 0.6rem 0.7rem;
  border-radius: 8px;
  background: var(--surface-soft);
}

.color-field {
  max-width: 110px;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 1rem;
}

.admin-tabs a {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.62rem 0.85rem;
  color: var(--muted);
  background: #fff;
  font-weight: 850;
}

.admin-tabs a.active,
.admin-tabs a:hover {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.admin-grid {
  align-items: start;
}

.compact-form {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr) auto;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.admin-list {
  display: grid;
  gap: 0.65rem;
}

.admin-action-bar {
  display: flex;
  justify-content: flex-end;
  margin: 1rem 0;
  padding: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.admin-row {
  justify-content: space-between;
}

.admin-row-main,
.admin-game-row,
.admin-user-row {
  display: grid;
  align-items: center;
  gap: 0.55rem;
}

.admin-row-main {
  grid-template-columns: 70px minmax(0, 1fr) auto;
  flex: 1;
}

.admin-game-row {
  grid-template-columns: minmax(180px, 1.2fr) minmax(220px, 1fr) 120px 120px minmax(240px, 1fr) auto auto;
  align-items: end;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-game-row > label {
  display: block;
}

.admin-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-self: center;
}

.admin-user-row {
  grid-template-columns: 100px minmax(140px, 1fr) 110px auto minmax(140px, 1fr) auto;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.check-row label,
.admin-game-row .admin-checks label,
.admin-user-row label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-weight: 800;
}

.check-row input,
.admin-game-row input[type="checkbox"],
.admin-user-row input[type="checkbox"] {
  width: auto;
}

.flash {
  margin-bottom: 1rem;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  font-weight: 800;
}

.flash-success {
  color: #166534;
  background: #dcfce7;
}

.flash-error {
  color: #991b1b;
  background: #fee2e2;
}

.empty-state {
  display: grid;
  justify-items: start;
  gap: 0.8rem;
  max-width: 640px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2rem;
  background: #fff;
  box-shadow: var(--shadow);
}

.empty-state h2,
.empty-state p {
  margin: 0;
}

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), rgba(217, 119, 6, 0.12)),
    var(--bg);
}

.auth-card {
  width: min(100%, 420px);
  display: grid;
  gap: 1rem;
  padding: 1.4rem;
}

.auth-brand {
  margin-bottom: 0.5rem;
}

@media (min-width: 1900px) {
  .game-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 2200px) {
  .game-card-body {
    grid-template-columns: minmax(0, 1fr) 260px;
  }
}

@media (max-width: 1500px) {
  .game-card-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1100px) {
  .dashboard-grid,
  .detail-grid,
  .admin-grid,
  .bracket-detail {
    grid-template-columns: 1fr;
  }

  .admin-game-row,
  .admin-user-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .main-content {
    padding: 1rem;
  }

  .page-header h1 {
    font-size: 2.1rem;
  }

  .game-card-grid,
  .team-grid,
  .bracket-mini,
  .score-table-rows,
  .form-grid,
  .bracket-config-grid,
  .compact-form,
  .inline-fields,
  .admin-row-main,
  .admin-game-row,
  .admin-user-row {
    grid-template-columns: 1fr;
  }

  .admin-row,
  .round-row,
  .inline-match-editor header,
  .inline-score-row {
    align-items: stretch;
    flex-direction: column;
  }

  .round-row select,
  .inline-score-row select {
    max-width: none;
  }

  .card-actions {
    justify-content: stretch;
  }

  .button {
    width: 100%;
  }
}
