:root {
  --B: #3b82f6;
  --I: #ef4444;
  --N: #a855f7;
  --G: #22c55e;
  --O: #f59e0b;
  --bg: #0d1024;
  --panel: rgba(255, 255, 255, .055);
  --panel-border: rgba(255, 255, 255, .1);
  --text: #eef0ff;
  --muted: #9aa2c8;
  --accent: #ff3d7f;
  --accent2: #ffb03b;
  --paper: #fffdf8;
  --ink: #1d2140;
  --radius: 18px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 600px at 5% -10%, rgba(59, 130, 246, .25), transparent 60%),
    radial-gradient(900px 600px at 105% 5%, rgba(255, 61, 127, .2), transparent 60%),
    radial-gradient(900px 500px at 50% 115%, rgba(34, 197, 94, .14), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }
h3 { margin: 0 0 10px; font-size: 1rem; letter-spacing: .02em; }
kbd {
  font: 600 .7em ui-monospace, monospace;
  padding: 2px 5px; margin-left: 6px; border-radius: 5px;
  background: rgba(0, 0, 0, .25); vertical-align: middle;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.spacer { flex: 1; }

/* ---------- Кнопки и поля ---------- */
.btn {
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, .08);
  padding: .7em 1.1em;
  border-radius: 12px;
  font-weight: 600;
  transition: transform .1s, background .2s, opacity .2s, box-shadow .2s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .15); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #ff7a59);
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 20px rgba(255, 61, 127, .35);
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(135deg, #ff5590, #ff8b6d); }
.btn.wide { width: 100%; }
.btn.ghost { background: transparent; }
.btn.small { padding: .45em .8em; font-size: .9rem; }
.btn.icon { min-width: 2.4em; }
.btn.toggle.on { background: rgba(34, 197, 94, .25); border-color: rgba(34, 197, 94, .7); }

input[type=text], input[type=number], select {
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--panel-border);
  padding: .75em 1em;
  border-radius: 12px;
  outline: none;
  font-size: 1rem;
  width: 100%;
}
select { width: auto; padding: .6em .8em; }
select option { background: #1a1d3a; }
input[type=text]:focus, input[type=number]:focus, select:focus { border-color: var(--accent); }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(8px);
}

/* ---------- Логотип ---------- */
.logo { display: flex; gap: 8px; justify-content: center; margin: 0; }
.logo span {
  --size: 58px;
  width: var(--size); height: var(--size);
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 900; font-size: calc(var(--size) * .5); color: #fff;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .6), transparent 35%), var(--c);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .35), inset -4px -6px 10px rgba(0, 0, 0, .25);
}
.logo span:nth-child(1) { --c: var(--B); }
.logo span:nth-child(2) { --c: var(--I); }
.logo span:nth-child(3) { --c: var(--N); }
.logo span:nth-child(4) { --c: var(--G); }
.logo span:nth-child(5) { --c: var(--O); }
.home .logo span { animation: bounce 2.4s ease-in-out infinite; }
.home .logo span:nth-child(2) { animation-delay: .12s; }
.home .logo span:nth-child(3) { animation-delay: .24s; }
.home .logo span:nth-child(4) { animation-delay: .36s; }
.home .logo span:nth-child(5) { animation-delay: .48s; }
.logo.small { gap: 3px; }
.logo.small span { --size: 28px; box-shadow: 0 3px 8px rgba(0, 0, 0, .35); }

/* ---------- Главный экран ---------- */
.home { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.home-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 30px 26px; }
.tagline { text-align: center; color: var(--muted); margin: 0 0 6px; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: .9rem; }
.invite {
  text-align: center; padding: 10px; border-radius: 12px;
  background: rgba(255, 176, 59, .12); border: 1px solid rgba(255, 176, 59, .4); color: #ffd38a;
}
.resume { border-color: rgba(34, 197, 94, .6); background: rgba(34, 197, 94, .14); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--panel-border); }
.join-row { display: flex; gap: 8px; }
#codeInput { text-transform: uppercase; letter-spacing: .35em; font-family: ui-monospace, monospace; text-align: center; font-weight: 700; }
.rules { color: var(--muted); font-size: .85rem; line-height: 1.45; margin: 6px 0 0; text-align: center; }

/* ---------- Верхняя панель ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 20px; flex-wrap: wrap; max-width: 1440px; margin: 0 auto; }
.room-info { display: flex; align-items: center; gap: 8px; }
.room-code {
  font-family: ui-monospace, monospace; font-size: 1.25rem; letter-spacing: .15em;
  background: rgba(255, 255, 255, .1); padding: 3px 10px; border-radius: 8px;
}
.badge { padding: 5px 12px; border-radius: 999px; background: rgba(255, 255, 255, .08); font-size: .9rem; }
.badge.accent { background: rgba(255, 61, 127, .18); color: #ffc2d6; }
.conn { color: #ffd38a; font-size: .9rem; }

/* ---------- Раскладка ---------- */
.layout {
  display: grid; gap: 16px;
  padding: 0 20px 24px;
  max-width: 1440px; margin: 0 auto;
  grid-template-columns: 300px minmax(0, 1fr) 300px;
  grid-template-areas: "caller card side" "board board side";
  align-items: start;
}
.caller { grid-area: caller; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.card-panel { grid-area: card; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.side { grid-area: side; display: flex; flex-direction: column; align-self: stretch; }
.board-panel { grid-area: board; }

@media (max-width: 1150px) {
  .layout { grid-template-columns: 280px minmax(0, 1fr); grid-template-areas: "caller card" "board board" "side side"; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "caller" "card" "board" "side"; padding: 0 10px 16px; gap: 12px; }
  .topbar { padding: 10px; gap: 8px; }
  .topbar .logo { display: none; }
  .panel { padding: 14px; }
  /* компактная панель шара: шар слева, остальное справа — карточка видна без прокрутки */
  .caller { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 14px; align-items: center; }
  .caller .ball.big { --size: 96px; grid-row: span 3; }
  .caller .countdown { width: 100%; }
  .caller .recent { justify-content: flex-start; min-height: 0; }
  .caller .recent .ball { --size: 32px; }
  .caller .status-text { text-align: left; font-size: .88rem; }
  .caller .host-controls { grid-column: 1 / -1; }
}

/* ---------- Шары ---------- */
.ball {
  --c: #4b5563;
  --size: 150px;
  width: var(--size); height: var(--size); flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, .7), rgba(255, 255, 255, 0) 30%),
    radial-gradient(circle at 50% 50%, var(--c) 55%, color-mix(in srgb, var(--c) 55%, #000) 100%);
  box-shadow: 0 14px 30px rgba(0, 0, 0, .45), inset -6px -10px 18px rgba(0, 0, 0, .3);
}
.ball .inner {
  width: 58%; height: 58%; border-radius: 50%;
  background: #fff; color: #15182e;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1; box-shadow: inset 0 -3px 6px rgba(0, 0, 0, .15);
}
.ball .letter { font-size: calc(var(--size) * .13); font-weight: 800; color: var(--c); }
.ball .num { font-size: calc(var(--size) * .27); font-weight: 900; font-variant-numeric: tabular-nums; }
.ball.empty .num { color: #9ca3af; }
.ball.small { --size: 42px; }
.ball.small .letter { display: none; }
.ball[data-letter="B"] { --c: var(--B); }
.ball[data-letter="I"] { --c: var(--I); }
.ball[data-letter="N"] { --c: var(--N); }
.ball[data-letter="G"] { --c: var(--G); }
.ball[data-letter="O"] { --c: var(--O); }
.ball.pop { animation: pop .65s cubic-bezier(.2, 1.4, .4, 1); }
.recent { display: flex; gap: 6px; min-height: 42px; flex-wrap: wrap; justify-content: center; }
.recent .ball:nth-child(n+4) { opacity: .6; }

.countdown { width: 70%; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .08); overflow: hidden; visibility: hidden; }
.countdown.on { visibility: visible; }
.countdown > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), var(--accent)); }

.status-text { text-align: center; color: var(--muted); margin: 0; line-height: 1.45; }

/* ---------- Управление ведущего ---------- */
.host-controls { width: 100%; display: none; }
body.is-host .host-controls { display: block; }
.hc { display: none; flex-direction: column; gap: 10px; align-items: center; }
.host-controls[data-status="lobby"] .hc-lobby,
.host-controls[data-status="playing"] .hc-playing,
.host-controls[data-status="finished"] .hc-finished { display: flex; }
.hc-label { color: var(--muted); font-size: .85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip {
  padding: .45em .85em; border-radius: 999px; font-size: .9rem;
  border: 1px solid var(--panel-border); background: rgba(255, 255, 255, .05);
}
.chip.active { background: rgba(255, 61, 127, .25); border-color: var(--accent); }
.auto-row { display: flex; gap: 8px; width: 100%; }
.auto-row .btn { flex: 1; white-space: nowrap; padding-inline: .6em; }
.interval-field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; }
.interval-field input { width: 4.8em; padding: .6em .4em; text-align: center; }
.chips.small .chip { padding: .3em .7em; font-size: .8rem; }
.host-only { display: none; }
body.is-host .host-only { display: inline-block; }

/* ---------- Карточка ---------- */
.card {
  width: min(100%, 440px);
  background: var(--paper);
  border-radius: 20px;
  padding: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px;
}
.card .head {
  display: grid; place-items: center;
  font-weight: 900; font-size: clamp(1.4rem, 5vw, 2.1rem); color: #fff;
  border-radius: 10px; padding: 2px 0;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .2);
}
.card .head:nth-child(1) { background: var(--B); }
.card .head:nth-child(2) { background: var(--I); }
.card .head:nth-child(3) { background: var(--N); }
.card .head:nth-child(4) { background: var(--G); }
.card .head:nth-child(5) { background: var(--O); }
.cell {
  aspect-ratio: 1;
  position: relative;
  display: grid; place-items: center;
  padding: 0;
  background: #fff;
  border: 2px solid #ebe5d8;
  border-radius: 12px;
  font-size: clamp(1.1rem, 4.6vw, 1.9rem); font-weight: 800; color: var(--ink);
  user-select: none; -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}
.cell:hover { border-color: #cfc6b3; }
.cell::before {
  content: ""; position: absolute; inset: 9%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ff86b0, #ff2d6f 60%, #cf1458);
  transform: scale(0); opacity: 0;
  transition: transform .2s cubic-bezier(.3, 1.6, .5, 1), opacity .15s;
}
.cell span { position: relative; }
.cell.marked::before { transform: scale(1); opacity: .92; }
.cell.marked { color: #fff; }
.cell.free { font-size: clamp(1.2rem, 5vw, 2rem); cursor: default; }
.cell.free::before { background: radial-gradient(circle at 35% 35%, #ffd98a, #f59e0b 60%, #c47400); }
.cell.win { border-color: var(--G); box-shadow: 0 0 0 3px rgba(34, 197, 94, .55); animation: winPulse 1.1s ease-in-out infinite; }
.shake { animation: shake .4s; }

.btn.bingo {
  width: min(100%, 440px);
  font-size: clamp(1.5rem, 4.5vw, 2.1rem); font-weight: 900; letter-spacing: .1em;
  padding: .55em 1em; border: none; border-radius: 18px; color: #fff;
  background: linear-gradient(135deg, #ff3d7f, #ff9f1c);
  box-shadow: 0 10px 30px rgba(255, 61, 127, .45);
}
.btn.bingo:hover:not(:disabled) { background: linear-gradient(135deg, #ff5590, #ffb03b); }
.btn.bingo:not(:disabled) { animation: glow 2.2s ease-in-out infinite; }
.btn.bingo:disabled { background: rgba(255, 255, 255, .08); box-shadow: none; color: var(--muted); }

.card-options { display: flex; gap: 14px; align-items: center; justify-content: center; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--muted); user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span {
  width: 38px; height: 22px; border-radius: 11px; position: relative;
  background: rgba(255, 255, 255, .15); transition: background .2s;
}
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .2s;
}
.switch input:checked + span { background: var(--G); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch.disabled { opacity: .5; cursor: not-allowed; }
.switch small { font-size: .8em; }

/* ---------- Табло ---------- */
.board { display: grid; grid-template-columns: 30px repeat(15, minmax(0, 1fr)); gap: 4px; }
.board .row-letter {
  display: grid; place-items: center; font-weight: 900; color: #fff;
  border-radius: 8px; background: var(--c);
}
.bn {
  aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  font-size: clamp(.6rem, 1.5vw, .9rem); font-weight: 700; font-variant-numeric: tabular-nums;
  background: rgba(255, 255, 255, .05); color: rgba(154, 162, 200, .7);
  transition: background .35s, color .35s, transform .35s, box-shadow .35s;
}
.bn.on { background: var(--c); color: #fff; }
.bn.last { transform: scale(1.2); box-shadow: 0 0 0 3px rgba(255, 255, 255, .7); }
.L-B { --c: var(--B); }
.L-I { --c: var(--I); }
.L-N { --c: var(--N); }
.L-G { --c: var(--G); }
.L-O { --c: var(--O); }

/* ---------- Игроки и события ---------- */
.players { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, .04); }
.players li.me { background: rgba(255, 61, 127, .1); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4b5563; flex: none; }
.dot.on { background: var(--G); box-shadow: 0 0 8px var(--G); }
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players li.me .pname { font-weight: 700; }
.players li.off .pname { color: var(--muted); }
.wins { font-size: .85rem; color: var(--accent2); white-space: nowrap; }
.pact { display: flex; gap: 2px; opacity: 0; transition: opacity .15s; }
.players li:hover .pact, .players li:focus-within .pact { opacity: 1; }
@media (hover: none) { .pact { opacity: 1; } }
.pact button { background: none; border: none; padding: 2px 5px; border-radius: 6px; font-size: .9rem; }
.pact button:hover { background: rgba(255, 255, 255, .12); }

.log { list-style: none; margin: 0; padding: 0; overflow: auto; max-height: 360px; display: flex; flex-direction: column; gap: 4px; font-size: .88rem; }
.log li { padding: 6px 8px; border-radius: 8px; color: var(--muted); line-height: 1.35; }
.log li.bingo { color: #fff; background: rgba(255, 61, 127, .2); font-weight: 600; }
.log li.false { color: #ffd38a; }
.log li.start { color: #c7f9d4; }
.log time { opacity: .55; margin-right: 6px; font-variant-numeric: tabular-nums; }

/* ---------- Окно победы ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 20px;
  background: rgba(5, 6, 20, .72); backdrop-filter: blur(6px);
}
.modal {
  width: min(420px, 100%); text-align: center;
  background: #171a36; border: 1px solid var(--panel-border); border-radius: 22px;
  padding: 26px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6);
  animation: modalIn .45s cubic-bezier(.2, 1.3, .4, 1);
}
.modal-title {
  font-size: 3.2rem; font-weight: 900; letter-spacing: .06em;
  background: linear-gradient(90deg, var(--B), var(--I), var(--N), var(--G), var(--O));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.winner-names { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }
.winner-you { color: var(--accent2); font-weight: 700; margin-top: 6px; }
.mini-card {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  background: var(--paper); padding: 8px; border-radius: 12px;
  margin: 18px auto; max-width: 250px;
}
.mini-card div {
  aspect-ratio: 1; display: grid; place-items: center; border-radius: 6px;
  font-weight: 800; color: var(--ink); font-size: .95rem;
  background: #fff; border: 1px solid #ebe5d8;
}
.mini-card .drawn { background: #ffe3ed; }
.mini-card .win { background: var(--accent); color: #fff; border-color: transparent; }
.modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Тосты и конфетти ---------- */
.toasts {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 70;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: min(92vw, 460px);
}
.toast {
  padding: 10px 16px; border-radius: 12px; text-align: center;
  background: #23274a; border: 1px solid var(--panel-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
  animation: toastIn .3s ease-out; transition: opacity .4s, transform .4s;
}
.toast.ok { border-color: rgba(34, 197, 94, .6); }
.toast.warn { border-color: rgba(255, 176, 59, .6); color: #ffe2b0; }
.toast.error { border-color: rgba(239, 68, 68, .7); color: #ffc9c9; }
.toast.bingo { border-color: var(--accent); background: #3a1a35; font-weight: 700; }
.toast.hide { opacity: 0; transform: translateY(10px); }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* ---------- Анимации ---------- */
@keyframes pop {
  0% { transform: translateY(-70px) rotate(-220deg) scale(.4); opacity: 0; }
  100% { transform: none; opacity: 1; }
}
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes glow {
  0%, 100% { box-shadow: 0 10px 30px rgba(255, 61, 127, .4); }
  50% { box-shadow: 0 10px 44px rgba(255, 159, 28, .65); }
}
@keyframes winPulse { 0%, 100% { box-shadow: 0 0 0 3px rgba(34, 197, 94, .55); } 50% { box-shadow: 0 0 0 6px rgba(34, 197, 94, .25); } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(4px); }
}
@keyframes modalIn { from { transform: scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

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