:root {
  color-scheme: dark;
  --bg: #160d2b;
  --surface: #261743;
  --surface-strong: #342052;
  --card: #fffaf1;
  --ink: #20172d;
  --text: #fffafc;
  --muted: #c8bdd8;
  --accent: #f64d78;
  --accent-deep: #cc2857;
  --yellow: #ffd45c;
  --turquoise: #46dfcf;
  --danger: #ff8a7a;
  --border: rgba(255, 255, 255, 0.14);
  --shadow: 0 22px 60px rgba(7, 2, 20, 0.35);
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 8%, rgba(246, 77, 120, 0.18), transparent 28rem),
    radial-gradient(circle at 88% 100%, rgba(70, 223, 207, 0.12), transparent 30rem),
    var(--bg);
  overflow-x: hidden;
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }

.ambient { position: fixed; border-radius: 999px; filter: blur(1px); opacity: .7; pointer-events: none; }
.ambient-one { width: 14rem; height: 14rem; border: 1px solid rgba(255, 212, 92, .2); top: -7rem; right: 5vw; }
.ambient-two { width: 9rem; height: 9rem; border: 1px solid rgba(70, 223, 207, .18); bottom: -4rem; left: 6vw; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 20px 0 48px; position: relative; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 48px; margin-bottom: 34px; }
.brand { color: var(--text); text-decoration: none; font-weight: 800; letter-spacing: -.02em; display: flex; gap: 11px; align-items: center; }
.brand-mark { width: 28px; height: 28px; display: flex; align-items: flex-end; justify-content: center; gap: 3px; padding: 6px; border-radius: 9px; background: var(--accent); transform: rotate(-4deg); }
.brand-mark i { display: block; width: 3px; border-radius: 3px; background: #fff; }
.brand-mark i:nth-child(1) { height: 8px; }.brand-mark i:nth-child(2) { height: 15px; }.brand-mark i:nth-child(3) { height: 11px; }

.connection { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .8125rem; }
.connection span { width: 8px; height: 8px; border-radius: 50%; background: var(--turquoise); box-shadow: 0 0 0 4px rgba(70, 223, 207, .12); }
.connection.is-offline span { background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 138, 122, .12); }

.start-card { width: min(680px, 100%); margin: 8vh auto 0; padding: clamp(24px, 5vw, 48px); border: 1px solid var(--border); border-radius: 30px; background: linear-gradient(145deg, rgba(52, 32, 82, .95), rgba(38, 23, 67, .92)); box-shadow: var(--shadow); }
.eyebrow { color: var(--yellow); font-size: .8125rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
h1 { margin: 10px 0 12px; font-size: clamp(2rem, 6vw, 4rem); line-height: .98; letter-spacing: -.055em; }
.lead { max-width: 34rem; margin: 0 0 30px; color: var(--muted); font-size: 1.0625rem; line-height: 1.55; }
.form-stack { display: grid; gap: 18px; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.purchase-summary { display: flex; align-items: baseline; justify-content: space-between; padding: 15px 17px; border-radius: 14px; background: rgba(255, 255, 255, .06); }
.purchase-summary span, .legal-note { color: var(--muted); }
.purchase-summary strong { color: var(--yellow); font-size: 1.35rem; }
.legal-note { text-align: center; }
label { display: grid; gap: 8px; color: var(--muted); font-size: .875rem; font-weight: 700; }
input, select { width: 100%; min-height: 52px; border: 1px solid var(--border); border-radius: 14px; padding: 0 15px; color: var(--text); background: rgba(18, 10, 35, .6); outline: none; }
input:focus, select:focus { border-color: var(--turquoise); box-shadow: 0 0 0 3px rgba(70, 223, 207, .14); }

.button { min-height: 50px; border: 0; border-radius: 15px; padding: 12px 18px; font-weight: 800; cursor: pointer; transition: transform .15s ease, filter .15s ease, background .15s ease; }
.button:not(:disabled):active { transform: translateY(1px) scale(.99); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button-primary { color: #24102c; background: var(--yellow); box-shadow: 0 8px 24px rgba(255, 212, 92, .18); }
.button-primary:hover:not(:disabled) { filter: brightness(1.05); }
.button-secondary { color: var(--text); background: var(--surface-strong); border: 1px solid var(--border); }
.button-quiet { width: 100%; color: var(--muted); background: transparent; border: 1px dashed var(--border); margin-top: 12px; }
.button-danger { color: var(--danger); background: rgba(255, 138, 122, .08); border: 1px solid rgba(255, 138, 122, .3); }
.error { margin: 16px 0 0; padding: 12px 14px; color: #ffe3de; background: rgba(255, 138, 122, .12); border-radius: 12px; }

.room-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 22px; }
.room-heading h1 { font-size: clamp(2rem, 5vw, 3.4rem); margin-bottom: 0; }
.room-code { min-width: 156px; padding: 12px 16px; border-radius: 16px; background: rgba(255, 255, 255, .07); border: 1px solid var(--border); }
.room-code span, .muted { display: block; color: var(--muted); font-size: .75rem; }
.room-code strong { display: block; margin-top: 3px; font-size: 1.5rem; letter-spacing: .12em; color: var(--turquoise); }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 20px; align-items: start; }
.play-surface, .panel, .answer-panel { background: rgba(38, 23, 67, .82); border: 1px solid var(--border); box-shadow: var(--shadow); }
.play-surface { border-radius: 24px; padding: clamp(12px, 2.4vw, 24px); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-header strong { display: block; margin-top: 3px; font-size: 1rem; letter-spacing: .08em; }
.turn-label { padding: 7px 11px; border-radius: 999px; color: var(--yellow); background: rgba(255, 212, 92, .1); font-size: .8125rem; font-weight: 800; }
.bingo-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: clamp(4px, 1vw, 8px); }
.cell { position: relative; display: grid; align-content: center; gap: 5px; min-width: 0; min-height: clamp(84px, 12vw, 118px); padding: 8px 6px; border: 3px solid transparent; border-radius: 14px; color: var(--ink); background: var(--card); line-height: 1.12; overflow-wrap: anywhere; cursor: pointer; box-shadow: 0 5px 0 rgba(9, 3, 18, .18); }
.cell strong { font-size: clamp(.7rem, 1.4vw, .9rem); }
.cell small { color: #706778; font-size: clamp(.58rem, 1.1vw, .72rem); line-height: 1.12; }
.cell.marked { border-color: var(--accent); background: #ffe1e8; transform: translateY(-2px); }
.cell.marked::after { content: "×"; position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%) rotate(-8deg); color: rgba(190, 24, 72, .2); font-size: 4rem; font-weight: 900; }
.cell.pending { border-color: var(--yellow); background: #fff3bd; transform: translateY(-2px); }
.cell.pending::after { content: "Выбрано"; color: #765700; }
.cell.confirmed { border-color: #149889; background: #c8fff5; }
.cell.confirmed::after { content: "Засчитано ✓"; color: #08675d; }
.cell.rejected { border-color: var(--accent); background: #ffe1e8; }
.cell.rejected::after { content: "Не угадано ×"; color: #9c1740; }
.cell:focus-visible { outline: 3px solid var(--turquoise); outline-offset: 3px; }

.side-panel { display: grid; gap: 14px; }
.panel { border-radius: 20px; padding: 18px; }
.rules-panel { margin-bottom: 16px; padding: 18px 22px; }
.rules-panel ol { margin: 12px 0 8px; padding-left: 1.25rem; color: var(--text); line-height: 1.5; }
.rules-panel p { margin: 0; color: var(--muted); }
.panel h2 { margin: 0; font-size: 1rem; }
.panel-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 14px; }
.panel-title span { color: var(--muted); font-size: .75rem; }
.qr { display: block; width: min(150px, 100%); aspect-ratio: 1; margin: 0 auto 12px; padding: 7px; border-radius: 13px; background: white; }
.panel .button { width: 100%; }
.add-tickets { display: grid; grid-template-columns: 76px 1fr; gap: 8px; margin-top: 10px; }
.add-tickets input { min-height: 46px; }
.participants { list-style: none; display: grid; gap: 8px; margin: 0 0 14px; padding: 0; }
.participant { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; min-height: 38px; padding: 7px 9px; border-radius: 11px; background: rgba(255, 255, 255, .055); }
.participant strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .875rem; }
.participant small { color: var(--muted); font-size: .6875rem; }
.participant .ticket-issued { color: var(--turquoise); }
.controls { display: grid; gap: 10px; }
.answer-panel { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; margin-bottom: 16px; padding: 16px 20px; border-radius: 18px; border-color: rgba(255, 212, 92, .35); background: linear-gradient(90deg, rgba(246, 77, 120, .2), rgba(255, 212, 92, .12)); }
.answer-panel span { color: var(--yellow); font-weight: 900; text-transform: uppercase; letter-spacing: .1em; font-size: .75rem; }
.answer-panel strong { font-size: 1.2rem; }
.answer-panel small { color: var(--muted); }
.winner { position: relative; margin-bottom: 18px; padding: 20px; border-radius: 22px; text-align: center; color: #281630; background: var(--yellow); overflow: hidden; }
.winner p { margin: 0; font-weight: 900; text-transform: uppercase; letter-spacing: .16em; }
.winner h2 { margin: 4px 0 0; font-size: clamp(1.8rem, 5vw, 3rem); }
.winner-burst { position: absolute; inset: -20px auto auto 6%; font-size: 6rem; opacity: .15; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 10; width: max-content; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 13px; color: var(--ink); background: var(--turquoise); font-weight: 800; box-shadow: var(--shadow); }

.participant-mode .topbar { justify-content: flex-end; margin-bottom: 12px; }
.participant-mode .brand,
.participant-mode .room-heading,
.participant-mode .side-panel { display: none; }
.participant-mode .game-layout { grid-template-columns: minmax(0, 720px); justify-content: center; }
.participant-mode .winner { width: min(720px, 100%); margin-left: auto; margin-right: auto; }
.participant-mode .rules-panel { width: min(720px, 100%); margin-left: auto; margin-right: auto; }
.participant-mode .play-surface { background: rgba(38, 23, 67, .94); }

@media (max-width: 820px) {
  .shell { width: min(100% - 20px, 680px); padding-top: 10px; }
  .topbar { margin-bottom: 22px; }
  .game-layout { grid-template-columns: 1fr; }
  #game-view[data-status="lobby"] .side-panel { grid-row: 1; }
  #game-view[data-status="lobby"] .participants-panel { order: -1; }
  .room-heading { align-items: center; }
}

@media (max-width: 520px) {
  .shell { width: min(100% - 16px, 680px); }
  .brand span:last-child { font-size: .9rem; }
  .connection { font-size: .75rem; }
  .start-card { margin-top: 3vh; padding: 22px 18px; border-radius: 22px; }
  .choice-grid { grid-template-columns: 1fr; }
  .room-heading { align-items: flex-start; }
  .room-heading h1 { font-size: 1.75rem; }
  .room-code { min-width: 122px; padding: 9px 11px; }
  .room-code strong { font-size: 1.08rem; }
  .game-layout { gap: 12px; }
  .play-surface { padding: 8px; border-radius: 18px; }
  .cell { min-height: clamp(78px, 23vw, 96px); padding: 5px 3px; border-width: 2px; border-radius: 10px; }
  .cell strong { font-size: clamp(.59rem, 2.8vw, .72rem); }
  .cell small { font-size: clamp(.49rem, 2.25vw, .61rem); }
  .cell.marked::after { font-size: 3rem; }
  .rules-panel { padding: 15px; }
  .answer-panel { grid-template-columns: 1fr; gap: 3px; }
}

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