/* Zahrajme si - charcoal header, blue accent. Placeholder palette until a brand exists. */
:root {
  --brand: #2f6fde;          /* accent: fills, borders, highlights */
  --brand-ink: #ffffff;      /* text on accent fills (4.7:1, WCAG AA) */
  --brand-text: #1f56b8;     /* accent for text/links on light backgrounds (AA) */
  --charcoal: #252525;       /* header / dark surfaces */
  --charcoal-deep: #111111;
  --on-dark: #ffffff;
  --on-dark-muted: #c5c5c5;
  --paper: #f2f2f2;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --muted: #636466;
  --line: #dcdcdc;
  --win: #1d7a4f;
  --loss: #b5372d;
  --focus: var(--brand);

  --b1: #f2c230; --b2: #2550b8; --b3: #c8332b; --b4: #5b3a8c;
  --b5: #e8762d; --b6: #1f7a4a; --b7: #7a2430;

  --font-display: "Bahnschrift", "DIN Alternate", "Barlow Semi Condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius-s: 6px;
  --radius-m: 12px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121212;
    --surface: #1e1e1e;
    --ink: #ececec;
    --muted: #a8a8a8;
    --line: #333333;
    --brand-text: #7aa7ff;
    --win: #49b07f;
    --loss: #e0675c;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--font-body);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
}
a { color: var(--brand-text); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; letter-spacing: .01em; }
h1 { font-size: 1.9rem; margin: .2em 0 .5em; }
h2 { font-size: 1.35rem; margin: 1.6em 0 .5em; }
h3 { font-size: 1.1rem; margin: 1.2em 0 .3em; }
.num { font-family: var(--font-display); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
/* Long names (guests, account display names) must never widen the page */
h1, h2, .admin-list, .pick-list, .profile-head, .saved, .board td, .winner label small { overflow-wrap: anywhere; }
.field-error { color: var(--loss); font-size: .85rem; margin: 6px 0 0; }

/* ------------------------------------------------------------ header */
.rail {
  background: var(--charcoal);
  color: var(--on-dark);
  border-bottom: 4px solid var(--brand);
  padding-top: env(safe-area-inset-top, 0px);
}
.rail-inner {
  max-width: 980px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--on-dark); text-decoration: none;
  font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; }
.brand svg { width: 30px; height: 30px; }
.topnav { display: none; gap: 4px; margin-left: 12px; }
.topnav a { color: var(--on-dark-muted); text-decoration: none; padding: 6px 10px; border-radius: var(--radius-s); white-space: nowrap; }
.topnav a:hover { background: var(--charcoal-deep); color: var(--on-dark); }
.topnav a[aria-current="page"] { background: var(--brand); color: var(--brand-ink); }
.lang { margin-left: auto; display: flex; gap: 2px; }
.lang a { color: var(--on-dark-muted); text-decoration: none; font-size: .85rem; padding: 4px 8px; border-radius: var(--radius-s); }
.lang a[aria-current="true"] { background: var(--charcoal-deep); color: var(--brand); }

main { max-width: 980px; margin: 0 auto; padding: 16px; }

/* ------------------------------------------------------------ bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current="page"] { color: var(--brand-text); font-weight: 600; }
/* The add button is the cue ball */
.tabbar .cue {
  width: 56px; height: 56px; margin: -22px auto 0; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0 40%, #e9ece8 75%, #cfd5d0);
  border: 4px solid var(--brand); box-shadow: 0 3px 8px rgba(0,0,0,.25);
  display: grid; place-items: center; color: var(--charcoal);
}
.tabbar .cue svg { width: 26px; height: 26px; }

@media (min-width: 760px) {
  body { padding-bottom: 32px; }
  .tabbar { display: none; }
  .topnav { display: flex; }
  .admin-link { display: none; }
}

/* ------------------------------------------------------------ game type tabs */
.gt-tabs { display: flex; gap: 8px; overflow-x: auto; margin: 0 0 16px; padding-bottom: 2px; }
.gt-tab { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px;
  border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--ink);
  background: var(--surface); white-space: nowrap; }
.gt-tab[aria-current="true"] { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.gt-ball { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--gt-color, #16181b); }
.gt-ball span { width: 15px; height: 15px; border-radius: 50%; background: #fff; color: #16181b;
  font: 600 .62rem/15px var(--font-display); text-align: center; }

/* ------------------------------------------------------------ ball avatars */
.ball { --c: var(--b1); flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: inline-grid; place-items: center; background: var(--c);
  box-shadow: inset -3px -4px 0 rgba(0,0,0,.18); }
.ball span { width: 22px; height: 22px; border-radius: 50%; background: #fff; color: #16181b;
  font: 600 .7rem/22px var(--font-display); text-align: center; }
/* Guests are striped balls */
.ball.guest { background: linear-gradient(#fff 0 22%, var(--c) 22% 78%, #fff 78%);
  box-shadow: inset -3px -4px 0 rgba(0,0,0,.12), 0 0 0 1px var(--line); }
.ball.sm { width: 26px; height: 26px; }
.ball.sm span { width: 16px; height: 16px; font-size: .55rem; line-height: 16px; }
.ball.lg { width: 64px; height: 64px; }
.ball.lg span { width: 38px; height: 38px; font-size: 1rem; line-height: 38px; }
.b1 { --c: var(--b1); } .b2 { --c: var(--b2); } .b3 { --c: var(--b3); } .b4 { --c: var(--b4); }
.b5 { --c: var(--b5); } .b6 { --c: var(--b6); } .b7 { --c: var(--b7); }

.person { display: inline-flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }

/* ------------------------------------------------------------ buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--radius-s); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: 600 1rem var(--font-body);
  text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--loss); border-color: currentColor; background: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .875rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-weight: 600; margin: 14px 0 6px; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=date], input[type=datetime-local],
input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; font: 1rem var(--font-body);
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s);
}
textarea { min-height: 140px; }
.field-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.check input { width: 22px; height: 22px; }

.errors, .flash { border-radius: var(--radius-s); padding: 10px 14px; margin: 0 0 16px; }
.errors { background: color-mix(in srgb, var(--loss) 12%, transparent); border: 1px solid var(--loss); }
.errors ul { margin: 0; padding-left: 18px; }
.flash.success { background: color-mix(in srgb, var(--win) 14%, transparent); border: 1px solid var(--win); }
.flash.error { background: color-mix(in srgb, var(--loss) 12%, transparent); border: 1px solid var(--loss); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.toolbar h1 { margin: 0 auto 0 0; }

/* ------------------------------------------------------------ add game */
.sides { display: grid; gap: 12px; margin-top: 16px; }
@media (min-width: 640px) { .sides { grid-template-columns: 1fr 1fr; } }
.side { border: 2px solid var(--line); border-radius: var(--radius-m); padding: 12px; background: var(--surface); min-width: 0; }
.side h2 { margin: 0 0 8px; font-size: 1.1rem; }
.side-players { display: flex; flex-direction: column; gap: 6px; min-height: 44px; }
.chip { display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 4px; border-radius: 999px;
  background: var(--paper); }
.chip .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: transparent; color: var(--muted); width: 36px; height: 36px;
  border-radius: 50%; font-size: 1.3rem; cursor: pointer; }
.add-player { margin-top: 8px; width: 100%; border-style: dashed; }

.winner { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; margin-top: 8px; }
.winner input { position: absolute; opacity: 0; }
.winner label { margin: 0; min-height: 76px; padding: 10px; border: 2px solid var(--line);
  border-radius: var(--radius-m); background: var(--surface); cursor: pointer; font-weight: 600;
  display: flex; flex-direction: column; justify-content: center; text-align: center; }
.winner label small { font-weight: 400; color: var(--muted); }
.winner input:checked + label { border-color: var(--brand); background: var(--charcoal); color: var(--on-dark); }
.winner input:checked + label small { color: var(--brand); }
.winner input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Optional details box: appears below the winner buttons, orange edge draws the eye */
.game-details { margin-top: 16px; padding: 12px 14px 14px; background: var(--surface);
  border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: var(--radius-m); }
.game-details h2 { margin: 0; font-size: 1.1rem; }
.game-details .opt { font: 400 .8rem var(--font-body); color: var(--muted); margin-left: 8px; }
.game-details .field-label { font-weight: 600; margin: 14px 0 8px; }
.game-details .field-label small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.game-details .hint { margin: 8px 0 0; }
@media (prefers-reduced-motion: no-preference) {
  .game-details:not([hidden]) { animation: reveal .25s ease-out; }
  @keyframes reveal { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
}
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pills input { position: absolute; opacity: 0; pointer-events: none; }
.pills label { margin: 0; min-height: 44px; padding: 0 14px; display: inline-flex; align-items: center;
  justify-content: center; border: 1px solid var(--line); border-radius: 999px; background: var(--paper);
  font-weight: 500; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
.pills input:checked + label { background: var(--brand); color: var(--brand-ink); border-color: var(--brand);
  font-weight: 600; }
.pills input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
/* 0..7 on one row even on narrow phones */
.pills.balls { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; max-width: 420px; }
.pills.balls label { min-height: 48px; padding: 0; font: 600 1.15rem var(--font-display); }

details.more { margin-top: 12px; border: 1px dashed var(--line); border-radius: var(--radius-m); padding: 0 14px; }
details.more[open] { padding-bottom: 14px; }
details.more summary { cursor: pointer; font-weight: 600; min-height: 48px; display: flex; align-items: center;
  justify-content: space-between; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary::after { content: "+"; font: 600 1.4rem var(--font-display); color: var(--brand-text); }
details.more[open] summary::after { content: "\2212"; }
.save-bar { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 8px);
  margin-top: 20px; }
@media (min-width: 760px) { .save-bar { position: static; } }

/* Player picker sheet */
dialog.sheet { border: 0; padding: 0; width: 100%; max-width: 560px; max-height: 85vh;
  margin: auto auto 0; border-radius: var(--radius-m) var(--radius-m) 0 0;
  background: var(--surface); color: var(--ink); }
@media (min-width: 640px) { dialog.sheet { margin: auto; border-radius: var(--radius-m); } }
dialog.sheet::backdrop { background: rgba(17, 17, 17, .6); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0 auto 0 0; font-size: 1.1rem; }
.sheet-body { padding: 12px 16px 20px; overflow-y: auto; max-height: calc(85vh - 60px); }
.pick-list { list-style: none; margin: 8px 0 0; padding: 0; }
.pick-list button { width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; color: inherit;
  text-align: left; font: inherit; cursor: pointer; min-height: 52px; }
.pick-list button:disabled { opacity: .4; }
.pick-list button > span:last-child { min-width: 0; }
.pick-list .detail { display: block; font-size: .8rem; color: var(--muted); }
.guest-row { display: flex; gap: 8px; margin-top: 16px; }
.guest-row input { flex: 1; min-width: 0; }
.section-label { font-size: .85rem; color: var(--muted); margin: 14px 0 0; }

/* ------------------------------------------------------------ game list */
.games { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.game { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center;
  padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m);
  color: inherit; text-decoration: none; }
.game .team { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.game .team.b { align-items: flex-end; text-align: right; }
.game .team .person { max-width: 100%; }
.game .team .person span.n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game .team.won .n { font-weight: 700; }
.game .team.lost { color: var(--muted); }
.game .mid { text-align: center; font-size: .75rem; color: var(--muted); }
.game .mid .score { display: block; font-family: var(--font-display); font-size: 1.15rem; color: var(--ink); }
.game .mid .crown { color: var(--win); font-weight: 700; }
.game-meta { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.margin-tag.close { color: var(--brand-text); font-weight: 600; }

.filters { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px;
  align-items: start; }
.filters > div { min-width: 0; }
.filters label { margin: 0 0 4px; font-size: .8rem; font-weight: 600; color: var(--muted); }
.filters input, .filters select { width: 100%; min-width: 0; }
.filters [data-player-search] { margin-top: 6px; }
@media (min-width: 760px) { .filters { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }

/* ------------------------------------------------------------ leaderboard */
.board { width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.board th, .board td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.board th { font-size: .78rem; color: var(--muted); font-weight: 600; }
.board th:nth-child(2), .board td:nth-child(2) { text-align: left; }
.board td:first-child { width: 2.5em; text-align: center; font-family: var(--font-display); font-size: 1.1rem; }
.board tr:last-child td { border-bottom: 0; }
.board tr.first td { background: color-mix(in srgb, var(--brand) 14%, transparent); }
.board .pct { font-family: var(--font-display); font-size: 1.1rem; }
.hide-s { display: none; }
@media (min-width: 560px) { .hide-s { display: table-cell; } }

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.segmented a { padding: 8px 12px; text-decoration: none; color: var(--ink); background: var(--surface);
  border-right: 1px solid var(--line); font-size: .9rem; }
.segmented a:last-child { border-right: 0; }
.segmented a[aria-current="true"] { background: var(--charcoal); color: var(--on-dark); box-shadow: inset 0 -3px 0 var(--brand); }

/* ------------------------------------------------------------ content pages */
.doc { max-width: 70ch; }
.doc-layout { display: grid; gap: 24px; }
@media (min-width: 900px) { .doc-layout { grid-template-columns: 1fr 220px; } }
.toc { font-size: .9rem; }
.toc ul { list-style: none; padding: 0; margin: 0; }
.toc a { display: block; padding: 4px 0; color: var(--muted); text-decoration: none; }
@media (min-width: 900px) { .toc { position: sticky; top: 16px; align-self: start; order: 2; } }
@media (max-width: 899px) { .toc { display: none; } }
.doc h2 { border-top: 1px solid var(--line); padding-top: 1em; }
.doc h2:first-of-type { border-top: 0; padding-top: 0; }
.doc ul, .doc ol { padding-left: 1.3em; }
.doc li { margin: .25em 0; }
.doc figure { margin: 16px 0; }
.doc img { width: 100%; max-width: 440px; height: auto; display: block; }
.doc figcaption { font-size: .85rem; color: var(--muted); margin-top: 6px; }
.doc .faq-link { margin-top: -4px; }
@media (min-width: 900px) { .doc .faq-link { display: none; } }
.doc .key { border-left: 4px solid var(--brand); padding: 8px 14px; background: var(--surface); border-radius: 0 var(--radius-s) var(--radius-s) 0; }
.doc table { border-collapse: collapse; width: 100%; }
.doc td, .doc th { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.house { border: 2px dashed var(--brand); border-radius: var(--radius-m); padding: 4px 16px 8px; margin-top: 32px; }

.stats { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin: 12px 0 24px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px; }
.stat .big { font-family: var(--font-display); font-size: 1.8rem; line-height: 1.1; }

.profile-head { display: flex; align-items: center; gap: 16px; margin-bottom: 8px; }
.profile-head h1 { margin: 0; }

.admin-list { list-style: none; padding: 0; margin: 0; }
.admin-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.admin-list li > :nth-child(2) { flex: 1; min-width: 0; }
.tag { font-size: .72rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
pre.json { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .75rem; margin: 4px 0 0; color: var(--muted); }

.saved { text-align: center; padding: 24px 0; }
.saved .actions { display: flex; flex-direction: column; gap: 10px; max-width: 360px; margin: 24px auto 0; }

@media (prefers-reduced-motion: no-preference) {
  .saved .ball.lg { animation: roll .6s ease-out; }
  @keyframes roll { from { transform: translateX(-60px) rotate(-200deg); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* Sign-in and account pages */
.narrow { max-width: 420px; margin: 0 auto; }
