:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --text: #1d1b16;
  --muted: #6b665c;
  --border: #ddd7ca;
  --accent: #e4572e;
  --accent-text: #ffffff;
  --marked: #2f6fde;
  --marked-text: #ffffff;
  --bingo: #f2b705;
  --ok: #1f8a4c;
  --danger: #c0392b;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15140f;
    --surface: #221f19;
    --text: #f1ede4;
    --muted: #a39d90;
    --border: #3a3529;
    --marked: #4a86f0;
    --bingo: #f5c22c;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(24px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}
main { max-width: 640px; margin: 0 auto; }
h1 { font-size: 1.4rem; margin: 4px 0 2px; }
h2 { font-size: 1.15rem; margin: 0 0 10px; }
p { margin: 0 0 8px; }
a { color: var(--marked); }
.muted { color: var(--muted); font-size: .9rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
}
label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: .95rem; }
input, textarea, button { font: inherit; }
input[type=text], input[type=number], textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}
textarea { min-height: 180px; resize: vertical; }
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
button.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
button.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1 1 160px; }
.error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  border-radius: 10px; padding: 10px 12px; margin: 10px 0;
}
.hidden { display: none !important; }

/* ---- Plansza ---- */
.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  width: 100%;
  max-width: min(100%, 560px);
  margin: 0 auto;
}
.cell {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 3px;
  min-height: 0; min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  font-size: clamp(9px, 2.4vw, 14px);
  line-height: 1.12;
  text-align: center;
  overflow: hidden;
  overflow-wrap: break-word;
  hyphens: auto;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, background .15s ease;
}
.cell > span { min-width: 0; max-width: 100%; overflow-wrap: break-word; }
.cell:active:not(:disabled) { transform: scale(.95); }
.cell.marked { background: var(--marked); color: var(--marked-text); border-color: var(--marked); }
.cell.free > span { font-size: 1.8em; }
.cell.free { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 800; }
.cell.win { box-shadow: inset 0 0 0 3px var(--bingo); }
.cell.pending { opacity: .6; }
.cell:disabled { opacity: 1; }
.board.readonly .cell { cursor: default; }
.board.readonly .cell:not(.marked):not(.free) { color: var(--muted); }

.status {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  margin: 10px 0;
}
.timer { font-variant-numeric: tabular-nums; font-size: 1.5rem; font-weight: 700; }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: .8rem; font-weight: 700;
  background: var(--border); color: var(--text);
}
.badge.running { background: var(--ok); color: #fff; }
.badge.finished { background: var(--muted); color: #fff; }
.badge.bingo { background: var(--bingo); color: #1d1b16; }

.bingo-banner {
  text-align: center;
  font-size: 2rem; font-weight: 900; letter-spacing: .06em;
  padding: 10px; margin: 10px 0;
  border-radius: var(--radius);
  background: var(--bingo); color: #1d1b16;
  animation: pop .5s ease;
}
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .bingo-banner { animation: none; } .cell { transition: none; } }

/* ---- Admin ---- */
.player { border-top: 1px solid var(--border); padding: 12px 0; }
.player:first-child { border-top: 0; padding-top: 0; }
.player-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.progress { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; margin: 6px 0; }
.progress > div { height: 100%; background: var(--marked); }
.mini { display: grid; grid-template-columns: repeat(5, 14px); gap: 2px; }
.mini span { width: 14px; height: 14px; border-radius: 3px; background: var(--border); }
.mini span.on { background: var(--marked); }
.mini span.free { background: var(--accent); }
.mini span.win { background: var(--bingo); }
.link-box {
  font-family: ui-monospace, monospace; font-size: .8rem;
  word-break: break-all; color: var(--muted); margin: 4px 0;
}
.game-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--border); color: inherit; text-decoration: none; }
.game-item:first-child { border-top: 0; }
details summary { cursor: pointer; font-weight: 600; }
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600;
  z-index: 10;
}

/* ---- Przełącznik trybu (segmentowy "slider") ---- */
.mode-switch {
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}
.mode-switch input { position: absolute; opacity: 0; pointer-events: none; }
.mode-switch label {
  position: relative; z-index: 1;
  margin: 0; padding: 10px 6px; min-height: 44px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-weight: 600; font-size: .92rem; line-height: 1.2;
  border-radius: 9px; cursor: pointer;
  color: var(--muted);
  transition: color .2s ease;
}
.mode-switch .thumb {
  position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 4px);
  background: var(--accent);
  border-radius: 9px;
  transition: transform .25s ease;
}
.mode-switch input:checked + label { color: var(--accent-text); }
.mode-switch input:nth-of-type(2):checked ~ .thumb { transform: translateX(100%); }
.mode-switch.tabs { margin: 4px 0 10px; }
.mode-switch input:focus-visible + label { outline: 2px solid var(--marked); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .mode-switch .thumb { transition: none; } }

.badge.mode { background: transparent; border: 1px solid var(--border); color: var(--muted); font-weight: 600; }
.ranking { list-style: none; padding: 0; margin: 0; }
.ranking li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-top: 1px solid var(--border); }
.ranking li:first-child { border-top: 0; }
.ranking .place { width: 2.2em; font-weight: 800; font-variant-numeric: tabular-nums; }
.ranking .who { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ranking .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.ranking li.top .place, .ranking li.top .who { color: var(--text); }
.ranking li.top { background: color-mix(in srgb, var(--bingo) 22%, transparent); border-radius: 8px; }
.ranking li.me .who { font-weight: 800; }
.counter { text-align: center; font-size: 1.1rem; margin: 6px 0 10px; }
.counter strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.ranking .tag { font-size: .72rem; margin-left: 6px; vertical-align: middle; }
.ranking .sub { display: block; font-size: .8rem; color: var(--muted); font-weight: 400; }
