:root {
  color-scheme: light;
  --bg: #f8f9fa;
  --panel: #ffffff;
  --card: linear-gradient(180deg, #fff 0%, #fafbfc 100%);
  --text: #1f1f1f;
  --muted: #5f6368;
  --line: #d2d5da;
  --primary: #1a73e8;
  --radius: 12px;
  --shadow: 0 1px 3px rgb(60 64 67 / 0.16), 0 4px 8px rgb(60 64 67 / 0.12);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111214;
  --panel: #1e2022;
  --card: #252729;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --line: #3c4043;
  --primary: #4da3ff;
  --shadow: 0 1px 3px rgb(0 0 0 / 0.4), 0 4px 8px rgb(0 0 0 / 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, Roboto, "Noto Sans", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem clamp(1rem, 3vw, 3rem);
  gap: 1rem;
}

.header-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.site-logo {
  width: 52px;
  height: 52px;
  flex-shrink: 0;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.1rem, 1.4rem + 0.8vw, 2rem);
}

.data-status {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.data-status[data-live="true"] {
  color: #34a853;
}

[data-theme="dark"] .data-status[data-live="true"] {
  color: #57bb76;
}

.lang-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  cursor: pointer;
}

.lang-globe {
  font-size: 1.2rem;
  line-height: 1;
  pointer-events: none;
}

.lang-picker select {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  border: none;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--text);
  align-self: end;
}

.theme-toggle:hover {
  background: var(--line);
}

main {
  display: grid;
  gap: 1rem;
  padding: 0 clamp(1rem, 3vw, 3rem) 2rem;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
}

.group-nav {
  margin-bottom: 0.75rem;
}

.group-nav-row {
  display: flex;
  gap: 0.45rem;
  margin-bottom: 0.4rem;
}

.group-nav-row:last-child { margin-bottom: 0; }

.group-nav-btn {
  flex: 1;
  padding: 0.4rem 0;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

.group-nav-btn:hover { color: var(--text); border-color: var(--muted); }

.group-nav-btn.active {
  color: var(--primary);
  border-color: var(--primary);
  font-weight: 600;
  background: rgba(26, 115, 232, 0.08);
}

[data-theme="dark"] .group-nav-btn.active {
  background: rgba(77, 163, 255, 0.12);
}

.group-list {
  display: grid;
  gap: 1rem;
}

.group {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
}

.group h3 {
  margin: 0 0 0.65rem;
  font-size: 1rem;
}

.group-matches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.65rem;
}

.match-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  display: grid;
  gap: 0.2rem;
  background: var(--card);
}

.match-meta {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  gap: 0.3rem;
}

.match-team-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.8rem;
}

.team {
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.team-flag {
  width: 20px;
  height: auto;
  border-radius: 2px;
  flex-shrink: 0;
}

.score {
  font-weight: 600;
}

.knockout-title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.drag-tip {
  color: var(--muted);
  font-size: 0.85rem;
}

.knockout-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem;
  cursor: grab;
  user-select: none;
}

.knockout-scroll.dragging {
  cursor: grabbing;
}

.knockout-bracket {
  display: flex;
  align-items: stretch;
  min-width: max-content;
  padding: 0.5rem 0 1rem;
}

.round {
  display: flex;
  flex-direction: column;
  flex: 0 0 250px;
}

.round h3 {
  margin: 0 0 0.75rem;
  color: var(--primary);
  font-size: 0.92rem;
  text-align: center;
  white-space: nowrap;
}

.bracket-slots {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.bracket-slot {
  display: flex;
  align-items: center;
  flex: 1;
  min-height: 90px;
  position: relative;
  padding: 4px 28px;
}

.bracket-slot .match-card {
  flex: 1;
}

.round:first-child .bracket-slot {
  padding-left: 0;
}

.round:last-child .bracket-slot {
  padding-right: 0;
}

/* Incoming horizontal connector from previous round */
.round:not(:first-child) .bracket-slot::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 28px;
  border-top: 2px solid var(--line);
}

/* Outgoing connector — top of pair: ─┐ (right + down) */
.round:not(:last-child) .bracket-slot:nth-child(odd):not(:only-child)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  width: 28px;
  height: calc(50% + 1px);
  border-top: 2px solid var(--line);
  border-right: 2px solid var(--line);
}

/* Outgoing connector — bottom of pair: ─┘ (up + right) */
.round:not(:last-child) .bracket-slot:nth-child(even)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  width: 28px;
  height: calc(50% + 1px);
  border-bottom: 2px solid var(--line);
  border-right: 2px solid var(--line);
}

/* Outgoing connector — only child: straight horizontal passthrough */
.round:not(:last-child) .bracket-slot:only-child::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  width: 28px;
  border-top: 2px solid var(--line);
}

@media (max-width: 780px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
