/* Layout: одна колонка до 560px, липкая шапка, фиксированная нижняя навигация.
   Экран строится из карточек; статусы кодируются цветом и формой (чипы, сегменты). */
:root {
  --bg: #F2F4F7;
  --surface: #FFFFFF;
  --surface-2: #F6F7F9;
  --fg: #141B24;
  --muted: #66717F;
  --line: #E2E6EC;
  --accent: #EE6A1C;
  --accent-fg: #FFFFFF;
  --accent-soft: #FDEADF;
  --ok: #1D9A58;   --ok-soft: #DDF4E6;
  --warn: #B8800A; --warn-soft: #FBF0D2;
  --bad: #D1483F;  --bad-soft: #FAE1DE;
  /* Команды: по цвету формы */
  --t0-bg: #F8F3E7; --t0-fg: #3A2E1A;
  --t1-bg: #202A36; --t1-fg: #F3F5F8;
  --t2-bg: #C4352C; --t2-fg: #FFFFFF;
  --t3-bg: #2B5BD7; --t3-fg: #FFFFFF;
  --t4-bg: #2E8B57; --t4-fg: #FFFFFF;
  --t5-bg: #E3B505; --t5-fg: #2A2114;
  --font-display: "Oswald", "Arial Narrow", "Roboto Condensed", sans-serif;
  --font-body: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 27, 36, .05), 0 4px 16px rgba(20, 27, 36, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1419;
    --surface: #171E26;
    --surface-2: #1F2731;
    --fg: #ECEFF3;
    --muted: #97A3B1;
    --line: #2A3440;
    --accent: #FF7A33;
    --accent-fg: #1A0D04;
    --accent-soft: #3A2416;
    --ok: #3DBD76;   --ok-soft: #163C28;
    --warn: #E3A816; --warn-soft: #3C2F0D;
    --bad: #E5655C;  --bad-soft: #44201D;
    --t0-bg: #EDE6D6; --t0-fg: #2A2114;
    --t1-bg: #2A3644; --t1-fg: #F3F5F8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; letter-spacing: .01em; text-wrap: balance; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
[hidden] { display: none !important; }

#app { max-width: 560px; margin: 0 auto; min-height: 100%; }

/* ---------- шапка и экран ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-block: calc(10px + env(safe-area-inset-top, 0px)) 10px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 22px; text-transform: uppercase; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { font-size: 17px; font-weight: 500; white-space: nowrap; }
.screen {
  display: flex; flex-direction: column; gap: 12px;
  padding-block: 8px calc(84px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.card { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 18px; text-transform: uppercase; margin-bottom: 10px; display: flex; align-items: baseline; gap: 8px; }
.count { font-family: var(--font-body); font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row > * { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.right { text-align: right; }
p { margin: 0; }
p + p { margin-top: 6px; }

/* ---------- кнопки ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--fg);
  border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; min-height: 46px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: none; color: var(--accent); padding: 6px 4px; min-height: 0; font-weight: 500; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; border-radius: 10px; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.danger-text { color: var(--bad); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .seg:focus-visible, .tab:focus-visible, .chip:focus-visible, .icon-btn:focus-visible,
input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn { border: none; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; flex: none; }
.member-edit { width: 100%; align-items: stretch; }
.member-edit input { flex: 1 1 140px; min-width: 0; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.member-edit .btn { flex: 0 0 auto; }

/* ---------- формы ---------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; color: var(--muted); }
.field input, .field textarea, .field select, .guest-form input {
  width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px;
  padding: 11px 12px; min-height: 46px; min-width: 0;
}
.field textarea { resize: vertical; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; flex: 0 0 auto; }
.field.inline select { width: auto; min-width: 72px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.confirm { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.confirm span { flex-basis: 100%; }

/* ---------- вкладки и список игр ---------- */
.tabs { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.tab { flex: 1; border: none; background: transparent; border-radius: 9px; padding: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.game-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.game-card {
  display: flex; align-items: center; gap: 14px; background: var(--surface); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); color: inherit;
}
.date-block { flex: 0 0 54px; text-align: center; background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 7px 0 6px; line-height: 1; }
.date-block .day { display: block; font-family: var(--font-display); font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.date-block .mon { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin-top: 3px; }
.game-main { flex: 1; min-width: 0; }
.game-title { font-weight: 600; }
.game-title::first-letter { text-transform: uppercase; }
.game-meta { font-size: 13px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty img { width: 56px; height: 56px; opacity: .5; margin-bottom: 10px; }

/* ---------- чипы ---------- */
.chip {
  display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; flex: none;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.admin { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.pay { cursor: pointer; min-height: 30px; }
.chip.pay:disabled { cursor: default; }
.chip.pay.sent { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.pay.confirmed { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* ---------- страница игры ---------- */
.hero { padding: 6px 2px 2px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 600; }
.hero h1 { font-size: 34px; line-height: 1.1; text-transform: uppercase; }
.hero-sub { font-size: 16px; color: var(--muted); margin-top: 2px; }
.note { margin-top: 8px; white-space: pre-wrap; }
.hero .btn { margin-top: 12px; }
.segmented { display: flex; gap: 6px; }
.seg { flex: 1; border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px; padding: 12px 4px; font-weight: 600; cursor: pointer; min-height: 48px; font-size: 15px; }
.seg.active.going { background: var(--ok); border-color: var(--ok); color: #fff; }
.seg.active.maybe { background: var(--warn); border-color: var(--warn); color: #fff; }
.seg.active.out { background: var(--bad); border-color: var(--bad); color: #fff; }

.price-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 10px; }
.price-big { font-family: var(--font-display); font-size: 32px; line-height: 1; font-variant-numeric: tabular-nums; }
.price-mid { font-family: var(--font-display); font-size: 20px; line-height: 1; font-variant-numeric: tabular-nums; }
.requisites { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 10px; }
.requisites .label { flex-basis: 100%; }
.req-text { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-weight: 600; }
.pay-state { border-radius: 10px; padding: 10px 12px; font-weight: 500; }
.pay-state.ok { background: var(--ok-soft); color: var(--ok); }
.pay-state.warn { background: var(--warn-soft); color: var(--warn); }
.pay-summary { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; font-size: 13px; color: var(--muted); margin-top: 10px; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); min-height: 46px; }
.person:first-child { border-top: none; }
.person-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.person.me .person-name { font-weight: 600; }
.people.dim .person-name { color: var(--muted); }
.team-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 1px solid var(--line); }
.team-dot.t0 { background: var(--t0-bg); } .team-dot.t1 { background: var(--t1-bg); }
.team-dot.t2 { background: var(--t2-bg); } .team-dot.t3 { background: var(--t3-bg); }
.team-dot.t4 { background: var(--t4-bg); } .team-dot.t5 { background: var(--t5-bg); }
.guest-form { margin-top: 10px; align-items: stretch; }
.guest-form .btn { flex: 0 0 auto; }
.hint { font-size: 13px; color: var(--muted); margin-top: 10px; }

.teams { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 10px; }
.team { border-radius: 12px; padding: 10px 12px; min-width: 0; }
.team.t0 { background: var(--t0-bg); color: var(--t0-fg); } .team.t1 { background: var(--t1-bg); color: var(--t1-fg); }
.team.t2 { background: var(--t2-bg); color: var(--t2-fg); } .team.t3 { background: var(--t3-bg); color: var(--t3-fg); }
.team.t4 { background: var(--t4-bg); color: var(--t4-fg); } .team.t5 { background: var(--t5-bg); color: var(--t5-fg); }
.team-name { font-family: var(--font-display); text-transform: uppercase; font-size: 16px; display: flex; justify-content: space-between; gap: 8px; }
.team-name .n { opacity: .7; font-variant-numeric: tabular-nums; }
.team ol { margin: 6px 0 0; padding-left: 20px; }
.team li { padding: 2px 0; overflow-wrap: anywhere; }
.team-subs { margin-top: 6px; font-size: 13px; opacity: .85; overflow-wrap: anywhere; }
.team-float { background: var(--surface-2); border: 1px dashed var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; overflow-wrap: anywhere; }
.team-dot.tf { background: repeating-linear-gradient(45deg, var(--t0-bg) 0 3px, var(--t1-bg) 3px 6px); }
.shuffle-form { align-items: center; flex-wrap: wrap; }
.shuffle-form .btn { flex: 1 1 160px; }

/* ---------- счёт ---------- */
.score-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 12px; margin-bottom: 10px; font-weight: 600; }
.score-num { font-family: var(--font-display); font-size: 40px; line-height: 1; font-variant-numeric: tabular-nums; }
.score-colon { font-family: var(--font-display); font-size: 32px; color: var(--muted); }
.score-row { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-top: 1px solid var(--line); }
.score-row:first-of-type { border-top: none; }
.score-team { flex: 1; min-width: 0; font-weight: 600; }
.score-row .btn { min-width: 52px; }
.score-actions { margin-top: 8px; }

/* ---------- таблица и достижения ---------- */
.stat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.stat-row { background: var(--surface); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); cursor: pointer; }
.stat-row.me { outline: 2px solid var(--accent-soft); }
.stat-main { display: flex; align-items: center; gap: 12px; }
.stat-rank { flex: 0 0 34px; font-family: var(--font-display); font-size: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.stat-name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.stat-points { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.stat-points b { font-family: var(--font-display); font-size: 22px; font-variant-numeric: tabular-nums; }
.stat-details { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.stat-grid div { background: var(--surface-2); border-radius: 10px; padding: 8px 6px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.stat-grid b { font-family: var(--font-display); font-size: 22px; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-grid span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 4px 10px; font-size: 13px; font-weight: 600; }

/* ---------- профиль и админ ---------- */
.code-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.code { font-size: 20px; letter-spacing: .14em; background: var(--surface-2); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; }
.code.wrap { font-size: 13px; letter-spacing: 0; overflow-wrap: anywhere; flex: 1; min-width: 0; }
.invite-code { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }

/* ---------- плавающая кнопка и навигация ---------- */
.fab {
  position: fixed; z-index: 6;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  background: var(--accent); color: var(--accent-fg); border-radius: 999px; padding: 14px 20px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(238, 106, 28, .35);
}
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center; gap: 8px;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-block: 6px calc(6px + env(safe-area-inset-bottom, 0px));
  padding-left: max(8px, env(safe-area-inset-left, 0px));
  padding-right: max(8px, env(safe-area-inset-right, 0px));
}
.bottom-nav a { position: relative; flex: 1; max-width: 170px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); padding: 4px 0; border-radius: 10px; }
.nav-badge { position: absolute; top: 0; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; }
.bottom-nav a.active { color: var(--accent); }
.bottom-nav svg { width: 24px; height: 24px; }

/* ---------- экран входа ---------- */
.join { min-height: 100vh; min-height: 100dvh; justify-content: center; padding-top: 48px; padding-bottom: 48px; }
.join-hero { text-align: center; margin-bottom: 8px; }
.join-hero img { width: 76px; height: 76px; margin-bottom: 10px; }
.join-hero h1 { font-size: 40px; text-transform: uppercase; }
.lead { color: var(--muted); margin-top: 4px; }
.invite-banner { background: var(--accent-soft); color: var(--accent); border-radius: 10px; padding: 10px 12px; font-weight: 500; text-align: center; }

/* ---------- тост ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: var(--shadow); text-align: center;
}
#toast[data-kind="bad"] { background: var(--bad); color: #fff; }
#toast[data-kind="ok"] { background: var(--ok); color: #fff; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .seg, .tab, .chip.pay { transition: background-color .15s ease, border-color .15s ease, opacity .15s ease; }
  .btn:active, .seg:active { transform: scale(.985); }
}

/* Аватарки: фото из Telegram поверх инициалов */
.ava { position: relative; flex: none; width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 12px; font-weight: 700; color: #fff; background: hsl(var(--h, 210) 45% 46%); overflow: hidden; line-height: 1; }
.ava img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.profile-head { display: flex; align-items: center; gap: 10px; }
.profile-head .ava { width: 36px; height: 36px; font-size: 13px; }

/* В Telegram вместо своей ссылки «‹ Игры» работает системная кнопка «Назад» */
body.tg .topbar .back { display: none; }
body.tg .topbar > a.btn { margin-left: auto; }
