/* BallSZN Analytics. PostHog's look, kept plain: a warm grey page, white cards with a hairline border, one blue.
   No inline styles anywhere (the Content-Security-Policy forbids them): app.js sets sizes through element.style and
   picks a series colour with the classes c0 to c8. 13 px is the smallest text. */

:root {
  color-scheme: light dark;
  --bg: #f3f4ef; --card: #ffffff; --border: #e0e0d8; --text: #1d1f27; --muted: #6b6f76; --blue: #1d4aff;
  --hover: #f6f6f1; --track: #eeefe9; --side: #eceee7; --red: #c0321f;
  --s0: #1d4aff; --s1: #f54e00; --s2: #5f9d32; --s3: #c7399d; --s4: #f1a82c; --s5: #29dbbb; --s6: #9b59d0;
  --s7: #a36b4f; --s8: #b0b3ba;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1f27; --card: #262932; --border: #3b3e4a; --text: #eceee8; --muted: #a4a8b1; --blue: #7391ff;
    --hover: #2e313c; --track: #333641; --side: #21232b; --red: #ff8a75;
    --s0: #6283ff; --s1: #ff6a2a; --s2: #7dbb47; --s3: #e062b9; --s4: #f1a82c; --s5: #29dbbb; --s6: #b47fe2;
    --s7: #c08a6d; --s8: #7d818c;
  }
}
.c0 { --c: var(--s0); } .c1 { --c: var(--s1); } .c2 { --c: var(--s2); } .c3 { --c: var(--s3); } .c4 { --c: var(--s4); }
.c5 { --c: var(--s5); } .c6 { --c: var(--s6); } .c7 { --c: var(--s7); } .c8 { --c: var(--s8); }
.fillc { fill: var(--c); } .strokec { stroke: var(--c); } .bgc { background: var(--c); }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
a { color: var(--blue); }
h1, h2, h3, h4, p { margin: 0; }
code, pre { font-family: var(--mono); font-size: 13px; }
code { background: var(--track); border-radius: 4px; padding: 1px 5px; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.muted { color: var(--muted); }
.error { color: var(--red); }
.grow { flex: 1 1 auto; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.offscreen { position: fixed; left: -9999px; top: 0; }

/* ---------- controls */
.btn { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--blue); opacity: .9; }
.btn.quiet { background: none; }
.btn:disabled { opacity: .5; cursor: default; }
.link { font: inherit; color: var(--blue); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; }
.badge { font-size: 13px; color: var(--muted); background: var(--card); border: 1px solid var(--border); border-radius: 11px; padding: 1px 10px; white-space: nowrap; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; position: relative; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex: none; width: 34px; height: 20px; border-radius: 10px; background: var(--border); position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .track { background: var(--blue); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---------- the frame */
.app { display: flex; min-height: 100vh; }
.side { flex: none; width: 212px; position: sticky; top: 0; height: 100vh; padding: 16px 10px; display: flex; flex-direction: column; gap: 14px; background: var(--side); border-right: 1px solid var(--border); }
.brand { font-size: 15px; font-weight: 700; padding: 4px 10px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { padding: 6px 10px; border: 1px solid transparent; border-radius: 6px; color: var(--text); text-decoration: none; white-space: nowrap; }
.nav a:hover { background: var(--hover); }
.nav a.on { background: var(--card); border-color: var(--border); color: var(--blue); font-weight: 600; }
.logout { margin-top: auto; }
.main { flex: 1 1 auto; min-width: 0; }
.top { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; padding: 12px 24px; background: var(--bg); border-bottom: 1px solid var(--border); }
.top-title { display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 18px; font-weight: 700; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; }
.control { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#custom { display: inline-flex; align-items: center; gap: 8px; }
#view { padding: 4px 24px 72px; }
.section { font-size: 15px; font-weight: 700; margin: 28px 0 12px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; margin: 14px 0; }
.note { margin-top: 20px; }

/* ---------- tiles */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: minmax(56px, auto); grid-auto-flow: row dense; gap: 14px; margin-top: 14px; }
.tile { grid-column: span var(--w, 6); grid-row: span var(--h, 5); min-width: 0; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; }
.tile-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.tile-titles { min-width: 0; }
.tile h3, .modal-card h3, .player h3 { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.desc { margin-top: 3px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.tile-body { flex: 1 1 0; min-height: 120px; margin-top: 10px; position: relative; }
.fill { position: absolute; inset: 0; overflow: auto; }
.fill.grow { position: static; overflow: visible; }
.tile-body:has(> .fill.grow) { flex: 1 0 auto; } /* the card takes the funnel's whole height, so the grid row grows with it */
.modal .tile-body { overflow: auto; }
.empty { display: flex; align-items: center; justify-content: center; height: 100%; min-height: 60px; color: var(--muted); text-align: center; }
.fill > .error { padding-top: 8px; overflow-wrap: anywhere; }
.skeleton { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; }
.skeleton span { height: 14px; border-radius: 4px; background: var(--track); animation: pulse 1.2s ease-in-out infinite; }
.skeleton span:nth-child(2) { width: 82%; }
.skeleton span:nth-child(3) { width: 58%; }
@keyframes pulse { 50% { opacity: .45; } }
.menu-box { position: relative; flex: none; }
.menu-btn { font: inherit; font-size: 18px; line-height: 1; color: var(--muted); background: none; border: 0; border-radius: 4px; padding: 2px 6px; cursor: pointer; }
.menu-btn:hover { background: var(--hover); color: var(--text); }
.menu { position: absolute; right: 0; top: 26px; z-index: 10; min-width: 180px; display: flex; flex-direction: column; padding: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.menu button { font: inherit; text-align: left; color: var(--text); background: none; border: 0; border-radius: 4px; padding: 7px 10px; cursor: pointer; white-space: nowrap; }
.menu button:hover:not(:disabled) { background: var(--hover); }
.menu button:disabled { color: var(--muted); cursor: default; }
.menu-note { margin-top: 4px; padding: 6px 10px 3px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; white-space: nowrap; }

/* text tiles */
.tile.text { justify-content: flex-start; }
.md { overflow-wrap: anywhere; }
.md p, .md ul, .md ol, .md h4 { margin: 0 0 8px; }
.md > :last-child { margin-bottom: 0; }
.md ul, .md ol { padding-left: 20px; }
.md li { margin: 3px 0; }
.md-h1 { font-size: 17px; } .md-h2 { font-size: 16px; } .md-h3 { font-size: 15px; }

/* ---------- charts */
svg { display: block; }
.chart { display: flex; flex-direction: column; height: 100%; }
.plot { flex: 1 1 0; min-height: 0; position: relative; overflow: hidden; }
.legend { flex: none; display: flex; flex-wrap: wrap; gap: 2px 8px; margin-bottom: 6px; max-height: 56px; overflow: auto; }
.key { font: inherit; font-size: 13px; color: var(--text); background: none; border: 0; border-radius: 4px; padding: 2px 5px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-align: left; }
.key:hover { background: var(--hover); }
.key.off { color: var(--muted); text-decoration: line-through; }
.key.off .sw { background: var(--border); }
.sw { flex: none; display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--c); }
.gridline { stroke: var(--border); stroke-width: 1; shape-rendering: crispEdges; }
.zero { stroke: var(--muted); stroke-width: 1; shape-rendering: crispEdges; }
.axis { fill: var(--muted); font-size: 13px; }
.line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { stroke: var(--card); stroke-width: 2; }
.crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.hover-band { fill: var(--text); opacity: .07; }
.catch { fill: transparent; cursor: crosshair; touch-action: pan-y; }
.bignum { display: flex; align-items: center; height: 100%; font-size: clamp(26px, 3vw, 40px); font-weight: 700; line-height: 1.1; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.bartrack { display: block; height: 14px; border-radius: 3px; background: var(--track); overflow: hidden; }
.bar { display: block; height: 100%; border-radius: 3px; }
.ranked { display: grid; grid-template-columns: fit-content(42%) minmax(40px, 1fr) auto auto; gap: 8px 12px; align-items: center; padding-right: 2px; }
.ranked.no-share { grid-template-columns: fit-content(42%) minmax(40px, 1fr) auto; }
.r-label { overflow-wrap: anywhere; }
.pie-label { overflow-wrap: break-word; }
.r-value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.r-share { text-align: right; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.flag { margin-right: 6px; }

.pie { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; min-height: 100%; }
.donut { flex: none; }
.donut-total { font-size: 18px; font-weight: 700; fill: var(--text); }
.slice { transition: opacity .12s; }
.pie:has(.slice.on) .slice:not(.on) { opacity: .4; }
.pie-keys { flex: 1 1 200px; min-width: 0; display: grid; grid-template-columns: auto minmax(9ch, 1fr) auto auto; gap: 2px 10px; } /* a label keeps room for a whole word; too narrow and the keys go under the ring */
.pie-key { grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; align-items: baseline; padding: 2px 5px; border-radius: 4px; }
.pie-key.on { background: var(--hover); }

.funnel { display: flex; flex-direction: column; gap: 14px; padding-right: 2px; }
.f-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.f-num { flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--track); font-size: 13px; font-weight: 600; line-height: 22px; text-align: center; }
.f-name { flex: 1 1 auto; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.f-count { font-weight: 600; font-variant-numeric: tabular-nums; }
.f-share { flex: none; min-width: 54px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.f-step .bartrack { height: 18px; }
.f-drop { margin-top: 4px; color: var(--muted); font-size: 13px; }

/* ---------- tables */
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.data th { position: sticky; top: 0; z-index: 1; padding: 7px 10px; background: var(--card); border-bottom: 1px solid var(--border); text-align: left; font-weight: 600; white-space: nowrap; }
.data th:has(.sort) { padding: 0; }
.sort { width: 100%; font: inherit; font-weight: 600; color: inherit; text-align: inherit; background: none; border: 0; padding: 7px 10px; cursor: pointer; white-space: nowrap; }
.sort:hover { background: var(--hover); }
.arrow { color: var(--blue); }
.data td { max-width: 460px; padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: break-word; }
.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data:not(.retention) tbody tr:hover > td { background: var(--hover); }
.more { margin: 10px; }
.retention td.ret { text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; border-bottom: 1px solid var(--card); border-right: 1px solid var(--card); background: color-mix(in srgb, var(--s0) calc(var(--a, 0) * 100%), transparent); }
.retention td.ret.strong { color: #fff; }
.ret-all td { font-weight: 600; }
.retention td:first-child, .retention th:first-child { position: sticky; left: 0; z-index: 2; background: var(--card); white-space: nowrap; }
.retention th:first-child { z-index: 3; }

/* ---------- the live feed and a player's timeline */
.scroll-x { overflow-x: auto; }
.feed-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.feed-hint { margin: 8px 0 6px; font-size: 13px; }
.feed-status { padding: 18px 0 6px; text-align: center; }
.event { font-family: var(--mono); font-size: 13px; background: var(--track); border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
.data td.props { width: 44%; max-width: 0; min-width: 160px; }
.one-line { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: var(--mono); font-size: 13px; color: var(--muted); }
tr.can-open { cursor: pointer; }
tr.open > td { background: var(--hover); }
tr.detail > td { max-width: none; background: var(--hover); }
tr.detail pre { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
tr.session > td { max-width: none; padding-top: 10px; background: var(--track); font-weight: 600; }
.slide-in { animation: slide-in .35s ease-out; }
.slide-in > td { animation: arrived 1.8s ease-out; }
@keyframes slide-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes arrived { from { background: color-mix(in srgb, var(--s0) 16%, transparent); } to { background: transparent; } }
.search { display: flex; gap: 10px; margin-top: 20px; }
.player-id { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 18px; }
.fact { display: flex; flex-direction: column; overflow-wrap: anywhere; }
.fact .muted { font-size: 13px; }

/* ---------- the SQL box */
.sql { margin-top: 20px; }
.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.editor { display: block; width: 100%; min-height: 210px; resize: vertical; font-family: var(--mono); font-size: 13px; line-height: 1.5; tab-size: 2; white-space: pre; overflow: auto; }
.sql-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.help { margin-top: 10px; font-size: 13px; }
.sql-error, .expanded { margin: 14px 0; padding: 12px 16px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.result-card { padding: 0; overflow: hidden; }
.result { max-height: 72vh; overflow: auto; }
.result .empty { padding: 28px 16px; }

/* ---------- the tooltip and the enlarged tile */
.tip { position: fixed; z-index: 100; pointer-events: none; max-width: 340px; padding: 8px 10px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 1px 2px rgba(0, 0, 0, .1); font-size: 13px; }
.tip-title { margin-bottom: 4px; font-weight: 600; }
.tip-row { display: flex; align-items: center; gap: 8px; }
.tip-name { flex: 1 1 auto; overflow-wrap: anywhere; }
.tip-value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: 12px; }
.tip-total { margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border); }
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(20, 22, 28, .5); }
.modal-card { display: flex; flex-direction: column; width: min(1240px, 100%); height: min(780px, 100%); padding: 16px 18px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; }

/* ---------- the login page */
body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 340px; padding: 28px; background: var(--card); border: 1px solid var(--border); border-radius: 6px; }
.login-card h1 { font-size: 18px; margin-bottom: 10px; }
.login-card label { font-weight: 600; }
.login-note { min-height: 20px; color: var(--muted); }

/* ---------- a middle width: two tiles a row. A narrow one: one column, the pages along the top. */
@media (max-width: 1180px) {
  .tile { grid-column: span 6; }
  .tile.w-l { grid-column: span 12; }
}
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .side { position: static; width: auto; height: auto; flex-direction: row; align-items: center; gap: 10px; padding: 8px 12px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { white-space: nowrap; padding: 4px 6px; }
  .nav { flex-direction: row; }
  .logout { margin: 0 0 0 auto; }
  .top { position: static; padding: 10px 14px; }
  #view { padding: 2px 14px 56px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .tile, .tile.w-l { grid-column: auto; grid-row: auto; min-height: calc(var(--h, 5) * 54px); }
  .tile.text { min-height: 0; }
  .wide-only { display: none; }
  .modal { padding: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
