:root {
  --bg: #120e0d;
  --bg-2: #1c1615;
  --line: #3a2f2c;
  --text: #f3ebe4;
  --muted: #a8988f;
  --gold: #e3b45a;
  --gold-ink: #2a1d07;
  --red: #d9434b;
  --felt-1: #1f3a2e;
  --felt-2: #10231b;
  --r-mafia: #d9434b;
  --r-don: #ff6b5a;
  --r-sheriff: #5aa9ff;
  --r-doctor: #4fd18b;
  --r-beauty: #ff7ac8;
  --r-maniac: #b98cff;
  --r-civil: #d8cfc7;
  --font-display: "Unbounded", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 40%, #1d1513 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ── верхняя панель ── */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 6px;
}
h1 {
  font: 700 20px/1 var(--font-display);
  letter-spacing: .02em;
  margin: 0;
  color: var(--gold);
}
.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stepper button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 22px;
  line-height: 1;
  transition: transform .12s ease, background-color .12s ease;
}
.stepper button:hover { background: #2a211f; transform: translateY(-2px); }
.stepper button:active { transform: scale(.92); }
.stepper button:disabled { opacity: .35; cursor: default; transform: none; }
.count { display: flex; flex-direction: column; align-items: center; min-width: 58px; }
.count b { font: 700 22px/1 var(--font-display); }
.count span { font-size: 11px; color: var(--muted); margin-top: 2px; }

.ghost {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  font-size: 14px;
  transition: transform .12s ease, background-color .12s ease, border-color .12s ease;
}
.ghost:hover { background: #2a211f; border-color: #54443f; transform: translateY(-2px); }
.ghost:active { transform: scale(.96); }
.ghost.on { border-color: var(--gold); color: var(--gold); }

/* ── стол и круг ── */
main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  min-height: 0;
}
.stage {
  position: relative;
  width: var(--w, 340px);
  height: var(--h, 340px);
}
.table {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--tw, 50%);
  height: var(--th, 50%);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, var(--felt-1), var(--felt-2) 72%);
  box-shadow: inset 0 0 0 6px #2b1d14, inset 0 0 0 8px #4a3220, 0 18px 40px rgba(0,0,0,.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}
.phase { display: flex; align-items: center; gap: 2px; }
.phase-name {
  white-space: nowrap;
  font: 700 clamp(14px, 4.2vw, 20px)/1 var(--font-display);
  padding: 8px 6px;
  border-radius: 10px;
  transition: transform .12s ease;
}
.phase-name:active { transform: scale(.95); }
.phase-name.day { color: var(--gold); }
.phase-step {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 22px;
  color: var(--muted);
  transition: background-color .12s ease, color .12s ease;
}
.phase-step:hover { background: rgba(255,255,255,.07); color: var(--text); }
.alive { font-size: 13px; color: #cfe3d6; }
.alive .mf { color: #ff9a9f; }

.seat {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--d);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: transform .35s cubic-bezier(.2,.8,.2,1), opacity .2s ease;
}
.seat .ball {
  width: var(--d);
  height: var(--d);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #2a2220;
  border: 2px solid var(--ring, #4a3d39);
  box-shadow: 0 6px 14px rgba(0,0,0,.4);
  font: 700 calc(var(--d) * .38)/1 var(--font-display);
  position: relative;
  transition: transform .15s ease, border-color .15s ease, background-color .15s ease;
}
.seat:hover .ball { transform: translateY(-2px); }
.seat:active .ball { transform: scale(.93); }
.seat.current .ball { box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(0,0,0,.4); }
.seat .label {
  margin-top: 3px;
  width: var(--lw);
  font-size: var(--fs, 12px);
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seat .label.empty { color: var(--muted); }
.seat .role {
  width: var(--lw);
  font-size: calc(var(--fs, 12px) - 1px);
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ring);
  font-weight: 600;
}
.seat.dead .ball { opacity: .38; background: #1a1513; }
.seat.dead .ball::after {
  content: "";
  position: absolute;
  inset: 18%;
  background:
    linear-gradient(45deg, transparent 46%, var(--red) 46%, var(--red) 54%, transparent 54%),
    linear-gradient(-45deg, transparent 46%, var(--red) 46%, var(--red) 54%, transparent 54%);
}
.seat.dead .label { text-decoration: line-through; color: var(--muted); }
.seat.dead .role { opacity: .5; }

/* цвет кольца по роли (если роли видны) */
body:not(.hidden-roles) .seat[data-role="mafia"]   { --ring: var(--r-mafia); }
body:not(.hidden-roles) .seat[data-role="don"]     { --ring: var(--r-don); }
body:not(.hidden-roles) .seat[data-role="sheriff"] { --ring: var(--r-sheriff); }
body:not(.hidden-roles) .seat[data-role="doctor"]  { --ring: var(--r-doctor); }
body:not(.hidden-roles) .seat[data-role="beauty"]  { --ring: var(--r-beauty); }
body:not(.hidden-roles) .seat[data-role="maniac"]  { --ring: var(--r-maniac); }
body:not(.hidden-roles) .seat[data-role="civil"]   { --ring: var(--r-civil); }
body:not(.hidden-roles) .seat[data-role="mafia"] .ball,
body:not(.hidden-roles) .seat[data-role="don"] .ball { background: #3a1719; }
body.hidden-roles .seat .role { visibility: hidden; }
body.hidden-roles .alive .mf { display: none; }

/* ── низ ── */
.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 14px calc(12px + env(safe-area-inset-bottom));
}
.hint { font-size: 12px; color: var(--muted); text-align: right; }
#new-game.armed { border-color: var(--red); color: #ff9a9f; }

/* ── карточка игрока ── */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  opacity: 0;
  transition: opacity .2s ease;
}
.backdrop.show { opacity: 1; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  background: #1f1917;
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px rgba(0,0,0,.5);
  transform: translateY(105%);
  transition: transform .26s cubic-bezier(.2,.8,.2,1);
  visibility: hidden;
}
.sheet.open { transform: none; visibility: visible; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet h2 { margin: 0; font: 700 18px/1.2 var(--font-display); }
.field { display: block; margin: 12px 0 10px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input {
  width: 100%;
  font-size: 17px;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #120e0d;
  color: var(--text);
}
.roles { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #15100f;
  font-size: 14px;
  transition: transform .12s ease, background-color .12s ease, border-color .12s ease, color .12s ease;
}
.chip:hover { transform: translateY(-2px); border-color: #5a4a45; }
.chip.sel { border-color: var(--c); color: var(--c); background: color-mix(in srgb, var(--c) 14%, #15100f); }
.sheet-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 8px;
  margin-top: 14px;
}
.sheet-actions button { padding: 12px 8px; border-radius: 12px; font-size: 15px; }
.danger {
  border: 1px solid #6b2a2e;
  background: #2c1416;
  color: #ff9a9f;
  transition: transform .12s ease, background-color .12s ease;
}
.danger:hover { background: #3a181b; transform: translateY(-2px); }
.danger.revive { border-color: #2f5a44; background: #14271d; color: #8fe3b4; }
.primary {
  background: var(--gold);
  color: var(--gold-ink);
  font-weight: 700;
  transition: transform .12s ease, filter .12s ease;
}
.primary:hover { filter: brightness(1.07); transform: translateY(-2px); }
.primary:active, .danger:active { transform: scale(.96); }

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

/* ── ночь ── */
.foot .primary { padding: 11px 16px; border-radius: 12px; font-size: 15px; }
.last { font-size: 12px; color: #f1d9a8; max-width: 80%; line-height: 1.25; }
.last:empty { display: none; }
.night {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 520px;
  margin: 0 auto;
  background: #161b26;
  border-top: 1px solid #2c3550;
  border-radius: 18px 18px 0 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px rgba(0,0,0,.5);
  animation: rise .24s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.night-top { display: flex; justify-content: space-between; align-items: center; }
.night-count { font-size: 12px; color: #9aa6c4; }
.link { font-size: 13px; color: #9aa6c4; padding: 6px 0; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--text); }
.night h2 { margin: 6px 0 4px; font: 700 17px/1.25 var(--font-display); }
.night h2 .who { color: var(--c, var(--gold)); }
.night-pick { margin: 0; font-size: 15px; min-height: 20px; }
.night-pick.wait { color: #9aa6c4; }
.night-info { font-size: 14px; margin-top: 6px; }
.night-info:empty { display: none; }
.night-info .res { display: inline-block; padding: 6px 10px; border-radius: 10px; font-weight: 700; margin-top: 2px; }
.night-info .res.bad { background: #3a181b; color: #ff9a9f; }
.night-info .res.good { background: #14271d; color: #8fe3b4; }
.night-info .res.off { background: #262a36; color: #b8c0d8; font-weight: 500; }
.night-info ul { margin: 6px 0 0; padding-left: 18px; color: #c9d0e4; }
.night-info li { margin: 2px 0; }
.night-info .verdict { font: 700 16px/1.3 var(--font-display); color: var(--text); margin: 2px 0 4px; }
.night-info .verdict.death { color: #ff9a9f; }
.night-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  gap: 8px;
  margin-top: 12px;
}
.night-actions button { padding: 12px 8px; border-radius: 12px; font-size: 15px; }
.night-actions button:disabled { opacity: .4; cursor: default; transform: none; filter: none; }
body.in-night .foot { visibility: hidden; }
body.in-night { background: radial-gradient(120% 80% at 50% 35%, #161a26 0%, #0c0e14 60%); }
body.in-night .seat.gone { pointer-events: none; }
.seat.target .ball { box-shadow: 0 0 0 3px var(--tc, var(--gold)), 0 0 18px var(--tc, var(--gold)); }
@media (prefers-reduced-motion: reduce) {
  .night { animation: none; }
}
.night.summary .night-actions { grid-template-columns: 1fr 1.6fr; }
.night-pick:empty { display: none; }
.seat[hidden] { display: none; }
