:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #64717c;
  --line: #dfe6ea;
  --surface: #ffffff;
  --surface-soft: #f5f8fa;
  --accent: #0a7c86;
  --accent-dark: #075963;
  --gold: #c7902e;
  --danger: #b42318;
  --success: #16784c;
  --shadow: 0 16px 40px rgba(24, 40, 50, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(180deg, rgba(10, 124, 134, 0.08), rgba(255, 255, 255, 0) 340px),
    #edf3f5;
  color: var(--ink);
}

a {
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
}

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

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  border-bottom: 1px solid rgba(223, 230, 234, 0.88);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(16px);
}

.header-grid {
  min-height: 72px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--accent-dark), var(--ink));
  color: white;
  font-weight: 800;
}

.brand-mark i[data-lucide] {
  width: 23px;
  height: 23px;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.76rem;
}

.main-nav,
.user-tools,
.inline-actions,
.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.main-nav {
  justify-content: center;
  flex-wrap: wrap;
}

.main-nav a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.main-nav a.active,
.main-nav a:hover {
  background: #e4f3f4;
  color: var(--accent-dark);
}

i[data-lucide],
svg.lucide {
  width: 17px;
  height: 17px;
  stroke-width: 2.3;
}

.icon-link,
.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  cursor: pointer;
}

.ghost {
  width: auto;
  min-width: 36px;
  gap: 5px;
}

.ghost.danger {
  color: var(--danger);
}

main.shell {
  padding: 28px 0 64px;
}

.flash {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  background: white;
  border: 1px solid var(--line);
  box-shadow: 0 8px 20px rgba(24, 40, 50, 0.06);
}

.flash.error {
  border-color: rgba(180, 35, 24, 0.35);
  color: var(--danger);
}

.flash.success {
  border-color: rgba(22, 120, 76, 0.35);
  color: var(--success);
}

.page-title,
.auth-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: end;
  margin: 18px 0 24px;
}

.auth-panel {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  min-height: 70vh;
  align-items: center;
}

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

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.8rem);
  letter-spacing: 0;
}

h2 {
  font-size: 1.18rem;
}

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

.panel {
  border: 1px solid rgba(223, 230, 234, 0.96);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.quick-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: end;
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: end;
}

.quick-stats span,
.status-pill,
.tag {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  padding: 7px 10px;
  color: var(--muted);
}

.status-pill.open {
  color: var(--success);
  border-color: rgba(22, 120, 76, 0.3);
}

.status-pill.locked {
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.3);
}

.tag {
  padding: 3px 8px;
  font-size: 0.72rem;
  border-radius: 6px;
  background: var(--surface-soft);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

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

tr.is-me {
  background: #e4f3f4;
}

.meta-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 14px;
  margin: 16px 0 0;
}

.meta-list dt {
  color: var(--muted);
  font-weight: 700;
}

.meta-list dd {
  margin: 0;
}

.form-stack {
  display: grid;
  gap: 14px;
}

.form-stack label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

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

textarea {
  resize: vertical;
}

.btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 9px 13px;
  font-weight: 800;
  cursor: pointer;
}

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

.btn.small {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 0.88rem;
}

.stack {
  display: grid;
  gap: 16px;
}

.match-list {
  display: grid;
  gap: 10px;
}

.match-list.compact {
  gap: 6px;
}

.match-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px 128px;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.match-main {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
  min-width: 0;
}

.match-main small {
  flex-basis: 100%;
  color: var(--muted);
  line-height: 1.35;
}

.match-teams {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  align-items: baseline;
}

.match-teams strong {
  overflow-wrap: anywhere;
}

.match-row.done {
  background: #f0fbf6;
}

.match-row.live {
  background: #fff7ed;
  border-color: #fed7aa;
}

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

.match-score,
.match-prono {
  display: grid;
  gap: 3px;
  justify-items: end;
  text-align: right;
}

.match-score small,
.match-prono small {
  color: var(--muted);
}

.match-score strong,
.match-prono strong {
  line-height: 1;
}

.match-score span,
.match-prono span {
  color: var(--muted);
  font-size: 0.82rem;
}

.prono-score {
  font-size: 1.05rem;
}

.match-prono .mismatch {
  cursor: help;
}

.reason-badge {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #fff1f0;
  color: var(--danger) !important;
  border: 1px solid #fecaca;
  padding: 3px 9px;
  font-weight: 800;
  white-space: nowrap;
}

.match-prono em {
  color: var(--success);
  font-style: normal;
  font-weight: 900;
}

.mismatch {
  color: var(--danger);
}

.score-pick {
  display: inline-grid;
  grid-template-columns: 62px auto 62px;
  gap: 7px;
  align-items: center;
}

.score-pick > span {
  min-width: 10px;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.score-pick.score-stack {
  grid-template-columns: 62px;
}

.score-pick select {
  min-width: 62px;
}

.sticky-submit {
  position: sticky;
  bottom: 18px;
  justify-self: end;
  box-shadow: var(--shadow);
}

.save-state {
  min-width: 82px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 1;
  transition: opacity 0.5s ease;
}

.save-state.saving::before {
  content: "";
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.save-state.saved {
  color: var(--success);
}

.save-state.is-fading {
  opacity: 0;
}

.save-state.error {
  min-width: min(260px, 100%);
  color: var(--danger);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.bracket-section {
  margin-bottom: 18px;
}

.bracket-section h2 {
  margin-bottom: 14px;
}

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

.bet-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.bet-card header {
  display: block;
  margin-bottom: 12px;
}

.bet-card header small {
  display: block;
  line-height: 1.35;
  color: var(--muted);
  text-align: center;
}

.group-card {
  display: grid;
  justify-items: center;
  gap: 9px;
  text-align: center;
}

.group-card strong {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.no-bet {
  min-height: 42px;
  display: grid;
  place-items: center;
  font-weight: 800;
}

.group-card select {
  width: 76px;
  text-align: center;
}

.finales-card {
  display: grid;
  justify-items: center;
  gap: 9px;
  text-align: center;
}

.finales-card select {
  width: 76px;
  text-align: center;
}

.finales-card strong {
  max-width: 100%;
  overflow-wrap: anywhere;
}

.finales-card .mismatch {
  color: var(--danger);
}

.tie-winner {
  display: grid;
  gap: 5px;
  justify-items: center;
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.tie-winner.is-hidden {
  display: none;
}

.tie-winner select {
  width: min(220px, 100%);
}

.finales-card em {
  color: var(--success);
  font-style: normal;
  font-weight: 800;
}

.locked-card {
  color: var(--muted);
}

.saved-bet {
  display: grid;
  gap: 4px;
}

.saved-bet {
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-radius: 8px;
  background: white;
  padding: 10px;
  margin-bottom: 10px;
  text-align: center;
}

.saved-bet em {
  grid-column: 1 / -1;
  color: var(--success);
  font-style: normal;
  font-weight: 800;
}

.mini {
  gap: 10px;
}

.team-picker {
  display: grid;
  gap: 8px;
}

.check {
  display: inline-flex !important;
  grid-auto-flow: column;
  justify-content: start;
  align-items: center;
  gap: 8px !important;
}

.check input {
  width: auto;
}

.messages {
  margin-top: 18px;
}

.message-form {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.message-list {
  display: grid;
  gap: 12px;
}

.message-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  overflow: hidden;
}

.message-card p {
  margin: 0;
  padding: 14px;
}

.message-card img {
  display: block;
  max-width: 100%;
  margin: 0 auto;
}

.message-card footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-top: 1px solid var(--line);
  background: white;
  padding: 9px 12px;
}

.live-score-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.live-score-list h3 {
  margin: 0;
  font-size: 0.95rem;
}

.live-score-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff7ed;
  padding: 10px;
}

.live-score-card div:first-child {
  display: flex;
  flex-wrap: wrap;
  gap: 3px 5px;
  align-items: baseline;
  min-width: 0;
}

.live-score-card div:first-child small {
  flex-basis: 100%;
  color: var(--muted);
}

.live-score-card div:last-child {
  display: grid;
  gap: 2px;
  justify-items: end;
  text-align: right;
}

.live-score-card div:last-child small {
  color: var(--muted);
}

.admin-match-row {
  grid-template-columns: minmax(220px, 1fr) minmax(520px, auto) auto;
}

.admin-result {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: end;
  gap: 7px;
}

.admin-result select {
  width: auto;
  min-width: 64px;
}

.admin-result select[name="status"] {
  min-width: 116px;
}

.admin-result select[name="winner_team_id"],
.admin-team-picks .admin-result select {
  max-width: 210px;
}

.admin-team-picks {
  display: flex;
  flex-wrap: nowrap;
  gap: 7px;
  justify-content: end;
  min-width: 0;
}

@media (max-width: 900px) {
  .header-grid,
  .page-title,
  .auth-panel,
  .dashboard-grid,
  .match-row {
    grid-template-columns: 1fr;
  }

  .main-nav {
    justify-content: start;
  }

  .match-score,
  .match-prono {
    justify-items: start;
    text-align: left;
  }

  .admin-result,
  .admin-team-picks {
    flex-wrap: wrap;
    justify-content: start;
  }

  .user-tools,
  .quick-stats,
  .title-actions {
    justify-content: start;
  }

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

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 1180px);
  }

  .site-header .shell {
    width: min(100% - 12px, 1180px);
  }

  .header-grid {
    min-height: 58px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) 34px;
    gap: 6px;
    align-items: center;
    padding: 8px 0;
  }

  .brand {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    line-height: 0;
  }

  .brand > span:not(.brand-mark) {
    display: none;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    margin: 0;
  }

  .brand-mark i[data-lucide],
  .brand-mark svg.lucide {
    width: 20px;
    height: 20px;
  }

  .user-tools {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    line-height: 0;
  }

  .user-tools form {
    display: none;
  }

  .icon-link {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
  }

  .icon-link i[data-lucide],
  .icon-link svg.lucide {
    width: 20px;
    height: 20px;
  }

  .main-nav {
    min-width: 0;
    height: 34px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 34px;
    justify-content: center;
    align-items: center;
    gap: 9px;
    line-height: 0;
  }

  .panel {
    padding: 14px;
  }

  .main-nav a {
    width: 34px;
    height: 34px;
    min-height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    line-height: 0;
  }

  .main-nav a span,
  .main-nav a.rules-link {
    display: none;
  }

  .main-nav a i[data-lucide],
  .main-nav a svg.lucide {
    width: 20px;
    height: 20px;
    display: block;
    margin: auto;
    align-self: center;
    justify-self: center;
  }

  .group-bet-row > div:first-child {
    justify-content: center;
    text-align: center;
  }

  .group-bet-row .score-pick {
    justify-self: center;
  }

  .bracket-grid {
    grid-template-columns: 1fr;
  }
}
