:root {
  color-scheme: dark;
  --bg: #141218;
  --bg-deep: #0d0b10;
  --surface: #1d1b20;
  --surface-2: #2b292f;
  --surface-3: #36343b;
  --primary: #ffb4ab;
  --on-primary: #690005;
  --primary-container: #93000a;
  --on-primary-container: #ffdad6;
  --secondary: #e7c365;
  --on-secondary: #3e2e00;
  --secondary-container: #5a4300;
  --on-secondary-container: #ffe08a;
  --outline: #938f99;
  --outline-variant: #49454f;
  --text: #e6e0e9;
  --muted: #cac4d0;
  --green: #9be7a8;
  --red: #ff9a95;
  --yellow: #ffd37a;
  --purple: #e8b4ff;
  --radius: 24px;
  --radius-lg: 28px;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

body {
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(147, 0, 10, 0.28), transparent 62%),
    radial-gradient(900px 500px at 100% 110%, rgba(90, 67, 0, 0.18), transparent 60%),
    linear-gradient(180deg, var(--bg-deep), var(--bg) 40%, #100e13);
  min-height: 100dvh;
}

#app { min-height: 100dvh; }

.screen {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
  animation: rise 260ms ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.brand {
  text-align: center;
  margin: 26px 0 8px;
}
.brand .mask { font-size: 46px; line-height: 1; }
.brand h1 {
  margin: 6px 0 0;
  font-size: clamp(44px, 15vw, 64px);
  line-height: 1;
  letter-spacing: 0.16em;
  font-weight: 900;
  color: var(--primary);
  text-shadow: 0 0 30px rgba(255, 180, 171, 0.16);
}
.brand p {
  margin: 12px auto 0;
  max-width: 420px;
  color: var(--muted);
  font-size: 15px;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(147, 143, 153, 0.16);
  border-radius: var(--radius);
  padding: 18px;
  margin: 12px 0;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.card.hero {
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border-radius: var(--radius-lg);
  padding: 20px;
}

.eyebrow {
  color: var(--secondary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

h2, h3 { margin: 0; }
h2 { font-size: 28px; line-height: 1.15; font-weight: 800; }
h3 { font-size: 18px; margin: 18px 2px 8px; }

.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.small { font-size: 13px; }

.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 10px; }

label.field { display: block; margin: 14px 0 0; }
label.field span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 6px 2px;
}

input {
  width: 100%;
  height: 54px;
  border-radius: 16px;
  border: 1px solid var(--outline-variant);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
  padding: 0 16px;
  outline: none;
  transition: border-color 140ms, box-shadow 140ms;
}
input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 180, 171, 0.14);
}
input::placeholder { color: #8f8a96; }

.btn {
  appearance: none;
  border: 0;
  width: 100%;
  min-height: 54px;
  border-radius: 20px;
  padding: 14px 18px;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 120ms, opacity 120ms, background 140ms;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.tonal { background: var(--surface-3); color: var(--text); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--outline-variant); }
.btn.danger { background: var(--primary-container); color: var(--on-primary-container); }

.icon-btn {
  appearance: none;
  border: 0;
  background: var(--surface-2);
  color: var(--muted);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 0 14px;
}
.topbar .room { font-weight: 800; font-size: 18px; }
.topbar .who { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  border: 1px solid rgba(147, 143, 153, 0.14);
}
.chip.gold { background: var(--secondary-container); color: var(--on-secondary-container); border-color: transparent; }

.list { display: grid; gap: 8px; }

.player {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid rgba(147, 143, 153, 0.12);
  border-radius: 18px;
  padding: 10px 14px;
  min-height: 58px;
}
.player.dead { opacity: 0.55; }
.player .avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--muted);
  flex: 0 0 auto;
}
.player .avatar svg { width: 21px; height: 21px; }
.player .pname {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.you {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
}
.dead-tag { color: var(--red); font-size: 12px; font-weight: 500; }
.role-tag { font-size: 13px; font-weight: 700; white-space: nowrap; }
.role-tag.mafia { color: var(--red); }
.role-tag.maniac { color: var(--yellow); }
.role-tag.jester { color: var(--purple); }
.role-tag.peaceful { color: var(--green); }

.role-card {
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  padding: 18px;
  text-align: center;
  margin: 12px 0;
}
.role-card.prominent {
  padding: 28px 20px;
  border-color: rgba(255, 180, 171, 0.5);
  box-shadow: 0 0 0 1px rgba(255, 180, 171, 0.08), 0 18px 50px rgba(0, 0, 0, 0.28);
}
.role-card .role-icon { font-size: 42px; line-height: 1; }
.role-card.prominent .role-icon { font-size: 64px; }
.role-card .role-title { font-size: 26px; font-weight: 900; margin-top: 6px; }
.role-card.prominent .role-title { font-size: 32px; }
.role-card.mafia .role-title { color: var(--red); }
.role-card.maniac .role-title { color: var(--yellow); }
.role-card.jester .role-title { color: var(--purple); }
.role-card.peaceful .role-title { color: var(--green); }

.phase { text-align: center; }
.phase-label { color: var(--primary); font-size: 22px; font-weight: 800; }
.phase-message { color: var(--muted); margin-top: 6px; }
.countdown { color: var(--secondary); font-weight: 700; margin-top: 8px; min-height: 1.2em; }

.prompt { border-color: rgba(255, 180, 171, 0.35); }
.prompt-title { font-size: 19px; font-weight: 800; margin-bottom: 4px; }
.targets { display: grid; gap: 8px; margin: 12px 0; }
.target {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 18px;
  border: 1px solid var(--outline-variant);
  background: var(--surface-2);
  cursor: pointer;
  user-select: none;
  transition: background 120ms, border-color 120ms, transform 120ms;
}
.target:active { transform: scale(0.99); }
.target.selected {
  background: var(--primary-container);
  border-color: var(--primary);
  color: var(--on-primary-container);
}
.target .avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface);
  display: grid;
  place-items: center;
  color: var(--muted);
  flex: 0 0 auto;
}
.target .avatar svg { width: 19px; height: 19px; }
.target .tname { flex: 1; font-weight: 600; }
.target .check { font-weight: 900; color: var(--primary); }
.target.selected .check { color: var(--on-primary-container); }

.banner {
  border-radius: 18px;
  padding: 12px 14px;
  margin: 12px 0;
  font-size: 14px;
  background: var(--surface-2);
  color: var(--muted);
}
.banner.error { background: var(--primary-container); color: var(--on-primary-container); }
.banner.gold { background: var(--secondary-container); color: var(--on-secondary-container); }

.winner {
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  text-align: center;
  font-size: 26px;
  font-weight: 900;
  margin: 12px 0;
}

.events ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 7px; }
.events li { color: var(--muted); font-size: 14px; padding-left: 14px; position: relative; }
.events li::before { content: "•"; position: absolute; left: 0; color: var(--secondary); }

.waiting { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--outline-variant);
  border-top-color: var(--primary);
  animation: spin 900ms linear infinite;
  flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress {
  height: 8px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 4px;
}
.progress > i {
  display: block;
  height: 100%;
  background: var(--secondary);
  border-radius: inherit;
  transition: width 240ms;
}

.hint { color: var(--muted); font-size: 13px; margin: 10px 2px; }

.footer { margin-top: 18px; text-align: center; color: #8f8a96; font-size: 12px; }

@media (min-width: 480px) {
  .screen { padding-left: 24px; padding-right: 24px; }
}

/* ─────────────────────────────────────────
   Ночь, появление карточек и «живые» детали
   ───────────────────────────────────────── */

body.night {
  background:
    radial-gradient(2px 2px at 18% 14%, rgba(255, 255, 255, 0.55), transparent 60%),
    radial-gradient(1.5px 1.5px at 72% 26%, rgba(255, 255, 255, 0.45), transparent 60%),
    radial-gradient(1.5px 1.5px at 42% 62%, rgba(255, 255, 255, 0.4), transparent 60%),
    radial-gradient(2px 2px at 88% 72%, rgba(255, 255, 255, 0.35), transparent 60%),
    radial-gradient(1200px 600px at 50% -10%, rgba(38, 34, 92, 0.5), transparent 62%),
    radial-gradient(900px 500px at 100% 110%, rgba(90, 67, 0, 0.14), transparent 60%),
    linear-gradient(180deg, #07060d, #0b0a14 50%, #05040a);
}

@keyframes pop {
  0% { opacity: 0; transform: translateY(10px) scale(0.98); }
  100% { opacity: 1; transform: none; }
}

@keyframes flipIn {
  0% { opacity: 0; transform: perspective(700px) rotateX(-24deg) translateY(14px); }
  100% { opacity: 1; transform: none; }
}

@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-6px) rotate(2deg); }
}

@keyframes winnerPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 195, 101, 0.35); transform: scale(1); }
  50% { box-shadow: 0 0 0 14px rgba(231, 195, 101, 0); transform: scale(1.012); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes badgePop {
  0% { transform: scale(0.4); }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.card, .player, .role-card, .winner, .banner {
  animation: pop 280ms ease-out both;
}
.player:nth-child(2) { animation-delay: 30ms; }
.player:nth-child(3) { animation-delay: 60ms; }
.player:nth-child(4) { animation-delay: 90ms; }
.player:nth-child(5) { animation-delay: 120ms; }
.player:nth-child(6) { animation-delay: 150ms; }
.player:nth-child(7) { animation-delay: 180ms; }
.player:nth-child(8) { animation-delay: 210ms; }

.role-card { animation: flipIn 460ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.role-card .role-icon { display: inline-block; animation: floaty 3.4s ease-in-out infinite; }
.role-card.prominent { animation: flipIn 520ms cubic-bezier(0.2, 0.8, 0.2, 1) both, winnerPulse 2.6s ease-in-out 600ms infinite; }

.winner { animation: pop 320ms ease-out both, winnerPulse 1.8s ease-in-out 320ms infinite; }

.target.selected { animation: pop 180ms ease-out; }
.target.selected .avatar { animation: floaty 1.8s ease-in-out infinite; }

.brand .mask { display: inline-block; animation: floaty 4s ease-in-out infinite; }

.progress > i { background: linear-gradient(90deg, var(--secondary), #ffe08a); }

.phase-label { animation: pop 300ms ease-out both; }

.dead-tag.gold-text { color: var(--secondary); }

.guardian-tag {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--secondary-container);
  color: var(--on-secondary-container);
  font-size: 12px;
  font-weight: 800;
  animation: pop 300ms ease-out both;
}

/* ─────────────────────────────────────────
   Чат
   ───────────────────────────────────────── */

.chat-dock {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
}
.chat-dock > * { pointer-events: auto; }
.chat-dock.hidden { display: none; }

.chat-log {
  display: none;
  width: min(340px, calc(100vw - 32px));
  max-height: 44vh;
  overflow-y: auto;
  background: rgba(29, 27, 32, 0.96);
  border: 1px solid rgba(147, 143, 153, 0.22);
  border-radius: 22px;
  padding: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}
.chat-dock.open .chat-log { display: block; animation: slideUp 220ms ease-out; }

.chat-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 8px; }

.chat-msg {
  background: var(--surface-2);
  border-radius: 14px;
  padding: 8px 11px;
  margin-bottom: 7px;
  animation: msgIn 180ms ease-out both;
}
.chat-msg.mine { background: var(--primary-container); color: var(--on-primary-container); }
.chat-msg.dead { opacity: 0.72; }
.chat-meta { font-size: 11px; font-weight: 700; opacity: 0.7; margin-bottom: 2px; }
.chat-text { font-size: 14px; word-wrap: break-word; overflow-wrap: anywhere; }

.chat-form {
  display: none;
  width: min(340px, calc(100vw - 32px));
  gap: 8px;
  align-items: center;
}
.chat-dock.open .chat-form { display: flex; animation: slideUp 200ms ease-out; }
.chat-form input {
  height: 46px;
  border-radius: 999px;
  background: rgba(29, 27, 32, 0.96);
  border: 1px solid var(--outline-variant);
}
.chat-send {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}
.chat-send:active { transform: scale(0.94); }

.chat-toggle {
  position: relative;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(255, 180, 171, 0.25);
  transition: transform 140ms;
}
.chat-toggle:active { transform: scale(0.94); }

.chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--secondary);
  color: var(--on-secondary);
  font-size: 12px;
  font-weight: 900;
  display: grid;
  place-items: center;
  animation: badgePop 220ms ease-out;
}
.chat-badge.hidden { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
