:root {
  --bg: #0a0e1a;
  --bg2: #0e1424;
  --panel: #121a2e;
  --panel2: #16203a;
  --line: #243150;
  --ink: #eef3ff;
  --muted: #8595b8;
  --faint: #56668c;
  --win: #25d07a;
  --run: #4aa8ff;
  --third: #ffb43d;
  --out: #44506e;
  --accent: #ff3d68;
  --accent2: #7b5cff;
  --mono: "JetBrains Mono", monospace;
  --head: "Archivo", system-ui, sans-serif;
  --body: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 700px at 15% -10%, rgba(255, 61, 104, 0.1) 0%, transparent 60%),
    radial-gradient(1100px 800px at 100% 0%, rgba(123, 92, 255, 0.12) 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---- top bar ---- */
.topbar {
  /* position: fixed (not sticky) is bulletproof on iOS Safari — nothing can float
     above it during momentum scroll. A JS-synced body padding-top offsets content. */
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 14px 26px;
  background: #0b1122;
  border-bottom: 1px solid var(--line);
}
.ctl-actions { display: flex; align-items: center; gap: 10px; flex-wrap: nowrap; }
.brand { display: flex; align-items: center; gap: 14px; }
.crest {
  width: 46px; height: 46px; border-radius: 13px;
  display: grid; place-items: center;
  font-family: var(--head); font-weight: 900; font-size: 19px; letter-spacing: -1px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; box-shadow: 0 8px 26px rgba(255, 61, 104, 0.35);
}
.brandtext h1 { margin: 0; font-family: var(--head); font-weight: 800; font-size: 19px; letter-spacing: -0.4px; }
.brandtext p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--out); box-shadow: 0 0 0 0 rgba(37,208,122,0.6); }
.dot.live { background: var(--win); animation: pulse 2s infinite; }
.dot.whatif { background: var(--third); }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(37,208,122,.5)} 70%{box-shadow:0 0 0 8px rgba(37,208,122,0)} 100%{box-shadow:0 0 0 0 rgba(37,208,122,0)} }

.mode-switch { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; padding: 3px; }
.mode-btn {
  border: 0; background: transparent; color: var(--muted);
  font-family: var(--body); font-weight: 600; font-size: 13px;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; transition: .18s;
}
.mode-btn.active { background: linear-gradient(135deg, var(--accent2), var(--accent)); color: #fff; }
.mode-btn[data-mode="whatif"].active { background: linear-gradient(135deg, #c98a16, var(--third)); color: #12101a; }

.ghost-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-family: var(--body); font-weight: 600; font-size: 13px;
  padding: 8px 13px; border-radius: 10px; cursor: pointer; transition: .16s;
}
.ghost-btn:hover { border-color: var(--accent2); transform: translateY(-1px); }
.hidden { display: none !important; }

.whatif-banner {
  margin: 14px 26px 0; padding: 11px 16px; border-radius: 12px; font-size: 13px;
  color: #ffe4b0; background: rgba(255, 180, 61, 0.08); border: 1px solid rgba(255, 180, 61, 0.3);
}

/* ---- layout ---- */
main {
  display: grid; grid-template-columns: minmax(520px, 1fr) minmax(560px, 1.15fr);
  gap: 18px; padding: 18px 26px 40px; align-items: start;
}
main > * { min-width: 0; }
.panel { background: linear-gradient(180deg, var(--panel), var(--bg2)); border: 1px solid var(--line); border-radius: 18px; padding: 16px 16px 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin: 2px 4px 14px; gap: 14px; }
.panel-head h2 { margin: 0; font-family: var(--head); font-weight: 800; font-size: 15px; letter-spacing: .4px; text-transform: uppercase; color: #cfd9f5; }
.legend { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); flex-wrap: wrap; }
.legend .sw, .sw { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.sw.win { background: var(--win); } .sw.run { background: var(--run); }
.sw.third { background: var(--third); } .sw.outl { background: #7a5a1e; } .sw.out { background: var(--out); }
.upcoming-panel { grid-column: 1 / -1; }

/* ---- group cards ---- */
.groups-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.gcard { background: var(--panel2); border: 1px solid var(--line); border-radius: 13px; padding: 10px 10px 6px; }
.gcard h3 { margin: 0 0 7px; font-family: var(--head); font-weight: 700; font-size: 12px; letter-spacing: 1.5px; color: var(--muted); text-transform: uppercase; display: flex; justify-content: space-between; }
.gcard h3 .live-tag { color: var(--win); font-size: 10px; letter-spacing: .5px; }
.grow { display: grid; grid-template-columns: 18px 1fr repeat(5, 22px) 30px; align-items: center; gap: 4px; padding: 5px 6px; border-radius: 9px; font-size: 12.5px; position: relative; }
.grow .num { color: var(--faint); font-weight: 700; font-family: var(--mono); font-size: 11px; text-align: center; }
.grow .team { display: flex; align-items: center; gap: 7px; min-width: 0; }
.grow .team img { width: 19px; height: 14px; object-fit: cover; border-radius: 2px; flex: none; box-shadow: 0 0 0 1px rgba(255,255,255,.08); background: #223; }
.grow .team span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.grow .st { text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11.5px; }
.grow .pts { text-align: center; font-weight: 800; font-family: var(--mono); color: var(--ink); }
.grow::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 3px; border-radius: 3px; background: transparent; }
.grow.winner::before { background: var(--win); } .grow.runner::before { background: var(--run); }
.grow.third-in::before { background: var(--third); } .grow.third-out::before { background: #7a5a1e; }
.grow.winner, .grow.runner { background: rgba(74, 168, 255, 0.05); }
.grow.third-in { background: rgba(255, 180, 61, 0.06); }
.grow.out { opacity: .5; }
.col-h { color: var(--faint); font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; }
.score-pulse { color: var(--accent) !important; }

/* ---- bracket ---- */
.bracket-scroll { overflow-x: auto; min-width: 0; padding-bottom: 8px; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.bracket { display: flex; gap: 30px; min-width: 1040px; align-items: stretch; }
.round { display: flex; flex-direction: column; justify-content: space-around; gap: 8px; min-width: 178px; }
.round-label { font-family: var(--head); font-weight: 700; font-size: 10.5px; letter-spacing: 1.4px; color: var(--muted); text-transform: uppercase; text-align: center; margin-bottom: 4px; }
.tie { background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; padding: 4px; position: relative; }
.tie .m-no { position: absolute; top: -8px; left: 9px; font-family: var(--mono); font-size: 8.5px; color: var(--faint); background: var(--bg2); padding: 0 5px; border-radius: 4px; }
.slot { display: grid; grid-template-columns: 21px 1fr auto; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 12.5px; }
.slot + .slot { margin-top: 3px; }
.slot img { width: 21px; height: 15px; object-fit: cover; border-radius: 2px; box-shadow: 0 0 0 1px rgba(255,255,255,.1); background: #223; }
.slot .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.slot .seedtag { font-family: var(--mono); font-size: 9.5px; color: var(--faint); }
.slot.ph .nm { color: var(--faint); font-style: italic; font-weight: 500; }
.slot.ph .seedtag { color: var(--out); }
.slot.third-slot { background: rgba(255, 180, 61, 0.09); }
.slot.third-slot .seedtag { color: var(--third); }
.slot.winner-advanced { background: rgba(37, 208, 122, 0.1); }
.tie.changed { animation: flipglow 1.1s ease; }
@keyframes flipglow { 0%{box-shadow:0 0 0 0 rgba(255,61,104,0)} 25%{box-shadow:0 0 0 3px rgba(255,61,104,.5)} 100%{box-shadow:0 0 0 0 rgba(255,61,104,0)} }
.final-wrap { display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.tie.final-tie { border-color: var(--third); background: linear-gradient(180deg, rgba(255,180,61,.12), var(--panel2)); }
.tie.final-tie .round-label { color: var(--third); }

/* ---- upcoming / what-if editor ---- */
.upcoming-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.umatch { background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; padding: 9px 11px; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.umatch .grp { font-family: var(--mono); font-size: 10px; color: var(--third); }
.uteam { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; min-width: 0; }
.uteam img { width: 18px; height: 13px; object-fit: cover; border-radius: 2px; }
.uteam.away { flex-direction: row-reverse; }
.uscore { width: 34px; flex: none; -webkit-appearance: none; appearance: none; margin: 0; text-align: center; font-family: var(--mono); font-weight: 700; font-size: 14px; background: var(--bg); border: 1px solid var(--line); color: var(--ink); border-radius: 7px; padding: 5px 0; }
.uscore::-webkit-outer-spin-button, .uscore::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.uteam span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.uscore:focus { outline: none; border-color: var(--third); }
.uvs { display: flex; align-items: center; gap: 5px; }
.edited { box-shadow: 0 0 0 1px var(--third) inset; }

.foot { padding: 0 26px 26px; color: var(--faint); font-size: 11.5px; }

@media (max-width: 1080px) {
  main { grid-template-columns: 1fr; }
  .groups-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px 14px; padding: 10px 14px; }
  .controls { width: 100%; justify-content: flex-start; gap: 10px; }
  .brandtext p { display: none; }          /* slim the sticky bar on phones */
  .brandtext h1 { font-size: 16px; }
  .crest { width: 38px; height: 38px; font-size: 15px; }
  .groups-grid { grid-template-columns: 1fr; }
  main { padding: 14px; gap: 14px; }
  .whatif-banner { margin: 12px 14px 0; }
  .foot { padding: 0 16px 22px; }
}
@media (max-width: 480px) {
  .crest { width: 40px; height: 40px; font-size: 16px; }
  .brandtext h1 { font-size: 17px; }
  /* tighten group rows so all stat columns fit a phone without overflow */
  .grow { grid-template-columns: 15px 1fr repeat(5, 18px) 25px; gap: 3px; padding: 5px 5px; font-size: 12px; }
  .grow .team img { width: 17px; height: 12px; }
  .grow .st { font-size: 10.5px; }
  .col-h { font-size: 9px; }
  .gcard { padding: 9px 8px 5px; }
  /* bracket stays horizontally scrollable but contained to its panel */
  .bracket { gap: 22px; }
  .round { min-width: 158px; }
  /* what-if editor: single column, no forced min-width that could overflow iOS */
  .upcoming-grid { grid-template-columns: minmax(0, 1fr); }
}
