/* Ведущий мафии, тёмная тема для игры вечером */

:root {
  --ink-deep: #0b0d12;
  --ground: #0e1014;
  --surface: #171b23;
  --surface-2: #1f2431;
  --surface-3: #272e3d;
  --line: #2c3243;
  --line-soft: #222836;

  --text: #e5e8f0;
  --text-dim: #9aa3b8;
  --text-faint: #6b7488;

  --accent: #c0473f;
  --accent-soft: #7e2f2a;
  --heal: #4f9a72;
  --lover: #c2749b;
  --gold: #c9a227;

  --r-mafia: #c0473f;
  --r-maniac: #8e63b8;
  --r-commissar: #4a86c7;
  --r-doctor: #4f9a72;
  --r-medic: #6fb894;
  --r-lover: #c2749b;
  --r-lucky: #c9a227;
  --r-civilian: #7b8399;

  --tile: clamp(46px, 8.4vw, 92px);
  --gap: clamp(6px, 1vw, 10px);
  --radius: 10px;

  --font-display: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-ui: "Golos Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
  -webkit-user-select: none;
  user-select: none;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* --- типографика --- */

.display {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(33px, 6.2vw, 50px);
  line-height: 1.08;
  letter-spacing: -0.02em;
  margin: 0;
  text-wrap: balance;
}

.display-sm { font-size: clamp(25px, 4.2vw, 33px); }

.eyebrow, .step-mark {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0;
}

.step-mark span {
  display: inline-block;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.lede {
  max-width: 46ch;
  color: var(--text-dim);
  font-size: 16px;
  margin: 0;
}

.hint {
  max-width: 62ch;
  color: var(--text-dim);
  font-size: 14px;
  margin: 0;
}

/* --- кнопки --- */

.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}

.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fdf3f2;
}
.btn-primary:hover { background: #cf5149; border-color: #cf5149; }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-lg { padding: 14px 26px; font-size: 16px; }

.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }

/* --- верхняя панель --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px clamp(16px, 3vw, 28px);
  background: rgba(14, 16, 20, .93);
  border-bottom: 1px solid var(--line-soft);
  backdrop-filter: blur(8px);
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }

.night-badge {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.01em;
  padding-right: 4px;
}

.view-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.view-btn {
  border: 0;
  background: transparent;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
.view-btn:hover { background: var(--surface-2); color: var(--text); }
.view-btn.is-on { background: var(--surface-3); color: var(--text); }

/* --- экраны --- */

.screen { padding: clamp(20px, 4vw, 40px) clamp(16px, 3vw, 28px) 64px; }

.screen-start {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.start-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
  max-width: 560px;
}

.start-inner .btn { margin-top: 6px; }

.setup-inner {
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  margin-top: 6px;
}

/* --- выбор ролей --- */

.role-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}

.role-chip {
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .15s ease, background .15s ease;
}

.role-chip:hover { background: var(--surface-2); }

.role-chip.is-on { border-color: var(--role-color); background: var(--surface-2); }

.role-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--role-color);
  flex: none;
  opacity: .35;
}

.role-chip.is-on .role-dot { opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--role-color) 22%, transparent); }

.role-chip-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.role-chip-name { font-weight: 600; font-size: 14px; }
.role-chip-note { font-size: 12px; color: var(--text-faint); }

/* --- игроки --- */

.name-form { display: flex; gap: 10px; flex-wrap: wrap; }

.text-input {
  flex: 1 1 220px;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 14px;
  color: var(--text);
  font: inherit;
}
.text-input::placeholder { color: var(--text-faint); }
.text-input { -webkit-user-select: text; user-select: text; }
.text-input:focus { border-color: var(--gold); outline: none; }

.roster-count { margin: 0; font-size: 13px; color: var(--text-faint); }
.roster-count.is-warn { color: var(--gold); }

.roster {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 8px;
}

.roster-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 9px 10px 9px 13px;
}

.roster-num {
  font-size: 12px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  min-width: 18px;
}

.roster-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }

.roster-drop {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
}
.roster-drop:hover { color: var(--accent); background: var(--surface-2); }

/* --- выбор раскладки --- */

.layout-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.layout-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  transition: border-color .15s ease, background .15s ease;
}
.layout-card:hover { border-color: var(--gold); background: var(--surface-2); }

.layout-name { font-family: var(--font-display); font-size: 21px; font-weight: 800; letter-spacing: -.01em; }
.layout-desc { font-size: 13px; color: var(--text-dim); }

/* Ширина стола равна ряду из четырёх мест, поэтому схема сходится по вертикали. */
.layout-art {
  --la-tile: 14px;
  --la-gap: 4px;
  --la-long: calc(4 * var(--la-tile) + 3 * var(--la-gap));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--la-gap);
  width: 100%;
  min-height: 96px;
  padding: 10px;
  border-radius: 8px;
  background: var(--ink-deep);
}
.layout-art i { display: block; width: var(--la-tile); height: var(--la-tile); border-radius: 3px; background: var(--surface-3); }
.la-sofa { align-self: center; width: var(--la-long); height: 6px; border-radius: 3px; background: var(--surface-2); }
.la-row { display: flex; gap: var(--la-gap); justify-content: center; }
.la-mid { display: flex; gap: var(--la-gap); align-items: stretch; justify-content: center; }
.la-side { display: flex; flex-direction: column; gap: var(--la-gap); }
.la-board { flex: 0 0 var(--la-long); border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); }

.layout-art-grid { display: grid; grid-template-columns: repeat(3, var(--la-tile)); gap: var(--la-gap); justify-content: center; align-content: center; }

/* --- очерёдность ходов --- */

.order-rail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  max-width: 1000px;
  margin: 0 auto 22px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
}

.order-label {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-right: 2px;
}

.order-step {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.order-step .order-i {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.order-step .role-dot { width: 8px; height: 8px; opacity: 1; }

/* --- стол --- */

.board-wrap { overflow-x: auto; padding-bottom: 8px; }

.board-table {
  display: grid;
  grid-template-columns: repeat(7, var(--tile));
  grid-template-rows: calc(var(--tile) * .4) repeat(4, var(--tile));
  gap: var(--gap);
  justify-content: center;
  min-width: calc(7 * 46px + 6 * 6px);
  margin: 0 auto;
  width: max-content;
}

.sofa {
  grid-area: 1 / 2 / 2 / 7;
  border-radius: 10px 10px 4px 4px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-bottom: 0;
  display: grid;
  place-items: center;
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.table-top {
  grid-area: 3 / 2 / 5 / 7;
  border-radius: 8px;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(201, 162, 39, .05), transparent 60%),
    var(--surface);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}

.table-top span {
  font-family: var(--font-display);
  font-size: clamp(13px, 2vw, 18px);
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: .01em;
}

/* --- место за столом и карточка игрока --- */

.seat {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 4px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  overflow: hidden;
  transition: border-color .15s ease, background .15s ease;
}

.seat:hover { border-color: var(--text-faint); background: var(--surface-2); }

.seat.is-empty { border-style: dashed; border-color: var(--line); background: transparent; }
.seat.is-empty .seat-name { color: var(--text-faint); font-weight: 500; }

.seat-num {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 9px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.seat-name {
  font-size: clamp(10px, 1.5vw, 13px);
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 2px;
}

.seat-role {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--role-color, var(--text-faint));
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-marks {
  display: flex;
  gap: 3px;
  align-items: center;
  height: 13px;
}

.seat-marks svg { width: 13px; height: 13px; display: block; }
.mark-heal { color: var(--heal); }
.mark-lover { color: var(--lover); }

.kill-x {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.kill-x::before,
.kill-x::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 50%;
  height: 3px;
  margin-top: -1.5px;
  border-radius: 2px;
  background: var(--accent);
  opacity: .85;
}

.kill-x::before { transform: rotate(45deg); }
.kill-x::after { transform: rotate(-45deg); }

.seat-name,
.seat-role,
.seat-marks { position: relative; z-index: 3; }

.seat-num,
.death-night { z-index: 3; }

.seat.is-killed { border-color: var(--accent-soft); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.seat.is-saved { border-color: var(--heal); background: color-mix(in srgb, var(--heal) 10%, var(--surface)); }

.seat.is-dead { background: var(--ink-deep); border-color: var(--line-soft); }
.seat.is-dead .seat-name { color: var(--text-dim); font-weight: 500; text-shadow: 0 1px 3px var(--ink-deep); }
.seat.is-dead .seat-role { opacity: .45; }

.skull {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 56%;
  height: 56%;
  z-index: 1;
  color: #dfe3ec;
  opacity: .22;
  pointer-events: none;
}

.death-night {
  position: absolute;
  bottom: 3px;
  right: 5px;
  font-size: 9px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

/* --- таблица --- */

.board-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-start;
  gap: 10px;
  max-width: 1000px;
  margin: 0 auto;
}

.board-list .seat {
  flex: 0 0 clamp(100px, 26vw, 150px);
  aspect-ratio: 1 / .82;
}

.board-legend {
  max-width: 1000px;
  margin: 20px auto 0;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

.empty-note {
  max-width: 520px;
  margin: 40px auto;
  text-align: center;
  color: var(--text-dim);
}

/* --- модалка --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(6, 7, 10, .72);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal {
  width: min(440px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 10px 20px;
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.modal-title {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -.01em;
  margin: 0;
  line-height: 1.15;
}

.modal-close {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 24px;
  line-height: 1;
  padding: 0 4px;
  border-radius: 6px;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 14px 20px 20px; display: flex; flex-direction: column; gap: 14px; }

.modal-group { display: flex; flex-direction: column; gap: 8px; }

.modal-group-label {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.act {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  font-weight: 600;
  font-size: 14px;
}
.act:hover { background: var(--surface-3); }

.act-kill.is-on { border-color: var(--accent); color: #f0b7b3; }
.act-heal.is-on { border-color: var(--heal); color: #a8dcc2; }
.act-lover.is-on { border-color: var(--lover); color: #e6b8cd; }

.act-icon { width: 16px; height: 16px; flex: none; }
.act-kill .act-icon { color: var(--accent); }
.act-heal .act-icon { color: var(--heal); }
.act-lover .act-icon { color: var(--lover); }

.role-list { display: flex; flex-wrap: wrap; gap: 7px; }

.role-pick {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
}
.role-pick:hover { background: var(--surface-3); }
.role-pick.is-on { border-color: var(--role-color); color: var(--role-color); }

.pick-list { display: flex; flex-direction: column; gap: 6px; }

.pick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: var(--surface-2);
  font-size: 14px;
  font-weight: 500;
}
.pick:hover { background: var(--surface-3); }
.pick-meta { font-size: 12px; color: var(--text-faint); }

.modal-note { font-size: 13px; color: var(--text-dim); margin: 0; }

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