/* ═══════════════════════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════════════════════ */
:root {
  --bg:          #0d0f0e;
  --surface:     #161a18;
  --surface2:    #1e2421;
  --border:      #2a3330;
  --green:       #3ddc84;
  --green-dim:   #2ba863;
  --green-glow:  rgba(61, 220, 132, 0.18);
  --white:       #f0f4f2;
  --muted:       #6b7c77;
  --danger:      #e05252;
  --gold:        #f5c842;

  --font-display: 'Bebas Neue', sans-serif;
  --font-body:    'DM Sans', sans-serif;

  --radius:  6px;
  --radius-lg: 12px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ═══════════════════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

ul { list-style: none; }
button { cursor: pointer; font-family: var(--font-body); }
input { font-family: var(--font-body); }

/* ═══════════════════════════════════════════════════════════
   PHASE VISIBILITY
═══════════════════════════════════════════════════════════ */
.phase {
  display: none;
  min-height: 100vh;
  animation: fadeIn 0.4s ease both;
}
.phase.active { display: flex; flex-direction: column; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: var(--radius);
  border: none;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: var(--transition);
}

.btn-primary {
  background: var(--green);
  color: #0d1510;
}
.btn-primary:hover:not(:disabled) {
  background: #56e89b;
  box-shadow: 0 0 20px var(--green-glow);
}
.btn-primary:disabled {
  background: var(--surface2);
  color: var(--muted);
  cursor: not-allowed;
}

.btn-accent {
  background: var(--green-dim);
  color: var(--bg);
  padding: 10px 18px;
  font-size: 18px;
  line-height: 1;
}
.btn-accent:hover { background: var(--green); }

.btn-outline {
  background: transparent;
  color: var(--green);
  border: 2px solid var(--green);
}
.btn-outline:hover { background: var(--green-glow); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--white); border-color: var(--muted); background: var(--surface2); }

.btn-reset-inline { color: var(--danger); border-color: rgba(224,82,82,0.3); }
.btn-reset-inline:hover { color: var(--danger); border-color: var(--danger); background: rgba(224,82,82,0.08); }

.btn-sm {
  padding: 5px 12px;
  font-size: 11px;
}

.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 4px 10px;
  font-size: 11px;
  border-radius: var(--radius);
}
.btn-danger:hover { background: rgba(224,82,82,0.12); }

/* ═══════════════════════════════════════════════════════════
   FORM ELEMENTS
═══════════════════════════════════════════════════════════ */
.field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--white);
  padding: 10px 14px;
  font-size: 14px;
  transition: border-color var(--transition);
  outline: none;
}
.field-input:focus { border-color: var(--green); }
.field-input::placeholder { color: var(--muted); }

.score-input {
  width: 52px;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--white);
  padding: 6px 4px;
  font-size: 16px;
  font-weight: 700;
  outline: none;
  transition: border-color var(--transition);
}
.score-input:focus { border-color: var(--green); }

/* ═══════════════════════════════════════════════════════════
   BADGE
═══════════════════════════════════════════════════════════ */
.badge {
  display: inline-block;
  background: var(--green-dim);
  color: var(--bg);
  border-radius: 20px;
  padding: 1px 9px;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin: 4px 0 16px;
}

/* ═══════════════════════════════════════════════════════════
   PHASE 0 — SETUP
═══════════════════════════════════════════════════════════ */
#phase-setup {
  position: relative;
  align-items: center;
  justify-content: center;
  padding: 40px 16px;
}

.setup-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(61,220,132,0.08) 0%, transparent 70%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 39px,
      rgba(61,220,132,0.04) 40px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 39px,
      rgba(61,220,132,0.04) 40px
    );
}

.setup-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 480px;
  text-align: center;
}

.logo-mark {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 12px;
  display: block;
  filter: drop-shadow(0 0 20px rgba(61,220,132,0.4));
  animation: spin-in 0.7s cubic-bezier(0.34,1.56,0.64,1) both;
}

@keyframes spin-in {
  from { transform: rotate(-180deg) scale(0); opacity: 0; }
  to   { transform: rotate(0) scale(1); opacity: 1; }
}

.site-title {
  font-family: var(--font-display);
  font-size: clamp(52px, 12vw, 80px);
  line-height: 0.95;
  letter-spacing: 0.04em;
  color: var(--white);
  margin-bottom: 36px;
}
.site-title span { color: var(--green); }

.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.teams-header { display: flex; flex-direction: column; gap: 8px; }

.team-add-row {
  display: flex;
  gap: 8px;
}
.team-add-row .field-input { flex: 1; }

.teams-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}
.teams-list::-webkit-scrollbar { width: 4px; }
.teams-list::-webkit-scrollbar-track { background: transparent; }
.teams-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.team-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  animation: slideIn 0.2s ease both;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

.team-item-name {
  font-weight: 500;
  font-size: 14px;
}
.team-item-num {
  font-size: 11px;
  color: var(--muted);
  margin-right: 10px;
}

#btn-start { width: 100%; padding: 14px; font-size: 15px; letter-spacing: 0.1em; }

/* ═══════════════════════════════════════════════════════════
   TOP BAR (Groups + Knockout)
═══════════════════════════════════════════════════════════ */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.phase-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--green);
}

.phase-title {
  font-family: var(--font-display);
  font-size: 26px;
  letter-spacing: 0.04em;
  color: var(--white);
  margin-top: 2px;
}

/* ═══════════════════════════════════════════════════════════
   PHASE 1 — GROUPS
═══════════════════════════════════════════════════════════ */
.groups-layout {
  flex: 1;
  padding: 28px;
  overflow-y: auto;
}

.groups-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 24px;
}

.group-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.group-header {
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.06em;
  color: var(--green);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Standings table */
.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.standings-table th {
  padding: 8px 10px;
  text-align: right;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.standings-table th:first-child { text-align: left; }
.standings-table td {
  padding: 9px 10px;
  text-align: right;
  border-bottom: 1px solid rgba(42,51,48,0.5);
}
.standings-table td:first-child { text-align: left; font-weight: 500; }
.standings-table tr:last-child td { border-bottom: none; }
.standings-table .pts { font-weight: 700; color: var(--green); }
.standings-table .rank { color: var(--muted); font-size: 12px; }
.standings-table tr.advances td:first-child::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 12px;
  background: var(--green);
  border-radius: 2px;
  margin-right: 8px;
  vertical-align: middle;
}
.standings-table tr.border-bottom-dash td {
  border-bottom: 1px dashed var(--border);
}

/* Fixtures */
.fixtures-section {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
}
.fixtures-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.fixture-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(42,51,48,0.4);
  font-size: 13px;
}
.fixture-row:last-child { border-bottom: none; }

.fixture-team { font-weight: 500; }
.fixture-team.home { text-align: right; }
.fixture-team.away { text-align: left; }
.fixture-team.winner { color: var(--green); }
.fixture-team.loser  { color: var(--muted); }

.fixture-score {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}
.score-sep { color: var(--muted); font-weight: 700; }

.btn-save-score {
  background: var(--green-dim);
  border: none;
  color: var(--bg);
  border-radius: var(--radius);
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.btn-save-score:hover { background: var(--green); }

.score-display {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 0.04em;
  color: var(--white);
  padding: 0 4px;
}

/* ═══════════════════════════════════════════════════════════
   PHASE 2 — KNOCKOUT BRACKET
═══════════════════════════════════════════════════════════ */
.bracket-wrapper {
  display: flex;
  gap: 0;
  flex: 1;
  overflow-x: auto;
  padding: 32px 28px;
  align-items: flex-start;
}

.bracket-round {
  display: flex;
  flex-direction: column;
  min-width: 220px;
  flex: 1;
}

.round-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--green);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  text-align: center;
}

.bracket-matches {
  display: flex;
  flex-direction: column;
  gap: 20px;
  justify-content: space-around;
  flex: 1;
}

.bracket-match {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition);
  position: relative;
}
.bracket-match.playable { border-color: var(--green-dim); }
.bracket-match.done { border-color: var(--border); }

.bracket-slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}
.bracket-slot:last-of-type { border-bottom: none; }
.bracket-slot.winner { background: rgba(61,220,132,0.08); color: var(--green); font-weight: 700; }
.bracket-slot.loser  { color: var(--muted); }
.bracket-slot.tbd    { color: var(--muted); font-style: italic; }

.slot-name { flex: 1; }
.slot-score {
  font-family: var(--font-display);
  font-size: 18px;
  min-width: 24px;
  text-align: center;
}

/* Bracket score entry form */
.bracket-form {
  padding: 10px 14px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

/* Connector lines between rounds */
.bracket-round:not(:last-child) {
  border-right: 1px dashed var(--border);
  margin-right: 0;
  padding-right: 0;
}

/* Third place match styling */
.third-place-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  margin-top: 24px;
  margin-bottom: 8px;
}

/* ═══════════════════════════════════════════════════════════
   PHASE 3 — PODIUM
═══════════════════════════════════════════════════════════ */
#phase-podium {
  position: relative;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
}

#phase-podium .top-bar {
  position: relative;
  width: 100%;
  align-self: flex-start;
}

#phase-podium .podium-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  width: 100%;
}

.podium-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(ellipse 70% 60% at 50% 40%, rgba(245,200,66,0.07) 0%, rgba(61,220,132,0.05) 40%, transparent 70%);
}

.podium-content {
  position: relative;
  z-index: 1;
  text-align: center;
  width: 100%;
  max-width: 620px;
}

.podium-headline {
  font-family: var(--font-display);
  font-size: clamp(60px, 14vw, 100px);
  letter-spacing: 0.06em;
  color: var(--gold);
  line-height: 1;
  margin-bottom: 48px;
  text-shadow: 0 0 40px rgba(245,200,66,0.3);
  animation: glow-pulse 2.5s ease-in-out infinite alternate;
}

@keyframes glow-pulse {
  from { text-shadow: 0 0 20px rgba(245,200,66,0.2); }
  to   { text-shadow: 0 0 60px rgba(245,200,66,0.5), 0 0 120px rgba(245,200,66,0.2); }
}

.podium-stage {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  margin-bottom: 48px;
}

.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.podium-medal { font-size: 36px; line-height: 1; }

.podium-team {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: 0.04em;
  color: var(--white);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 16px;
  min-width: 140px;
  text-align: center;
}
.podium-champ {
  font-size: 26px;
  background: rgba(245,200,66,0.1);
  border-color: var(--gold);
  color: var(--gold);
}

.podium-bar {
  border-radius: 6px 6px 0 0;
  width: 140px;
}
.bar-1st { height: 100px; background: var(--gold); }
.bar-2nd { height: 70px;  background: #aab8c2; }
.bar-3rd { height: 50px;  background: #b87333; }

/* ═══════════════════════════════════════════════════════════
   GITHUB BADGE (setup screen)
═══════════════════════════════════════════════════════════ */
.gh-badge {
  position: absolute;
  top: 16px;
  right: 20px;
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: 0.04em;
  transition: var(--transition);
}
.gh-badge:hover { color: var(--white); border-color: var(--muted); }

/* ═══════════════════════════════════════════════════════════
   SCROLLBAR GLOBAL
═══════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ═══════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════ */
@media (max-width: 600px) {
  .top-bar { flex-wrap: wrap; gap: 10px; padding: 12px 16px; }
  .top-bar-right { margin-left: auto; }
  .groups-layout { padding: 16px; }
  .bracket-wrapper { padding: 16px; }
  .groups-container { grid-template-columns: 1fr; }
  .bracket-round { min-width: 180px; }
  .podium-team { min-width: 100px; font-size: 16px; }
  .podium-champ { font-size: 20px; }
  .bar-1st { width: 100px; }
  .bar-2nd { width: 100px; }
  .bar-3rd { width: 100px; }
  .modal-groups-grid { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════
   MODAL — EDIT GROUPS
═══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease both;
}
.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  width: 100%;
  max-width: 860px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.modal-header { display: flex; flex-direction: column; gap: 4px; }
.modal-title {
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: 0.04em;
  color: var(--white);
}
.modal-subtitle { font-size: 13px; color: var(--muted); }

.modal-groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
}

.modal-group-col {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  min-height: 120px;
  transition: border-color var(--transition), background var(--transition);
}
.modal-group-col.drag-over {
  border-color: var(--green);
  background: rgba(61,220,132,0.06);
}

.modal-group-label {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.08em;
  color: var(--green);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-group-count {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  background: var(--border);
  color: var(--muted);
  border-radius: 99px;
  padding: 2px 8px;
  letter-spacing: 0.05em;
}

.modal-team-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: grab;
  user-select: none;
  touch-action: none;       /* allow JS touch handling */
  -webkit-user-select: none;
  transition: border-color var(--transition), box-shadow var(--transition), opacity var(--transition);
}
.modal-team-chip:hover {
  border-color: var(--green-dim);
  box-shadow: 0 0 8px var(--green-glow);
}
.modal-team-chip.dragging {
  opacity: 0.4;
  cursor: grabbing;
}
.modal-team-chip::before {
  content: '⠿';
  color: var(--muted);
  font-size: 14px;
  flex-shrink: 0;
}

.modal-drop-placeholder {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.modal-warning {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  background: rgba(224,82,82,0.1);
  border-radius: var(--radius);
  border: 1px solid rgba(224,82,82,0.3);
}
.modal-warning[hidden] { display: none; }

.modal-note {
  font-size: 12px;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
