:root {
  --bg: #0b0f19;
  --bg-soft: #111828;
  --surface: rgba(16, 23, 37, 0.88);
  --surface-strong: rgba(21, 29, 46, 0.96);
  --surface-2: #182235;
  --surface-3: #202c43;
  --border: rgba(118, 140, 178, 0.18);
  --border-strong: rgba(143, 168, 220, 0.28);
  --text: #eef2ff;
  --text-muted: #93a0be;
  --accent: #7c5cff;
  --accent-2: #4cc9f0;
  --accent-glow: rgba(124, 92, 255, 0.28);
  --win: #3ddc97;
  --win-bg: rgba(61, 220, 151, 0.14);
  --warn: #f8c145;
  --warn-bg: rgba(248, 193, 69, 0.16);
  --danger: #ff7b7b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --radius: 20px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(124, 92, 255, 0.22), transparent 30%),
    radial-gradient(circle at bottom right, rgba(76, 201, 240, 0.12), transparent 28%),
    linear-gradient(180deg, #0b0f19 0%, #0f1422 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: radial-gradient(circle at center, black 45%, transparent 100%);
  pointer-events: none;
  opacity: 0.35;
}

button,
input {
  font: inherit;
}

button {
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
  transform: none;
}

button:not(:disabled):active {
  transform: translateY(1px);
}

.hidden {
  display: none !important;
}

.app {
  position: relative;
  z-index: 1;
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 18px 14px 32px;
}

.hero,
.admin-panel,
.bracket-section,
.champion-banner,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero {
  border-radius: 28px;
  padding: 18px;
  margin-bottom: 16px;
}

.hero-top,
.hero-main,
.panel-header,
.section-head,
.hero-actions,
.admin-actions,
.score-row,
.branches-row,
.legend {
  display: flex;
}

.hero-top,
.panel-header,
.section-head {
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hero-top-actions {
  justify-content: flex-end;
}

.hero-main {
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 18px;
}

.hero-copy {
  flex: 1 1 380px;
}

.hero-actions {
  gap: 10px;
  align-items: center;
}

.hero-cards {
  flex: 1 1 360px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
}

.eyebrow,
.panel-kicker {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.logo {
  margin-top: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: #ffffff;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-badge.draft {
  background: rgba(147, 160, 190, 0.16);
  border-color: rgba(147, 160, 190, 0.22);
}

.status-badge.active {
  background: var(--warn-bg);
  border-color: rgba(248, 193, 69, 0.24);
  color: var(--warn);
}

.status-badge.finished {
  background: var(--win-bg);
  border-color: rgba(61, 220, 151, 0.26);
  color: var(--win);
}

.tournament-name {
  margin-top: 14px;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
}

.tournament-meta {
  margin-top: 10px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-muted);
  max-width: 720px;
}

.stat-card {
  border-radius: 20px;
  padding: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent),
    var(--surface-strong);
  border: 1px solid var(--border);
}

.stat-label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-value {
  display: block;
  margin-top: 10px;
  font-size: 18px;
  line-height: 1.3;
}

.btn-icon,
.btn-toolbar,
.btn-small,
.btn-primary,
.btn-ghost,
.pick-player {
  border-radius: 14px;
  cursor: pointer;
}

.btn-icon,
.btn-toolbar,
.btn-small,
.btn-ghost,
.pick-player {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface-2);
}

.btn-icon:hover,
.btn-toolbar:hover,
.btn-small:hover,
.btn-ghost:hover,
.pick-player:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}

.btn-icon {
  width: 46px;
  height: 46px;
  font-size: 19px;
}

.btn-toolbar {
  min-height: 46px;
  padding: 0 16px;
  font-weight: 600;
}

.admin-panel,
.bracket-section,
.champion-banner,
.empty-state {
  border-radius: 24px;
  padding: 18px;
  margin-bottom: 16px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.input {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid var(--border);
  outline: none;
}

.input:focus {
  border-color: rgba(124, 92, 255, 0.5);
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.16);
}

.branches-row {
  flex-wrap: wrap;
  gap: 8px;
}

.btn-small {
  min-width: 58px;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 700;
}

.btn-small.active,
.btn-primary {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  box-shadow: none;
}

.btn-primary {
  min-height: 48px;
  padding: 0 18px;
  font-weight: 600;
}

.btn-small.active:hover,
.btn-primary:hover {
  background: #2a3854;
  border-color: var(--border-strong);
  filter: none;
}

.hint,
.modal-text {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.admin-actions {
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.admin-actions .btn-primary,
.admin-actions .btn-ghost {
  flex: 1 1 220px;
  min-height: 44px;
}

.admin-panel .input:focus {
  border-color: var(--border-strong);
  box-shadow: none;
}

.section-head {
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.section-head h2,
.panel-header h2 {
  margin-top: 6px;
  font-size: 24px;
}

.legend {
  flex-wrap: wrap;
  gap: 10px 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.live {
  background: #b9964f;
}

.legend-dot.win {
  background: #4f8f73;
}

.loading,
.empty-state {
  text-align: center;
}

.loading {
  padding: 64px 24px;
  color: var(--text-muted);
}

.spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 14px;
  border: 3px solid rgba(255, 255, 255, 0.08);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty-state {
  padding: 54px 22px;
}

.empty-icon {
  font-size: 54px;
  margin-bottom: 12px;
}

.empty-state h2 {
  font-size: 24px;
  margin-bottom: 10px;
}

.empty-state p {
  color: var(--text-muted);
  line-height: 1.5;
  max-width: 620px;
  margin: 0 auto;
}

.bracket-wrap {
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

.svg-container {
  display: inline-block;
  min-width: 100%;
}

.bracket-svg {
  display: block;
  width: 100%;
  min-width: 960px;
  height: auto;
}

.champion-banner {
  background:
    radial-gradient(circle at top left, rgba(124, 92, 255, 0.22), transparent 38%),
    linear-gradient(135deg, rgba(19, 30, 48, 0.94), rgba(18, 28, 43, 0.9));
}

.champion-copy {
  text-align: center;
}

.champion-chip {
  display: inline-flex;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--warn);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.placements-line {
  margin-top: 14px;
  font-size: 18px;
  line-height: 1.6;
  font-weight: 700;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none !important;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 16, 0.72);
}

.modal-content {
  position: relative;
  width: min(100%, 520px);
  border-radius: 24px 24px 0 0;
  background: #121a29;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 22px 18px max(18px, env(safe-area-inset-bottom));
}

.modal-content .input:focus {
  border-color: var(--border-strong);
  box-shadow: none;
}

.modal-content h3 {
  font-size: 22px;
}

.modal-text {
  margin: 10px 0 14px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions .btn-primary,
.modal-actions .btn-ghost {
  flex: 1;
  min-height: 44px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.modal-actions .btn-ghost {
  color: var(--text-muted);
}

.modal-actions .btn-ghost:hover {
  color: var(--text);
}

.modal-players {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.pick-player {
  padding: 14px;
  text-align: left;
  font-weight: 600;
}

.pick-player.selected {
  background: var(--win-bg);
  border-color: rgba(61, 220, 151, 0.4);
  color: var(--win);
}

.score-row {
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.score-row label {
  color: var(--text-muted);
}

.input-score {
  width: 68px;
  min-height: 44px;
  text-align: center;
}

.bracket-svg .g-export-bg {
  fill: #0b0f19;
}

.bracket-svg .g-round-chip {
  fill: rgba(255, 255, 255, 0.03);
  stroke: rgba(154, 167, 191, 0.14);
  stroke-width: 1;
}

.bracket-svg .g-round-chip-text {
  fill: #b2bdd3;
  font: 700 11px Inter, system-ui, sans-serif;
  letter-spacing: 0.12em;
}

.bracket-svg .g-line {
  stroke: rgba(132, 144, 167, 0.42);
  stroke-width: 1.6;
}

.bracket-svg .g-card {
  fill: rgba(16, 22, 35, 0.98);
  stroke: rgba(122, 135, 160, 0.22);
  stroke-width: 1.2;
}

.bracket-svg .g-card-third {
  fill: rgba(18, 24, 38, 0.98);
}

.bracket-svg .g-card-place {
  fill: rgba(14, 18, 28, 0.92);
  stroke: rgba(122, 135, 160, 0.16);
}

.bracket-svg .g-live .g-card {
  stroke: rgba(193, 160, 91, 0.72);
}

.bracket-svg .g-ready .g-card {
  stroke: rgba(118, 132, 159, 0.42);
}

.bracket-svg .g-divider {
  stroke: rgba(130, 149, 184, 0.12);
  stroke-width: 1;
}

.bracket-svg .g-slot-win {
  fill: rgba(68, 108, 88, 0.16);
}

.bracket-svg .g-slot-editable {
  fill: rgba(255, 255, 255, 0.03);
}

.bracket-svg .g-name,
.bracket-svg .g-lose,
.bracket-svg .g-win,
.bracket-svg .g-empty,
.bracket-svg .g-score,
.bracket-svg .g-hint,
.bracket-svg .g-badge,
.bracket-svg .g-section-label {
  font-family: Inter, system-ui, sans-serif;
}

.bracket-svg .g-name {
  fill: #edf1fb;
  font-size: 12.5px;
  font-weight: 600;
}

.bracket-svg .g-lose {
  fill: #7f8aa1;
  font-size: 12.5px;
  font-weight: 500;
}

.bracket-svg .g-win {
  fill: #77b191;
  font-size: 12.5px;
  font-weight: 700;
}

.bracket-svg .g-empty {
  fill: #7b879e;
  font-size: 12px;
  font-weight: 500;
}

.bracket-svg .g-hint {
  fill: #96a1b8;
  font-size: 12px;
  font-weight: 500;
}

.bracket-svg .g-score {
  fill: #c8b07a;
  font-size: 12px;
  font-weight: 700;
}

.bracket-svg .g-badge {
  fill: #7f8ba2;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.bracket-svg .g-section-label {
  fill: #9da8bd;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.bracket-svg .g-hit {
  cursor: pointer;
}

@media (max-width: 900px) {
  .app {
    padding-inline: 10px;
  }

  .hero,
  .admin-panel,
  .bracket-section,
  .champion-banner,
  .empty-state {
    border-radius: 22px;
    padding: 16px;
  }

  .tournament-name {
    font-size: 30px;
  }
}

@media (max-width: 640px) {
  .hero-top,
  .panel-header,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .hero-actions {
    width: 100%;
  }

  .hero-actions .btn-toolbar,
  .hero-actions .btn-icon,
  .panel-header .btn-toolbar {
    flex: 1 1 auto;
  }

  .legend {
    gap: 8px 12px;
  }

  .placements-line {
    font-size: 16px;
  }

  .bracket-svg {
    min-width: 780px;
  }
}
