:root {
  --bg-color: #040611;
  --line-color: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(145, 174, 255, 0.18);
  --glass-bg: rgba(15, 20, 35, 0.65);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-strong: rgba(10, 14, 25, 0.85);
  
  --text-main: #f5f7ff;
  --text-muted: #9aa8ca;
  --accent: #3b82f6;
  --accent-glow: #60a5fa;
  --winner: #10b981;
  --hot: #f43f5e;
  
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-display: 'Outfit', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-sans);
  overscroll-behavior: none;
}

/* Base styling / Effects */
.bg-orb { position: absolute; border-radius: 50%; filter: blur(100px); pointer-events: none; opacity: 0.4; }
.bg-orb--a { width: 300px; height: 300px; top: -50px; left: -100px; background: rgba(59, 130, 246, 0.3); }
.bg-orb--b { width: 400px; height: 400px; bottom: -100px; right: -100px; background: rgba(16, 185, 129, 0.2); }

.bg-grid {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.2;
  background-image: 
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(circle at center, black 40%, transparent 100%);
  -webkit-mask-image: radial-gradient(circle at center, black 40%, transparent 100%);
}

.bg-grain {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.15;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.glass-strong {
  background: var(--glass-strong);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--glass-border);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
}

.eyebrow {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 700;
  color: var(--text-muted);
  margin: 0;
}

/* Map Viewport Area */
.viewport {
  position: absolute;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  touch-action: none;
  cursor: grab;
}
.viewport:active { cursor: grabbing; }

.bracket-scene {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.connector-layer, .nodes-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.connector-layer { overflow: visible; pointer-events: none; }

.connector-line {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.6;
}

.connector-line.is-champion {
  stroke: url(#championGradient);
  stroke-width: 4;
  opacity: 1;
  filter: drop-shadow(0 0 8px rgba(16, 185, 129, 0.4));
}

/* Nodes */
.match-card {
  position: absolute;
  width: 160px;
  height: 60px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line-color);
  background: linear-gradient(180deg, rgba(20, 25, 40, 0.9), rgba(10, 15, 30, 0.95));
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  color: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  outline: none;
  transition: border-color 0.2s, transform 0.2s;
  pointer-events: auto;
}

.match-card:hover { border-color: rgba(255,255,255,0.2); }
.match-card:active { transform: scale(0.97); }

.match-card.is-focused, .match-card:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3), 0 8px 24px rgba(0,0,0,0.6);
}

.match-card.is-champion {
  border-color: rgba(16, 185, 129, 0.5);
  background: linear-gradient(180deg, rgba(20, 40, 30, 0.95), rgba(10, 25, 20, 0.98));
}

.card-teams { font-family: var(--font-display); font-size: 0.85rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.1; margin: 0; }
.card-winner { font-size: 0.7rem; color: var(--text-muted); margin: 0; }
.card-winner-highlight { color: #fff; font-weight: 600; }

.region-label {
  position: absolute;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 900;
  color: rgba(255,255,255,0.04);
  text-transform: uppercase;
  letter-spacing: 0.3em;
  pointer-events: none;
  white-space: nowrap;
}

/* Heads Up Display */
.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(env(safe-area-inset-top), 16px) 16px 0;
  pointer-events: none;
  display: flex;
  justify-content: center;
}

.hud-title-card {
  padding: 10px 20px;
  border-radius: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.hud-title { margin: 0; font-family: var(--font-display); font-size: 1.1rem; font-weight: 800; letter-spacing: -0.02em; }
.hud-subtitle { margin: 0; font-size: 0.75rem; color: var(--text-muted); opacity: 0.8; }

.hud-bottom-actions {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom), 24px);
  right: 24px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fab {
  width: 56px;
  height: 56px;
  border-radius: 28px;
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: white;
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: transform 0.2s, background 0.2s;
  padding: 0;
}

.fab:active { transform: scale(0.92); }
.fab--primary { background: var(--accent); border-color: var(--accent-glow); }

/* Bottom Sheet */
.bottom-sheet {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
}

.bottom-sheet.is-open { pointer-events: auto; }

.bottom-sheet__backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; transition: opacity 0.3s ease; pointer-events: none;
}
.bottom-sheet.is-open .bottom-sheet__backdrop { opacity: 1; pointer-events: auto; }

.bottom-sheet__panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 85dvh;
  border-top-left-radius: 24px; border-top-right-radius: 24px;
  padding: 0 20px 32px;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: auto;
}

.bottom-sheet.is-open .bottom-sheet__panel { transform: translateY(0); }

.bottom-sheet__drag-handle {
  width: 40px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.2);
  margin: 12px auto 16px;
}

.bottom-sheet__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

.icon-btn {
  background: none; border: none; color: var(--text-muted); font-size: 1.25rem;
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; padding: 0;
}
.icon-btn:active { background: rgba(255,255,255,0.1); }

.detail-matchup { font-family: var(--font-display); font-size: 1.5rem; font-weight: 800; margin: 0 0 16px; line-height: 1.1; }

.detail-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.badge { display: inline-flex; padding: 6px 10px; border-radius: 100px; font-size: 0.75rem; font-weight: 600; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.05); }
.badge--winner { background: rgba(16, 185, 129, 0.15); color: #34d399; border-color: rgba(16, 185, 129, 0.3); }

.scrollable { overflow-y: auto; padding-right: 4px; }
.scrollable::-webkit-scrollbar { width: 4px; }
.scrollable::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.text-body { color: var(--text-muted); line-height: 1.6; font-size: 0.95rem; margin: 0 0 20px; }

.detail-highlight {
  display: grid; grid-template-columns: 80px 1fr; gap: 16px; align-items: center;
  background: rgba(0,0,0,0.2); padding: 12px; border-radius: 16px; border: 1px solid rgba(255,255,255,0.05);
}
.highlight-img { width: 80px; height: 80px; border-radius: 12px; object-fit: cover; background: rgba(255,255,255,0.05); }
.highlight-title { margin: 4px 0; font-size: 1.05rem; }
.text-caption { margin: 0; font-size: 0.85rem; color: var(--text-muted); line-height: 1.4; }

/* Desktop overrides */
@media (min-width: 768px) {
  .hud-title-card { padding: 16px 32px; }
  .hud-title { font-size: 1.4rem; }
  .hud-bottom-actions { right: 40px; bottom: 40px; }
  
  .bottom-sheet__panel {
    top: 24px; right: 24px; bottom: 24px; left: auto;
    width: 420px;
    border-radius: 24px;
    max-height: none;
    padding: 24px 32px;
    border: 1px solid var(--glass-border);
    transform: translateX(100%);
  }
  .bottom-sheet.is-open .bottom-sheet__panel { transform: translateX(0); }
  .bottom-sheet__drag-handle { display: none; }
}
