:root {
  --ink: #f7fbff;
  --muted: #a9b7c6;
  --panel: rgba(8, 16, 24, 0.85);
  --panel-strong: rgba(12, 28, 42, 0.94);
  --line: rgba(255, 255, 255, 0.14);
  --grass: #2bd071;
  --gold: #f5c84b;
  --red: #ff4e64;
  --blue: #3da9ff;
  --surface: #050a11;
  --radius: 6px;
  --pad-x: clamp(10px, 2vw, 24px); /* Reduced padding to save horizontal space */
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(5, 10, 17, 0.82), rgba(5, 10, 17, 0.98)),
    url("../cup vang.jpg") center top / cover fixed,
    #050a11;
  font-family: "Be Vietnam Pro", "Segoe UI", Arial, sans-serif;
  line-height: 1.55;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  max-width: 1680px;
  margin: 0 auto;
  width: 100%;
  height: calc(100vh - 52px); /* Header is ~52px, fill remaining space */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(3, 9, 15, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  flex-shrink: 0;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px var(--pad-x);
  max-width: 1680px;
  margin: 0 auto;
  width: 100%;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 900;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  color: #081018;
  background: var(--gold);
  border-radius: 50%;
  font-family: "Barlow Condensed", Impact, sans-serif;
  font-size: 1.1rem;
}

nav {
  display: flex;
  gap: 10px;
}

nav a {
  padding: 6px 12px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

nav a:hover,
nav a.active {
  color: var(--ink);
  border-color: var(--line);
}

nav a.active {
  background: rgba(255, 255, 255, 0.08);
}

/* Hero Header */
.hero-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 4px var(--pad-x) 2px;
  text-align: center;
  flex-shrink: 0;
}

.eyebrow {
  margin: 0;
  color: var(--grass);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
}

h1 {
  font-family: "Barlow Condensed", "Be Vietnam Pro", sans-serif;
  font-size: 1.6rem;
  line-height: 0.95;
  margin: 0;
  text-transform: uppercase;
  font-weight: 800;
}

h2 {
  font-family: "Barlow Condensed", "Be Vietnam Pro", sans-serif;
  font-size: 1.25rem;
  color: var(--gold);
  line-height: 0.95;
  margin: 1px 0 2px;
  text-transform: uppercase;
}

.date-range {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.host-nations {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.host-nations .flag {
  font-size: 1rem;
}

/* Bracket Layout */
.bracket-container {
  flex: 1;
  padding: 8px var(--pad-x);
  overflow: visible; /* must be visible so connector-forks outside match-slots are not clipped */
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.bracket-scroll-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  width: 100%;
  overflow-y: auto; /* Enable vertical scroll if grid height exceeds container */
}

.bracket-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr) 1.2fr repeat(4, 1fr); /* Reduced center column ratio to widen other columns */
  gap: clamp(4px, 0.6vw, 10px);
  width: 100%;
  height: 100%;
  max-height: clamp(540px, 82vh, 780px); /* Responsive to viewport height */
  margin: 0 auto;
}

@media (max-width: 1024px) {
  .bracket-scroll-wrapper {
    overflow-x: auto;
    overflow-y: auto;
  }
  .bracket-grid {
    min-width: 960px;
  }
}

.bracket-column {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  overflow: visible; /* allow connector-forks to extend into gap between columns */
}

.column-title {
  text-align: center;
  font-size: clamp(0.68rem, 0.75vw, 0.8rem);
  color: var(--ink);
  text-transform: uppercase;
  margin: 0 auto 12px;
  padding: 4px clamp(8px, 1.2vw, 20px);
  border: 1px solid rgba(61, 169, 255, 0.25);
  background: rgba(12, 36, 64, 0.85);
  border-radius: 6px;
  font-weight: 700;
  font-family: "Barlow Condensed", "Be Vietnam Pro", sans-serif;
  letter-spacing: 0.8px;
  align-self: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.match-slots {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  flex-grow: 1;
  position: relative;
  overflow: visible; /* critical: connector-fork divs extend outside this container */
}

/* Match Slot Styling (High Contrast Glassmorphism) */
.match-card-slot {
  background: linear-gradient(135deg, rgba(16, 32, 48, 0.94), rgba(8, 16, 24, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-left: 3.5px solid rgba(255, 255, 255, 0.22); /* Left side status indicator */
  border-radius: var(--radius);
  padding: clamp(6px, 0.9vh, 10px) clamp(6px, 0.7vw, 11px); /* Reduced padding to give more horizontal room for text */
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  gap: clamp(2px, 0.3vh, 4px);
  position: relative;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, border-left-color 0.2s ease;
  min-width: 0;
}

.match-card-slot.status-finished {
  border-left-color: var(--grass);
}

.match-card-slot.status-live {
  border-left-color: var(--blue);
}

.match-card-slot:hover {
  transform: translateY(-2px);
  border-color: rgba(245, 200, 75, 0.55);
  box-shadow: 0 10px 28px rgba(245, 200, 75, 0.22);
}

.slot-team {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: clamp(0.68rem, 0.75vw, 0.84rem); /* Shrunk name text further to guarantee names fit */
  font-weight: 600;
  min-width: 0;
}

.team-info {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.team-info .flag {
  font-size: clamp(0.9rem, 1vw, 1.15rem); /* Reduced slightly to save horizontal space */
  flex-shrink: 0;
}

.team-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.team-score {
  font-family: "Barlow Condensed", Impact, sans-serif;
  font-size: clamp(0.85rem, 0.95vw, 1.08rem); /* Shrunk score font size to look cleaner and save space */
  font-weight: 600; /* Removed bold (changed from 800) */
  min-width: 15px;
  text-align: right;
  color: var(--gold);
  flex-shrink: 0;
}

.team-score.pen-detail {
  font-size: 0.65rem;
  color: var(--muted);
}

/* Connectors */
/* We align match connections with precise height levels */

/* Center Stage & Trophy */
.center-stage {
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  align-items: center;
  height: 100%;
  width: 100%;
  overflow: visible;
}

/* Row 1: Top Area with Hero Title and 3D Cup */
.center-top-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  height: 100%;
  width: 100%;
  gap: 4px;
  padding-top: 4px; /* Reduced vertical padding */
}

.center-hero {
  text-align: center;
  flex-shrink: 0;
}

.center-hero .eyebrow {
  margin: 0 0 1px;
  color: var(--grass);
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.center-hero h1 {
  font-family: "Barlow Condensed", "Be Vietnam Pro", sans-serif;
  font-size: clamp(1.3rem, 2vw, 2.1rem);
  line-height: 1.05;
  margin: 0;
  text-transform: uppercase;
  font-weight: 900;
  color: var(--ink);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.center-hero h2 {
  font-family: "Barlow Condensed", "Be Vietnam Pro", sans-serif;
  font-size: clamp(1rem, 1.3vw, 1.4rem);
  color: var(--gold);
  line-height: 1.1;
  margin: 2px 0 1px;
  text-transform: uppercase;
}

.center-hero .date-range {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.trophy-wrapper {
  width: 100%;
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  min-height: 100px; /* Reduced min-height */
  max-height: clamp(150px, 24vh, 250px); /* Height-sensitive sizing */
}

.trophy-scene {
  width: 100%;
  height: 100%;
}

.trophy-scene canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Fallback Cup */
.css-trophy {
  position: absolute;
  width: 35%;
  height: 85%;
  max-width: 90px;
  max-height: 180px;
  background: url("../trophy-3d-cutout.png") no-repeat center / contain;
  filter: drop-shadow(0 16px 36px rgba(245, 200, 75, 0.4));
  animation: float-cup 4s ease-in-out infinite;
}

@keyframes float-cup {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

/* Row 2: Chung Kết centered vertically */
.final-match-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  gap: 8px;
  margin: 4px 0; /* Reduced margin */
  transform: translateY(20px); /* Adjusted visual offset to align center with Semifinal cards */
}

/* Row 3: Tranh Hạng Ba positioned under Final */
.third-place-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start; /* Changed from flex-end to bring it closer to Final */
  height: 100%;
  width: 100%;
  padding-top: clamp(12px, 3vh, 32px); /* Responsive spacing under Final */
  padding-bottom: 4px;
  gap: 8px;
}

.stage-label {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 2px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: -2px;
}

.stage-label.highlight {
  color: var(--gold);
  text-shadow: 0 0 10px rgba(245, 200, 75, 0.35);
}

.center-slot {
  border-width: 2px;
  width: 83.33%; /* Default center column is 1.2fr, so 1/1.2 = 83.33% to match 1fr width */
  min-width: 83.33%;
}

/* 3D Loading Status inside Trophy container */
.trophy-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 8px 16px;
  border-radius: 20px;
  background: rgba(8, 16, 24, 0.85);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
  pointer-events: none;
}

/* Blinking highlights */
@keyframes winner-pulse {
  0% {
    text-shadow: 0 0 4px rgba(43, 208, 113, 0.4), 0 0 8px rgba(43, 208, 113, 0.2);
    color: #4dfa94;
  }
  50% {
    text-shadow: 0 0 12px rgba(43, 208, 113, 0.8), 0 0 20px rgba(43, 208, 113, 0.5);
    color: #ffffff;
  }
  100% {
    text-shadow: 0 0 4px rgba(43, 208, 113, 0.4), 0 0 8px rgba(43, 208, 113, 0.2);
    color: #4dfa94;
  }
}

.winner-glow {
  color: #4dfa94;
  font-weight: 800;
  animation: winner-pulse 2.2s infinite ease-in-out;
}
.placeholder-team {
  color: var(--muted);
  opacity: 0.55;
  font-size: 0.92em;
  font-weight: 500;
}
.loser-row {
  opacity: 0.40;
  filter: grayscale(40%);
  transition: opacity 0.2s ease;
}
.footnote {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 8px;
  margin-bottom: 5px;
  flex-shrink: 0;
}

img.emoji {
  height: 1.1em;
  width: 1.1em;
  margin: 0 .15em 0 .1em;
  vertical-align: -0.15em;
}

/* Custom horizontal scroll styling for sleek scrollbars */
.bracket-scroll-wrapper::-webkit-scrollbar {
  height: 8px;
}

.bracket-scroll-wrapper::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 999px;
}

.bracket-scroll-wrapper::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
}

.bracket-scroll-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--gold);
}

/* Connector-fork divs are now just invisible spacers; SVG overlay handles drawing */
.connector-fork { display: none; }

/* Responsive grid sizing */
@media (min-width: 1601px) {
  .bracket-grid {
    grid-template-columns: repeat(4, 1fr) 1.25fr repeat(4, 1fr); /* Widen match columns by reducing center stage ratio */
    gap: clamp(12px, 1.4vw, 26px);
    max-height: clamp(620px, 80vh, 810px); /* Limit grid height on shorter screens to prevent cutoff */
    width: 100%;
    max-width: 1720px; /* Increased from 1600px to make slots wider */
    margin: 0 auto;
  }
  .center-slot {
    width: 80%; /* Center column is 1.25fr, so 1/1.25 = 80% to match 1fr width */
    min-width: 80%;
  }
}

@media (max-width: 1600px) and (min-width: 1025px) {
  .bracket-grid {
    grid-template-columns: repeat(4, 1fr) 1.2fr repeat(4, 1fr); /* Widen match columns by reducing center stage ratio */
    gap: clamp(10px, 1.2vw, 20px);
    max-height: clamp(560px, 78vh, 730px); /* Limit grid height on shorter screens to prevent cutoff */
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
  }
  .center-slot {
    width: 83.33%; /* Center column is 1.2fr, so 1/1.2 = 83.33% to match 1fr width */
    min-width: 83.33%;
  }
}

