:root {
  --court-blue: #2E2A5C;
  --court-blue-dark: #1C1840;
  --turf: #00C48C;
  --turf-bright: #1BE0A6;
  --ball: #EEFF5C;
  --ball-dark: #C7DE2E;
  --sand: #F7F5FB;
  --chalk: #FFFFFF;
  --line-white: #FFFFFF;
  --score-red: #FF4D6D;
  --ink: #1B1930;
  --ink-soft: #6C6B85;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--sand); }
.app {
  font-family: 'Inter', sans-serif;
  background: var(--sand);
  color: var(--ink);
  min-height: 100vh;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: 84px;
  position: relative;
}
.header {
  background:
    radial-gradient(ellipse at 100% 0%, rgba(27,224,166,0.35), transparent 55%),
    radial-gradient(ellipse at 0% 100%, rgba(238,255,92,0.12), transparent 50%),
    linear-gradient(160deg, var(--court-blue) 0%, var(--court-blue-dark) 100%);
  color: var(--chalk);
  padding: 22px 20px 20px;
  position: relative;
  overflow: hidden;
}
.header::after {
  content: "";
  position: absolute;
  right: -30px; top: -30px;
  width: 140px; height: 140px;
  border: 3px solid rgba(255,255,255,0.08);
  border-radius: 50%;
}
.header::before {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: repeating-linear-gradient(90deg, var(--line-white) 0 14px, var(--ball) 14px 16px, transparent 16px 24px);
  opacity: 0.45;
}
.eyebrow {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--turf-bright);
  margin: 0 0 4px;
}
h1.title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: 32px;
  letter-spacing: 0.5px;
  margin: 0;
  line-height: 1;
}
.subtitle { font-size: 13px; color: rgba(251,249,244,0.7); margin-top: 6px; }

.tabs {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: 480px;
  background: var(--court-blue-dark);
  display: flex;
  z-index: 20;
  box-shadow: 0 -4px 16px rgba(0,0,0,0.2);
}
.tab {
  flex: 1;
  text-align: center;
  padding: 12px 4px 10px;
  color: rgba(251,249,244,0.5);
  font-size: 10px;
  font-family: 'Space Mono', monospace;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  cursor: pointer;
  border-top: 2px solid transparent;
  transition: color 0.15s;
  position: relative;
}
.tab .icon { font-size: 18px; display: block; margin-bottom: 3px; }
.tab.active { color: var(--turf-bright); border-top-color: var(--ball); }

.content { padding: 18px 16px 20px; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--chalk);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 2px 12px rgba(46,42,92,0.08);
  border: 1px solid rgba(46,42,92,0.06);
}
.card h2 {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--court-blue);
}
label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-soft);
  margin-bottom: 5px;
  margin-top: 12px;
}
label:first-of-type { margin-top: 0; }
input[type=text], input[type=number], select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 7px;
  border: 1.5px solid rgba(46,42,92,0.18);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid var(--turf-bright); outline-offset: 1px; }

.format-grid { display: flex; gap: 8px; margin-top: 6px; }
.format-opt {
  flex: 1;
  border: 1.5px solid rgba(46,42,92,0.18);
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  position: relative;
  transition: border-color 0.15s, background 0.15s;
}
.format-opt.selected {
  border-color: var(--turf);
  background: rgba(0,196,140,0.1);
  color: var(--turf);
}
.format-opt.selected::after {
  content: "";
  position: absolute;
  top: -4px; right: -4px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--ball);
  border: 1.5px solid var(--chalk);
}
.format-opt .fname { font-family: 'Barlow Condensed', sans-serif; font-size: 15px; display:block; }
.format-opt .fdesc { font-size: 10px; opacity: 0.8; display: block; margin-top: 2px; }

.btn {
  display: inline-block;
  background: var(--turf);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
  margin-top: 14px;
  box-shadow: 0 4px 14px rgba(0,196,140,0.32);
  transition: background 0.15s, transform 0.1s;
}
.btn:active { background: var(--turf-bright); transform: translateY(1px); }
.btn.secondary {
  background: transparent;
  color: var(--court-blue);
  border: 1.5px solid var(--court-blue);
  box-shadow: none;
}
.btn.danger { background: var(--score-red); box-shadow: 0 2px 8px rgba(255,77,109,0.25); }
.btn.small { width: auto; padding: 7px 12px; font-size: 12px; margin-top: 0; }

.team-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(46,42,92,0.08);
}
.team-row:last-child { border-bottom: none; }
.team-num {
  background: var(--court-blue);
  color: var(--chalk);
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.team-names { flex: 1; font-size: 13px; font-weight: 600; }
.team-names .vs-players { font-weight: 400; color: var(--ink-soft); font-size: 11px; }
.remove-x {
  color: var(--score-red);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
}

.empty-state {
  text-align: center;
  padding: 30px 16px;
  color: var(--ink-soft);
}
.empty-state .big-icon { font-size: 36px; display: block; margin-bottom: 10px; }
.empty-state .msg { font-size: 13px; }

.match-card {
  background: var(--court-blue);
  border-radius: 10px;
  padding: 0;
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(46,42,92,0.2);
}
.match-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(0,0,0,0.15);
}
.court-tag {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: 13px;
  color: var(--turf-bright);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.round-tag {
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  color: rgba(251,249,244,0.6);
  text-transform: uppercase;
}
.match-body { padding: 14px 14px 12px; color: var(--chalk); }
.matchup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.matchup-row:last-of-type { margin-bottom: 0; }
.team-label { font-size: 14px; font-weight: 600; flex: 1; }
.team-label.winner { color: var(--turf-bright); }
.score-input {
  width: 46px;
  text-align: center;
  padding: 6px 4px;
  border-radius: 6px;
  border: 1.5px solid rgba(251,249,244,0.25);
  background: rgba(251,249,244,0.08);
  color: var(--chalk);
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 15px;
}
.score-input:focus { outline: 1.5px solid var(--turf-bright); background: rgba(251,249,244,0.15); }
.vs-divider { font-family: 'Space Mono', monospace; font-size: 10px; color: rgba(251,249,244,0.4); text-align: center; margin: 4px 0; }

.round-heading {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 17px;
  font-weight: 700;
  color: var(--court-blue);
  margin: 18px 0 10px;
  border-left: 4px solid var(--turf);
  padding-left: 10px;
}
.round-heading:first-child { margin-top: 0; }

table.standings { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.standings th {
  text-align: left;
  font-family: 'Space Mono', monospace;
  font-size: 9.5px;
  text-transform: uppercase;
  color: var(--ink-soft);
  padding: 6px 4px;
  border-bottom: 2px solid rgba(46,42,92,0.15);
}
table.standings td { padding: 9px 4px; border-bottom: 1px solid rgba(46,42,92,0.08); }
table.standings tr:first-child td { font-weight: 700; color: var(--turf); }
.rank-badge {
  display: inline-block;
  width: 20px; height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 50%;
  background: var(--court-blue);
  color: var(--chalk);
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  font-weight: 700;
}
table.standings tr:first-child .rank-badge { background: var(--turf); }
.center-num { text-align: center; }

.setup-summary { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill {
  background: rgba(0,196,140,0.12);
  color: var(--turf);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 20px;
}

.tourn-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(46,42,92,0.08);
}
.tourn-item:last-child { border-bottom: none; }
.tourn-name { font-weight: 700; font-size: 14px; }
.tourn-meta { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }

/* Player photo + avatar */
.player-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid rgba(46,42,92,0.15);
  background: var(--sand);
}
.avatar-placeholder {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--court-blue);
  color: var(--chalk);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}
.avatar-upload-btn {
  font-size: 15px;
  cursor: pointer;
  color: var(--turf);
  padding: 2px 6px;
  flex-shrink: 0;
}

/* Podium */
.podium-wrap {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 10px;
  padding: 16px 4px 6px;
  margin-bottom: 6px;
}
.podium-step {
  text-align: center;
  flex: 1;
  max-width: 110px;
}
.podium-step .p-avatar-wrap { position: relative; display: inline-block; margin-bottom: 8px; }
.podium-step .p-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--chalk);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.podium-step .p-avatar-placeholder {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 800;
  font-size: 22px;
  color: var(--chalk);
  border: 3px solid var(--chalk);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.podium-step .medal {
  position: absolute;
  bottom: -4px; right: -4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  border: 2px solid var(--chalk);
}
.podium-step.first .p-avatar-placeholder { background: linear-gradient(160deg, #E8B923, #C4941A); }
.podium-step.first .medal { background: #E8B923; }
.podium-step.second .p-avatar-placeholder { background: linear-gradient(160deg, #A9B4B8, #7C868A); }
.podium-step.second .medal { background: #9AA5A9; }
.podium-step.third .p-avatar-placeholder { background: linear-gradient(160deg, #C77B45, #A05F31); }
.podium-step.third .medal { background: #C77B45; }
.podium-step .p-block {
  border-radius: 8px 8px 0 0;
  background: var(--court-blue);
  padding: 8px 6px 10px;
}
.podium-step.first .p-block { background: var(--court-blue); height: 74px; }
.podium-step.second .p-block { height: 56px; }
.podium-step.third .p-block { height: 42px; }
.podium-step .p-name {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--chalk);
  line-height: 1.2;
}
.podium-step .p-score {
  font-family: 'Space Mono', monospace;
  font-size: 15px;
  font-weight: 700;
  color: var(--turf-bright);
  margin-top: 2px;
}
.podium-banner {
  text-align: center;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: var(--turf);
  margin-bottom: 4px;
}
table.standings tr.top-3 td { background: rgba(232,185,35,0.06); }
table.standings tr.top-1 .rank-badge { background: #E8B923; }
table.standings tr.top-2 .rank-badge { background: #9AA5A9; color: #fff; }
table.standings tr.top-3 .rank-badge { background: #C77B45; }


.toast {
  position: fixed;
  bottom: 92px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--chalk);
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 12px;
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(46,42,92,0.08);
}
.history-item:last-child { border-bottom: none; }
.history-name { font-weight: 700; font-size: 13.5px; }
.history-meta { font-size: 11px; color: var(--ink-soft); }
