/* Кодовые имена — телефон и планшет. Минимализм: графит, светлые плоские плитки, бирюзовый акцент.
   Портрет: шапка → счёт и часы → поле → панель действий (прилипает к низу) → команды → журнал.
   Горизонталь: поле слева на всю высоту экрана, справа счёт, действия, команды, журнал. */

:root {
  --bg: #0f1115;
  --s1: #171a20;
  --s2: #1e2229;
  --line: #2a2f38;
  --text: #eef1f5;
  --muted: #8d96a5;
  --accent: #22d3c5;
  --accent-ink: #032321;
  --red: #ff4d5a;
  --red-d: #e0323f;
  --red-l: #ff8a93;
  --blue: #3b82ff;
  --blue-d: #2363e0;
  --blue-l: #8db7ff;
  --tile: #f3f4f6;
  --tile-ink: #15171c;
  --gold: #ffd166;
  --radius: 16px;
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --ui: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --word: 'Fira Sans Condensed', 'Arial Narrow', 'Roboto Condensed', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; touch-action: manipulation; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(600px 300px at 50% -120px, rgba(34, 211, 197, .08), transparent 70%), var(--bg);
  color: var(--text);
  font: 500 15px/1.45 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
input { font: inherit; font-size: 16px; } /* меньше 16px — iPhone приближает страницу при вводе */
b { font-weight: 700; }
.muted { color: var(--muted); }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 0;
  font-weight: 700; font-size: 15px; line-height: 1.2; text-align: center;
  cursor: pointer; transition: transform .12s ease, filter .15s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-lg { min-height: 54px; font-size: 16px; border-radius: 14px; }
.btn-sm { min-height: 40px; padding: 6px 12px; font-size: 14px; border-radius: 11px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: var(--s2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.btn-red { background: var(--red); color: #fff; }
.btn-blue { background: var(--blue); color: #fff; }
@media (hover: hover) {
  .btn-primary:hover, .btn-red:hover, .btn-blue:hover { filter: brightness(1.07); }
  .btn-ghost:hover { background: #252a33; }
}
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; padding: 10px; }

.chip {
  display: inline-flex; align-items: center; gap: 8px; min-width: 0;
  height: 42px; padding: 0 12px; border-radius: 12px; border: 0;
  background: var(--s1); box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer; color: var(--text);
}
.chip svg { width: 16px; height: 16px; opacity: .6; flex: none; }
.chip-lbl { color: var(--muted); font-size: 13px; }
.chip b { font-family: var(--word); font-size: 18px; letter-spacing: .1em; font-weight: 700; }
.icon-btn {
  width: 44px; height: 42px; border-radius: 12px; border: 0; display: grid; place-items: center; flex: none;
  background: var(--s1); box-shadow: inset 0 0 0 1px var(--line); cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; }

.mark { width: 28px; height: 28px; flex: none; }
.mark-lg { width: 56px; height: 56px; }

/* ---------- главная ---------- */
.home {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: calc(20px + var(--st)) calc(16px + var(--sr)) calc(20px + var(--sb)) calc(16px + var(--sl));
}
.home-card {
  width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px;
  background: var(--s1); border: 1px solid var(--line); border-radius: 22px; padding: 28px 20px 20px;
}
.logo { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.logo-t { font: 800 30px/1.05 var(--ui); letter-spacing: -.02em; text-align: center; }
.home-sub { margin: 0; text-align: center; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .join-row input, .sheet-form input, .copy-input {
  height: 52px; border-radius: 13px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  padding: 0 14px; outline: none; transition: border-color .15s; width: 100%; min-width: 0;
}
.field input:focus, .join-row input:focus, .sheet-form input:focus { border-color: var(--accent); }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .14em; font-weight: 700; }
.join-row input::placeholder { text-transform: none; letter-spacing: 0; font-weight: 500; }
.join-row .btn { min-height: 52px; flex: none; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ---------- комната: портрет (основа) ---------- */
.room {
  max-width: 980px; margin: 0 auto;
  padding: calc(8px + var(--st)) calc(12px + var(--sr)) calc(24px + var(--sb)) calc(12px + var(--sl));
}
.top { display: flex; align-items: center; gap: 8px; padding: 2px 0 12px; min-width: 0; }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); text-decoration: none; font: 800 16px/1 var(--ui); letter-spacing: -.01em; flex: none; }
.brand span { display: none; }
.chip-lbl { display: none; }
.spacer { flex: 1; min-width: 0; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--red); flex: none; }
.conn.ok { background: #34d399; }
.me-chip { padding: 0 12px 0 7px; max-width: 46vw; flex-shrink: 1; }
.me-chip .me-txt { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; min-width: 0; overflow: hidden; }
.me-chip .me-txt b { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.me-chip .me-txt small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.av {
  width: 28px; height: 28px; border-radius: 9px; display: inline-grid; place-items: center; flex: none;
  font: 700 12.5px/1 var(--ui); color: #fff; background: #343a46;
}
.av.t-red { background: var(--red); }
.av.t-blue { background: var(--blue); }

/* счёт и часы */
.score { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 10px; margin: 0 0 12px; }
.score-side { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; font-size: 12px; color: var(--muted); }
.score-side span { display: none; }
.score-side b { font: 700 34px/1 var(--word); }
.score-side.red { justify-content: flex-end; }
.score-side.red b { color: var(--red); }
.score-side.blue b { color: var(--blue); }
.turn-pill {
  min-width: 156px; padding: 8px 18px 9px; border-radius: 14px; text-align: center; white-space: nowrap;
  color: #fff; display: flex; flex-direction: column; align-items: center; gap: 2px; transition: background .3s;
}
.tp-main { font: 700 15px/1.1 var(--ui); letter-spacing: .01em; }
.tp-sub { font: 600 12px/1.15 var(--ui); opacity: .92; font-variant-numeric: tabular-nums; }
.tp-sub:empty { display: none; }
.tp-time { font: 700 18px/1 var(--word); letter-spacing: .02em; }
.turn-pill.t-red { background: var(--red); }
.turn-pill.t-blue { background: var(--blue); }
.turn-pill.won { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--gold); }
.turn-pill.hurry { animation: hurry 1s ease-in-out infinite; }
@keyframes hurry { 50% { filter: brightness(1.25); transform: scale(1.04); } }
.timebar { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--s2); overflow: hidden; }
.timebar i { display: block; height: 100%; width: 100%; transform-origin: left center; background: var(--accent); transition: transform .25s linear; }
.timebar[data-team="red"] i { background: var(--red); }
.timebar[data-team="blue"] i { background: var(--blue); }
.timebar.paused i { background: var(--gold); }
.timebar.hurry i { background: #fff; }

/* раскладка */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: start; }
.center { grid-column: 1 / -1; order: -1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.below { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-top: 10px; }
.panel { background: var(--s1); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.panel-h { font-weight: 700; font-size: 13px; color: var(--muted); margin-bottom: 8px; }

/* ---------- команды ---------- */
.team {
  background: var(--s1); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 10px;
  display: flex; flex-direction: column; gap: 7px; position: relative; overflow: hidden; min-width: 0;
  transition: box-shadow .3s, border-color .3s;
}
.team::before { content: ''; position: absolute; inset: 0 0 auto; height: 3px; }
.team.red::before { background: var(--red); }
.team.blue::before { background: var(--blue); }
.team.red.active { border-color: var(--red); }
.team.blue.active { border-color: var(--blue); }
.team.pulse { animation: pulse 1.2s ease 2; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px var(--accent); } }
.team-h { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; margin-top: 2px; min-width: 0; }
.team-name { font: 800 18px/1 var(--ui); letter-spacing: -.01em; }
.team.red .team-name { color: var(--red-l); }
.team.blue .team-name { color: var(--blue-l); }
.team-left { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.team-left b { color: var(--text); font-size: 15px; }
.team-sec { font-size: 11.5px; font-weight: 600; color: var(--muted); margin-top: 4px; }
.team .btn { width: 100%; }

.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.pl { display: flex; align-items: center; gap: 7px; padding: 4px; border-radius: 10px; min-height: 38px; min-width: 0; }
.pl.me { background: var(--s2); }
.pl.off { opacity: .45; }
.pn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tag { font-size: 10.5px; font-weight: 700; color: var(--muted); background: var(--s2); padding: 2px 6px; border-radius: 6px; white-space: nowrap; flex: none; }
.host-i { width: 18px; height: 18px; color: var(--accent); flex: none; display: grid; place-items: center; }
.host-i svg { width: 16px; height: 16px; }
.tag.t-me, .tag.t-off { display: none; } /* «вы» видно по подсветке, «не в сети» — по бледности */
.empty { color: var(--muted); font-size: 13px; padding: 4px; }
.kick { width: 34px; height: 34px; border: 0; border-radius: 9px; background: var(--s2); display: grid; place-items: center; cursor: pointer; flex: none; }
.kick svg { width: 14px; height: 14px; }

/* ---------- поле ---------- */
.board { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: clamp(5px, 1.2vw, 10px); min-width: 0; }

.card {
  --fs: 16px;
  position: relative; aspect-ratio: 1.5 / 1; border-radius: 12px; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--tile); color: var(--tile-ink);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .08), 0 4px 12px rgba(0, 0, 0, .28);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; outline: none;
  transition: transform .14s ease, box-shadow .2s ease, background .25s ease;
}
.card-word {
  position: relative; z-index: 1; max-width: calc(100% - 12px);
  font: 700 var(--fs)/1 var(--word); letter-spacing: .02em; text-transform: uppercase; white-space: nowrap;
  overflow: hidden; text-overflow: clip;
}
.card-icon { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; }
.card-icon svg { width: 42%; height: 42%; max-width: 64px; }
.card-marks { position: absolute; top: 5px; left: 5px; display: flex; gap: 2px; z-index: 2; pointer-events: none; max-width: calc(100% - 40px); overflow: hidden; padding: 2px; }
.mchip {
  width: 20px; height: 20px; border-radius: 7px; display: grid; place-items: center; flex: none;
  font: 700 10.5px/1 var(--ui); color: #fff; box-shadow: 0 0 0 2px var(--tile);
}
.mchip.t-red { background: var(--red); }
.mchip.t-blue { background: var(--blue); }
.mchip.me { box-shadow: 0 0 0 2px var(--tile), 0 0 0 4px var(--accent); }
.mchip.more { background: #4b5160; }
.card-pen {
  position: absolute; top: 1px; right: 1px; z-index: 3; width: 34px; height: 34px; border: 0; border-radius: 10px;
  display: none; place-items: center; cursor: pointer; background: none; color: #6b7280; opacity: .45;
}
.card-pen svg { width: 15px; height: 15px; }
.card.can-note .card-pen { display: grid; }
.card-note {
  position: absolute; left: 6%; right: 6%; bottom: -6px; z-index: 2;
  font: 600 12px/1.25 var(--ui); text-align: center; color: #3b2f00;
  background: var(--gold); padding: 2px 6px; border-radius: 7px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
  pointer-events: none;
}
.card.has-note .card-word { margin-bottom: 10%; }

.card.can { cursor: pointer; }
.card.can:active { transform: scale(.95); }
@media (hover: hover) {
  .card.can:hover { transform: translateY(-2px); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .08), 0 10px 22px rgba(0, 0, 0, .35); }
  .card-pen:hover { background: rgba(0, 0, 0, .06); opacity: 1; }
}
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* отмеченные агентами */
.card.mk { transform: translateY(-2px); }
.card.mk-red { outline: 3px solid var(--red); outline-offset: 2px; }
.card.mk-blue { outline: 3px solid var(--blue); outline-offset: 2px; }

/* что видит капитан (и все — после конца партии): заливка оттенком + полоса снизу */
.card.k-red { background: #ffd6d9; color: #5c0b13; box-shadow: inset 0 -5px 0 var(--red), 0 4px 12px rgba(0, 0, 0, .28); }
.card.k-blue { background: #d6e4ff; color: #0b2766; box-shadow: inset 0 -5px 0 var(--blue), 0 4px 12px rgba(0, 0, 0, .28); }
.card.k-neutral { background: #ebe6dc; color: #3d362a; box-shadow: inset 0 -5px 0 #c9bea8, 0 4px 12px rgba(0, 0, 0, .28); }
.card.k-assassin { background: #2b2f37; color: #fff; box-shadow: inset 0 -5px 0 #0a0b0d, inset 0 0 0 2px #ff4d5a, 0 4px 12px rgba(0, 0, 0, .35); }
.card.k-assassin .card-pen { color: #c7ccd6; }
.card.k-red .mchip, .card.k-blue .mchip, .card.k-neutral .mchip { box-shadow: 0 0 0 2px #fff; }
.card.over { opacity: .72; }

/* открытые */
.card.rv { box-shadow: 0 2px 8px rgba(0, 0, 0, .25); }
.card.rv .card-word {
  font-size: calc(var(--fs) * .6); opacity: .8;
  position: absolute; bottom: 9%; margin: 0; letter-spacing: .05em;
}
.card.rv .card-icon { padding-bottom: 14%; }
.card.rv-red { background: var(--red); color: #fff; }
.card.rv-blue { background: var(--blue); color: #fff; }
.card.rv-neutral { background: #3a3f49; color: #c9ced8; }
.card.rv-assassin { background: #050506; color: #ff4d5a; box-shadow: inset 0 0 0 2px #ff4d5a; }
.card.rv-red .card-icon, .card.rv-blue .card-icon { color: rgba(255, 255, 255, .9); }
.card.rv-neutral .card-icon { color: rgba(255, 255, 255, .35); }
.card.rv-assassin .card-icon { color: #ff4d5a; }
.card.last { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent); }

.card.flip { animation: flip .55s cubic-bezier(.2, .8, .2, 1); }
@keyframes flip {
  0% { transform: perspective(600px) rotateY(-90deg) scale(.94); }
  100% { transform: perspective(600px) rotateY(0) scale(1); }
}

/* «Скрыть лишнее»: погашенные слова видит только сам игрок */
.card.hid { background: transparent !important; color: var(--muted) !important; box-shadow: inset 0 0 0 1.5px var(--line) !important; }
.card.hid .card-word { text-decoration: line-through; text-decoration-thickness: 2px; opacity: .55; }
.card.hid .card-note, .card.hid .card-pen { display: none !important; }
.card.hid.has-note .card-word, .board[data-size="s"] .card.hid.has-note .card-word { margin-bottom: 0; }
body.hide-mode .board { outline: 2px dashed var(--accent); outline-offset: 5px; border-radius: 12px; }
body.hide-mode .card-pen { display: none !important; }

/* мелкие карточки (телефон): размер ставит скрипт по ширине карточки */
.board[data-size="s"] .card { border-radius: 9px; }
.board[data-size="s"] .card-word { max-width: calc(100% - 4px); letter-spacing: .01em; }
.board[data-size="s"] .card.has-note .card-word { margin-bottom: 22%; }
.board[data-size="s"] .card-marks { top: 1px; left: 1px; gap: 1px; max-width: calc(100% - 22px); padding: 2px; }
.board[data-size="s"] .mchip { width: 14px; height: 14px; border-radius: 5px; font-size: 8px; box-shadow: 0 0 0 1.5px var(--tile); }
.board[data-size="s"] .mchip.me { box-shadow: 0 0 0 1.5px var(--tile), 0 0 0 3px var(--accent); }
.board[data-size="s"] .card-pen { top: -3px; right: -3px; width: 28px; height: 28px; }
.board[data-size="s"] .card-pen svg { width: 12px; height: 12px; }
.board[data-size="s"] .card-note { left: 2px; right: 2px; bottom: 2px; font-size: 10px; padding: 1px 3px; border-radius: 5px; box-shadow: none; }
.board[data-size="s"] .card.mk-red, .board[data-size="s"] .card.mk-blue { outline-width: 2.5px; outline-offset: 1px; }
.board[data-size="s"] .card.k-red, .board[data-size="s"] .card.k-blue, .board[data-size="s"] .card.k-neutral { box-shadow: inset 0 -4px 0 var(--kbar, transparent), 0 2px 6px rgba(0, 0, 0, .28); }
.board[data-size="s"] .card.k-red { --kbar: var(--red); }
.board[data-size="s"] .card.k-blue { --kbar: var(--blue); }
.board[data-size="s"] .card.k-neutral { --kbar: #c9bea8; }
.board[data-size="s"] .card.rv .card-word { bottom: 6%; }
.board[data-size="s"] .card.rv .card-icon { padding-bottom: 18%; }
.board[data-size="s"] .card-icon svg { width: 40%; height: 40%; }
.board[data-size="s"] .card.last { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }

/* ---------- баннер и панель действий ---------- */
.banner {
  display: flex; align-items: baseline; justify-content: center; flex-wrap: wrap; gap: 4px 12px;
  padding: 12px 14px; border-radius: var(--radius); color: #fff; text-align: center;
  animation: drop .4s cubic-bezier(.2, .8, .2, 1);
}
.banner b { font: 800 20px/1.15 var(--ui); }
.banner span { opacity: .92; font-weight: 600; }
.banner.t-red { background: var(--red); }
.banner.t-blue { background: var(--blue); }
@keyframes drop { from { transform: translateY(-8px); opacity: 0; } }

.actionbar {
  display: flex; flex-direction: column; align-items: stretch; gap: 10px;
  background: var(--s1); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px;
  position: sticky; bottom: calc(8px + var(--sb)); z-index: 5; box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
}
.ab-text { min-width: 0; font-size: 14px; line-height: 1.4; }
.ab-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.ab-btns .btn { flex: 1 1 100px; min-width: 0; padding: 0 12px; }
.ab-tools { display: flex; gap: 6px; flex-wrap: wrap; width: 100%; }
.tool {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 10px; border: 0;
  background: transparent; box-shadow: inset 0 0 0 1px var(--line); color: var(--muted); font: 600 13px/1 var(--ui); cursor: pointer;
}
.tool svg { width: 16px; height: 16px; flex: none; }
.tool:active { transform: scale(.97); }
.wchip { display: inline-block; font: 700 13px/1 var(--word); letter-spacing: .04em; padding: 4px 7px; border-radius: 6px; margin: 2px 2px 0 0; color: #fff; text-transform: uppercase; }
.wchip.t-red { background: var(--red); }
.wchip.t-blue { background: var(--blue); }

/* ---------- журнал ---------- */
.log { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; font-size: 14px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.log li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 4px 2px; min-width: 0; overflow-wrap: anywhere; }
.log .by { margin-left: auto; color: var(--muted); font-size: 12px; }
.log .lg-start, .log .lg-turn { color: var(--muted); }
.log .lg-win { font-weight: 800; }
.log .lg-win.t-red { color: var(--red-l); }
.log .lg-win.t-blue { color: var(--blue-l); }
.dot { width: 8px; height: 8px; border-radius: 3px; flex: none; }
.dot.t-red { background: var(--red); }
.dot.t-blue { background: var(--blue); }
.c-red { color: var(--red-l); font-weight: 600; }
.c-blue { color: var(--blue-l); font-weight: 600; }
.c-neutral { color: #c9bea8; font-weight: 600; }
.c-assassin { color: var(--red); font-weight: 800; }

/* ---------- модалка ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  padding: calc(12px + var(--st)) calc(12px + var(--sr)) calc(12px + var(--sb)) calc(12px + var(--sl));
  background: rgba(5, 7, 10, .66); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  overscroll-behavior: contain;
}
.sheet {
  width: 100%; max-width: 460px; max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--s1); border: 1px solid var(--line); border-radius: 22px; padding: 20px 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55); animation: pop .22s cubic-bezier(.2, .8, .2, 1);
}
@keyframes pop { from { transform: translateY(12px); opacity: 0; } }
.sheet-h { font: 800 20px/1.2 var(--ui); letter-spacing: -.01em; margin-bottom: 14px; }
.sheet-p { margin: 0 0 12px; overflow-wrap: anywhere; }
.sheet-p.tc { text-align: center; }
.sheet-p.warn { color: var(--red-l); font-weight: 600; }
.sheet-form { display: flex; flex-direction: column; gap: 12px; }
.sheet-btns { display: flex; gap: 8px; margin-top: 16px; }
.sheet-form .sheet-btns { margin-top: 4px; }
.sheet-btns .btn { flex: 1; min-width: 0; }
.reveal-word {
  margin: 0 auto 14px; padding: 18px 12px; border-radius: 14px; text-align: center; max-width: 300px;
  font: 700 28px/1 var(--word); letter-spacing: .03em; text-transform: uppercase;
  background: var(--tile); color: var(--tile-ink); overflow-wrap: anywhere;
}
.reveal-word.small { font-size: 22px; padding: 12px; }
.reveal-word.k-red { background: #ffd6d9; color: #5c0b13; box-shadow: inset 0 -5px 0 var(--red); }
.reveal-word.k-blue { background: #d6e4ff; color: #0b2766; box-shadow: inset 0 -5px 0 var(--blue); }
.reveal-word.k-neutral { background: #ebe6dc; color: #3d362a; box-shadow: inset 0 -5px 0 #c9bea8; }
.reveal-word.k-assassin { background: #2b2f37; color: #fff; box-shadow: inset 0 0 0 2px var(--red); }
.menu { display: flex; flex-direction: column; gap: 6px; }
.menu-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; min-height: 52px; justify-content: center;
  padding: 10px 14px; border-radius: 13px; border: 0; background: var(--s2); cursor: pointer; font-weight: 700;
}
.menu-item small { font-weight: 500; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.packs { display: flex; flex-direction: column; gap: 6px; }
.pack { display: flex; align-items: center; gap: 12px; padding: 10px 12px; min-height: 54px; border-radius: 13px; background: var(--s2); cursor: pointer; }
.pack input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; margin: 0; }
.pack span { display: flex; flex-direction: column; min-width: 0; }
.pack small { color: var(--muted); font-size: 12.5px; }
.set { margin-bottom: 14px; }
.set-h { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.seg { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.seg-b {
  min-height: 44px; border: 0; border-radius: 11px; background: var(--s2); box-shadow: inset 0 0 0 1px var(--line);
  font: 700 15px/1 var(--ui); font-variant-numeric: tabular-nums; cursor: pointer; color: var(--text);
}
.seg-b.on { background: var(--accent); color: var(--accent-ink); box-shadow: none; }
.seg-b:disabled { cursor: default; opacity: .7; }
.seg-b:disabled.on { opacity: 1; }
.rules p { margin: 0 0 10px; }

/* ---------- уведомления: сверху, чтобы не прятались за панелью действий ---------- */
.toast {
  position: fixed; left: 50%; top: calc(10px + var(--st)); z-index: 60;
  transform: translate(-50%, -16px); opacity: 0; pointer-events: none;
  width: max-content; max-width: min(calc(100vw - 24px), 460px); padding: 12px 16px; border-radius: 14px; text-align: center;
  background: var(--text); color: #12151a; font-weight: 600; box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
  transition: opacity .2s, transform .2s;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ================= адаптив ================= */

/* очень узкие телефоны */
@media (max-width: 359px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .me-chip .me-txt small { display: none; }
  .turn-pill { min-width: 0; padding: 7px 12px; }
  .score-side b { font-size: 28px; }
}

/* телефон в портрете: карточки повыше, окна выезжают снизу */
@media (orientation: portrait) and (max-width: 640px) {
  .card { aspect-ratio: 1 / .88; }
  .modal { place-items: end stretch; padding: calc(12px + var(--st)) 0 0; }
  .sheet { max-width: none; border-radius: 22px 22px 0 0; border-bottom: 0; padding: 20px 16px calc(18px + var(--sb)); }
}

/* планшет в портрете */
@media (orientation: portrait) and (min-width: 641px) {
  .room { padding-left: calc(20px + var(--sl)); padding-right: calc(20px + var(--sr)); }
  .brand span, .chip-lbl, .score-side span { display: inline; }
  .score-side b { font-size: 42px; }
  .turn-pill { min-width: 220px; padding: 10px 24px 11px; }
  .tp-main { font-size: 17px; }
  .tp-time { font-size: 22px; }
  .layout, .below { gap: 14px; }
  .below { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); margin-top: 14px; }
  .team { padding: 14px; }
  .team-name { font-size: 21px; }
  .actionbar { flex-direction: row; align-items: center; flex-wrap: wrap; padding: 12px 14px; }
  .ab-text { flex: 1 1 280px; font-size: 15px; }
  .ab-btns { flex: 0 1 auto; flex-wrap: nowrap; }
  .ab-btns .btn { flex: none; }
  .ab-tools { flex-basis: 100%; }
  .banner b { font-size: 24px; }
}

/* горизонталь (телефон боком, планшет боком): поле слева по высоте экрана, остальное справа */
@media (orientation: landscape) and (min-width: 560px) {
  .room {
    --top: 56px;
    --g: clamp(4px, .7vw, 9px);
    --bw: min(
      calc(1.6 * (100vh - var(--top) - 22px - var(--st) - var(--sb) - 4 * var(--g)) + 4 * var(--g)),
      calc(100vw - 370px - var(--sl) - var(--sr)),
      1100px);
    --bw: min(
      calc(1.6 * (100dvh - var(--top) - 22px - var(--st) - var(--sb) - 4 * var(--g)) + 4 * var(--g)),
      calc(100vw - 370px - var(--sl) - var(--sr)),
      1100px);
    max-width: none;
    display: grid; align-items: start; justify-content: center; column-gap: 14px;
    grid-template-columns: var(--bw) minmax(0, 320px) minmax(0, 320px);
    grid-template-rows: auto auto auto auto auto auto 1fr;
    grid-template-areas:
      "top top top"
      "board score score"
      "board banner banner"
      "board action action"
      "board red blue"
      "board spec spec"
      "board log log";
    padding: calc(6px + var(--st)) calc(12px + var(--sr)) calc(12px + var(--sb)) calc(12px + var(--sl));
  }
  .layout, .center, .below { display: contents; }
  .top { grid-area: top; height: var(--top); padding: 0; }
  .score { grid-area: score; margin: 0 0 10px; }
  .banner { grid-area: banner; margin-bottom: 10px; }
  .board { grid-area: board; width: var(--bw); gap: var(--g); position: sticky; top: calc(8px + var(--st)); }
  .actionbar { grid-area: action; position: static; box-shadow: none; margin-bottom: 10px; }
  #teamRed { grid-area: red; margin-right: 5px; }
  #teamBlue { grid-area: blue; margin-left: 5px; }
  .spectators { grid-area: spec; margin-top: 10px; }
  .log-panel { grid-area: log; margin-top: 10px; }
  .card { aspect-ratio: 1.6 / 1; }
  .ab-btns .btn { min-height: 42px; }
}

/* горизонталь на телефоне — низкий экран, всё компактнее */
@media (orientation: landscape) and (max-height: 540px) {
  .room { --top: 48px; }
  .chip, .icon-btn { height: 38px; }
  .turn-pill { min-width: 0; padding: 6px 12px 7px; }
  .tp-main { font-size: 14px; }
  .score-side b { font-size: 28px; }
  .team { padding: 10px 8px; gap: 5px; }
  .team-name { font-size: 16px; }
  .team-sec { margin-top: 2px; }
  .pl { min-height: 32px; padding: 2px 4px; }
  .av { width: 24px; height: 24px; font-size: 11px; border-radius: 8px; }
  .actionbar { padding: 10px; gap: 8px; }
  .ab-text { font-size: 13px; }
  .banner { padding: 8px 10px; }
  .banner b { font-size: 17px; }
  .log { max-height: 160px; font-size: 13px; }
  .home-card { gap: 10px; padding: 18px; }
  .logo { flex-direction: row; }
  .mark-lg { width: 40px; height: 40px; }
  .logo-t { font-size: 24px; }
  .sheet { max-width: 560px; padding: 14px 16px; }
  .sheet-h { margin-bottom: 10px; }
  .sheet-btns { margin: 10px -16px -14px; padding: 10px 16px 14px; position: sticky; bottom: -14px; background: var(--s1); border-top: 1px solid var(--line); }
  .reveal-word { padding: 10px; margin-bottom: 8px; font-size: 24px; }
  .pack { min-height: 46px; padding: 6px 10px; }
  .packs { display: grid; grid-template-columns: 1fr 1fr; }
  .seg { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .set { margin-bottom: 10px; }
}

/* горизонталь на планшете — просторнее */
@media (orientation: landscape) and (min-height: 541px) {
  .brand span, .chip-lbl, .score-side span { display: inline; }
  .score-side b { font-size: 38px; }
  .team { padding: 14px 12px; }
  .team-name { font-size: 20px; }
}

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