:root {
  --bg: #0d1117;
  --panel: #0d1117;
  --line: #30363d;
  --text: #e8ecf5;
  --dim: #8b949e;
  --accent: #19f5d8;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; overflow: hidden; }
#globe { position: fixed; inset: 0; }

/* Starfield: two tiled layers drawn at the screen's pixel ratio (see app.js), so stars stay sharp */
#stars { position: fixed; inset: 0; overflow: hidden; pointer-events: none;
  background: #000; }
#stars .layer { position: absolute; left: 0; top: 0; width: calc(100% + 1024px); height: calc(100% + 1024px);
  background-size: 1024px 1024px; will-change: transform; }
a { color: var(--accent); }

/* Logo + title + hint. Line heights are explicit (30 + 2 + 20 = 52px) so the logo is exactly as tall as the text block */
#title { --logo: 52px; position: fixed; top: 16px; left: 20px; pointer-events: none; display: flex; align-items: center; gap: 12px; }
#title img { height: var(--logo); width: auto; display: block;
  filter: drop-shadow(0 0 5px rgba(25, 245, 216, .35)) drop-shadow(0 0 14px rgba(25, 245, 216, .25)); } /* soft neon glow, milder than the globe's */
#title h1 { margin: 0; font-size: 22px; line-height: 30px; letter-spacing: .01em; }
#title p { margin: 2px 0 0; font-size: 15px; line-height: 20px; color: var(--dim); }
/* Tournament counter: centered under the filter bar */
#stats { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); margin: 0; text-align: center;
  white-space: nowrap; pointer-events: none; color: var(--dim); font-size: 17px; font-weight: 700;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .8); }

#area { position: fixed; top: 16px; right: 16px; max-height: calc(100vh - 32px); width: min(380px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 0 8px;
  display: flex; flex-direction: column; }
#area[hidden], #modal[hidden] { display: none; }
#area h2 { margin: 0 44px 10px 18px; font-size: 17px; }
#area ul { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; }
#area li button { all: unset; box-sizing: border-box; display: block; width: 100%; cursor: pointer;
  padding: 10px 18px; border-top: 1px solid var(--line); }
#area li button:hover, #area li button:focus-visible { background: #161b22; }
#area .sub { color: var(--dim); font-size: 13px; }
#area .loc { color: var(--accent); }

/* open/close animations (delete this block to remove them; the closing delay in app.js is then harmless) */
/* Tournament list: slides in from the right */
#area:not([hidden]) { transform-origin: top right; animation: area-in .22s cubic-bezier(.2, .8, .2, 1); }
#area.closing { animation: area-out .18s ease-in forwards; pointer-events: none; } /* must stay after the rule above */
@keyframes area-in { from { opacity: 0; transform: translateX(24px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes area-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(24px) scale(.98); } }
/* Tournament popup: the dimmed backdrop fades while the card rises and scales in */
#modal:not([hidden]) { animation: fade-in .2s ease-out; }
#modal:not([hidden]) .card { animation: card-in .26s cubic-bezier(.2, .8, .2, 1); }
#modal.closing { animation: fade-out .18s ease-in forwards; pointer-events: none; } /* must stay after the rules above */
#modal.closing .card { animation: card-out .18s ease-in forwards; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes card-in { from { transform: translateY(14px) scale(.97); } to { transform: none; } }
@keyframes card-out { from { transform: none; } to { transform: translateY(10px) scale(.98); } }
@media (prefers-reduced-motion: reduce) {
  #area:not([hidden]), #area.closing, #modal:not([hidden]), #modal.closing,
  #modal:not([hidden]) .card, #modal.closing .card { animation: none; }
}

/* "Ordered by" dropdown in the tournament list */
#order { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 0 18px 12px; font-size: 13px; color: var(--dim); }
#order[hidden] { display: none; }
#order select { font: inherit; color: var(--text); background: #161b22; border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 8px; cursor: pointer; }
#order select:hover { border-color: var(--accent); }

/* Winner preview: floats to the left of the tournament list while hovering a tournament */
#peek { position: fixed; z-index: 4; width: 240px; overflow: hidden; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
  opacity: 0; visibility: hidden; transform: translateX(8px);
  transition: opacity .15s ease, transform .18s ease, visibility .15s; }
#peek.on { opacity: 1; visibility: visible; transform: none; }
.peek-art { display: flex; aspect-ratio: 626 / 457; background: #161b22; }
.peek-art[hidden] { display: none; }
.peek-art img { flex: 1; min-width: 0; height: 100%; object-fit: cover; }
.peek-body { padding: 10px 12px 12px; }
.peek-body small { display: block; font-size: 12px; color: var(--accent); }
.peek-body b { display: block; margin: 2px 0; font-size: 15px; line-height: 1.3; }
.peek-body span { display: block; font-size: 13px; color: var(--dim); }
@media (hover: none) { #peek { display: none; } }
@media (prefers-reduced-motion: reduce) { #peek { transition: none; } }

/* Winner preview, "row" mode: the winner's art fades in behind the hovered tournament */
#area li button { position: relative; isolation: isolate; overflow: hidden; }
.row-art { position: absolute; inset: 0; z-index: -1; display: flex; opacity: 0; transition: opacity .2s ease; pointer-events: none; }
.row-art.on { opacity: 1; }
.row-art img { flex: 1; min-width: 0; height: 100%; object-fit: cover; object-position: center 22%; }
.row-art::after { content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, rgba(13, 17, 23, .95) 0%, rgba(13, 17, 23, .75) 45%, rgba(13, 17, 23, .25) 100%); }
@media (prefers-reduced-motion: reduce) { .row-art { transition: none; } }

.close { position: absolute; top: 10px; right: 12px; width: 32px; height: 32px; border: 0;
  border-radius: 6px; background: transparent; color: var(--dim); font-size: 22px; cursor: pointer; }
.close:hover { color: var(--text); background: #161b22; }

#modal { position: fixed; inset: 0; z-index: 20; /* above the filter bar, so the dimming covers it too */
  background: rgba(4, 7, 14, .72); display: grid; place-items: center;
  padding: 80px 16px 16px; /* top padding keeps the popup clear of the filter bar */ }
.card { position: relative; width: min(760px, 100%); max-height: calc(100vh - 96px); display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.card .close { z-index: 2; color: var(--text); background: rgba(13, 17, 23, .55); }

.banner { flex: none; min-height: 130px; padding: 22px 56px 14px 20px; display: flex; flex-direction: column; justify-content: flex-end;
  background-image: linear-gradient(180deg, rgba(13, 17, 23, .25), var(--panel)), var(--banner-art, none);
  background-size: cover; background-position: center 22%; }
.banner h2 { margin: 0 0 2px; font-size: 22px; text-shadow: 0 1px 8px rgba(0, 0, 0, .8); }
#m-meta { margin: 0 0 10px; color: #c9d3e8; text-shadow: 0 1px 6px rgba(0, 0, 0, .8); }
#m-bracket { align-self: flex-start; font-size: 13px; text-decoration: none; padding: 3px 12px;
  border: 1px solid var(--accent); border-radius: 999px; background: rgba(13, 17, 23, .6); }
#m-bracket:hover { background: var(--accent); color: #04201c; }

.scroll { overflow: auto; padding: 10px 14px 14px; }
#m-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.msg { padding: 14px; color: var(--dim); }

.entry { position: relative; isolation: isolate; display: flex; align-items: center; gap: 14px; min-height: 64px;
  padding: 10px 16px 10px 8px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: #161b22; color: var(--text); text-decoration: none; }
.entry:hover { border-color: var(--accent); }
.entry::before { content: ""; position: absolute; inset: 0; z-index: -1;
  background: linear-gradient(90deg, rgba(13, 17, 23, .95) 0%, rgba(13, 17, 23, .75) 45%, rgba(13, 17, 23, .2) 100%); }
.art { position: absolute; inset: 0; z-index: -2; display: flex; }
.art img { flex: 1; min-width: 0; height: 100%; object-fit: cover; object-position: center 22%; }
.rank { flex: none; width: 46px; text-align: center; font-size: 14px; font-weight: 700; color: var(--dim); }
.who { flex: 1; min-width: 0; }
.who b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who span { display: block; font-size: 13px; color: #b9c5de; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec { flex: none; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; text-shadow: 0 1px 4px rgba(0, 0, 0, .9); }
.rec i { font-style: normal; font-weight: 400; font-size: 11px; color: var(--dim); margin: 0 7px 0 2px; }
.rec i:last-child { margin-right: 0; }

footer { position: fixed; bottom: 12px; left: 20px; color: var(--dim); font-size: 13px; line-height: 1.6; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }


/* Floating filter bar (solid background: backdrop blur over WebGL is expensive) */
#filters { position: fixed; top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 18px;
  padding: 6px 10px; background: rgba(13, 17, 23, .78); border: 1px solid var(--accent); border-radius: 17px;
  white-space: nowrap; z-index: 5; }
#filters .group { display: flex; align-items: center; gap: 2px; }
#filters .group + .group { padding-left: 18px; border-left: 1px solid var(--line); }
#filters span { color: var(--dim); font-size: 13px; margin-right: 8px; }
/* the last button has 11px of inner padding on the right: mirror it before the first label so both sides match */
#filters .group:first-child > span { padding-left: 11px; }
#filters button { border: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px;
  padding: 5px 11px; border-radius: 10px; cursor: pointer; }
#filters button:hover { background: #161b22; }
#filters button.on { background: var(--accent); color: #04201c; font-weight: 600; }

/* Cluster bubbles: outer = positioned by globe.gl, .dot = visual circle that grows on hover */
.bubble { pointer-events: auto; position: relative; padding: 0; border: 0; background: none; cursor: pointer; font: inherit; }
.bubble .dot { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-weight: 700;
  color: var(--fg); background: var(--c); border: 2px solid #fff;
  box-shadow: 0 0 10px var(--c), 0 0 2px rgba(0, 0, 0, .6);
  transition: transform .15s ease, box-shadow .15s ease; }
.bubble:hover { z-index: 10; }
.bubble:hover .dot { transform: scale(1.25); box-shadow: 0 0 18px var(--c), 0 0 2px rgba(0, 0, 0, .6); }

/* the filter bar would overlap the panel below ~1450px, so the panel starts under it */
@media (max-width: 1450px) {
  #area { top: 72px; max-height: calc(100vh - 88px); }
}

/* Mid-size screens: the filter bar would run into the hint line, so show a compact title (logo + name only) */
@media (max-width: 1500px) {
  #title { --logo: 30px; }
  #title p { display: none; }
}

@media (max-width: 900px) {
  /* the filter bar drops below the title here: keep a clear gap between the two */
  #title { --logo: 52px; top: 12px; } /* ends at 64px */
  #title p { display: block; }
  #filters { top: 80px; gap: 10px; max-width: calc(100vw - 16px); overflow-x: auto; } /* ends at ~123px */
  #filters .group + .group { padding-left: 10px; }
  #filters span { display: none; }
  #stats { top: 130px; }
  #modal { padding-top: 136px; }
  .card { max-height: calc(100vh - 152px); }
  #area { top: 132px; max-height: calc(100vh - 244px); } /* below the bar, above the 4-line footer */
}

/* Phones */
@media (max-width: 600px) {
  /* filters: two stacked rows with bigger tap targets instead of one scrolling row (ends at ~169px) */
  #filters { flex-direction: column; gap: 0; width: calc(100vw - 16px); max-width: 420px; overflow: visible; padding: 6px 8px; }
  #filters .group { gap: 4px; }
  #filters .group + .group { margin-top: 6px; padding: 6px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  #filters button { flex: 1; padding: 6px 4px; }
  #stats { top: 176px; font-size: 15px; }
  #modal { padding-top: 180px; } /* same popup, just clear of the taller filter bar */
  .card { max-height: calc(100vh - 196px); }
  /* tournament list: a bottom sheet above the footer, so the globe stays visible (tap it to close the list) */
  #area { top: auto; left: 8px; right: 8px; bottom: 124px; width: auto; max-height: 42vh; }
  #area:not([hidden]) { transform-origin: bottom center; animation-name: sheet-in; }
  #area.closing { animation-name: sheet-out; }
}
@keyframes sheet-in { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
@keyframes sheet-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(24px); } }