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

:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #333;
  --text: #f0f0f0;
  --text-muted: #888;
  --accent: #4ab3e8;
  --accent2: #e8a44a;
  --winner-glow: rgba(74, 179, 232, 0.4);
  --radius: 8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Helvetica Neue', Arial, sans-serif;
  min-height: 100vh;
}

/* ── HOME PAGE ── */
.home-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 40px 20px;
  max-width: 400px;
  width: 100%;
}

.title {
  font-size: 3.5rem;
  font-weight: 900;
  text-align: center;
  letter-spacing: 0.05em;
  line-height: 1;
  text-transform: uppercase;
}

.title-bracket {
  color: var(--accent);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.divider {
  color: var(--text-muted);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  position: relative;
  width: 100%;
  text-align: center;
}

.divider::before, .divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--border);
}

.divider::before { left: 0; }
.divider::after { right: 0; }

.load-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.key-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.1rem;
  letter-spacing: 0.15em;
  text-align: center;
  text-transform: uppercase;
  outline: none;
}

.key-input:focus { border-color: var(--accent); }
.key-input::placeholder { color: var(--text-muted); letter-spacing: 0.05em; text-transform: none; }

/* ── BUTTONS ── */
.btn {
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}

.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: #000; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-copy { width: auto; padding: 4px 12px; font-size: 0.75rem; background: var(--surface2); color: var(--text); border: 1px solid var(--border); }

/* ── ERRORS ── */
.error-msg { color: #e05a5a; font-size: 0.85rem; text-align: center; }
.hidden { display: none !important; }

/* ── BRACKET PAGE ── */
.bracket-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.back-link { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; }
.back-link:hover { color: var(--text); }

.title-small { font-size: 1.1rem; font-weight: 900; letter-spacing: 0.12em; }

.key-display {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: monospace;
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.1em;
}

.copy-confirm { color: #5adb8a; font-size: 0.75rem; }

/* ── BRACKET CONTAINER ── */
.bracket-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  overflow-x: auto;
  min-height: calc(100vh - 61px);
}

/* ── BRACKET LAYOUT ── */
.bracket-layout {
  display: flex;
  align-items: center;
  gap: 0;
}

.bracket-col {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}

.round-qf { height: 560px; }
.round-sf { height: 280px; }
.round-final { height: 140px; }

.matchup {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 8px 0;
}

.matchup-spacer { flex: 1; }

/* ── COMPETITOR CARD ── */
.competitor {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  width: 190px;
  height: 58px;
  position: relative;
  user-select: none;
}

.competitor:hover:not(.tbd):not(.selected) {
  border-color: var(--accent);
  background: var(--surface2);
}

.competitor.selected {
  border-color: var(--accent);
  background: var(--surface2);
  box-shadow: 0 0 12px var(--winner-glow);
}

.competitor.tbd {
  cursor: default;
  opacity: 0.4;
}

.competitor.eliminated {
  opacity: 0.3;
}

.competitor-img {
  width: 38px;
  height: 38px;
  object-fit: contain;
  border-radius: 50%;
  flex-shrink: 0;
}

.competitor-img-placeholder {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
}

.competitor-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.competitor-seed {
  font-size: 0.62rem;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.competitor-name {
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── BRACKET CONNECTOR LINES ── */
.bracket-line {
  width: 24px;
  align-self: stretch;
  position: relative;
}

/* Vertical bar on the right side (connecting to the next round on the right) */
.bracket-line.line-right::after {
  content: '';
  position: absolute;
  top: 25%;
  bottom: 25%;
  right: 0;
  width: 1px;
  background: #444;
}

/* Horizontal tick going right */
.bracket-line.line-right::before {
  content: '';
  position: absolute;
  height: 1px;
  background: #444;
  width: 100%;
  top: 50%;
}

/* Vertical bar on the left side (connecting from previous round on the right) */
.bracket-line.line-left::after {
  content: '';
  position: absolute;
  top: 25%;
  bottom: 25%;
  left: 0;
  width: 1px;
  background: #444;
}

/* Horizontal tick going left */
.bracket-line.line-left::before {
  content: '';
  position: absolute;
  height: 1px;
  background: #444;
  width: 100%;
  top: 50%;
}

/* ── WINNER MODAL ── */
.winner-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.winner-modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px 36px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.winner-modal-label {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  color: var(--accent2);
  text-transform: uppercase;
  margin-bottom: 24px;
}

.winner-modal-img-wrap {
  margin-bottom: 20px;
}

.winner-modal-img {
  width: 150px;
  height: 150px;
  object-fit: contain;
  border-radius: 50%;
  border: 3px solid var(--accent2);
  box-shadow: 0 0 48px rgba(232, 164, 74, 0.4);
}

.winner-modal-name {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* TBD tooltip */
.competitor.tbd::after {
  content: 'Pick a winner above to unlock';
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: var(--text-muted);
  font-size: 0.72rem;
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}

.competitor.tbd:hover::after { opacity: 1; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ── MOBILE ── */
@media (max-width: 600px) {
  /* Header */
  .bracket-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
  }

  .title-small { font-size: 0.95rem; }

  .key-display {
    font-size: 0.8rem;
    gap: 6px;
  }

  /* Bracket — horizontal scroll with touch support */
  .bracket-container {
    padding: 20px 12px;
    justify-content: flex-start;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
  }

  /* Smaller competitor cards */
  .competitor {
    width: 150px;
    height: 52px;
    padding: 6px 10px;
    gap: 8px;
  }

  .competitor-img { width: 32px; height: 32px; }
  .competitor-img-placeholder { width: 32px; height: 32px; }
  .competitor-name { font-size: 0.78rem; }
  .competitor-seed { font-size: 0.58rem; }

  /* Proportionally shrink bracket column heights */
  .round-qf   { height: 460px; }
  .round-sf   { height: 230px; }
  .round-final { height: 115px; }

  /* Winner modal */
  .winner-modal-box { padding: 36px 24px 28px; }
  .winner-modal-img { width: 120px; height: 120px; }
  .winner-modal-name { font-size: 1.6rem; }

  /* Home page */
  .title { font-size: 2.8rem; }
  .home-container { padding: 32px 20px; }
}
