:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --panel: #ffffff;
  --ink: #17201c;
  --muted: #67736d;
  --line: #d9dfda;
  --accent: #c51f32;
  --accent-2: #0d6b57;
  --warn: #9b5c00;
  --shadow: 0 18px 50px rgba(23, 32, 28, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent-2);
}

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

.crumb {
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

.crumb a {
  color: var(--accent-2);
  text-decoration: none;
}

.crumb a:hover {
  text-decoration: underline;
}

.topbar,
.next-match,
.controls,
.match-list,
.editor {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 24px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.9rem, 4vw, 3.5rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.clock {
  min-width: 210px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: right;
}

.clock-label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.clock time {
  display: block;
  margin-top: 3px;
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.next-match {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  margin-top: 16px;
  padding: 22px 24px;
}

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

.countdown {
  min-width: 230px;
  color: var(--accent-2);
  font-size: clamp(1.7rem, 4vw, 3rem);
  font-weight: 850;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.controls {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-top: 16px;
  padding: 16px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segmented button {
  min-width: 94px;
  border: 0;
  padding: 9px 12px;
  background: transparent;
}

.segmented button.active {
  background: var(--ink);
  color: white;
}

.search {
  display: grid;
  gap: 6px;
  min-width: min(340px, 100%);
  color: var(--muted);
  font-size: 0.85rem;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fbfcfb;
  color: var(--ink);
}

input:focus {
  outline: 2px solid rgba(13, 107, 87, 0.22);
  border-color: var(--accent-2);
}

.match-list,
.editor {
  margin-top: 16px;
  padding: 20px;
}

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

.section-head h2 {
  margin-bottom: 4px;
}

.data-note {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.section-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.section-head button {
  padding: 8px 10px;
  color: var(--muted);
}

#download-all {
  border-color: var(--accent-2);
  color: var(--accent-2);
  font-weight: 800;
}

.matches {
  display: grid;
  gap: 10px;
}

.match {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr) 120px 62px 42px;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.date-block {
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.date-block span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.teams {
  min-width: 0;
}

.teams strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 1.08rem;
}

.teams small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.status {
  justify-self: end;
  color: var(--accent-2);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.status.soon {
  color: var(--warn);
}

.status.done {
  color: var(--muted);
}

.calendar,
.delete {
  width: 38px;
  height: 38px;
  color: var(--muted);
}

.calendar {
  width: 62px;
  font-size: 0.82rem;
  font-weight: 800;
}

.empty {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

/* connection / live status */
.conn {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.conn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}

.conn-dot.live {
  background: var(--accent-2);
  box-shadow: 0 0 0 0 rgba(13, 107, 87, 0.5);
  animation: pulse 1.8s infinite;
}

.conn-dot.loading { background: var(--warn); }
.conn-dot.stale { background: var(--warn); }
.conn-dot.offline { background: var(--accent); }

.conn #refresh {
  margin-left: 4px;
  padding: 7px 12px;
  font-weight: 700;
  color: var(--accent-2);
  border-color: var(--accent-2);
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(13, 107, 87, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(13, 107, 87, 0); }
  100% { box-shadow: 0 0 0 0 rgba(13, 107, 87, 0); }
}

/* live match emphasis */
.status.live {
  color: var(--accent);
  font-weight: 850;
}

.countdown.live {
  color: var(--accent);
}

.match.is-live {
  border-color: var(--accent);
  background: #fff6f6;
}

.delete-spacer {
  width: 38px;
  height: 38px;
}

/* knockout flow / bracket */
.bracket-wrap {
  margin-top: 16px;
  padding: 20px;
}

.bracket-empty {
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  line-height: 1.5;
}

.bracket-empty strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
}

.bracket-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.bracket-summary .pill {
  padding: 5px 11px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.85rem;
}

.pill.in { background: rgba(13, 107, 87, 0.12); color: var(--accent-2); }
.pill.out { background: rgba(197, 31, 50, 0.1); color: var(--accent); }

.bracket-out-list {
  color: var(--muted);
  font-size: 0.85rem;
}

.bracket-cols {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.bracket-flow {
  align-self: center;
  color: var(--line);
  font-size: 1.5rem;
  font-weight: 800;
  flex: none;
}

.bracket-col {
  display: grid;
  gap: 10px;
  min-width: 190px;
  flex: none;
}

.bracket-col-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  padding-bottom: 4px;
  border-bottom: 2px solid var(--line);
}

.bracket-col-head span {
  color: var(--muted);
  font-weight: 700;
}

.bk-match {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  overflow: hidden;
}

.bk-match.is-live {
  border-color: var(--accent);
  background: #fff6f6;
}

.bk-team {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  font-size: 0.95rem;
}

.bk-team + .bk-team {
  border-top: 1px solid var(--line);
}

.bk-team.won {
  font-weight: 850;
  color: var(--accent-2);
}

.bk-team.lost {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--accent);
}

.bk-score {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.bk-tag {
  padding: 5px 11px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.bk-tag.live { color: var(--accent); font-weight: 800; }
.bk-tag.done { color: var(--muted); }

.editor form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

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

.editor button {
  align-self: end;
  min-height: 44px;
  padding: 11px 14px;
  background: var(--accent-2);
  color: white;
  font-weight: 800;
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 20px, 1080px);
    padding-top: 10px;
  }

  .topbar,
  .next-match,
  .controls,
  .section-head {
    display: grid;
  }

  .clock,
  .countdown,
  .status {
    min-width: 0;
    text-align: left;
  }

  .controls {
    align-items: stretch;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    min-width: 0;
  }

  .match {
    grid-template-columns: 1fr 42px;
  }

  .date-block,
  .teams,
  .status {
    grid-column: 1;
  }

  .delete {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .calendar {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
  }

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