/* ---------------------------------------------------------------------------
   Oche — wygląd tablicy wyników z transmisji turnieju.
   Granatowe studio, dwa kolory graczy wzięte z pierścieni tarczy (czerwień
   i zieleń, podkręcone do ekranu) i duże, wąskie cyfry — to one są treścią.
   Aplikacja świadomie żyje tylko w ciemnej odsłonie: siedzi pod obrazem
   z kamery, a jasny interfejs odbijałby się w ekranie przy tarczy.
--------------------------------------------------------------------------- */

@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/oswald-500-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/oswald-500-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/oswald-600-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/oswald-600-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* Granat studia transmisyjnego zamiast czerni — ekran siedzi pod obrazem
     z kamery, więc zostaje ciemny, ale nie martwy. */
  --bg: #070a13;
  --panel: #0e1322;
  --raised: #151c30;
  --raised-2: #1c2540;
  --line: #232c46;
  --line-lit: #36415f;
  --text: #edf0f7;
  --muted: #8f98b3;
  --faint: #5f6884;

  /* Kolory graczy to pierścienie tarczy, podkręcone do ekranu. Wariant „ink”
     jest na drobny tekst — czysty kolor zostaje na płaszczyzny. */
  --p0: #ff5b4f;
  --p0-ink: #ff8b82;
  --p1: #1fd19d;
  --p1-ink: #62e6c0;
  --amber: #ffb443;
  --live: #6cb8ff;

  --numbers: 'Oswald', 'Arial Narrow', system-ui, sans-serif;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --r-s: 12px;
  --r-m: 16px;
  --r-l: 22px;
  --gap: 10px;
  --ease: cubic-bezier(0.2, 0.8, 0.3, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  overflow: hidden;
}

body {
  background:
    radial-gradient(120% 60% at 50% -10%, #111a33 0%, transparent 60%),
    var(--bg);
}

button {
  font: inherit;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 90ms ease;
}
button:active:not(:disabled) { transform: scale(0.97); }
button:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }
button:disabled { color: var(--faint); cursor: not-allowed; }

button.primary { background: var(--text); color: var(--bg); border-color: transparent; font-weight: 700; }
button.danger { background: rgba(255, 91, 79, 0.12); border-color: rgba(255, 91, 79, 0.45); color: var(--p0-ink); font-weight: 600; }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }

@media (hover: hover) and (pointer: fine) {
  button:not(:disabled):hover { background: var(--raised-2); border-color: var(--line-lit); }
  button.primary:not(:disabled):hover { background: #fff; }
  button.danger:not(:disabled):hover { background: rgba(255, 91, 79, 0.2); border-color: var(--p0); }
  button.ghost:not(:disabled):hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------------------------------------------------------------------------
   Układ: w pionie kolumna, na szerokim ekranie i w poziomie — szyna z lewej.
--------------------------------------------------------------------------- */
.app {
  --turn: var(--text);
  --turn-ink: var(--text);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top))
           calc(12px + env(safe-area-inset-right))
           calc(10px + env(safe-area-inset-bottom))
           calc(12px + env(safe-area-inset-left));
  overflow: hidden;
}
.app[data-current="0"] { --turn: var(--p0); --turn-ink: var(--p0-ink); }
.app[data-current="1"] { --turn: var(--p1); --turn-ink: var(--p1-ink); }

.brand { display: none; align-items: center; gap: 9px; flex: none; }
.brand-mark { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 1.8; }
.brand-mark .fill { fill: var(--turn); stroke: none; transition: fill 300ms ease; }
.brand-name {
  font-family: var(--numbers);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* --- tablica wyników ------------------------------------------------------
   Gracz przy tarczy dostaje więcej miejsca: kafelek się rozszerza, a zza jego
   prawej krawędzi wygląda wycinek tarczy w jego kolorze. */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex: none;
  transition: grid-template-columns 360ms var(--ease);
}
.app[data-current="0"] .scoreboard { grid-template-columns: 1.45fr 1fr; }
.app[data-current="1"] .scoreboard { grid-template-columns: 1fr 1.45fr; }

.player {
  --c: var(--muted);
  --ink: var(--muted);
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 11px 14px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  overflow: hidden;
  transition: border-color 300ms ease, background 300ms ease;
}
#player0 { --c: var(--p0); --ink: var(--p0-ink); }
#player1 { --c: var(--p1); --ink: var(--p1-ink); }

.player::before {
  content: '';
  position: absolute;
  z-index: -1;
  top: 50%;
  right: -100px;
  width: 190px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: repeating-conic-gradient(from -9deg,
    color-mix(in srgb, var(--c) 17%, transparent) 0deg 18deg,
    transparent 18deg 36deg);
  -webkit-mask: radial-gradient(circle, transparent 0 9%, #000 10% 52%, transparent 53% 60%, #000 61% 94%, transparent 95%);
  mask: radial-gradient(circle, transparent 0 9%, #000 10% 52%, transparent 53% 60%, #000 61% 94%, transparent 95%);
  opacity: 0;
  transform: translateY(-50%) rotate(-36deg) scale(0.8);
  transition: opacity 400ms ease, transform 600ms var(--ease);
}
.player::after {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  background: radial-gradient(110% 90% at 0% 0%, color-mix(in srgb, var(--c) 20%, transparent), transparent 65%);
  opacity: 0;
  transition: opacity 300ms ease;
}
.player.active,
.player.winner { border-color: color-mix(in srgb, var(--c) 55%, var(--line)); background: var(--raised); }
.player.active::before,
.player.winner::before { opacity: 1; transform: translateY(-50%) rotate(0deg) scale(1); }
.player.active::after,
.player.winner::after { opacity: 1; }

.player-head { display: flex; align-items: center; gap: 7px; min-width: 0; }
.player-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--c);
  opacity: 0.45;
  transition: opacity 300ms ease, box-shadow 300ms ease;
}
.player.active .player-dot,
.player.winner .player-dot { opacity: 1; box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 22%, transparent); }
.player-name {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player.active .player-name,
.player.winner .player-name { color: var(--ink); }

.player-score {
  font-family: var(--numbers);
  font-weight: 600;
  font-size: clamp(34px, 10vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  transition: font-size 360ms var(--ease), color 300ms ease;
}
.player.active .player-score,
.player.winner .player-score { font-size: clamp(44px, 14vw, 62px); color: var(--text); }
.player-darts {
  font-size: 12px;
  min-height: 16px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player.active .player-darts { color: var(--text); font-weight: 600; }

@keyframes tick {
  from { transform: translateY(10px); opacity: 0; filter: blur(2px); }
  to { transform: none; opacity: 1; filter: none; }
}
.player-score.tick { animation: tick 260ms var(--ease); }

/* --- bieżąca kolejka ------------------------------------------------------ */
.turn { display: flex; flex-direction: column; gap: 6px; flex: none; }

.throws { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.throw-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 56px;
  padding: 6px 4px;
  border-radius: var(--r-m);
  background: transparent;
  border: 1px dashed var(--line-lit);
  color: var(--faint);
  overflow: hidden;
}
.throw-slot .label {
  font-family: var(--numbers);
  font-weight: 600;
  font-size: 22px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.throw-slot .points {
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.throw-slot.filled {
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--muted);
}
.throw-slot.filled::before {
  content: '';
  position: absolute;
  top: 0;
  left: 22%;
  right: 22%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--turn);
}
.throw-slot.filled .label { color: var(--text); }
.throw-slot.last { border-color: var(--turn-ink); box-shadow: inset 0 0 0 1px var(--turn-ink); }
.throw-slot.uncertain { border-color: var(--amber); background: rgba(255, 180, 67, 0.09); }
.throw-slot.uncertain::before { background: var(--amber); }
.throw-slot.uncertain .label,
.throw-slot.uncertain .points { color: var(--amber); }
.throw-slot:disabled { cursor: default; }

/* Pasek stanu bez ramki — jedna linijka głosu aplikacji. Wysokość na dwa
   wiersze stała, żeby zmieniający się komunikat nie przesuwał ekranu. */
.status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 0 6px;
}
.status-dot {
  position: relative;
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--faint);
}
.status-text {
  font-size: 13.5px;
  line-height: 1.3;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.status[data-tone="ok"] .status-dot { background: var(--live); box-shadow: 0 0 10px var(--live); }
.status[data-tone="ok"] .status-text { color: var(--text); }
.status[data-tone="warn"] .status-dot { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.status[data-tone="warn"] .status-text { color: var(--amber); }
.status[data-tone="search"] .status-dot { background: var(--text); }
.status[data-tone="search"] .status-dot::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 1.5px solid var(--text);
  animation: ping 1.4s ease-out infinite;
}
@keyframes ping { from { transform: scale(0.4); opacity: 0.9; } to { transform: scale(1.4); opacity: 0; } }

/* --- przełącznik trybów: suwak jedzie pod wybraną opcję ------------------- */
.modes {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  flex: none;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.modes::before {
  content: '';
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc((100% - 8px) / 3);
  border-radius: 999px;
  background: var(--raised-2);
  box-shadow: inset 0 0 0 1px var(--line-lit), 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: transform 320ms var(--ease);
}
.modes:has([data-mode="board"].on)::before { transform: translateX(100%); }
.modes:has([data-mode="keypad"].on)::before { transform: translateX(200%); }
.modes button {
  position: relative;
  min-height: 40px;
  padding: 6px 4px;
  font-size: 13.5px;
  font-weight: 500;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
}
.modes button.on { color: var(--text); font-weight: 650; }
@media (hover: hover) and (pointer: fine) {
  .modes button:not(:disabled):hover { background: transparent; color: var(--text); }
}

/* --- obszar roboczy ------------------------------------------------------- */
main { flex: 1 1 auto; min-height: 0; display: flex; }
.view { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.view.hidden { display: none; }
.view-hint {
  flex: none;
  margin: 6px 0 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.stage {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  background:
    radial-gradient(circle at 50% 50%, #0f1528 0%, #05070d 75%);
  border: 1px solid var(--line);
  border-radius: var(--r-l);
  overflow: hidden;
}
.stage video,
.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.stage canvas { touch-action: manipulation; }

/* Narożniki wizjera — kadr, w którym ma się zmieścić tarcza. */
.viewfinder {
  --vf: rgba(237, 240, 247, 0.55);
  --len: 22px;
  position: absolute;
  inset: 14px;
  pointer-events: none;
  background:
    linear-gradient(var(--vf) 0 0) left top / var(--len) 2px,
    linear-gradient(var(--vf) 0 0) left top / 2px var(--len),
    linear-gradient(var(--vf) 0 0) right top / var(--len) 2px,
    linear-gradient(var(--vf) 0 0) right top / 2px var(--len),
    linear-gradient(var(--vf) 0 0) left bottom / var(--len) 2px,
    linear-gradient(var(--vf) 0 0) left bottom / 2px var(--len),
    linear-gradient(var(--vf) 0 0) right bottom / var(--len) 2px,
    linear-gradient(var(--vf) 0 0) right bottom / 2px var(--len);
  background-repeat: no-repeat;
}

.stage-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 28px;
  text-align: center;
  background: rgba(7, 10, 19, 0.7);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.stage-msg::before {
  content: '';
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background:
    radial-gradient(circle, var(--turn) 0 12%, transparent 13% 38%, rgba(237, 240, 247, 0.8) 39% 43%, transparent 44% 70%, rgba(237, 240, 247, 0.35) 71% 74%, transparent 75%);
}
.stage-msg.hidden { display: none; }
.stage-msg p { margin: 0; max-width: 30ch; line-height: 1.5; color: var(--text); font-size: 15px; text-wrap: balance; }
.stage-msg button { min-height: 50px; padding: 12px 26px; border-radius: 999px; font-size: 15px; }

#boardSvg {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  filter: drop-shadow(0 18px 40px rgba(0, 0, 0, 0.55));
}

/* --- klawiatura z numerami ------------------------------------------------ */
.keypad { flex: 1 1 auto; min-height: 0; display: grid; grid-template-rows: 1fr auto auto auto; gap: 7px; }
.keypad .view-hint { margin: 0; }

.keypad-numbers {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 7px;
  min-height: 0;
}
.keypad-numbers button {
  padding: 0;
  font-family: var(--numbers);
  font-weight: 500;
  font-size: clamp(22px, 7vw, 32px);
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border-color: var(--line);
  border-radius: var(--r-m);
}
.keypad-numbers button:active { background: color-mix(in srgb, var(--turn) 22%, var(--panel)); border-color: var(--turn); }

.keypad-special { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 7px; }
.keypad-special button {
  min-height: 46px;
  padding: 8px 4px;
  font-family: var(--numbers);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.06em;
  border-radius: var(--r-m);
  background: var(--panel);
}

/* Mnożniki w kolorach pierścieni: podwójne czerwone, potrójne zielone. */
.keypad-mult { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.keypad-mult button {
  --ring: var(--p0);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  line-height: 1.15;
  border-radius: var(--r-m);
  background: color-mix(in srgb, var(--ring) 8%, var(--panel));
  border-color: color-mix(in srgb, var(--ring) 40%, var(--line));
}
.keypad-mult button[data-ring="triple"] { --ring: var(--p1); }
.keypad-mult .mult-key { font-size: 14px; font-weight: 700; letter-spacing: 0.02em; color: color-mix(in srgb, var(--ring) 55%, #fff); }
.keypad-mult .mult-target {
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.keypad-mult button.on { background: var(--ring); border-color: var(--ring); }
.keypad-mult button.on .mult-key,
.keypad-mult button.on .mult-target { color: var(--bg); }

/* --- dok ------------------------------------------------------------------ */
.dock {
  display: grid;
  grid-template-columns: 54px 54px minmax(0, 1fr) 54px;
  grid-template-areas: "undo calib turn menu";
  gap: 8px;
  flex: none;
}
#btnUndo { grid-area: undo; }
#btnCalibrate { grid-area: calib; }
#btnMenu { grid-area: menu; }
.turn-button { grid-area: turn; }

.dock-key {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 56px;
  padding: 0;
  border-radius: var(--r-m);
  background: var(--panel);
  color: var(--muted);
}
.dock-key:not(:disabled):active { color: var(--text); }
/* Na telefonie same ikony; podpis zostaje dla czytników ekranu. */
.dock-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.turn-button {
  min-height: 56px;
  padding: 8px 14px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  border-radius: var(--r-m);
  background: var(--raised-2);
  border-color: var(--line-lit);
}
.turn-button.primary {
  background: var(--turn);
  color: #0a0d18;
  border-color: transparent;
  box-shadow: 0 8px 26px color-mix(in srgb, var(--turn) 35%, transparent);
}
.turn-button:disabled { background: var(--panel); border-color: var(--line); }
@media (hover: hover) and (pointer: fine) {
  .turn-button.primary:not(:disabled):hover { background: color-mix(in srgb, var(--turn) 85%, #fff); }
}

/* --- okna ------------------------------------------------------------------
   Na telefonie arkusz wysuwany od dołu, na dużym ekranie okno na środku. */
dialog {
  width: min(440px, 92vw);
  max-height: 88dvh;
  padding: 0;
  overflow-y: auto;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-lit);
  border-radius: var(--r-l);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transition:
    opacity 220ms var(--ease),
    transform 260ms var(--ease),
    overlay 260ms allow-discrete,
    display 260ms allow-discrete;
}
dialog[open] { opacity: 1; transform: none; }
@starting-style {
  dialog[open] { opacity: 0; transform: translateY(12px) scale(0.98); }
}

dialog::backdrop {
  background: rgba(3, 5, 10, 0);
  -webkit-backdrop-filter: blur(0);
  backdrop-filter: blur(0);
  transition:
    background 240ms var(--ease),
    backdrop-filter 240ms var(--ease),
    overlay 240ms allow-discrete,
    display 240ms allow-discrete;
}
dialog[open]::backdrop { background: rgba(3, 5, 10, 0.66); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
@starting-style {
  dialog[open]::backdrop { background: rgba(3, 5, 10, 0); backdrop-filter: blur(0); }
}

@media (max-width: 599px) {
  dialog {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 26px 26px 0 0;
    transform: translateY(100%);
  }
  dialog[open] { transform: none; }
  @starting-style {
    dialog[open] { transform: translateY(100%); }
  }
  dialog .dialog-body { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  dialog .dialog-body::before {
    content: '';
    align-self: center;
    width: 40px;
    height: 4px;
    margin: -8px 0 2px;
    border-radius: 4px;
    background: var(--line-lit);
  }
}

.dialog-body { display: flex; flex-direction: column; gap: 14px; padding: 22px; }
.dialog-body h2 {
  margin: 0;
  font-family: var(--numbers);
  font-weight: 600;
  font-size: 26px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.dialog-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.dialog-body input[type="text"],
.dialog-body select {
  -webkit-appearance: none;
  appearance: none;
  min-height: 48px;
  padding: 11px 14px;
  font: inherit;
  font-size: 15px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
  background-color: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
  transition: border-color 140ms ease, background-color 140ms ease;
}
.dialog-body select {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238f98b3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
}
.dialog-body select option { background: var(--raised); color: var(--text); }
.dialog-body input[type="text"]:focus-visible,
.dialog-body select:focus-visible { outline: none; border-color: var(--live); box-shadow: 0 0 0 3px rgba(108, 184, 255, 0.22); }

/* Przełącznik zamiast kwadracika; cały wiersz jest polem dotyku. */
.dialog-body label.row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 52px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-s);
}
.dialog-body label.row span { order: -1; }
.dialog-body input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  margin: 0;
  border-radius: 999px;
  background: var(--raised-2);
  border: 1px solid var(--line-lit);
  cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease;
}
.dialog-body input[type="checkbox"]::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 220ms var(--ease), background 200ms ease;
}
.dialog-body input[type="checkbox"]:checked { background: var(--live); border-color: var(--live); }
.dialog-body input[type="checkbox"]:checked::before { transform: translateX(18px); background: #fff; }
.dialog-body input[type="checkbox"]:focus-visible { outline: 2px solid var(--live); outline-offset: 2px; }

.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.dialog-actions button { min-height: 48px; padding: 10px 18px; border-radius: 999px; }
@media (max-width: 599px) {
  .dialog-actions button { flex: 1 1 auto; }
}
.settings-footer {
  display: grid;
  gap: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 11px;
  text-align: center;
}
.settings-credit { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.settings-credit a { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); text-underline-offset: 3px; }
.settings-credit a:hover, .settings-credit a:focus-visible { color: var(--text); }
.settings-credit img { width: 14px; height: 14px; flex: none; object-fit: contain; }
.dialog-note { margin: -4px 0 0; font-size: 12.5px; color: var(--faint); line-height: 1.55; }

/* --- instalacja jako aplikacja ------------------------------------------- */
.install { display: flex; flex-direction: column; gap: 10px; }
.install[hidden] { display: none; }
.install-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  border-radius: 999px;
  border-color: var(--live);
  color: var(--text);
  font-weight: 600;
}
.install-button + .dialog-note { margin: 0; }

/* --- poprawianie lotki ---------------------------------------------------- */
.suggestions { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.suggestions button {
  min-height: 64px;
  padding: 9px 8px;
  font-family: var(--numbers);
  font-size: 22px;
  font-weight: 600;
  border-radius: var(--r-m);
  background: var(--raised);
  border-color: var(--line-lit);
}
.suggestions button small {
  display: block;
  margin-top: 2px;
  font-family: var(--ui);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#editPicker summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
}
#editPicker summary::-webkit-details-marker { display: none; }
#editPicker summary::before {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 200ms var(--ease);
}
#editPicker[open] summary::before { transform: rotate(45deg); }
.picker { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.picker-rings,
.picker-special { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.picker-rings button,
.picker-special button { min-height: 44px; font-size: 13px; }
.picker-rings button.on { background: var(--text); color: var(--bg); border-color: transparent; font-weight: 700; }
.picker-numbers { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.picker-numbers button {
  min-height: 46px;
  padding: 8px 0;
  font-family: var(--numbers);
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

/* --- koniec gry ----------------------------------------------------------- */
#winDialog { --player: var(--amber); width: min(400px, 92vw); overflow: hidden; }
#winDialog[data-winner="0"] { --player: var(--p0); }
#winDialog[data-winner="1"] { --player: var(--p1); }
@media (max-width: 599px) {
  #winDialog { width: 100%; }
}

.dialog-body.win {
  position: relative;
  isolation: isolate;
  align-items: center;
  gap: 0;
  padding: 30px 22px 22px;
  text-align: center;
}
.dialog-body.win::after {
  content: '';
  position: absolute;
  z-index: -1;
  top: -150px;
  left: 50%;
  width: 360px;
  aspect-ratio: 1;
  margin-left: -180px;
  border-radius: 50%;
  background: repeating-conic-gradient(from -9deg,
    color-mix(in srgb, var(--player) 26%, transparent) 0deg 18deg,
    transparent 18deg 36deg);
  -webkit-mask: radial-gradient(circle, #000 0 20%, transparent 65%);
  mask: radial-gradient(circle, #000 0 20%, transparent 65%);
}

.win-mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  color: var(--bg);
  background: var(--player);
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--player) 20%, transparent), 0 10px 40px color-mix(in srgb, var(--player) 45%, transparent);
}
.win-mark svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 3; }

#winTitle {
  margin: 20px 0 0;
  font-size: clamp(36px, 12vw, 54px);
  line-height: 1;
  letter-spacing: 0;
  color: var(--text);
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.win-line {
  margin: 8px 0 0;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--player) 60%, #fff);
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  margin: 24px 0 0;
}
.win-stats > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 4px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--r-m);
}
.win-stats dt {
  font-family: var(--numbers);
  font-weight: 600;
  font-size: 28px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.win-stats dd { margin: 0; font-size: 10px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }

.dialog-body.win .dialog-actions { width: 100%; margin-top: 22px; flex-wrap: nowrap; }
.dialog-body.win .dialog-actions button { flex: 1 1 0; }
#btnRematch { background: var(--player); color: #0a0d18; }

@keyframes win-rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes win-mark { from { opacity: 0; transform: scale(0.4) rotate(-90deg); } }
#winDialog[open] .win-mark { animation: win-mark 520ms var(--ease) 60ms backwards; }
#winDialog[open] #winTitle { animation: win-rise 500ms var(--ease) 140ms backwards; }
#winDialog[open] .win-line { animation: win-rise 500ms var(--ease) 200ms backwards; }
#winDialog[open] .win-stats { animation: win-rise 500ms var(--ease) 270ms backwards; }
#winDialog[open] .dialog-actions { animation: win-rise 500ms var(--ease) 340ms backwards; }

@media (max-height: 620px) {
  .dialog-body.win { padding: 18px 20px; }
  .win-mark { width: 44px; height: 44px; }
  .win-mark svg { width: 24px; height: 24px; }
  #winTitle { margin-top: 12px; font-size: clamp(28px, 7vh, 38px); }
  .win-stats { margin-top: 14px; }
  .win-stats > div { padding: 8px 4px; }
  .win-stats dt { font-size: 22px; }
  .dialog-body.win .dialog-actions { margin-top: 14px; }
}

/* ---------------------------------------------------------------------------
   Szyna z lewej: komputer i telefon w poziomie. Pole robocze dostaje resztę.
--------------------------------------------------------------------------- */
@media (min-width: 900px), (orientation: landscape) and (max-height: 620px) {
  .app {
    display: grid;
    max-width: 1320px;
    grid-template-columns: minmax(250px, 360px) minmax(0, 1fr);
    grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand   main"
      "score   main"
      "turn    main"
      "modes   main"
      ".       main"
      "dock    main";
    column-gap: 20px;
    row-gap: var(--gap);
  }
  .brand { grid-area: brand; }
  .scoreboard { grid-area: score; }
  .turn { grid-area: turn; }
  .modes { grid-area: modes; }
  main { grid-area: main; }
  .dock { grid-area: dock; }
}

@media (min-width: 900px) {
  .app { padding: 24px 28px; row-gap: 14px; column-gap: 28px; grid-template-columns: 380px minmax(0, 1fr); }
  .brand { display: flex; padding: 2px 4px 6px; }

  /* Na szerokiej szynie kafelki graczy leżą jeden pod drugim. */
  .scoreboard,
  .app[data-current="0"] .scoreboard,
  .app[data-current="1"] .scoreboard { grid-template-columns: 1fr; }
  .player { padding: 16px 18px; }
  .player::before { width: 240px; right: -110px; }
  .player-score { font-size: 44px; }
  .player.active .player-score,
  .player.winner .player-score { font-size: 72px; }
  .player-darts { font-size: 13px; }

  .dock {
    grid-template-columns: repeat(3, 1fr);
    grid-template-areas:
      "turn  turn  turn"
      "undo  calib menu";
  }
  .dock-key { min-height: 46px; font-size: 13px; font-weight: 500; }
  .dock-key .icon { width: 19px; height: 19px; }
  .dock-label { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
  .turn-button { min-height: 64px; font-size: 18px; }

  .stage, #boardSvg { border-radius: 28px; }
  #keypadView { justify-content: center; }
  .keypad { flex: 0 1 auto; width: min(100%, 640px); height: min(100%, 720px); margin: 0 auto; }
  .keypad-numbers button:active { transform: scale(0.97); }
}

@media (orientation: landscape) and (max-height: 620px) {
  .app { --gap: 7px; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); column-gap: 12px; }
  .scoreboard,
  .app[data-current="0"] .scoreboard,
  .app[data-current="1"] .scoreboard { grid-template-columns: 1fr 1fr; }
  .player { padding: 7px 10px 8px; border-radius: var(--r-m); }
  .player::before { width: 130px; right: -74px; }
  .player-score { font-size: 24px; }
  .player.active .player-score,
  .player.winner .player-score { font-size: 32px; }
  .player-darts { font-size: 11px; }
  .throw-slot { min-height: 44px; border-radius: var(--r-s); }
  .throw-slot .label { font-size: 18px; }
  .status { min-height: 34px; }
  .status-text { font-size: 12.5px; }
  .modes button { min-height: 34px; font-size: 12.5px; }
  .dock { grid-template-columns: 44px 44px minmax(0, 1fr) 44px; gap: 6px; }
  .dock-key,
  .turn-button { min-height: 46px; border-radius: var(--r-s); }
  .turn-button { font-size: 14px; padding: 6px 10px; }
  .keypad-special button { min-height: 38px; }
  .keypad .view-hint { display: none; }
}

/* Krótki ekran w pionie — ciaśniej, żeby pole robocze nie zniknęło. */
@media (orientation: portrait) and (max-height: 720px) {
  .app { --gap: 8px; }
  .player { padding: 8px 12px 9px; }
  .player.active .player-score,
  .player.winner .player-score { font-size: clamp(38px, 12vw, 50px); }
  .throw-slot { min-height: 48px; }
  .modes button { min-height: 36px; }
  .dock-key,
  .turn-button { min-height: 50px; }
  .keypad .view-hint { display: none; }
}

@media (max-width: 360px) {
  .app { padding-left: 8px; padding-right: 8px; }
  .dock { grid-template-columns: 46px 46px minmax(0, 1fr) 46px; gap: 6px; }
  .turn-button { font-size: 14px; }
  .modes button { font-size: 12.5px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
