/* Цвета берём из темы Telegram (он сам ставит --tg-theme-*), запасные — для браузера. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #14201a);
  --hint: var(--tg-theme-hint-color, #7d8a83);
  --sec: var(--tg-theme-secondary-bg-color, #eef2ef);
  --btn: var(--tg-theme-button-color, #1f7a4d);
  --btn-fg: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #1f7a4d);
  --line: color-mix(in srgb, var(--hint) 30%, transparent);
  --plus: #2f9e5b; --minus: #d9483b; --brass: #c8962e;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: var(--tg-theme-bg-color, #17211c); --fg: var(--tg-theme-text-color, #eef3ef);
    --sec: var(--tg-theme-secondary-bg-color, #0f1713); --plus: #5fd18b; --minus: #ff7b6e; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--sec); color: var(--fg); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
#app { max-width: 640px; margin: 0 auto; padding: 12px max(12px, env(safe-area-inset-left)) 140px max(12px, env(safe-area-inset-right)); display: grid; gap: 12px; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
h1 { font-size: 22px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--hint); font-weight: 600; padding: 4px 4px 0; }
.hint { color: var(--hint); font-size: 13px; }
.pad { padding: 16px; }
.num, table { font-variant-numeric: tabular-nums; }
.ok { color: var(--plus); } .bad { color: var(--minus); }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: 10px 14px; min-height: 42px; background: var(--bg); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--btn); outline-offset: 2px; }
.primary { background: var(--btn); color: var(--btn-fg); font-weight: 600; }
.ghost { background: var(--sec); }
.link { background: none; color: var(--link); padding: 6px 0; min-height: 0; }
input, select { background: var(--sec); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; min-width: 0; }

.card { background: var(--bg); border-radius: 14px; padding: 12px; display: grid; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stack { display: grid; gap: 8px; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: var(--bg); padding: 4px; border-radius: 12px; }
.tabs button { min-height: 36px; padding: 6px; background: none; }
.tabs button.on { background: var(--sec); font-weight: 600; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--sec); padding: 3px; border-radius: 10px; }
.seg button { background: none; min-height: 38px; }
.seg button.on { background: var(--bg); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.toggle { background: var(--sec); }
.toggle.on { background: var(--brass); color: #1d1405; font-weight: 600; }

.item { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; text-align: left; width: 100%; }
.item .hint { grid-column: 1; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--sec); color: var(--hint); align-self: center; grid-row: 1 / span 2; grid-column: 2; }
.pill.live { background: var(--btn); color: var(--btn-fg); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--sec); border-radius: 99px; padding: 8px 14px; display: inline-flex; gap: 6px; align-items: center; }
.chip.on { background: var(--btn); color: var(--btn-fg); }
.chip b { font-size: 12px; }

.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; border: 1px solid rgba(0,0,0,.35); box-shadow: inset -2px -2px 3px rgba(0,0,0,.3); }
.dot.x { background: none; border-style: dashed; box-shadow: none; display: inline-grid; place-items: center; font-size: 12px; line-height: 1; }
.dot.w { background: #f6f3e8; } .dot.r { background: #cf2c31; } .dot.b { background: #161616; border-color: #666; }
.tablebar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.tablebar span { display: inline-flex; gap: 5px; align-items: center; }

.players { display: grid; gap: 8px; }
.pcard { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; text-align: left; width: 100%; padding: 10px 12px; border: 2px solid transparent; }
.pcard.sel { border-color: var(--btn); }
.pos { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--sec); font-weight: 700; }
.pcard .pts { font-size: 26px; font-weight: 700; }
.pcard .name { font-weight: 600; overflow-wrap: anywhere; }

#app:has(.shotpanel) { padding-bottom: 360px; }   /* панель удара не закрывает карточки игроков */
.shotpanel { position: fixed; left: 0; right: 0; bottom: 0; background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.08);
  padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.shotpanel > div { max-width: 640px; margin: 0 auto; display: grid; gap: 8px; }
.balls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.balls button { display: flex; flex-direction: column; align-items: center; gap: 2px; background: var(--sec); padding: 8px 4px; }
.balls .dot { width: 22px; height: 22px; }
.haprow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; align-items: center; }
.haprow button { background: var(--sec); }
.log { display: grid; gap: 2px; font-size: 13px; color: var(--hint); }

.tw { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--hint); font-weight: 500; font-size: 12px; }
td small { color: var(--hint); }
details summary { cursor: pointer; padding: 6px 0; }

#toast { position: fixed; left: 12px; right: 12px; top: calc(12px + env(safe-area-inset-top)); max-width: 616px; margin: 0 auto; background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 10px; z-index: 10; }
@media (prefers-reduced-motion: no-preference) { button { transition: background-color .12s; } }

.rules p { margin: 0; }
.rules td, .rules th { white-space: normal; }
.rules td:first-child { white-space: nowrap; }
.balls.wide { grid-auto-flow: column; grid-auto-columns: 1fr; grid-template-columns: none; }
.update { position: sticky; top: env(safe-area-inset-top); z-index: 9; display: flex; gap: 10px; align-items: center; justify-content: space-between; max-width: 640px; margin: 0 auto; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.btnlink { display: block; text-align: center; text-decoration: none; padding: 12px 14px; border-radius: 10px; }
