:root {
  --bg: #0e0f14;
  --surface: #171923;
  --surface-2: #21242f;
  --line: #2b2f3f;
  --text: #f4f1ea;
  --muted: #8b90a3;
  --cta: #ff5b44;
  --cta-ink: #1c0a06;
  --good: #3ddc97;
  --bad: #ff6b6b;
  --yellow: #f2c230;
  --display: "Arial Black", "Archivo Black", "Roboto Black", Impact, system-ui, sans-serif;
  /* Зерно для плакатных карточек (SVG-шум, ничего не качается из сети) */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .7 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100%;
  overscroll-behavior: none;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
}

h1, h2, h3 { margin: 0; font-family: var(--display); font-weight: 900; text-transform: uppercase; letter-spacing: -.01em; }
h1 { font-size: 22px; }
.muted { color: var(--muted); }
.row { display: flex; align-items: center; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.spread { justify-content: space-between; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }

/* ---------- шапка ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-family: var(--display); font-weight: 900; font-size: 21px; letter-spacing: -.01em; white-space: nowrap; }
.brand i { font-style: normal; color: var(--cta); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who-name { font-size: 15px; color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 17px;
}

/* ---------- 1. Пригласить друзей ---------- */
.invite {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  border: 0;
  border-radius: 22px;
  padding: 16px;
  background: var(--cta);
  color: var(--cta-ink);
  text-align: left;
  cursor: pointer;
  transition: transform .1s;
}
.invite:active { transform: scale(.98); }
.invite .ico { width: 50px; height: 50px; border-radius: 50%; background: var(--cta-ink); display: grid; place-items: center; flex: none; }
.invite .ico i { width: 28px; height: 28px; background: var(--cta); -webkit-mask: url(/icons/invite.svg) center / contain no-repeat; mask: url(/icons/invite.svg) center / contain no-repeat; }
.invite-title { display: block; font-family: var(--display); font-weight: 900; font-size: 20px; line-height: 1.05; text-transform: uppercase; }
.invite-sub { display: block; font-size: 14px; opacity: .8; margin-top: 4px; }
.invite .arrow { font-size: 26px; font-weight: 800; flex: none; }

.linkbtn { align-self: center; background: none; border: 0; padding: 4px 8px; color: var(--muted); font: inherit; font-size: 15px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.code-row { display: flex; align-items: center; gap: 12px; }

/* ---------- 2. Игры: фильтр и полки ---------- */
.section-title { font-size: 28px; margin-top: 6px; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: -4px -16px 0; padding: 4px 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar, .rail::-webkit-scrollbar, .slides::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 11px 20px;
  font: inherit;
  font-size: 16px;
  cursor: pointer;
  white-space: nowrap;
}
.chip.on { background: var(--text); color: #14141a; border-color: var(--text); }

.shelf { display: flex; flex-direction: column; gap: 12px; }
.sec-head { display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 0; color: var(--text); cursor: pointer; text-align: left; align-self: flex-start; }
.sec-title { font-size: 24px; font-weight: 700; }
.sec-arrow { font-size: 26px; color: var(--muted); line-height: 1; }

.rail { display: flex; gap: 12px; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scroll-snap-type: x mandatory; scroll-padding: 0 16px; scrollbar-width: none; }
.tile { flex: 0 0 52%; display: block; background: none; border: 0; padding: 0; color: inherit; text-align: left; cursor: pointer; scroll-snap-align: start; transition: transform .12s; }
.rail.big .tile { flex-basis: 84%; }
.tile:active { transform: scale(.97); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid .tile { flex: none; }
.empty { text-align: center; color: var(--muted); padding: 30px 0; }

/* ---------- обложки игр ---------- */
/* Сверху слева плашки Новинка/Хит, название строго по центру обложки. */
.poster {
  --poster: #a897e3;
  --ink: #1b1236;
  position: relative;
  container-type: inline-size;
  aspect-ratio: 3 / 4;
  border-radius: 16px;
  background: var(--poster);
  color: var(--ink);
  overflow: hidden;
  box-shadow: 0 0 0 1px #0004 inset;
}
.poster::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--grain);
  opacity: .3;
  mix-blend-mode: multiply;
  pointer-events: none;
}
.badges { position: absolute; z-index: 2; top: 12px; left: 12px; right: 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.slide .badges { top: 16px; left: 16px; right: 16px; }
.pill {
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
  background: var(--ink);
  color: var(--poster);
}
/* на маленьких карточках плашки мельче, на больших и на экране игры обычные */
.tile .pill { font-size: 11px; padding: 4px 8px; }
.tile .badges { top: 8px; left: 8px; right: 8px; gap: 4px; }
.rail.big .tile .pill { font-size: 13px; padding: 6px 10px; }
.rail.big .tile .badges { top: 12px; left: 12px; right: 12px; gap: 6px; }
.pill.new { background: var(--text); color: #14141a; }
.pill.hit { background: var(--cta); color: var(--cta-ink); }
.poster-title {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 0 6cqw;
  font-family: var(--display);
  font-weight: 900;
  text-transform: uppercase;
  font-size: 13cqw;
  line-height: .98;
  letter-spacing: -.02em;
}
.poster.land { aspect-ratio: 4 / 3; }
.poster.land .poster-title { font-size: 11cqw; }
.rail.big .poster.land { aspect-ratio: 16 / 10; }

/* ---------- страница раздела и экран игры ---------- */
.navbar { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.navbar .nav-title { text-align: center; font-size: 18px; font-weight: 700; }
.navbar .pager { text-align: right; color: var(--muted); font-size: 16px; }
.back { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--text); font-size: 26px; line-height: 1; cursor: pointer; padding: 0 0 3px; }

.slides { display: flex; gap: 14px; overflow-x: auto; margin: 0 -16px; padding: 4px 10%; scroll-snap-type: x mandatory; scroll-padding: 0 10%; scrollbar-width: none; }
.slide { flex: 0 0 100%; scroll-snap-align: center; } /* 100% от внутренней ширины (80% экрана), по бокам видны края соседних */
.slide .poster { border-radius: 22px; padding: 16px; }
.detail-info { display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; }
.facts { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px 12px; color: var(--muted); font-size: 16px; font-weight: 600; line-height: 1; }
.fact { display: inline-flex; align-items: center; gap: 5px; height: 28px; }
.fact .age { display: inline-flex; align-items: center; height: 28px; padding: 0 8px; border-radius: 8px; background: #ffffff26; color: var(--text); font-weight: 800; }
.fi { width: 20px; height: 20px; flex: none; background: currentColor; -webkit-mask: center / contain no-repeat; mask: center / contain no-repeat; }
.fi.players { -webkit-mask-image: url(/icons/players.svg); mask-image: url(/icons/players.svg); }
.fi.clock { -webkit-mask-image: url(/icons/clock.svg); mask-image: url(/icons/clock.svg); }
.fi.level { -webkit-mask-image: url(/icons/level.svg); mask-image: url(/icons/level.svg); }
.detail-desc { color: #c9c6bd; font-size: 17px; line-height: 1.45; margin: 0; max-width: 420px; }

/* ---------- кнопки и поля ---------- */
button, input { font: inherit; }
.btn {
  border: 0;
  border-radius: 999px;
  padding: 16px 24px;
  background: var(--cta);
  color: var(--cta-ink);
  font-weight: 800;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform .1s, opacity .1s;
}
.btn:active { transform: scale(.97); }
.btn[disabled] { background: var(--surface-2); color: var(--muted); cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.block { width: 100%; }
.btn.round { width: 54px; height: 54px; padding: 0; flex: none; font-size: 24px; background: var(--text); color: #14141a; }

.input {
  width: 100%;
  height: 54px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 20px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .2em;
  outline: none;
}
.input:focus { border-color: var(--text); }

/* ---------- лобби и игра ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.code { font-family: var(--display); font-weight: 900; font-size: 42px; letter-spacing: .2em; text-align: center; padding: 8px 0; }

.players { display: flex; flex-direction: column; gap: 8px; }
.player { display: flex; align-items: center; gap: 12px; padding: 8px 14px 8px 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.player.turn { border-color: var(--cta); box-shadow: 0 0 0 1px var(--cta) inset; }
.avatar.sm { width: 34px; height: 34px; font-size: 15px; }
.badge.left { background: var(--bad); color: #2a0a0a; }
.player.gone { color: var(--muted); }
.avatar.off { opacity: .35; filter: grayscale(1); } /* игрок отключился */
.badge { font-size: 12px; font-weight: 700; background: var(--text); color: #14141a; border-radius: 999px; padding: 3px 10px; }


.status { text-align: center; font-weight: 800; font-size: 30px; line-height: 1.15; padding-top: 12px; }
.status.x { color: var(--cta); }    /* ходят крестики: красный, как X на поле */
.status.o { color: var(--yellow); }
.status.win { color: var(--good); }
.status.lose { color: var(--bad); } /* ходят нолики: жёлтый, как O на поле */

.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: min(100%, 360px); margin: 40px auto 0; }
.cell {
  aspect-ratio: 1;
  border: 0;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--display);
  font-size: clamp(40px, 16vw, 72px);
  font-weight: 900;
  cursor: pointer;
}
.cell:disabled { cursor: default; }
.cell.x { color: var(--cta); }
.cell.o { color: var(--yellow); }
.cell.win { box-shadow: inset 0 0 0 3px var(--good); }
.cell.can:active { background: var(--line); }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #000d;
  backdrop-filter: blur(6px);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 30;
  max-width: 90vw;
}

/* ---------- поиск быстрой игры ---------- */
.search { min-height: calc(100dvh - 48px); display: flex; flex-direction: column; gap: 24px; }
.search-mid { flex: 1; display: grid; place-items: center; }
.search-text { text-align: center; }
.search-title { margin: 0 0 6px; font-size: 30px; line-height: 1.1; }
.search-text p { margin: 0; font-size: 17px; }

.hourglass { width: 150px; height: 210px; overflow: visible; animation: hg-flip 4.4s infinite; }
.hourglass .glass { fill: #ffffff10; stroke: var(--text); stroke-width: 3.5; stroke-linejoin: round; }
.hourglass .cap { fill: var(--text); }
.hourglass .sand { fill: var(--cta); transform-box: fill-box; transform-origin: bottom; }
.hourglass .sand.top { animation: hg-top 4.4s linear infinite; }
.hourglass .sand.bottom { transform: scaleY(0); animation: hg-bottom 4.4s linear infinite; }
.hourglass .stream { fill: var(--cta); animation: hg-stream 4.4s linear infinite; }
/* 0–78%: песок пересыпается; 78–100%: переворот. После переворота картинка та же, что в начале. */
@keyframes hg-flip { 0%, 80% { transform: rotate(0); animation-timing-function: cubic-bezier(.6, 0, .25, 1); } 100% { transform: rotate(180deg); } }
@keyframes hg-top { 0% { transform: scaleY(1); } 76%, 100% { transform: scaleY(0); } }
@keyframes hg-bottom { 0% { transform: scaleY(0); } 76%, 100% { transform: scaleY(1); } }
@keyframes hg-stream { 0%, 2% { opacity: 0; } 6%, 72% { opacity: 1; } 76%, 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .hourglass, .hourglass .sand, .hourglass .stream { animation: none; } .hourglass .sand.top { transform: scaleY(.6); } .hourglass .sand.bottom { transform: scaleY(.4); } }

/* ---------- комната ---------- */
.stack.tight { gap: 10px; }
.room-h { display: flex; align-items: center; justify-content: space-between; font-size: 20px; font-weight: 700; }
.player.empty { background: none; border: 2px solid var(--line); color: var(--muted); justify-content: center; }
.rail.pick { padding-top: 4px; padding-bottom: 4px; }
.tile.picked .poster { outline: 3px solid var(--cta); outline-offset: 2px; }
.tile.dim { opacity: .4; }
.tile[disabled] { cursor: default; }
.setting { display: flex; flex-direction: column; gap: 6px; }
.seg { display: flex; gap: 6px; }
.hint { color: var(--muted); font-size: 14px; }
.seg-b { flex: 1; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 12px; padding: 10px 8px; font-weight: 700; cursor: pointer; }
.seg-b.on { background: var(--text); color: #14141a; border-color: var(--text); }
.seg-b[disabled]:not(.on) { color: var(--muted); cursor: default; }

/* ---------- очки и плотный список игроков (когда игроков много) ---------- */
.score { font-weight: 800; font-size: 18px; min-width: 24px; text-align: center; }
.player .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players.dense { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.players.dense .player { padding: 6px 10px 6px 6px; gap: 8px; }
.players.dense .avatar.sm { width: 28px; height: 28px; font-size: 13px; }

/* ---------- Виселица ---------- */
.hang { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.hang-meta { color: var(--muted); font-weight: 600; text-align: center; }
.gallows { width: 190px; height: 190px; overflow: visible; }
.gal { stroke: var(--muted); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.fig { stroke: var(--text); stroke-width: 5; stroke-linecap: round; fill: none; }
.fig.dot { fill: var(--text); }
.gallows.dead .fig { stroke: var(--bad); }
.gallows.dead .fig.dot { fill: var(--bad); }
.word { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.wbox { width: 34px; height: 46px; border-bottom: 3px solid var(--muted); display: grid; place-items: center; font-family: var(--display); font-weight: 900; font-size: 28px; line-height: 1; }
.word.long .wbox { width: 28px; height: 40px; font-size: 23px; }
.wbox.miss { color: var(--bad); border-color: var(--bad); }
.lasttry { color: var(--muted); text-align: center; min-height: 22px; }
.kb { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; width: 100%; }
.key { aspect-ratio: 1; padding: 0; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 800; font-size: 18px; cursor: pointer; }
.key:active:not(:disabled) { background: var(--line); }
.key:disabled { cursor: default; }
.key:disabled:not(.hit):not(.miss) { opacity: .4; }
.key.hit { background: #1d4d3b; border-color: var(--good); color: var(--good); }
.key.miss { background: #3a1d22; border-color: var(--bad); color: var(--bad); }
.wordform { display: flex; gap: 8px; width: 100%; }
.wordform .input { flex: 1; min-width: 0; text-transform: uppercase; }
.status.mine { color: var(--cta); }

/* ---------- таймер хода и форма загадывания ---------- */
.tbar { display: flex; align-items: center; gap: 12px; width: 100%; }
.tbar .track { flex: 1; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.tbar .track i { display: block; height: 100%; width: calc(var(--p, 1) * 100%); background: var(--cta); border-radius: 999px; transition: width .2s linear; }
.tbar.low .track i { background: var(--bad); }
.tnum { font-weight: 800; font-size: 20px; min-width: 28px; text-align: right; }
.tbar.low .tnum { color: var(--bad); }
.wbox.dim { color: var(--muted); }
.setup { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.setup .input { letter-spacing: normal; text-transform: none; font-size: 16px; }
.setup .input::placeholder { letter-spacing: normal; text-transform: none; font-size: 15px; }
