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

html, body { width: 100%; height: 100%; overflow: hidden; }

body {
  background: #070a14 radial-gradient(1200px 700px at 50% 20%, #101a33 0%, #070a14 70%);
  font-family: "Trebuchet MS", "Segoe UI", Arial, sans-serif;
  color: #fff;
  user-select: none;
}

#app { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; }

#stage { position: relative; }

#game { display: block; width: 100%; height: 100%; border-radius: 8px; box-shadow: 0 30px 90px rgba(0,0,0,.75), 0 0 0 1px rgba(255,255,255,.08); }

#ui { position: absolute; top: 0; left: 0; width: 1280px; height: 720px; transform-origin: top left; }

.hidden { display: none !important; }

#topButtons { position: absolute; top: 16px; right: 16px; display: flex; gap: 12px; z-index: 40; }

.iconBtn {
  width: 48px; height: 48px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25);
  background: rgba(12,18,38,.72);
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
  transition: transform .15s cubic-bezier(.4,0,.2,1), background .15s ease, border-color .15s ease, box-shadow .15s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.iconBtn:hover { transform: scale(1.12); background: rgba(255,140,26,.88); border-color: #fff; box-shadow: 0 8px 20px rgba(255,140,26,.4); }
.iconBtn:active { transform: scale(.92); }
.iconBtn:focus-visible { outline: 3px solid #ffb02e; outline-offset: 3px; }

.screen {
  position: absolute; inset: 0; z-index: 30;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px;
  background: radial-gradient(900px 560px at 50% 38%, rgba(9,14,30,.68) 0%, rgba(5,8,18,.86) 100%);
  backdrop-filter: blur(6px);
  animation: screenIn .35s cubic-bezier(.4,0,.2,1);
}

@keyframes screenIn { from { opacity: 0; transform: scale(1.04); } to { opacity: 1; transform: scale(1); } }

.titleWrap { text-align: center; animation: titleFloat 3.6s ease-in-out infinite; }
@keyframes titleFloat { 0%,100% { transform: translateY(0) rotate(-.4deg); } 50% { transform: translateY(-12px) rotate(.4deg); } }

.gameTitle {
  font-size: 100px; font-weight: 900; font-style: italic; letter-spacing: 2px; line-height: .95;
  color: #fff;
  text-shadow: 0 4px 0 #c2570a, 0 8px 0 #7a3400, 0 18px 40px rgba(0,0,0,.75), 0 0 60px rgba(255,176,46,.15);
  animation: titlePulse 3s ease-in-out infinite;
}
@keyframes titlePulse { 0%,100% { text-shadow: 0 4px 0 #c2570a, 0 8px 0 #7a3400, 0 18px 40px rgba(0,0,0,.75), 0 0 60px rgba(255,176,46,.15); } 50% { text-shadow: 0 4px 0 #c2570a, 0 8px 0 #7a3400, 0 18px 40px rgba(0,0,0,.75), 0 0 80px rgba(255,176,46,.25); } }
.gameTitle em { font-style: italic; color: #ffb02e; }
.gameSubtitle {
  margin-top: 12px; font-size: 24px; font-weight: 800; letter-spacing: 14px; color: #8fd3ff;
  display: flex; align-items: center; gap: 18px; justify-content: center;
  text-shadow: 0 0 20px rgba(143,211,255,.4);
}
.gameSubtitle span { display: inline-block; width: 80px; height: 3px; background: linear-gradient(90deg, transparent, #8fd3ff); }
.gameSubtitle span:last-child { background: linear-gradient(90deg, #8fd3ff, transparent); }

.menuButtons { display: flex; flex-direction: column; gap: 18px; align-items: center; }
.menuButtons.row { flex-direction: row; }

.menuBtn {
  min-width: 340px; padding: 18px 52px;
  font-family: inherit; font-size: 26px; font-weight: 900; letter-spacing: 3px;
  color: #fff; cursor: pointer;
  background: linear-gradient(180deg, #ffb02e 0%, #f97316 55%, #dd5c07 100%);
  border: none; border-radius: 18px;
  border-bottom: 6px solid #9a3d02;
  box-shadow: 0 12px 28px rgba(249,115,22,.4), inset 0 2px 0 rgba(255,255,255,.35), 0 0 0 1px rgba(255,255,255,.1);
  text-shadow: 0 2px 4px rgba(122,52,0,.6);
  transition: transform .15s cubic-bezier(.4,0,.2,1), filter .15s ease, box-shadow .15s ease;
  position: relative;
  overflow: hidden;
}
.menuBtn::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.2), transparent);
  transition: left .5s ease;
}
.menuBtn:hover::before { left: 100%; }
.menuBtn:hover { transform: translateY(-4px) scale(1.03); filter: brightness(1.12); box-shadow: 0 20px 40px rgba(249,115,22,.55), inset 0 2px 0 rgba(255,255,255,.35), 0 0 0 1px rgba(255,255,255,.15); }
.menuBtn:active { transform: translateY(3px); border-bottom-width: 3px; filter: brightness(.95); }
.menuBtn:focus-visible { outline: 3px solid #ffb02e; outline-offset: 4px; }

.menuBtn.ghost {
  background: rgba(255,255,255,.08);
  border-bottom: 6px solid rgba(0,0,0,.45);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.2), 0 8px 20px rgba(0,0,0,.3);
  font-size: 20px; min-width: 280px; padding: 14px 44px;
}
.menuBtn.ghost:hover { background: rgba(255,255,255,.16); box-shadow: inset 0 0 0 2px rgba(255,255,255,.3), 0 12px 28px rgba(0,0,0,.4); }

.backBtn {
  margin-top: 8px; padding: 12px 34px;
  font-family: inherit; font-size: 17px; font-weight: 800; letter-spacing: 2px;
  color: #cfe3ff; background: transparent; cursor: pointer;
  border: 2px solid rgba(255,255,255,.25); border-radius: 14px;
  transition: all .15s ease;
  backdrop-filter: blur(4px);
}
.backBtn:hover { border-color: #8fd3ff; color: #fff; background: rgba(143,211,255,.12); box-shadow: 0 0 20px rgba(143,211,255,.2); }
.backBtn:focus-visible { outline: 3px solid #8fd3ff; outline-offset: 3px; }

.panelTitle {
  font-size: 52px; font-weight: 900; font-style: italic; letter-spacing: 5px;
  text-shadow: 0 4px 0 #7a3400, 0 12px 30px rgba(0,0,0,.7), 0 0 40px rgba(255,176,46,.2);
  animation: titleIn .5s cubic-bezier(.4,0,.2,1);
}
@keyframes titleIn { from { opacity: 0; transform: translateY(-20px) scale(.95); } to { opacity: 1; transform: translateY(0) scale(1); } }

.roundLabel { font-size: 22px; font-weight: 800; letter-spacing: 7px; color: #ffb02e; text-shadow: 0 0 20px rgba(255,176,46,.4); }

.menuFooter { position: absolute; bottom: 26px; font-size: 15px; letter-spacing: 2px; color: rgba(255,255,255,.5); }

#teamGrid {
  display: grid; grid-template-columns: repeat(4, 156px); gap: 18px;
  padding: 12px 30px; max-height: 480px; overflow-y: auto;
}
.teamCard {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 14px 10px 12px; border-radius: 16px; cursor: pointer;
  background: rgba(255,255,255,.07);
  border: 2px solid rgba(255,255,255,.14);
  transition: transform .15s cubic-bezier(.4,0,.2,1), border-color .15s, background .15s, box-shadow .15s;
  position: relative;
  overflow: hidden;
}
.teamCard::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,176,46,.15), transparent 70%);
  opacity: 0;
  transition: opacity .2s ease;
}
.teamCard:hover::before { opacity: 1; }
.teamCard:hover { transform: translateY(-6px) scale(1.05); border-color: #ffb02e; background: rgba(255,176,46,.12); box-shadow: 0 16px 32px rgba(255,140,26,.35); }
.teamCard:active { transform: translateY(-2px) scale(1.02); }
.teamCard.selected { border-color: #ffb02e; box-shadow: 0 0 0 3px rgba(255,176,46,.4), 0 16px 32px rgba(255,140,26,.35); }
.teamCard canvas { width: 80px; height: 54px; border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,.5); }
.teamCard span { font-size: 14px; font-weight: 800; letter-spacing: 1.5px; }

#bracketView { display: flex; gap: 40px; align-items: center; }
.roundCol { display: flex; flex-direction: column; gap: 20px; }
.roundCol h3 { text-align: center; font-size: 16px; letter-spacing: 4px; color: #8fd3ff; margin-bottom: 4px; text-shadow: 0 0 15px rgba(143,211,255,.3); }
.matchCard {
  min-width: 220px; padding: 10px 14px; border-radius: 14px;
  background: rgba(10,16,34,.85); border: 2px solid rgba(255,255,255,.12);
  transition: all .2s ease;
}
.matchCard.playerCard { border-color: #ffb02e; box-shadow: 0 0 20px rgba(255,176,46,.3); }
.bRow { display: flex; align-items: center; gap: 10px; padding: 6px 4px; font-size: 16px; font-weight: 700; color: #c9d6ee; transition: all .2s ease; }
.bRow + .bRow { border-top: 1px solid rgba(255,255,255,.08); }
.bRow canvas { width: 30px; height: 20px; border-radius: 4px; flex: none; }
.bRow .bName { flex: 1; white-space: nowrap; overflow: hidden; }
.bRow .bScore { font-weight: 900; min-width: 18px; text-align: right; }
.bRow.winner { color: #7dff8a; text-shadow: 0 0 10px rgba(125,255,138,.4); }
.bRow.loser { opacity: .4; }
.bRow.tbd { opacity: .5; font-style: italic; }

.settingsRows { display: flex; flex-direction: column; gap: 24px; min-width: 560px; }
.settingRow { display: flex; align-items: center; justify-content: space-between; gap: 36px; }
.settingRow > span { font-size: 20px; font-weight: 800; letter-spacing: 3px; color: #cfe3ff; }
.seg { display: flex; border: 2px solid rgba(255,255,255,.2); border-radius: 14px; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,.3); }
.seg button {
  padding: 12px 26px; font-family: inherit; font-size: 16px; font-weight: 800; letter-spacing: 1px;
  color: #cfe3ff; background: rgba(255,255,255,.05); border: none; cursor: pointer;
  border-right: 2px solid rgba(255,255,255,.12); transition: all .15s ease;
}
.seg button:last-child { border-right: none; }
.seg button:hover { background: rgba(255,255,255,.14); }
.seg button.active { background: linear-gradient(180deg,#ffb02e,#f97316); color: #fff; text-shadow: 0 1px 3px rgba(122,52,0,.6); box-shadow: inset 0 1px 0 rgba(255,255,255,.3); }

#resultInfo { display: flex; align-items: center; gap: 36px; }
#resultInfo .flagBox { display: flex; flex-direction: column; align-items: center; gap: 12px; }
#resultInfo .flagBox canvas { width: 130px; height: 86px; border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.6); }
#resultInfo .flagBox span { font-size: 20px; font-weight: 800; letter-spacing: 2px; }
#resultInfo .scoreLine { font-size: 80px; font-weight: 900; font-style: italic; text-shadow: 0 6px 0 rgba(0,0,0,.5), 0 0 30px rgba(255,176,46,.3); }
#resultInfo .champCup { font-size: 70px; filter: drop-shadow(0 8px 16px rgba(255,200,0,.5)); animation: champPulse 1.5s ease-in-out infinite; }
@keyframes champPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }

#touchControls { position: absolute; inset: 0; z-index: 20; pointer-events: none; }
.touchZone { position: absolute; bottom: 28px; display: flex; gap: 20px; pointer-events: auto; }
.touchZone.left { left: 30px; }
.touchZone.right { right: 30px; }
.touchZone button {
  width: 100px; height: 100px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.3);
  background: rgba(20,28,54,.45); color: rgba(255,255,255,.9);
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
  backdrop-filter: blur(6px);
  transition: all .12s ease;
  box-shadow: 0 8px 20px rgba(0,0,0,.4);
}
.touchZone button:active { background: rgba(255,140,26,.55); transform: scale(.92); box-shadow: 0 4px 12px rgba(255,140,26,.4); }

::-webkit-scrollbar { width: 12px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,.2); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.2); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.3); }

#loadingOverlay {
  position: absolute; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(7,10,20,.9);
  backdrop-filter: blur(8px);
  transition: opacity .4s ease;
}
#loadingOverlay.hidden { opacity: 0; pointer-events: none; }
.loader {
  width: 60px; height: 60px;
  border: 4px solid rgba(255,176,46,.2);
  border-top-color: #ffb02e;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
