@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap');

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

:root {
  --bg-darkest: #141416;
  --bg-dark: #1a1a1e;
  --bg-mid: #222228;
  --bg-light: #2a2a32;
  --bg-lighter: #35353f;
  --border: #3a3a44;
  --border-light: #4a4a56;
  --text: #e0e0e6;
  --text-dim: #8888a0;
  --text-muted: #5a5a70;

  --patch-orange: #d76b2b;
  --patch-orange-deep: #b55a23;
  --patch-yellow: #e8a020;
  --patch-green: #6aa15c;
  --patch-green-deep: #4e7c43;
  --patch-blue: #3a6bc5;
  --patch-red: #c14a3a;
  --patch-teal: #3b8a8a;
  --patch-cream: #fae7cd;
  --patch-pink: #d6588f;

  --panel-bg: #1d1d22;
  --panel-stitch: #8a7a5a;
  --panel-shadow: 0 8px 22px rgba(0,0,0,0.5), 0 2px 4px rgba(0,0,0,0.35);

  --topbar-h: 68px;
  --radius: 14px;
}

[data-theme="light"] {
  --bg-darkest: #fae7cd;
  --bg-dark: #f5dbb8;
  --bg-mid: #eedcbe;
  --bg-light: #e8d2b0;
  --bg-lighter: #dfc8a2;
  --border: #d4b896;
  --border-light: #c9a97e;
  --text: #2a1f14;
  --text-dim: #6b5a45;
  --text-muted: #a08a70;

  --panel-bg: #f1dfbf;
  --panel-stitch: #b59566;
  --panel-shadow: 0 8px 22px rgba(120,80,40,0.2), 0 2px 4px rgba(120,80,40,0.12);
}

html, body {
  height: 100%;
  background: var(--bg-darkest);
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  overflow-x: hidden;
  min-height: 100vh;
  background-color: var(--bg-darkest);
  background-image:
    radial-gradient(ellipse 80% 60% at 20% 80%, rgba(58,107,197,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 20%, rgba(215,107,43,0.05) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-darkest) 0%, #101016 100%);
  position: relative;
  padding-bottom: 60px;
}
[data-theme="light"] body {
  background-image:
    radial-gradient(ellipse 80% 60% at 20% 80%, rgba(215,107,43,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 20%, rgba(232,160,32,0.05) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-darkest) 0%, #f0d4ac 100%);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
  animation: grain 0.18s steps(1) infinite;
  mix-blend-mode: overlay;
}
[data-theme="light"] body::after { opacity: 0.12; mix-blend-mode: multiply; }

@keyframes grain {
  0%   { background-position: 0% 0%; }
  20%  { background-position: -15% 5%; }
  40%  { background-position: -5% 25%; }
  60%  { background-position: 15% 0%; }
  80%  { background-position: 3% 35%; }
  100% { background-position: 0% 5%; }
}
@media (prefers-reduced-motion: reduce) { body::after { animation: none; } }

/* TOPBAR */
.topbar {
  position: sticky; top: 0; z-index: 10;
  min-height: var(--topbar-h);
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px;
  background: linear-gradient(180deg, var(--bg-dark), rgba(26,26,30,0.9));
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
[data-theme="light"] .topbar { background: linear-gradient(180deg, var(--bg-dark), rgba(245,219,184,0.9)); }

.logo-patch {
  position: relative;
  width: 56px; height: 56px;
  background: var(--panel-bg);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.35);
  padding: 4px;
  flex-shrink: 0;
  transform: rotate(-2deg);
  transition: transform 0.2s;
  isolation: isolate;
}
.logo-patch:hover { transform: rotate(0deg) scale(1.04); }
.logo-patch::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1.5px dashed var(--panel-stitch);
  border-radius: 6px;
  pointer-events: none;
  opacity: 0.6;
}
.logo-patch::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  background-size: 120px 120px;
  opacity: 0.08;
  mix-blend-mode: overlay;
  z-index: -1;
}
.logo-patch img { width: 100%; height: 100%; object-fit: contain; display: block; }

.topbar .brand { display: flex; flex-direction: column; justify-content: center; line-height: 1.1; }
.topbar .app-name {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--patch-orange);
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
  text-transform: uppercase;
}
[data-theme="light"] .topbar .app-name {
  color: var(--patch-orange-deep);
  text-shadow: 0 1px 1px rgba(255,255,255,0.4);
}
.topbar .tagline {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 1.5px;
  margin-top: 2px;
  text-transform: uppercase;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s;
}
.topbar .tagline:hover { color: var(--patch-orange); }

.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.theme-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-mid); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font-size: 15px;
  transition: all 0.15s;
}
.theme-btn:hover {
  background: var(--bg-light); color: var(--patch-orange);
  border-color: var(--patch-orange); box-shadow: 0 0 10px rgba(215,107,43,0.3);
}

/* Back to Game Night kit */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg-mid);
  color: var(--text-dim);
  border: 1.5px dashed var(--border);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  text-decoration: none;
  font-family: inherit;
  flex-shrink: 0;
  transition: all 0.15s;
}
.back-btn:hover {
  border-color: var(--patch-orange);
  color: var(--patch-orange);
  border-style: solid;
  box-shadow: 0 0 10px rgba(215,107,43,0.25);
}
.back-btn-arrow { font-size: 14px; line-height: 1; }
@media (max-width: 640px) {
  .back-btn { padding: 7px 9px; }
  .back-btn-text { display: none; }
}

.ctrl-toggle {
  background: var(--bg-mid);
  color: var(--text-dim);
  border: 1px solid var(--border);
  width: 34px; height: 34px;
  font-size: 14px;
  border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.ctrl-toggle:hover { border-color: var(--patch-orange); color: var(--patch-orange); }
.ctrl-toggle.active {
  background: var(--patch-orange);
  color: #fff;
  border-color: var(--patch-orange);
  box-shadow: 0 0 10px rgba(215,107,43,0.4);
}

/* LAYOUT */
.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 24px 60px;
  position: relative;
  z-index: 2;
}

/* PATCH */
.patch {
  position: relative;
  background: var(--panel-bg);
  border-radius: var(--radius);
  box-shadow: var(--panel-shadow);
  padding: 22px 22px 22px;
  margin-top: 28px;
  isolation: isolate;
}
.patch::before {
  content: '';
  position: absolute;
  inset: 7px;
  border: 2px dashed var(--panel-stitch);
  border-radius: calc(var(--radius) - 4px);
  pointer-events: none;
  opacity: 0.55;
}
.patch::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  opacity: 0.05;
  mix-blend-mode: overlay;
  z-index: -1;
}
.patch > * { position: relative; z-index: 1; }

.patch-tag {
  position: absolute;
  top: -14px; left: 20px;
  padding: 5px 14px 6px;
  font-size: 11px; font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #fff;
  background: var(--tag-color, var(--patch-orange));
  border-radius: 6px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.2);
  z-index: 2;
}
.patch-tag::before {
  content: '';
  position: absolute;
  inset: 3px 5px;
  border: 1px dashed rgba(255,255,255,0.45);
  border-radius: 3px;
  pointer-events: none;
}
.tag-orange { --tag-color: var(--patch-orange); }
.tag-yellow { --tag-color: var(--patch-yellow); color: #2a1f14; }
.tag-yellow::before { border-color: rgba(42,31,20,0.4); }
.tag-green  { --tag-color: var(--patch-green-deep); }
.tag-blue   { --tag-color: var(--patch-blue); }
.tag-red    { --tag-color: var(--patch-red); }
.tag-teal   { --tag-color: var(--patch-teal); }

[hidden] { display: none !important; }

/* SETUP */
.setup-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.setup-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.setup-label-text {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.text-input {
  width: 100%;
  background: var(--bg-darkest);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.text-input:focus { border-color: var(--patch-orange); box-shadow: 0 0 0 3px rgba(215,107,43,0.18); }

.players-input {
  width: 100%;
  min-height: 160px;
  background: var(--bg-darkest);
  color: var(--text);
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: 'Nunito', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.3px;
  line-height: 1.55;
  outline: none;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.players-input:focus {
  border-color: var(--patch-orange);
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(215,107,43,0.18);
}

.players-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.players-meta .spacer { flex: 1; }
.player-count {
  font-size: 11px;
  font-weight: 800;
  color: var(--patch-orange);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 4px 10px;
  background: rgba(215,107,43,0.10);
  border: 1px dashed rgba(215,107,43,0.35);
  border-radius: 5px;
}
.player-count.warn { color: var(--patch-red); background: rgba(193,74,58,0.1); border-color: rgba(193,74,58,0.4); }

/* Format chips */
.format-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.format-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-mid);
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
  font-family: inherit;
  transition: all 0.15s;
}
.format-chip input { display: none; }
.format-chip:hover { border-color: var(--patch-orange); }
.format-chip.active {
  border-color: var(--patch-orange);
  border-style: solid;
  background: rgba(215,107,43,0.12);
  box-shadow: inset 0 0 0 1px rgba(215,107,43,0.3);
}
.chip-icon {
  font-size: 24px;
  width: 32px;
  text-align: center;
  flex-shrink: 0;
}
.chip-text { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.chip-text strong {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.format-chip.active .chip-text strong { color: var(--patch-orange); }
.chip-text small {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.2px;
}

.setup-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
}

.btn {
  background: var(--patch-blue);
  color: #fff;
  border: none;
  padding: 9px 18px;
  font-size: 12px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
  position: relative;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.15s, transform 0.05s;
}
.btn::before {
  content: '';
  position: absolute; inset: 3px;
  border: 1px dashed rgba(255,255,255,0.35);
  border-radius: 3px;
  pointer-events: none;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--patch-orange); }

.big-btn {
  font-size: 16px;
  padding: 14px 28px;
  letter-spacing: 1.5px;
}
.big-btn::before { inset: 5px; border-width: 2px; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 7px 12px;
  font-size: 11px;
  border-radius: 5px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}
.btn-ghost:hover:not(:disabled) { border-color: var(--patch-orange); color: var(--patch-orange); }
.btn-ghost:disabled { opacity: 0.35; cursor: not-allowed; }

/* BRACKET TOOLBAR */
.bracket-shell { margin-top: 24px; }

.bracket-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 0 4px;
}
.bracket-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
.bracket-toolbar-right {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.bracket-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--patch-orange);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin: 0;
}
[data-theme="light"] .bracket-title { color: var(--patch-orange-deep); }

.bracket-format-pill {
  font-size: 10px;
  font-weight: 800;
  background: var(--patch-blue);
  color: #fff;
  padding: 3px 10px;
  border-radius: 5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}

.bracket-progress {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-variant-numeric: tabular-nums;
}

/* CHAMPION BANNER */
.champion-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: linear-gradient(135deg, rgba(232,160,32,0.18), rgba(215,107,43,0.12));
  border: 2px dashed var(--patch-yellow);
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  box-shadow: 0 0 20px rgba(232,160,32,0.25);
  animation: pulseChamp 2s ease-in-out infinite;
}
@keyframes pulseChamp {
  0%, 100% { box-shadow: 0 0 20px rgba(232,160,32,0.25); }
  50%      { box-shadow: 0 0 36px rgba(232,160,32,0.45); }
}
.champion-trophy { font-size: 26px; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4)); }
.champion-text strong { color: var(--patch-yellow); margin-left: 4px; }
[data-theme="light"] .champion-text strong { color: #8a6418; }

/* BRACKET STAGE */
.bracket-stage {
  background: var(--panel-bg);
  border-radius: var(--radius);
  padding: 22px;
  position: relative;
  box-shadow: var(--panel-shadow);
  isolation: isolate;
  overflow-x: auto;
  overflow-y: visible;
  min-height: 200px;
}
.bracket-stage::before {
  content: '';
  position: absolute;
  inset: 7px;
  border: 2px dashed var(--panel-stitch);
  border-radius: calc(var(--radius) - 4px);
  pointer-events: none;
  opacity: 0.55;
}

/* BRACKET (single + double elim) */
.bracket-tree {
  display: flex;
  gap: 28px;
  align-items: stretch;
  min-width: max-content;
  position: relative;
  padding: 4px 4px;
}

.bracket-section-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin: 18px 4px 8px;
}
.bracket-section-label.winners { color: var(--patch-green); }
.bracket-section-label.losers { color: var(--patch-red); }
.bracket-section-label.grand { color: var(--patch-yellow); }

.bracket-round {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 16px;
  min-width: 180px;
  position: relative;
  padding-top: 24px;
}

.bracket-round-title {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  color: var(--round-color, var(--text-dim));
  text-transform: uppercase;
  letter-spacing: 1.4px;
  padding: 3px 8px;
  background: var(--bg-darkest);
  border: 1px dashed var(--round-color, var(--border));
  border-radius: 4px;
  margin: 0 auto;
  width: fit-content;
}

/* MATCH CARD (small patch with dashed border) */
.match-card {
  position: relative;
  background: var(--bg-mid);
  border: 1.5px dashed var(--match-color, var(--border));
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  isolation: isolate;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  flex-shrink: 0;
  min-width: 160px;
  user-select: none;
}
.match-card:hover {
  border-style: solid;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.match-card.complete { border-style: solid; }
.match-card.bye-only { cursor: default; opacity: 0.65; }

.match-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-darkest);
  border-radius: 5px;
  padding: 7px 9px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  position: relative;
  border: 1px solid transparent;
  min-height: 32px;
}
.match-slot.tbd { color: var(--text-muted); font-style: italic; font-weight: 600; }
.match-slot.bye { color: var(--text-muted); font-weight: 600; }
.match-slot.winner {
  border-color: var(--patch-yellow);
  background: rgba(232,160,32,0.12);
  color: var(--text);
  font-weight: 800;
}
.match-slot.winner::after {
  content: '✓';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--patch-yellow);
  font-size: 14px;
  font-weight: 800;
}
.match-slot.loser {
  opacity: 0.45;
  text-decoration: line-through;
}

.match-slot-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 18px;
}
.match-slot-seed {
  font-size: 9px;
  font-weight: 800;
  color: var(--text-muted);
  background: var(--bg-mid);
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: 0.6px;
  flex-shrink: 0;
}

/* Match number badge in corner */
.match-num {
  position: absolute;
  top: -6px;
  left: 6px;
  font-size: 9px;
  font-weight: 800;
  background: var(--match-color, var(--patch-blue));
  color: #fff;
  padding: 1px 6px;
  border-radius: 3px;
  letter-spacing: 0.8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.35);
}

/* Connector lines drawn as overlays via SVG (simpler approach: use pseudo-elements between matches) */
.match-card.has-connector::after {
  content: '';
  position: absolute;
  right: -28px;
  top: 50%;
  width: 28px;
  height: 0;
  border-top: 2px solid var(--connector-color, var(--border-light));
  pointer-events: none;
}
.match-card.has-pair-connector::before {
  content: '';
  position: absolute;
  right: -16px;
  height: var(--pair-h, 100%);
  width: 12px;
  border-top: 2px solid var(--connector-color, var(--border-light));
  border-right: 2px solid var(--connector-color, var(--border-light));
  border-bottom: 2px solid var(--connector-color, var(--border-light));
  border-radius: 0 6px 6px 0;
  pointer-events: none;
}

/* ROUND ROBIN */
.roundrobin-wrap {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.standings-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 4px;
  font-family: 'Nunito', sans-serif;
}
.standings-table th {
  font-size: 10px;
  font-weight: 800;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 10px;
  text-align: center;
  background: var(--bg-mid);
  border-radius: 4px;
}
.standings-table th.player-col { text-align: left; min-width: 140px; padding-left: 14px; }
.standings-table td {
  padding: 10px 10px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  background: var(--bg-mid);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.standings-table td.player-cell {
  text-align: left;
  padding-left: 14px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.standings-table tr.leader-row td.player-cell { color: var(--patch-yellow); }
.standings-table tr.leader-row td.player-cell::before {
  content: '🏆';
  margin-right: 6px;
}
[data-theme="light"] .standings-table tr.leader-row td.player-cell { color: #8a6418; }

.rr-matches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}
.rr-match {
  background: var(--bg-mid);
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.rr-match.complete { border-style: solid; border-color: var(--patch-orange); }
.rr-match-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  transition: background 0.12s;
  min-height: 32px;
  position: relative;
}
.rr-match-row:hover { background: var(--bg-darkest); }
.rr-match-row.winner {
  color: var(--patch-yellow);
  font-weight: 800;
}
.rr-match-row.winner::after {
  content: '✓';
  position: absolute;
  right: 8px;
  color: var(--patch-yellow);
}
.rr-match-row.loser { opacity: 0.5; text-decoration: line-through; }
.rr-vs {
  display: block;
  text-align: center;
  font-size: 9px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 2px 0;
}

/* CONFETTI */
.confetti-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9998;
}
.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  opacity: 0.95;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0%   { transform: translate3d(0,0,0) rotate(0deg); opacity: 1; }
  100% { transform: translate3d(var(--dx, 0), 110vh, 0) rotate(var(--rot, 720deg)); opacity: 0.9; }
}

/* TOAST */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(-160px);
  background: var(--panel-bg);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px dashed var(--patch-orange);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 100;
  pointer-events: none;
  box-shadow: var(--panel-shadow);
  opacity: 0;
  visibility: hidden;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
}

/* TOUR / PROMPT MODAL */
.picker-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.tour-modal {
  position: relative;
  background: var(--panel-bg);
  border-radius: var(--radius);
  padding: 28px 22px 22px;
  box-shadow: var(--panel-shadow);
  isolation: isolate;
  max-width: 460px;
  width: 100%;
}
.tour-modal::before {
  content: '';
  position: absolute;
  inset: 7px;
  border: 2px dashed var(--panel-stitch);
  border-radius: calc(var(--radius) - 4px);
  pointer-events: none;
  opacity: 0.55;
}
.tour-modal-tag {
  position: absolute;
  top: -14px; left: 20px;
  padding: 5px 14px 6px;
  font-size: 11px; font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: #fff;
  background: var(--patch-orange);
  border-radius: 6px;
  box-shadow: 0 3px 8px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.2);
  z-index: 2;
}
.tour-modal-tag::before {
  content: '';
  position: absolute;
  inset: 3px 5px;
  border: 1px dashed rgba(255,255,255,0.45);
  border-radius: 3px;
  pointer-events: none;
}
.tour-modal-close {
  position: absolute;
  top: 6px; right: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 26px; height: 26px;
  font-size: 16px;
  border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  z-index: 2;
  cursor: pointer;
  font-family: inherit;
}
.tour-modal-close:hover { color: var(--patch-red); border-color: var(--patch-red); }

.tour-slide {
  text-align: center;
  padding: 10px 4px 18px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.tour-icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 14px;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.3));
}
.tour-title {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 18px;
  color: var(--patch-orange);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.4);
}
[data-theme="light"] .tour-title { color: var(--patch-orange-deep); text-shadow: none; }
.tour-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  font-weight: 600;
  max-width: 380px;
  letter-spacing: 0.2px;
}
.tour-body strong { color: var(--patch-orange); }
[data-theme="light"] .tour-body strong { color: var(--patch-orange-deep); }

.tour-dots { display: flex; justify-content: center; gap: 6px; margin: 10px 0 14px; }
.tour-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--bg-light);
  border: 1px solid var(--border);
  transition: all 0.15s;
  cursor: pointer;
  padding: 0;
}
.tour-dot.active {
  background: var(--patch-orange);
  border-color: var(--patch-orange);
  width: 22px;
  border-radius: 4px;
}
.tour-dot:hover:not(.active) { border-color: var(--patch-orange); }

.tour-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}
.tour-skip {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  padding: 8px 12px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: inherit;
  cursor: pointer;
}
.tour-skip:hover { color: var(--patch-red); }
.tour-nav-btns { display: flex; gap: 6px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--patch-orange);
  border-radius: 5px;
  border: 2px solid var(--bg-darkest);
}
::-webkit-scrollbar-thumb:hover { background: var(--patch-orange-deep); }

/* RESPONSIVE */
@media (max-width: 640px) {
  .topbar { padding: 8px 12px; gap: 10px; }
  .logo-patch { width: 48px; height: 48px; }
  .topbar .app-name { font-size: 18px; letter-spacing: 1.5px; }
  .topbar .right { gap: 4px; }
  .ctrl-toggle, .theme-btn { width: 32px; height: 32px; font-size: 13px; }
  .app { padding: 18px 10px 60px; }
  .patch { padding: 22px 14px 16px; }
  .bracket-toolbar {
    padding: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .bracket-toolbar-left, .bracket-toolbar-right { width: 100%; }
  .bracket-toolbar-left { gap: 8px; }
  .bracket-toolbar-right { justify-content: flex-start; }
  .bracket-title { font-size: 16px; }
  .bracket-stage { padding: 16px 12px; }
  .bracket-round { min-width: 150px; gap: 10px; }
  .match-card { min-width: 140px; padding: 5px; }
  .match-slot { font-size: 12px; padding: 6px 8px; min-height: 28px; }
  .big-btn { font-size: 14px; padding: 12px 22px; width: 100%; }
}

/* PRINT */
@media print {
  .topbar, .toast, .confetti-wrap, .picker-backdrop,
  .setup-patch, .bracket-toolbar-right, body::after { display: none !important; }
  body { background: white !important; color: #111 !important; padding: 0 !important; }
  .bracket-stage {
    background: white !important;
    box-shadow: none !important;
    border: 1px solid #999;
    overflow: visible !important;
  }
  .bracket-stage::before { display: none; }
  .match-card { background: white !important; border-color: #555 !important; box-shadow: none !important; }
  .match-slot { background: #f5f5f5 !important; color: #111 !important; }
  .match-slot.winner { background: #fff7d8 !important; color: #111 !important; }
  .match-slot.loser { color: #888 !important; }
  .bracket-title { color: #111 !important; }
  .standings-table th, .standings-table td { background: white !important; color: #111 !important; border-bottom: 1px solid #ccc !important; }
  .champion-banner { background: #fff7d8 !important; color: #111 !important; box-shadow: none !important; animation: none !important; }
  .champion-text strong { color: #b58814 !important; }
}
