*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #06101c;
  --bg-2: #0b1627;
  --surface: rgba(10, 18, 31, 0.94);
  --surface-2: rgba(13, 24, 42, 0.95);
  --surface-3: rgba(18, 33, 56, 0.96);
  --surface-4: rgba(23, 41, 70, 0.98);
  --border: rgba(146, 167, 199, 0.16);
  --border-strong: rgba(96, 165, 250, 0.34);
  --text: #ecf4ff;
  --muted: #9eb2d3;
  --muted-2: #7891b7;
  --accent: #3b82f6;
  --accent-2: #22d3ee;
  --accent-3: #60a5fa;
  --success: #34d399;
  --red: #f87171;
  --gold: #fbbf24;
  --silver: #cbd5e1;
  --bronze: #fb923c;
  --shadow: 0 22px 60px rgba(1, 8, 18, 0.46);
  --radius: 22px;
  --radius-sm: 16px;
  --t: 0.2s ease;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background:
    radial-gradient(circle at 0% 0%, rgba(59, 130, 246, 0.18), transparent 24%),
    radial-gradient(circle at 100% 0%, rgba(34, 211, 238, 0.12), transparent 18%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
}

img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

.shell {
  width: min(1700px, calc(100vw - 32px));
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(4, 10, 18, 0.86);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(146, 167, 199, 0.1);
}

.topbar-inner {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.wdv-logo-frame {
  width: 108px;
  height: 54px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.02));
  border: 1px solid rgba(146, 167, 199, 0.14);
  padding: 0.55rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.wdv-logo {
  max-height: 100%;
  width: auto;
  object-fit: contain;
}

.logo-fallback .wdv-logo { opacity: 0.08; }
.logo-fallback-text {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  letter-spacing: 0.18em;
  font-size: 0.86rem;
  color: rgba(255,255,255,0.5);
}
.logo-fallback .logo-fallback-text { display: flex; }

.brand-kicker,
.section-kicker,
.stat-label,
.rail-label,
.sub-section h3,
.players-head h3,
.creator-topline {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: #91b8ff;
  font-weight: 800;
}

.brand-title {
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-chip,
.topbar-link,
.pill-note,
.sidebar-pill,
.hero-meta span,
.summary-chip,
.summary-stat,
.players-sub {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  border-radius: 999px;
  border: 1px solid rgba(96, 165, 250, 0.18);
  background: rgba(59, 130, 246, 0.1);
  color: #d8ecff;
  padding: 0.45rem 0.82rem;
  font-size: 0.79rem;
  font-weight: 700;
}

.topbar-link {
  background: rgba(255,255,255,0.04);
}

.app-shell {
  padding: 1.2rem 0 2rem;
}

.card {
  background: linear-gradient(180deg, rgba(12, 21, 36, 0.96), rgba(9, 16, 29, 0.98));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.masthead {
  overflow: hidden;
  position: relative;
  margin-bottom: 1rem;
  padding: 1.35rem 1.45rem;
}

.masthead::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 10% 20%, rgba(59,130,246,0.17), transparent 26%),
    radial-gradient(circle at 88% 14%, rgba(34,211,238,0.12), transparent 20%),
    linear-gradient(110deg, rgba(255,255,255,0.03), transparent 42%);
  pointer-events: none;
}

.masthead-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(420px, 0.95fr);
  gap: 1.2rem;
  align-items: center;
}

.masthead-copy h1 {
  margin-top: 0.4rem;
  font-size: clamp(2rem, 2.9vw, 3.45rem);
  line-height: 1.02;
  letter-spacing: -0.05em;
  max-width: 14ch;
}

.lead {
  margin-top: 0.8rem;
  color: var(--muted);
  font-size: 1rem;
  max-width: 65ch;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1.15rem;
}

.masthead-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.stat-card {
  min-height: 150px;
  padding: 1rem;
  border-radius: 18px;
  border: 1px solid rgba(146, 167, 199, 0.12);
  background: linear-gradient(180deg, rgba(18, 31, 52, 0.9), rgba(12, 22, 38, 0.98));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.stat-card strong {
  display: block;
  font-size: 1.12rem;
  line-height: 1.18;
}

.stat-card small {
  color: var(--muted);
  font-size: 0.84rem;
}

.accent-card {
  background: linear-gradient(135deg, rgba(25, 56, 108, 0.88), rgba(14, 30, 56, 0.98));
  border-color: rgba(96, 165, 250, 0.26);
}

.workspace {
  display: grid;
  grid-template-columns: 370px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.sidebar-column {
  position: sticky;
  top: 98px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.main-column {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.dashboard-rail {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.rail-card {
  border-radius: 18px;
  padding: 1rem 1.05rem;
  background: linear-gradient(180deg, rgba(14, 25, 43, 0.95), rgba(11, 19, 34, 0.98));
  border: 1px solid rgba(146, 167, 199, 0.12);
  min-height: 116px;
}

.rail-card strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1rem;
}

.rail-card small {
  display: block;
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.control-panel,
.team-panel,
.progress-panel,
.creator-panel,
.empty-state,
#standingsSection,
#step4 {
  padding: 1.15rem;
}

.section-head-row,
.results-header,
.sidebar-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
}

.section-head-row h2,
.results-header h2,
.sidebar-head-row h2,
.control-panel h2,
.empty-state h2 {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-top: 0.35rem;
  font-size: 1.22rem;
  letter-spacing: -0.02em;
}

.compact-head {
  margin-bottom: 0.95rem;
}

.section-intro,
.hint,
#analysisStatusText,
.microcopy,
.empty-grid span,
.creator-panel p {
  color: var(--muted);
  font-size: 0.9rem;
}

.step-num {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 900;
  font-size: 0.78rem;
  box-shadow: 0 8px 20px rgba(34, 211, 238, 0.2);
}

.field-stack {
  margin-top: 1rem;
}

.form-stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}

.field label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted-2);
  font-size: 0.75rem;
  font-weight: 800;
}

input[type="text"],
select {
  width: 100%;
  background: rgba(18, 31, 54, 0.96);
  border: 1px solid rgba(146, 167, 199, 0.14);
  border-radius: 14px;
  padding: 0.82rem 0.92rem;
  color: var(--text);
  font-size: 0.96rem;
  font-family: inherit;
  transition: border-color var(--t), box-shadow var(--t), transform var(--t);
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: rgba(96, 165, 250, 0.52);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
}

.radio-group {
  display: grid;
  gap: 0.65rem;
}

.radio-opt {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 0.95rem;
  border-radius: 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(146, 167, 199, 0.12);
  cursor: pointer;
  transition: border-color var(--t), background var(--t), transform var(--t);
}

.radio-opt input {
  accent-color: var(--accent);
  transform: scale(1.06);
}

.radio-opt span {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.radio-opt strong {
  font-size: 0.96rem;
}

.radio-opt small {
  color: var(--muted);
  font-size: 0.81rem;
}

.radio-opt:hover,
.radio-opt:has(input:checked) {
  border-color: var(--border-strong);
  background: linear-gradient(180deg, rgba(59,130,246,0.12), rgba(34,211,238,0.06));
}

.action-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-top: 1rem;
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.88rem 1.3rem;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.92rem;
  cursor: pointer;
  transition: transform var(--t), box-shadow var(--t), background var(--t), color var(--t), border-color var(--t), opacity var(--t);
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 14px 28px rgba(34, 211, 238, 0.16);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px rgba(34, 211, 238, 0.22);
}

.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-outline {
  color: #d8ecff;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(96,165,250,0.32);
}

.btn-outline:hover {
  background: rgba(59,130,246,0.12);
}

.mini-spinner,
.big-spinner {
  border-radius: 999px;
  border: 3px solid rgba(146, 167, 199, 0.2);
  border-top-color: var(--accent-2);
  animation: spin 0.9s linear infinite;
}

.mini-spinner { width: 24px; height: 24px; }
.big-spinner {
  width: 52px;
  height: 52px;
  border-width: 4px;
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.1);
}

@keyframes spin { to { transform: rotate(360deg); } }

.error {
  margin-top: 0.85rem;
  padding: 0.85rem 0.95rem;
  border-radius: 14px;
  background: rgba(248, 113, 113, 0.1);
  color: #ffd3d3;
  border: 1px solid rgba(248, 113, 113, 0.16);
}

.team-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.6rem;
  margin-top: 0.9rem;
  max-height: 380px;
  overflow: auto;
  padding-right: 0.15rem;
}

.team-btn {
  width: 100%;
  border: 1px solid rgba(146, 167, 199, 0.12);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(18, 31, 53, 0.95), rgba(12, 22, 38, 0.98));
  color: var(--text);
  padding: 0.92rem 1rem;
  text-align: left;
  cursor: pointer;
  transition: transform var(--t), border-color var(--t), background var(--t), box-shadow var(--t);
}

.team-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: rgba(96, 165, 250, 0.32);
  box-shadow: 0 16px 24px rgba(2, 8, 18, 0.2);
}

.team-btn:disabled { opacity: 0.55; cursor: wait; }

.team-btn.active {
  border-color: rgba(34, 211, 238, 0.42);
  background: linear-gradient(180deg, rgba(24, 46, 80, 0.98), rgba(13, 29, 50, 0.98));
}

.team-btn-name {
  display: block;
  font-weight: 800;
  font-size: 0.95rem;
}

.team-btn-sub {
  display: block;
  margin-top: 0.22rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.team-btn-arrow {
  float: right;
  opacity: 0.7;
}

.sidebar-pill-live { background: rgba(52, 211, 153, 0.12); color: #c7ffe6; border-color: rgba(52,211,153,0.2); }

.loading-state {
  display: flex;
  gap: 0.9rem;
  align-items: center;
  padding: 1rem;
  border-radius: 18px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(146, 167, 199, 0.1);
}

.compact-loading-state {
  margin-top: 0.9rem;
}

#analysisTeamLabel {
  display: block;
  margin-bottom: 0.22rem;
  font-size: 0.98rem;
}

.log-box {
  margin-top: 0.9rem;
  background: rgba(4, 11, 20, 0.6);
  border: 1px solid rgba(146, 167, 199, 0.12);
  border-radius: 16px;
  padding: 0.9rem 0.95rem;
  font-size: 0.83rem;
  font-family: 'Consolas', 'SFMono-Regular', monospace;
  color: #c5d7ef;
  max-height: 220px;
  overflow: auto;
  line-height: 1.65;
}

.creator-panel {
  background: linear-gradient(180deg, rgba(16, 30, 52, 0.98), rgba(9, 19, 35, 0.98));
}

.creator-brand {
  margin-top: 0.3rem;
  font-size: 1.2rem;
  font-weight: 900;
}

.creator-panel p {
  margin-top: 0.7rem;
}

.creator-links {
  margin-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  color: #d3e8ff;
  font-size: 0.84rem;
}

.creator-links a {
  font-weight: 800;
}

.empty-state {
  min-height: 220px;
}

.empty-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
}

.empty-grid article {
  border-radius: 18px;
  padding: 1rem;
  border: 1px solid rgba(146, 167, 199, 0.12);
  background: linear-gradient(180deg, rgba(16, 28, 49, 0.95), rgba(11, 19, 35, 0.98));
}

.empty-grid strong {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.96rem;
}

.tbl-wrap {
  overflow-x: auto;
  border-radius: 18px;
  border: 1px solid rgba(146, 167, 199, 0.12);
  background: rgba(5, 11, 21, 0.42);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th {
  padding: 0.82rem 0.95rem;
  text-align: left;
  font-size: 0.71rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted-2);
  background: rgba(18, 31, 53, 0.98);
  border-bottom: 1px solid rgba(146, 167, 199, 0.12);
  white-space: nowrap;
}

td {
  padding: 0.85rem 0.95rem;
  border-bottom: 1px solid rgba(146, 167, 199, 0.08);
  vertical-align: top;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(59,130,246,0.05); }
tr.rank-1 td:first-child { color: var(--gold); font-weight: 900; }
tr.rank-2 td:first-child { color: var(--silver); font-weight: 800; }
tr.rank-3 td:first-child { color: var(--bronze); font-weight: 800; }
tr.rank-1 { background: rgba(251,191,36,0.04); }
tr.rank-2 { background: rgba(203,213,225,0.03); }
tr.rank-3 { background: rgba(251,146,60,0.03); }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

.summary-card {
  min-height: 120px;
  padding: 0.95rem 1rem;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(18, 31, 53, 0.95), rgba(11, 21, 36, 0.98));
  border: 1px solid rgba(96, 165, 250, 0.12);
}

.summary-card label {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.68rem;
  font-weight: 800;
}

.summary-card strong {
  display: block;
  font-size: 1.06rem;
  line-height: 1.2;
}

.summary-card span {
  display: block;
  margin-top: 0.28rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.summary-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.stat-block {
  margin-bottom: 0;
}

.players-block {
  margin-top: 1.1rem;
}

.players-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}

#playerResults {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.player-card {
  padding: 1rem;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(20, 34, 58, 0.96), rgba(11, 22, 38, 0.98));
  border: 1px solid rgba(146, 167, 199, 0.12);
}
.player-card.rank-1 { border-color: rgba(251,191,36,0.22); }
.player-card.rank-2 { border-color: rgba(203,213,225,0.18); }
.player-card.rank-3 { border-color: rgba(251,146,60,0.2); }

.player-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
}

.player-name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 800;
  font-size: 1rem;
}

.player-rank-badge {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(59,130,246,0.16);
  font-size: 0.9rem;
}

.player-count {
  background: rgba(59,130,246,0.12);
  border: 1px solid rgba(96,165,250,0.15);
  color: #d2eaff;
  padding: 0.28rem 0.62rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.player-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.8rem;
}

.summary-chip {
  background: rgba(255,255,255,0.04);
  padding: 0.34rem 0.62rem;
  font-size: 0.75rem;
}

.dist-bars {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.dist-item {
  min-width: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28rem;
}

.dist-pct,
.dist-label {
  color: var(--muted);
  font-size: 0.72rem;
}

.dist-pos {
  font-size: 0.77rem;
  font-weight: 800;
}

.dist-bar-wrap {
  width: 38px;
  height: 76px;
  border-radius: 9px;
  background: rgba(5, 11, 21, 0.66);
  border: 1px solid rgba(146, 167, 199, 0.08);
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.dist-bar {
  width: 100%;
  min-height: 2px;
  border-radius: 9px 9px 0 0;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
}

.match-avg-list {
  margin-top: 0.95rem;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(146, 167, 199, 0.1);
}

.match-avg-title,
.match-avg-head,
.match-avg-row {
  display: grid;
  grid-template-columns: 1.1fr 0.7fr 0.85fr;
  gap: 0.6rem;
  padding: 0.72rem 0.82rem;
}

.match-avg-title {
  background: rgba(255,255,255,0.03);
  font-weight: 800;
}

.match-avg-head {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted-2);
  font-size: 0.67rem;
  font-weight: 800;
  background: rgba(18, 31, 53, 0.98);
  border-top: 1px solid rgba(146, 167, 199, 0.08);
  border-bottom: 1px solid rgba(146, 167, 199, 0.08);
}

.match-avg-grid {
  background: rgba(5, 11, 21, 0.22);
}

.match-avg-row {
  border-bottom: 1px solid rgba(146, 167, 199, 0.06);
  font-size: 0.83rem;
}
.match-avg-row:last-child { border-bottom: none; }

@media (min-width: 1600px) {
  #playerResults {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1280px) {
  .shell {
    width: min(100vw - 24px, 1500px);
  }

  .workspace {
    grid-template-columns: 340px minmax(0, 1fr);
  }

  .summary-grid,
  .empty-grid,
  .masthead-stats,
  .dashboard-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #playerResults {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1080px) {
  .masthead-grid,
  .workspace,
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .sidebar-column {
    position: static;
  }

  .main-column {
    order: 2;
  }

  .sidebar-column {
    order: 1;
  }
}

@media (max-width: 720px) {
  .shell {
    width: calc(100vw - 14px);
  }

  .topbar-inner,
  .section-head-row,
  .results-header,
  .sidebar-head-row,
  .player-header,
  .players-head,
  .loading-state {
    flex-direction: column;
    align-items: stretch;
  }

  .brand-wrap {
    align-items: flex-start;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .masthead-stats,
  .dashboard-rail,
  .empty-grid,
  .summary-grid,
  .analysis-grid,
  #playerResults,
  .form-stack {
    grid-template-columns: 1fr;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .action-row {
    flex-wrap: wrap;
  }

  .wdv-logo-frame {
    width: 92px;
    height: 50px;
  }

  .match-avg-title,
  .match-avg-head,
  .match-avg-row {
    grid-template-columns: 1fr 0.7fr 0.8fr;
  }
}
