:root {
  color-scheme: dark;
  --bg: #06090f;
  --surface: #0b0f17;
  --surface-2: #111724;
  --line: #1c2434;
  --grid: #161d2a;
  --text: #e8edf6;
  --text-2: #9aa6ba;
  --muted: #5d6a80;
  --up: #19d27a;
  --up-bg: rgba(25, 210, 122, .16);
  --down: #ff4d5e;
  --down-bg: rgba(255, 77, 94, .16);
  --warn: #ffb020;
  --jody: #4a7dff;
  --katy: #e8559e;
  --gold: #ffd166;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
a { color: inherit; }
button { font: inherit; color: inherit; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.muted { color: var(--muted); }
.dim { color: var(--text-2); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--text-2); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  /* Equal side columns keep the leader pill centred on the screen, whatever the logo's width. */
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, auto) minmax(0, 1fr); align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(6, 9, 15, .86); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo { font-family: var(--mono); font-weight: 800; letter-spacing: .12em; font-size: 14px; }
.logo span { color: var(--gold); }
.top-actions { display: flex; gap: 10px; justify-self: end; }
.iconbtn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; font-size: 16px; }



main { max-width: 1100px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h2 { margin: 0 0 12px; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.card h2 .spacer { flex: 1; }


/* ---------- player cards ---------- */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.player { position: relative; padding: 14px 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.player::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--c); }
.player.leader { border-color: color-mix(in srgb, var(--gold) 50%, var(--line)); }
.player .name { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; }
/* Ghosted portrait on the right of the card: a soft oval centred on the face, tinted toward the player's colour. */
.player .photo { position: absolute; top: 0; bottom: 0; right: 0; width: 72%; background: var(--photo) 50% 18% / cover no-repeat; opacity: .26; filter: grayscale(.55) contrast(1.1);
  -webkit-mask-image: radial-gradient(ellipse 62% 58% at 52% 34%, #000 50%, transparent 100%);
  mask-image: radial-gradient(ellipse 62% 58% at 52% 34%, #000 50%, transparent 100%); pointer-events: none; }
.player .photo::after { content: ''; position: absolute; inset: 0; background: var(--c); mix-blend-mode: color; opacity: .35; }
.player > :not(.photo) { position: relative; }
.player .avatar { width: 22px; height: 22px; border-radius: 50%; flex: none; background: var(--photo) center 20% / cover; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--c); }
/* Leader's crown sits on the top-left of the photo, tilted to follow the circle. */
.player .avatar { position: relative; }
.player .avatar .crown { position: absolute; top: -12px; left: -8px; font-size: 15px; line-height: 1; transform: rotate(-32deg); opacity: 0; transition: opacity .4s, transform .4s;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.6)); pointer-events: none; }
.player .avatar.crowned .crown { opacity: 1; animation: crown-drop .6s cubic-bezier(.2,1.6,.4,1); }
@keyframes crown-drop { from { transform: translateY(-8px) rotate(-55deg); opacity: 0; } to { transform: rotate(-32deg); opacity: 1; } }
.player .total { font-family: var(--mono); font-size: clamp(20px, 6.2vw, 34px); font-weight: 700; margin: 6px 0 2px; border-radius: 6px; padding: 0 2px; margin-left: -2px; transition: background-color .8s; }
.player .chg { font-family: var(--mono); font-size: 12px; display: flex; gap: 6px; flex-wrap: wrap; }
.player .meta { margin-top: 10px; display: grid; gap: 4px; font-size: 11px; color: var(--text-2); }
.player .meta div { display: flex; justify-content: space-between; gap: 6px; }
.player .meta .num { color: var(--text); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: .04em; }
.chip.good { background: var(--up-bg); color: var(--up); }
.chip.bad { background: var(--down-bg); color: var(--down); }
.chip.warn { background: rgba(255,176,32,.15); color: var(--warn); }

/* ---------- together ---------- */
.together { position: relative; overflow: hidden; text-align: center; padding: 18px 16px 16px;
  background: radial-gradient(60% 120% at 0% 0%, color-mix(in srgb, var(--jody) 16%, transparent), transparent),
              radial-gradient(60% 120% at 100% 0%, color-mix(in srgb, var(--katy) 16%, transparent), transparent), var(--surface); }
.tg-hearts { position: relative; width: 64px; height: 44px; margin: 0 auto 4px; }
.tg-hearts svg { position: absolute; top: 2px; width: 36px; height: 36px; fill: var(--c); filter: drop-shadow(0 0 10px var(--c)); transform-origin: 50% 60%; }
.tg-hearts .h1 { left: 4px; transform: rotate(-12deg); animation: beat 1.6s ease-in-out infinite; }
.tg-hearts .h2 { right: 4px; transform: rotate(12deg); animation: beat 1.6s ease-in-out .2s infinite; opacity: .92; mix-blend-mode: screen; }
@keyframes beat { 0%, 40%, 100% { scale: 1; } 15% { scale: 1.16; } 28% { scale: 1.05; } }
.tg-label { font-size: 11px; letter-spacing: .18em; text-transform: uppercase; color: var(--text-2); }
.tg-label span { color: var(--katy); }
.tg-total { font-size: clamp(30px, 9vw, 44px); font-weight: 800; margin: 4px auto 2px; display: inline-block; padding: 0 6px; border-radius: 8px; }
.tg-chg { font-size: 12px; }
.tg-split { display: flex; gap: 2px; height: 8px; margin: 14px 0 6px; border-radius: 999px; overflow: hidden; }
.tg-split .seg { background: var(--c); transition: flex-grow 1s; min-width: 4px; }
.tg-legend { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: var(--text-2); }
.tg-legend .lt { color: var(--muted); }
.tg-legend > span { display: inline-flex; align-items: center; }

/* flashing */
.flash-up { animation: flashUp 1.1s ease-out; }
.flash-down { animation: flashDown 1.1s ease-out; }
@keyframes flashUp { 0% { background: rgba(25,210,122,.55); color: #fff; } 100% { background: transparent; } }
@keyframes flashDown { 0% { background: rgba(255,77,94,.55); color: #fff; } 100% { background: transparent; } }

/* ---------- race track ---------- */
.lane { margin: 10px 0 18px; }
.lane:last-child { margin-bottom: 4px; }
.lane-top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 6px; }
.lane-top .num { color: var(--text-2); }
.track { position: relative; height: 14px; border-radius: 999px; background: repeating-linear-gradient(90deg, var(--surface-2) 0 10%, #0e1420 10% 20%); border: 1px solid var(--line); }
.track .fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: linear-gradient(90deg, color-mix(in srgb, var(--c) 30%, transparent), var(--c)); transition: width 1s cubic-bezier(.2,.8,.2,1); min-width: 14px; }
.track .runner { position: absolute; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; background: var(--c) center 20% / cover no-repeat;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--c), 0 0 16px var(--c); transition: left 1s cubic-bezier(.2,.8,.2,1); z-index: 1; }
.lane { margin-bottom: 30px; }
.lane:last-child { margin-bottom: 18px; }
.lane-top { margin-bottom: 12px; }
.track .ghost { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--text-2); opacity: .7; }
.track .ghost::after { content: attr(data-label); position: absolute; top: 100%; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--muted); white-space: nowrap; margin-top: 9px; }
.track .flag { position: absolute; right: -4px; top: 50%; transform: translateY(-58%); font-size: 16px; }

/* ---------- leaderboard ---------- */
.board { width: 100%; border-collapse: collapse; font-size: 13px; }
.board th { text-align: right; font-weight: 700; font-size: 11px; padding: 0 0 8px; }
.board th:first-child { text-align: left; color: var(--text-2); font-weight: 600; }
.board td { padding: 9px 0; border-top: 1px solid var(--line); text-align: right; font-family: var(--mono); font-size: 12px; }
.board td:first-child { text-align: left; font-family: var(--sans); color: var(--text-2); font-size: 12px; }
.board td.win { color: var(--text); font-weight: 700; }
.board td.win::before { content: '▸ '; color: var(--gold); }
.board td.lose { color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 5px; }

/* ---------- chart ---------- */
.ranges { display: flex; gap: 2px; }
.chart-head { flex-wrap: wrap; row-gap: 8px; }
.chart-head .title { white-space: nowrap; }
.ranges button { background: none; border: 1px solid transparent; border-radius: 8px; padding: 4px 8px; font-family: var(--mono); font-size: 11px; color: var(--text-2); cursor: pointer; }
.ranges button.on { border-color: var(--line); background: var(--surface-2); color: var(--text); }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: 240px; touch-action: pan-y; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-top: 8px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; min-width: 150px; box-shadow: 0 6px 20px rgba(0,0,0,.4); opacity: 0; transition: opacity .1s; }
.tooltip .t { color: var(--text-2); font-size: 11px; margin-bottom: 4px; }
.tooltip .r { display: flex; justify-content: space-between; gap: 12px; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--text-2); font-size: 11px; text-decoration: underline; cursor: pointer; letter-spacing: 0; text-transform: none; font-weight: 500; }
.tablewrap { max-height: 260px; overflow: auto; margin-top: 10px; }
.tablewrap table { width: 100%; font-size: 12px; border-collapse: collapse; }
.tablewrap td, .tablewrap th { padding: 4px 6px; text-align: right; border-bottom: 1px solid var(--line); font-family: var(--mono); }
.tablewrap td:first-child, .tablewrap th:first-child { text-align: left; }
.empty { color: var(--muted); font-size: 13px; padding: 30px 0; text-align: center; }

/* ---------- accounts ---------- */
.acct-group + .acct-group { margin-top: 16px; }
.acct-group h3 { margin: 0 0 6px; font-size: 13px; display: flex; align-items: center; }
.acct { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.acct .ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); font-size: 15px; }
.acct .nm { font-size: 13px; font-weight: 600; }
.acct .sub { font-size: 11px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.acct .val { text-align: right; }
.acct .val .num { font-size: 14px; font-weight: 700; border-radius: 4px; padding: 0 2px; }
.acct .val .c { font-family: var(--mono); font-size: 11px; }
.src { font-size: 9px; font-weight: 700; letter-spacing: .06em; padding: 1px 5px; border-radius: 4px; background: var(--surface-2); color: var(--text-2); }
.src.ok { background: var(--up-bg); color: var(--up); }
.src.err { background: var(--down-bg); color: var(--down); }
.src.stale { background: rgba(255,176,32,.15); color: var(--warn); }

/* ---------- ISA ---------- */
.isa-row { margin-bottom: 12px; }
.isa-row .top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 5px; }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > div { height: 100%; border-radius: 999px; background: var(--c); transition: width 1s; }

/* ---------- badges ---------- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.badge { position: relative; text-align: center; padding: 10px 6px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.badge .i { font-size: 24px; filter: grayscale(1) opacity(.25); }
.badge .n { font-size: 10px; font-weight: 700; margin-top: 4px; color: var(--muted); }
.badge .owners { display: flex; justify-content: center; gap: 3px; margin-top: 5px; min-height: 14px; }
.badge .owners span { font-size: 9px; font-weight: 700; padding: 1px 4px; border-radius: 4px; color: #fff; }
.badge.got .i { filter: none; }
.badge.got .n { color: var(--text); }
.badge.got { border-color: color-mix(in srgb, var(--gold) 35%, var(--line)); }

/* ---------- mortgage ---------- */
.mortgage .lbl { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--text-2); }
.mg-goal { text-align: center; padding: 14px 10px 16px; margin-bottom: 14px; border-radius: 12px; position: relative; overflow: hidden;
  background: radial-gradient(closest-side, rgba(255, 209, 102, .14), transparent) center / 100% 160% no-repeat, var(--surface-2); border: 1px solid color-mix(in srgb, var(--gold) 35%, var(--line)); }
.mg-goal .date { font-family: var(--mono); font-size: clamp(34px, 11vw, 52px); font-weight: 800; color: var(--gold); line-height: 1.1; margin-top: 4px; letter-spacing: -.02em; }
.mg-goal .countdown { font-size: 15px; font-weight: 700; margin-top: 2px; }
.mg-goal .pace { font-size: 12px; color: var(--text-2); margin-top: 6px; }
.mg-owed .owed { font-family: var(--mono); font-size: clamp(24px, 7vw, 34px); font-weight: 800; border-radius: 6px; padding: 0 2px; margin-left: -2px; }
.mg-owed .est { font-size: 11px; }
.mg-contract { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--text-2); }
.mg-contract .v { font-size: 16px; font-weight: 700; color: var(--text-2); margin-top: 2px; }
.mg-contract .s { font-size: 11px; color: var(--muted); margin-top: 2px; }
.mg-bar { position: relative; height: 12px; border-radius: 999px; background: var(--surface-2); margin: 14px 0 22px; border: 1px solid var(--line); }
.mg-bar .fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: linear-gradient(90deg, rgba(25,210,122,.35), var(--up)); transition: width 1s; }
.mg-bar .ghost { position: absolute; top: -5px; bottom: -5px; width: 2px; background: var(--gold); }
.mg-bar .ghost::after { content: attr(data-label); position: absolute; top: 100%; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--muted); white-space: nowrap; margin-top: 2px; }
.mg-bar .pct { position: absolute; right: 0; top: 100%; margin-top: 3px; font-family: var(--mono); font-size: 10px; color: var(--text-2); }
.mg-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mg-stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; min-width: 0; }
.mg-stat .k { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); }
.mg-stat .v { font-family: var(--mono); font-size: 16px; font-weight: 700; margin-top: 3px; }
.mg-stat .s { font-size: 11px; color: var(--muted); margin-top: 2px; }
.mg-stat .bar { margin-top: 6px; height: 6px; }
.mg-chart svg { display: block; width: 100%; height: 200px; margin-top: 14px; }
.mg-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 11px; color: var(--text-2); margin-top: 6px; }
.mg-legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--c); margin-right: 5px; vertical-align: middle; }
.mg-legend i.dash { border-top-style: dashed; }
@media (min-width: 820px) { .mg-stats { grid-template-columns: repeat(3, 1fr); } .mg-chart svg { height: 260px; } }

.grid-2 { display: grid; gap: 16px; }
footer { text-align: center; color: var(--muted); font-size: 11px; padding: 10px 16px 30px; }

@media (min-width: 820px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .chart-wrap svg { height: 320px; }
}

/* ---------- admin ---------- */
.admin main { max-width: 760px; }
.form { display: grid; gap: 10px; }
.form .row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
input[type=date] { min-width: 0; }
label { display: grid; gap: 4px; font-size: 11px; color: var(--text-2); font-weight: 600; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 11px; }
input:focus, select:focus { outline: 2px solid var(--jody); outline-offset: 0; border-color: transparent; }
.btn { appearance: none; border: 0; border-radius: 10px; padding: 11px 14px; font-weight: 700; font-size: 14px; background: var(--jody); color: #fff; cursor: pointer; }
.btn.ghost { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.danger { background: var(--down-bg); color: var(--down); }
.btn:disabled { opacity: .5; }
/* Tabs wrap onto extra rows so every section is visible on a phone. */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs button { flex: none; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 6px 11px; font-size: 12.5px; cursor: pointer; color: var(--text-2); }
.tabs button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 13px; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.toast.err { border-color: var(--down); color: var(--down); }
.note { font-size: 12px; color: var(--text-2); line-height: 1.5; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
details summary { cursor: pointer; font-size: 13px; font-weight: 600; padding: 4px 0; }
.coin-id { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.coin-id img { border-radius: 50%; flex: none; background: var(--surface-2); }
.coin-id small { display: block; font-size: 11px; color: var(--muted); }
.coin-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); align-items: center; }
.coin-row .coin-id { grid-column: 1 / -1; }
.coin-row .coin-btns { grid-column: 1 / -1; display: flex; gap: 8px; }
.coin-result { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; margin-top: 6px; cursor: pointer; font-size: 13px; }
.coin-result .muted { margin-left: auto; font-size: 11px; }
.danger-zone { margin-top: 26px; padding-top: 16px; border-top: 1px dashed color-mix(in srgb, var(--down) 45%, var(--line)); display: grid; gap: 10px; }
.danger-zone h2 { color: var(--down) !important; margin: 0 !important; }
.danger-zone .btn { justify-self: start; }
.hidden { display: none !important; }
.src.est { background: color-mix(in srgb, var(--gold) 16%, transparent); color: var(--gold); }

/* ---------- holdings ---------- */
.acct.expandable { cursor: pointer; }
.acct.expandable:hover .nm { color: var(--text); text-decoration: underline; text-decoration-color: var(--line); }
.chev { color: var(--muted); font-size: 11px; }
.holdings { margin: 0 0 6px 40px; padding: 4px 0 6px 12px; border-left: 2px solid color-mix(in srgb, var(--c) 45%, var(--line)); }
.pos { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 7px 0; border-top: 1px dashed var(--line); }
.pos:first-child { border-top: 0; }
.pos img, .pos-tag { width: 24px; height: 24px; border-radius: 50%; }
.pos-tag { display: grid; place-items: center; background: var(--surface-2); font-size: 7px; font-weight: 800; letter-spacing: -.02em; color: var(--text-2); font-family: var(--mono); }
.pos-n { display: flex; flex-direction: column; min-width: 0; font-size: 12px; }
.pos-n span { font-size: 11px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos-n small { font-size: 10px; color: var(--muted); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos-v { display: flex; flex-direction: column; align-items: flex-end; }
.pos-v .v { font-size: 13px; font-weight: 700; border-radius: 4px; padding: 0 2px; }
.pos-v .pl { font-size: 10px; }
.pos-foot { font-size: 10px; padding-top: 6px; }
.tg-net { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); text-align: left; }
.tg-net-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 13px; font-weight: 600; }
.tg-net-row .nw { font-size: 17px; font-weight: 800; border-radius: 4px; padding: 0 3px; }
.tg-net-sub { font-size: 10px; margin-top: 2px; }

/* ---------- monthly saving ---------- */
.saving { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.sv { min-width: 0; }
.sv-head { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.sv-head .avatar { width: 20px; height: 20px; border-radius: 50%; flex: none; background: var(--photo) center 20% / cover; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--c); }
.sv-streak { margin-left: auto; font-size: 10px; color: var(--gold); white-space: nowrap; }
.sv-amt { margin-top: 6px; font-size: 11px; }
.sv-amt .paid { font-size: clamp(18px, 5.5vw, 24px); font-weight: 800; border-radius: 4px; padding: 0 2px; margin-left: -2px; }
.sv-bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 6px 0; }
.sv-bar .fill { height: 100%; border-radius: 999px; background: var(--c); transition: width 1s; }
.sv-bar .fill.over { background: linear-gradient(90deg, var(--c), var(--gold)); }
.sv-status { font-size: 11px; min-height: 15px; }
.sv-status .warn { color: var(--warn); }
.sv-strip { margin-top: 10px; }
.sv-badges { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px 2px; }
.sv-badge { display: grid; justify-items: center; gap: 2px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.sv-badge i { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; font-style: normal; font-size: 13px; line-height: 1;
  background: radial-gradient(circle, var(--surface) 58%, transparent 60%), conic-gradient(var(--ring, var(--up)) var(--p), var(--line) 0); }
.sv-badge { position: relative; }
.sv-badge small { font-size: 9px; color: var(--muted); }
.sv-gift { position: absolute; top: -6px; right: 0; font-size: 10px; font-style: normal; }
.sv-badge.hit i { --ring: var(--gold); box-shadow: 0 0 10px color-mix(in srgb, var(--gold) 45%, transparent); }
.sv-badge.some i { --ring: var(--up); }
.sv-badge.now i { --ring: var(--c); animation: sv-pulse 2s ease-in-out infinite; }
.sv-badge.none i { opacity: .45; }
.sv-badge.out i { --ring: var(--down); background: radial-gradient(circle, var(--surface) 58%, transparent 60%), var(--down); }
.sv-badge.na i { background: none; border: 1.5px solid var(--line); }
.sv-badge.na, .sv-badge.future { cursor: default; }
.sv-badge.future i { background: none; border: 1.5px dashed var(--line); }
.sv-badge.future small, .sv-badge.na small { opacity: .6; }
.sv-year { font-size: 11px; margin-bottom: 6px; }
.sv-year b { color: var(--text-2); }
.sv-badge.sel i { outline: 2px solid var(--text-2); outline-offset: 1px; }
.sv-badge-read { font-size: 11px; margin-top: 6px; min-height: 1.4em; }
.sv-where { margin-top: 3px; line-height: 1.5; color: var(--text-2); }
@keyframes sv-pulse { 50% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 30%, transparent); } }
.sv-cheer { margin: -2px 0 12px; padding: 8px 12px; border-radius: 10px; font-size: 13px; background: color-mix(in srgb, var(--gold) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--gold) 40%, var(--line)); }
#saving-card { position: relative; overflow: hidden; }
.confetti { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.confetti i { position: absolute; top: -10px; width: 7px; height: 11px; border-radius: 2px; animation: confetti-fall linear forwards; }
@keyframes confetti-fall { to { transform: translate(var(--dx), 420px) rotate(var(--r)); opacity: 0; } }
.sv-period { font-size: 10px; margin-top: 5px; }
.saving-note { font-size: 10px; line-height: 1.5; margin: 12px 0 0; }
.sv-impact { font-size: 11px; line-height: 1.5; margin-top: 6px; }
.sv-impact b { color: var(--text); }
.sv-of a { color: var(--gold); }
.player .meta .chip { font-size: 9.5px; padding: 2px 6px; }
.chip.peer-top { background: color-mix(in srgb, var(--gold) 18%, transparent); color: var(--gold); }
.chip.peer-above { background: var(--up-bg); color: var(--up); }
.chip.peer-typical { background: var(--surface-2); color: var(--text-2); }
.chip.peer-below { background: rgba(255,176,32,.15); color: var(--warn); }
.tg-peers { font-size: 11px; margin-top: 10px; line-height: 1.5; }
.tg-peers b { color: var(--text); font-weight: 600; }

/* Make the hidden attribute win over layout rules like .player .meta div { display:flex } */
[hidden] { display: none !important; }

/* ---------- admin: £1M what-if slider ---------- */
.whatif { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 12px 10px; }
.wi-slider { width: 100%; padding: 0; border: 0; background: transparent; accent-color: var(--c); height: 28px; }
.wi-scale { display: flex; justify-content: space-between; font-size: 9px; margin-top: -2px; }
.wi-out { margin-top: 8px; font-size: 12px; line-height: 1.6; }
.wi-big { font-size: 15px; color: var(--text); }
.wi-big span { font-size: 11px; color: var(--muted); }

/* ---------- player card: more stats ---------- */
.more-btn { margin-top: 10px; background: none; border: 0; padding: 2px 0; font-size: 11px; color: var(--text-2); cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); }
.player .meta.more { margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--line); }
.player .meta.more .mix-wrap { justify-content: flex-start; }
.mix { display: flex !important; gap: 2px; height: 8px; border-radius: 999px; overflow: hidden; margin: 2px 0 4px; }
.mix span { display: block; min-width: 3px; }
.mix-legend { display: flex !important; flex-wrap: wrap; gap: 3px 10px; font-size: 10px; color: var(--text-2); justify-content: flex-start !important; }
.mix-legend span { display: inline-flex; align-items: center; gap: 4px; }
.mix-legend i { width: 7px; height: 7px; border-radius: 2px; display: inline-block; }

/* ---------- top bar: leader pill ---------- */
/* ---------- freedom planner ---------- */
.fr-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.fr-tile { display: grid; gap: 2px; justify-items: start; text-align: left; min-width: 0; padding: 10px; border-radius: 12px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); }
.fr-tile.on { border-color: var(--c); box-shadow: 0 0 0 1px var(--c) inset; }
.fr-who { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.fr-who .avatar { width: 18px; height: 18px; border-radius: 50%; background: var(--photo) center 20% / cover; box-shadow: 0 0 0 1.5px var(--c); }
.fr-age { font-size: 26px; font-weight: 800; color: var(--c); line-height: 1.1; }
.fr-sub { font-size: 11px; line-height: 1.35; color: var(--muted); max-width: 100%; }
.fr-race { margin: 10px 0 0; font-size: 13px; }
.fr-race:empty { display: none; }
.fr-hint { font-size: 11px; margin-top: 8px; }
.fr-detail { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.fr-slider-label { display: grid; gap: 6px; font-size: 13px; }
.fr-slider { width: 100%; accent-color: var(--c, var(--gold)); }
.fr-out { display: grid; gap: 4px; font-size: 13px; }
.fr-out .warn { color: var(--warn); }
.fr-mc { padding: 6px 0; }
.fr-units { display: inline-flex; gap: 3px; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); justify-self: start; }
.fr-units button { border: 0; background: none; color: var(--text-2); font: inherit; font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 8px; cursor: pointer; }
.fr-units button.on { background: var(--surface); color: var(--text); box-shadow: inset 0 -2px 0 var(--gold); }
.fr-growth { margin-top: 4px; padding-top: 10px; border-top: 1px dashed var(--line); }
.fr-growth-head { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.fr-gwrap svg { display: block; width: 100%; height: 190px; touch-action: pan-y; }
.fr-gtip { font-size: 11.5px; min-height: 2.8em; line-height: 1.5; margin-top: 2px; }
.fr-glegend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11px; color: var(--text-2); margin: 4px 0 8px; }
.fr-glegend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; opacity: .8; }
.fr-glegend i.band { background: var(--text-2); opacity: .25; }
.fr-keys { display: flex; flex-wrap: wrap; gap: 6px; }
.fr-key { font-size: 11.5px; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); }
.fr-key.bad { border-color: color-mix(in srgb, var(--down) 50%, var(--line)); }
.bm { display: grid; gap: 4px; margin-top: 8px; padding-top: 10px; border-top: 1px dashed var(--line); }
.bm-bar { position: relative; height: 8px; margin: 22px 4px 20px; border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--down) 45%, var(--surface-2)), color-mix(in srgb, var(--warn) 45%, var(--surface-2)), color-mix(in srgb, var(--up) 55%, var(--surface-2))); }
.bm-tick, .bm-own { position: absolute; top: 0; transform: translateX(-50%); display: grid; justify-items: center; }
.bm-tick i { width: 2px; height: 14px; margin-top: -3px; background: var(--text-2); }
.bm-tick small { font-size: 9.5px; color: var(--muted); white-space: nowrap; margin-top: 2px; }
.bm-own { top: -19px; }
.bm-own i { width: 2px; height: 14px; background: var(--gold); }
.bm-own small { font-size: 9.5px; color: var(--gold); white-space: nowrap; }
.bm-you { position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%; transform: translate(-50%, -50%);
  background: var(--c); border: 2px solid var(--surface); box-shadow: 0 0 0 2px var(--c), 0 0 10px var(--c); }
.fr-big { font-size: 15px; }
.fr-big b { font-family: var(--mono); font-size: 17px; color: var(--text); }
.fr-story { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 0; }
.fr-story li { display: grid; padding: 7px 0; border-left: 2px solid var(--line); margin-left: 6px; padding-left: 12px; position: relative; font-size: 12.5px; }
.fr-story li::before { content: ''; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--c, var(--gold)); }
.fr-story li.short::before { border-color: var(--down); }
.fr-story li.end { border-left-color: transparent; }
.fr-when { font-weight: 700; color: var(--c, var(--gold)); white-space: nowrap; margin-right: 4px; }
.fr-why { font-weight: 600; margin-bottom: 2px; }
.fr-ages { font-size: 11px; margin-bottom: 2px; }

/* ---------- crown race ---------- */
.crown-dialog { padding: 0; border: 0; background: transparent; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); color: var(--text); }
.crown-dialog::backdrop { background: rgba(3, 5, 9, .72); backdrop-filter: blur(3px); }
.crown-dialog .crown-card { margin: 0; max-height: calc(100dvh - 40px); overflow-y: auto; }
.crown-dialog[open] .crown-card { animation: cd-in .22s ease-out; }
@keyframes cd-in { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.cd-close { margin-left: 8px; background: none; border: 0; color: var(--text-2); font-size: 16px; cursor: pointer; padding: 2px 4px; }
.player .avatar { cursor: pointer; }
.crown-month { color: var(--gold); margin-left: 4px; }
.hist-dialog { width: min(760px, calc(100vw - 24px)); }
.hist-dialog > .card { margin: 0; max-height: calc(100dvh - 40px); overflow-y: auto; }
.hist-dialog[open] > .card { animation: cd-in .22s ease-out; }
.track-card { cursor: pointer; }
.track-more { font-size: 11px; color: var(--text-2); margin-top: 10px; text-decoration: underline; text-decoration-color: var(--line); }
.crown-left { letter-spacing: 0; text-transform: none; font-weight: 500; }
.cr-score { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.cr-side { display: grid; justify-items: center; gap: 4px; padding: 10px 6px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.cr-side.lead { border-color: var(--gold); box-shadow: 0 0 18px color-mix(in srgb, var(--gold) 25%, transparent); }
.cr-side .avatar { position: relative; width: 40px; height: 40px; border-radius: 50%; background: var(--photo) center 20% / cover; box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--c); }
.cr-mini { position: absolute; top: -14px; left: 50%; transform: translateX(-50%) rotate(-12deg); font-size: 18px; }
.cr-name { font-size: 12px; color: var(--text-2); }
.cr-pts { font-size: 30px; font-weight: 800; color: var(--c); line-height: 1; }
.cr-dash { font-size: 22px; }
.cr-status { text-align: center; font-size: 13px; margin: 10px 0 6px; }
.cr-table { display: grid; }
.cr-row { display: grid; grid-template-columns: 1fr 64px 64px; gap: 6px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); font-size: 13px; }
.cr-head { font-size: 11px; border-top: 0; padding-bottom: 4px; }
.cr-head span:not(:first-child), .cr-v { text-align: right; }
.cr-cat { display: grid; min-width: 0; }
.cr-cat small { font-size: 10.5px; }
.cr-w { font-size: 10px; color: var(--muted); margin-left: 2px; }
.cr-v { color: var(--text-2); }
.cr-v.win { color: var(--c); font-weight: 700; }
.cr-v.draw { color: var(--text); }
.cr-row.na { opacity: .55; }
.cr-note { font-size: 11px; margin: 8px 0 0; }
.cr-year { margin-top: 10px; font-size: 12px; display: grid; gap: 6px; }
.cr-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.cr-chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--c) 50%, var(--line)); background: color-mix(in srgb, var(--c) 12%, var(--surface)); }

/* ---------- notifications banner ---------- */
.notify-banner { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; font-size: 13px;
  background: color-mix(in srgb, var(--gold) 10%, var(--surface)); border: 1px solid color-mix(in srgb, var(--gold) 35%, var(--line)); }
.nb-text { flex: 1; min-width: 0; }
.review-banner { text-decoration: none; color: inherit; }
.nb-x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px; }

/* ---------- pay review wizard ---------- */
.klog { margin-top: 6px; font-size: 11px; }
.klog summary { cursor: pointer; color: var(--text-2); }
.klog div { padding: 2px 0; }
.rv-who { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.rv-steps { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.rv-steps .on { color: var(--gold); font-weight: 700; }
.rv-steps .done { color: var(--up); }
.rv-step h3 { margin: 0; font-size: 15px; }
.rv-live { font-size: 13px; line-height: 1.6; min-height: 1.6em; }
.rv-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; }
.rv-pension { display: grid; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); }
.rv-sum { display: grid; gap: 4px; font-size: 13px; }
.rv-sum > div { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
#rv-min-slider { width: 100%; accent-color: var(--gold); }

/* ---------- medals hanging from the player cards ---------- */
.player { padding-bottom: 66px; }
.player > .medals { position: absolute; left: 0; right: 0; bottom: 0; overflow: hidden; z-index: 2; height: 58px; display: flex; align-items: flex-start; gap: 4px; padding: 0 10px;
  background: none; border: 0; cursor: pointer; font: inherit; color: inherit; }
.medals .rail { position: absolute; left: 10px; right: 10px; top: 6px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--c) 70%, var(--line)) 12%, color-mix(in srgb, var(--c) 70%, var(--line)) 88%, transparent); }
.medal { position: relative; display: grid; justify-items: center; margin-top: 6px; transform-origin: top center; animation: medal-sway 6s ease-in-out infinite; }
.medal:nth-child(odd) { animation-delay: -2s; }
.medal .ribbon { width: 12px; height: 16px; background: linear-gradient(90deg, var(--c) 0 50%, color-mix(in srgb, var(--c) 55%, #fff) 50%); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 75%, 0 100%); }
.medal b { display: grid; place-items: center; width: 25px; height: 25px; margin-top: -4px; border-radius: 50%; font-size: 14px; font-weight: 700;
  background: radial-gradient(circle at 35% 30%, #fff3c4, var(--gold) 45%, #b8862a); box-shadow: 0 2px 6px rgba(0,0,0,.5), inset 0 0 0 2px rgba(255,255,255,.25); }
.medal.more b { font-size: 10px; color: #3a2a00; }
.medal.empty { opacity: .35; filter: grayscale(1); }
.medals small { align-self: center; margin-top: 8px; font-size: 11px; }
.medal.new { animation: medal-jiggle .5s ease-in-out 5; }
@keyframes medal-sway { 50% { transform: rotate(3deg); } }
@keyframes medal-jiggle { 25% { transform: rotate(-22deg) scale(1.15); } 75% { transform: rotate(22deg) scale(1.15); } }
.burst { position: fixed; width: 6px; height: 9px; border-radius: 2px; pointer-events: none; z-index: 60; animation: burst-out 1.2s cubic-bezier(.2,.7,.3,1) forwards; }
@keyframes burst-out { to { transform: translate(var(--dx), calc(var(--dy) + 60px)) rotate(var(--r)); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .medal, .medal.new { animation: none; } }

.lead-pill { display: inline-flex; align-items: center; gap: 6px; min-width: 0; max-width: 100%; justify-self: center; padding: 3px 10px 3px 3px; border-radius: 999px;
  background: color-mix(in srgb, var(--c, var(--gold)) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c, var(--gold)) 45%, var(--line));
  font-size: 12px; white-space: nowrap; box-shadow: 0 0 14px color-mix(in srgb, var(--c, var(--gold)) 25%, transparent); }
.lead-pill:empty { visibility: hidden; }
.lp-avatar { width: 22px; height: 22px; border-radius: 50%; flex: none; background: center 20% / cover; box-shadow: 0 0 0 1.5px var(--c); }
.lp-text { overflow: hidden; text-overflow: ellipsis; color: var(--text-2); }
.lp-text b { color: var(--c); }
.lp-gap { color: var(--text); font-weight: 700; }
.lead-pill a { color: var(--gold); text-decoration: none; padding-left: 8px; }

/* ---------- crown steal ---------- */
.player .avatar.crowned { cursor: pointer; }
.player .avatar.crowned.no-drop .crown { animation: none; }
.crown-fly { position: fixed; z-index: 100; font-size: 15px; line-height: 1; pointer-events: none; transform-origin: 50% 60%;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.6)) drop-shadow(0 0 8px rgba(255,209,102,.6)); }

/* ---------- title ribbons ---------- */
.titles { display: grid; gap: 4px; margin: 8px 0 2px; }
.titles:empty { display: none; }
.ribbon { position: relative; overflow: hidden; display: flex; align-items: center; gap: 6px; padding: 4px 8px 4px 5px; border-radius: 4px 10px 10px 4px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--gold) 30%, transparent), color-mix(in srgb, var(--gold) 8%, transparent));
  border-left: 3px solid var(--gold); transform-origin: left center;
  animation: ribbon-in .7s cubic-bezier(.2,1.3,.4,1) both; animation-delay: calc(.35s + var(--i) * .18s); }
.ribbon::after { content: ''; position: absolute; inset: 0; background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,.45) 50%, transparent 65%);
  transform: translateX(-120%); animation: ribbon-shine 1.1s ease-out both; animation-delay: calc(1s + var(--i) * .18s); pointer-events: none; }
.r-icon { font-size: 14px; line-height: 1; animation: ribbon-pop .5s cubic-bezier(.2,1.8,.4,1) both; animation-delay: calc(.75s + var(--i) * .18s); }
.r-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.r-text b { font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--gold); }
.r-text small { font-size: 9.5px; color: var(--text-2); }
@keyframes ribbon-in { from { opacity: 0; transform: translateX(-24px) scaleX(.2) skewX(-12deg); } to { opacity: 1; transform: none; } }
@keyframes ribbon-shine { to { transform: translateX(120%); } }
@keyframes ribbon-pop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }

/* ---------- risk meter ---------- */
.risk-meter { position: relative; height: 6px !important; border-radius: 999px; margin: 2px 0 8px; display: block !important;
  background: linear-gradient(90deg, #19d27a, #ffd166 50%, #ff4d5e); }
.risk-meter i { position: absolute; top: -3px; width: 10px; height: 12px; border-radius: 3px; background: var(--text); box-shadow: 0 0 0 2px var(--surface); transition: left 1s; }
.risk-meter::before, .risk-meter::after { position: absolute; top: 8px; font-size: 10px; }
.risk-meter::before { content: '🛡️'; left: -2px; }
.risk-meter::after { content: '🎢'; right: -2px; }

/* ---------- leaderboard (collapsible) ---------- */
.board-summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.board-summary b { font-size: 18px; }
.board-summary .bs-of { font-size: 11px; margin-left: auto; }
.board { margin-top: 12px; }
.sv-inout { font-size: 10.5px; margin-top: 2px; color: var(--text-2); }
/* A month with a withdrawal gets a small red marker under its bar. */
/* Paid in / Taken out toggle */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg label { display: block; }
.seg input { position: absolute; opacity: 0; pointer-events: none; width: auto; }
.seg span { display: block; text-align: center; padding: 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text-2); font-size: 13px; font-weight: 600; cursor: pointer; }
.seg input:checked + span { color: var(--text); border-color: var(--up); background: var(--up-bg); }
.seg label:last-child input:checked + span { border-color: var(--down); background: var(--down-bg); }
.seg input:focus-visible + span { outline: 2px solid var(--jody); }
.mg-more-btn { margin: 0 0 4px; }
.mg-more { margin-top: 10px; }

/* Line the two saving cards up row by row: each card spans the same 10 rows of a shared grid (subgrid),
   so a line one person has and the other doesn't leaves a matching gap instead of shifting everything up. */
.saving { row-gap: 0; }
.sv { display: grid; grid-row: span 10; grid-template-rows: subgrid; align-content: start; }
.sv-line { font-size: 11px; line-height: 1.5; }
.sv-line b { color: var(--text); }
.sv-event { margin-top: 6px; }
.sv-inout:empty, .sv-line:empty { min-height: 0; }

/* ---------- race history (collapsible) ---------- */
.hist-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; font-size: 13px; }
.hist-summary > span { display: inline-flex; align-items: center; gap: 4px; }
.hist-summary .hs-of { font-size: 11px; margin-left: auto; }
#hist-toggle { margin-top: 8px; }
#hist-body { margin-top: 10px; }
.pos img { object-fit: cover; background: #fff; }

/* Player cards share one row grid (subgrid), so every line sits at the same height on both cards and the cards
   are always equal height. The stat lists use display:contents so each stat row is its own grid row. */
.players { grid-template-rows: repeat(24, auto); row-gap: 0; }
.player { display: grid; grid-row: 1 / span 24; grid-template-rows: subgrid; align-content: start; row-gap: 0; }
.player .meta, .player .meta.more { display: contents; }
.player .meta > div { margin-top: 4px; font-size: 11px; color: var(--text-2); align-items: center; }
.player .meta:not(.more) > div:first-child { margin-top: 10px; }
.player .meta.more > div:first-child { margin-top: 6px; padding-top: 8px; border-top: 1px dashed var(--line); }
.player .more-btn { justify-self: start; }
.player .meta > .mix { align-items: stretch; margin-top: 2px; }

/* Top bar: eye + settings on the right. */
#privacy-toggle { margin-left: auto; cursor: pointer; }
@media (max-width: 400px) { .logo { font-size: 13px; } }

/* ==================== Admin (redesign): sidebar, pages, tables, save bar ==================== */
body.admin { --nav-w: 232px; }
.admin .adm-top { display: flex; align-items: center; gap: 10px; }
.admin .adm-top .logo span { color: var(--gold); }
.adm-where { font-size: 13px; font-weight: 600; color: var(--text-2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-where::before { content: '›'; margin-right: 8px; color: var(--muted); }
.adm-who { font-size: 11px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); align-items: start; max-width: 1180px; margin: 0 auto; }
.adm-nav { position: sticky; top: 58px; display: flex; flex-direction: column; gap: 2px; padding: 16px 10px 24px; max-height: calc(100dvh - 58px); overflow-y: auto; }
.adm-group { font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.adm-group:first-child { padding-top: 0; }
.adm-nav button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; border-radius: 9px; padding: 8px 10px;
  font-size: 13.5px; color: var(--text-2); cursor: pointer; }
.adm-nav button i { font-style: normal; width: 18px; text-align: center; }
.adm-nav button:hover { background: var(--surface); color: var(--text); }
.adm-nav button.on { background: var(--surface-2); color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--gold); }
.adm-badge { margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--warn); color: #241600; font-size: 10.5px; font-weight: 800; display: grid; place-items: center; }
.adm-badge.dot { min-width: 9px; width: 9px; height: 9px; padding: 0; background: var(--down); box-shadow: 0 0 8px var(--down); }
.adm-badge[hidden] { display: none; }
.adm-back { display: none; margin-top: 18px; padding: 8px 10px; font-size: 13px; color: var(--text-2); text-decoration: none; }
.adm-menu { display: none; }
.adm-scrim { display: none; }
.admin main.adm-main { max-width: 860px; width: 100%; padding: 22px 20px 120px; margin: 0; display: grid; gap: 14px; }
.page { display: grid; gap: 14px; }
.page.hidden { display: none; }
.page-head { padding: 2px 2px 4px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }
.page-head h1 .spacer { flex: 1; }
.page-head p { margin: 6px 0 0; font-size: 13px; color: var(--text-2); line-height: 1.55; max-width: 680px; }
.admin .page > .card, .admin .adm-cols > .card { margin: 0; }
.admin .card h2 { display: flex; align-items: center; gap: 8px; }
.help { margin: 0 0 12px; font-size: 12px; color: var(--text-2); line-height: 1.55; }
small.help { display: block; margin: -2px 0 2px; font-size: 11px; color: var(--muted); }
.adm-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.adm-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.admin .danger-zone { border-color: color-mix(in srgb, var(--down) 45%, var(--line)); background: color-mix(in srgb, var(--down) 5%, var(--surface)); margin-top: 0; padding-top: 16px; }
.admin details summary { cursor: pointer; list-style: none; }
.admin details summary::-webkit-details-marker { display: none; }
.admin details summary::after { content: ' ▾'; color: var(--muted); }
.admin details[open] summary::after { content: ' ▴'; }

/* Targets: one person at a time, grouped fields */
.adm-switch { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); justify-self: start; }
.adm-switch button { border: 0; background: none; color: var(--text-2); font: inherit; font-size: 13px; font-weight: 600; padding: 7px 18px; border-radius: 9px; cursor: pointer; }
.adm-switch button.on { background: var(--surface-2); color: var(--c); box-shadow: inset 0 -2px 0 var(--c); }
#targets { display: grid; gap: 14px; }
#targets form[hidden] { display: none; }
.grp { margin: 10px 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
form > .grp:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
/* Forms with the save bar do not need their own Save button. */
form[data-sticky] > button.btn:last-child { display: none; }

/* Save bar */
.savebar { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 10px 16px; border-radius: 14px; background: var(--surface-2); border: 1px solid color-mix(in srgb, var(--gold) 45%, var(--line));
  box-shadow: 0 12px 40px rgba(0,0,0,.6); font-size: 13px; animation: cd-in .2s ease-out; }
.savebar > span { color: var(--gold); font-weight: 600; margin-right: 4px; }
.savebar[hidden] { display: none; }

/* Tables */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.tbl td small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.tbl .r { text-align: right; }
.tbl .nowrap { white-space: nowrap; }
.tbl .acts { text-align: right; white-space: nowrap; }
.tbl .acts .btn { margin-left: 4px; }
.tbl code { font-size: 11.5px; color: var(--text-2); }
.tbl-filter { width: auto; font-size: 12px; padding: 5px 8px; border-radius: 8px; }

/* Overview */
.ov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.ov-acct { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; min-width: 0; }
.ov-acct > div { min-width: 0; }
.ov-acct small { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
.ov-dot { flex: none; width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--up); box-shadow: 0 0 8px var(--up); }
.ov-acct.warn .ov-dot { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.ov-acct.bad { border-color: color-mix(in srgb, var(--down) 50%, var(--line)); }
.ov-acct.bad .ov-dot { background: var(--down); box-shadow: 0 0 8px var(--down); }
.ov-todo { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 12px; margin-top: 6px; border-radius: 10px; cursor: pointer; font: inherit; font-size: 13px;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--line); }
.ov-todo:first-child { margin-top: 0; }
.ov-todo i { margin-left: auto; font-style: normal; color: var(--muted); }
.ov-todo:hover { border-color: var(--text-2); }
.ov-todo.bad { border-color: color-mix(in srgb, var(--down) 50%, var(--line)); }
.ov-todo.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.ov-allgood { font-size: 13px; color: var(--up); }
.ov-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Phones: the menu slides in from the left */
@media (max-width: 860px) {
  .adm-shell { grid-template-columns: minmax(0, 1fr); }
  .adm-menu { display: grid; }
  .adm-who { display: none; }
  .adm-nav { position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; width: min(280px, 84vw); max-height: none; padding: calc(env(safe-area-inset-top) + 18px) 12px 24px;
    background: var(--bg); border-right: 1px solid var(--line); transform: translateX(-102%); transition: transform .22s ease-out; }
  body.menu-open .adm-nav { transform: none; box-shadow: 20px 0 60px rgba(0,0,0,.6); }
  .adm-back { display: block; }
  .adm-scrim { position: fixed; inset: 0; z-index: 25; background: rgba(3,5,9,.6); }
  body.menu-open .adm-scrim { display: block; }
  .admin main.adm-main { padding: 14px 12px 110px; }
  .page-head h1 { font-size: 19px; }
  .adm-cols { grid-template-columns: minmax(0, 1fr); }
  .tbl .acts .btn { margin: 2px 0 0 4px; }
}

/* ---------- help popups ---------- */
.help-btn { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text-2); font: inherit; font-size: 12px; font-weight: 800; letter-spacing: 0; cursor: pointer; }
.help-btn:hover { color: var(--text); border-color: var(--text-2); }
.help-card h3 { margin: 16px 0 4px; font-size: 13px; color: var(--gold); }
.help-card p, .help-card li { font-size: 13px; line-height: 1.55; color: var(--text-2); margin: 4px 0; }
.help-card b { color: var(--text); }
.help-card ul { margin: 4px 0; padding-left: 18px; }
.help-card .muted { color: var(--muted); }

/* Public demo site */
.demo-banner { padding: 10px 14px; border-radius: 12px; font-size: 13px; background: color-mix(in srgb, var(--jody) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--jody) 45%, var(--line)); }
.demo-banner[hidden] { display: none; }

/* ---------- popups (dialogs): iPhone-safe ----------
   The popup sits inside the safe screen area (below the notch / status bar, above the home bar), only the card
   inside it scrolls, and its title row with the ✕ stays pinned at the top. The page behind is locked while a
   popup is open (see lockScrollWhileDialogOpen in app.js). */
dialog.crown-dialog[open] {
  position: fixed; inset: 0; margin: auto; display: flex; flex-direction: column;
  top: calc(env(safe-area-inset-top, 0px) + 12px); bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  height: fit-content;
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px);
}
dialog.crown-dialog[open] > .card {
  flex: 1 1 auto; min-height: 0; max-height: none; margin: 0; overflow-y: auto;
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-top: 0;
}
dialog.crown-dialog[open] > .card > h2:first-child {
  position: sticky; top: 0; z-index: 2; margin: 0 -2px 8px; padding: 14px 2px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
dialog.crown-dialog .cd-close { min-width: 36px; min-height: 36px; font-size: 18px; }
html.modal-open, html.modal-open body { overflow: hidden; }

/* "A new version is available" */
.update-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 10px 14px; border-radius: 12px;
  font: inherit; font-size: 13px; color: var(--text); cursor: pointer; text-align: left;
  background: color-mix(in srgb, var(--up) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--up) 45%, var(--line)); }
.update-banner b { padding: 4px 12px; border-radius: 8px; background: var(--up); color: #032; }
.update-banner[hidden] { display: none; }

/* Pull to refresh (home-screen app) */
.ptr { position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 6px); z-index: 60; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,.5);
  transform: translate(-50%, -60px); opacity: 0; pointer-events: none; transition: opacity .15s; }
.ptr span { font-size: 17px; color: var(--text-2); transition: transform .2s; }
.ptr.ready span { transform: rotate(180deg); color: var(--up); }
.ptr.loading span { animation: ptr-spin .8s linear infinite; }
@keyframes ptr-spin { to { transform: rotate(360deg); } }

/* "How it works" ? buttons on the cards */
.card h2 .help-btn { margin-left: 4px; flex: none; }
.player > .pc-help { position: absolute; top: 12px; right: 10px; z-index: 3; width: 20px; height: 20px; font-size: 11px; opacity: .75; }
.together { position: relative; }
.together > .tg-help { position: absolute; top: 12px; right: 12px; z-index: 3; }
.adm-guide { margin-top: 18px; padding: 8px 10px; font-size: 13px; color: var(--text-2); text-decoration: none; }
.adm-guide + .adm-back { margin-top: 0; }
/* Room at the end of the guide, so its last sections can still scroll to the top when opened from a ? */
#guide .card::after { content: ""; display: block; height: 45dvh; }
