:root {
  --bg: #0f1419; --panel: #182029; --panel2: #1f2a36; --line: #2c3a4a;
  --text: #e6edf3; --muted: #8b9bab; --accent: #e5484d; --accent2: #f2b84b; --ok: #3fb97a;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent2); }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h2 { font-size: 20px; } h3 { font-size: 16px; color: var(--muted); font-weight: 600; }

button, .btn {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 14px; cursor: pointer; transition: background .15s, border-color .15s;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: #f05a5f; }
button.ok { background: var(--ok); border-color: var(--ok); color: #06281a; font-weight: 600; }
.small { padding: 3px 9px; font-size: 13px; }
a.btn { text-decoration: none; display: inline-block; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent2); outline-offset: 1px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* вход */
.auth { max-width: 380px; margin: 8vh auto; padding: 0 16px; }
.auth .logo { font-size: 56px; text-align: center; }
.auth h1 { text-align: center; font-size: 26px; }
.auth form { display: grid; gap: 10px; }
.err { color: var(--accent); min-height: 22px; font-size: 14px; }

/* шапка */
header { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
header .in { max-width: 1200px; margin: 0 auto; padding: 8px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
header .brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav button { border: none; background: transparent; color: var(--muted); position: relative; }
nav button.on { color: var(--text); background: var(--panel2); }
.badge { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; margin-left: 4px; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* игра */
.room { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.code { font: 700 22px/1 Consolas, monospace; letter-spacing: 3px; color: var(--accent2); }
.timer { font: 700 44px/1 Consolas, monospace; }
.timer.low { color: var(--accent); }
.status { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.players { display: grid; gap: 6px; }
.player { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--panel2); border-radius: 8px; }
.player.me { outline: 1px solid var(--line); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); }
.score { font-weight: 700; color: var(--accent2); min-width: 22px; text-align: right; }
.card { display: flex; gap: 14px; align-items: center; padding: 14px; border-radius: var(--radius);
  background: linear-gradient(135deg, #24384d, #1b2836); border: 1px solid var(--line); }
.card.spy { background: linear-gradient(135deg, #5a1c22, #2b1418); border-color: var(--accent); }
.card .big { font-size: 20px; font-weight: 700; }
.ico { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; font-size: 32px; flex: none; }
.ico img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.ico.lg { width: 64px; height: 64px; font-size: 46px; }
/* карточки локаций: картинка сверху, подпись снизу */
.pic { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; background: #111a23; overflow: hidden; }
.pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.locs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.loc { position: relative; background: var(--panel2); border: 2px solid transparent; border-radius: 10px; overflow: hidden; cursor: pointer; }
.loc .pic { font-size: 56px; }
.loc .name { padding: 7px 8px 8px; font-size: 13.5px; font-weight: 600; line-height: 1.25; text-align: center; }
.loc.x { opacity: .32; } .loc.x .name { text-decoration: line-through; }
.loc.ok { border-color: var(--ok); box-shadow: 0 0 0 2px rgba(63, 185, 122, .25); }
.locs.pick .loc { border-color: var(--accent); }
.marks { position: absolute; top: 6px; right: 6px; display: flex; flex-direction: column; gap: 6px; }
.mk { width: 30px; height: 30px; padding: 0; border-radius: 50%; font-weight: 700; line-height: 1; background: rgba(15, 20, 25, .82); border: 1px solid var(--line); }
.mk.ok { color: var(--ok); } .mk.x { color: var(--accent); }
.mk.ok[aria-pressed=true] { background: var(--ok); border-color: var(--ok); color: #06281a; }
.mk.x[aria-pressed=true] { background: var(--accent); border-color: var(--accent); color: #fff; }
.loc.x .marks { opacity: 1; }
/* моя карта: сверху название локации, под ним роль */
.deal { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.mycard { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: linear-gradient(160deg, #24384d, #1b2836); margin-bottom: 16px; }
.mycard .pic { font-size: 130px; }
.mycard .cap { padding: 12px 14px 14px; text-align: center; }
.cap-loc { font-size: 21px; font-weight: 700; line-height: 1.2; }
.cap-role { margin-top: 4px; font-size: 16px; color: var(--accent2); font-weight: 600; }
.mycard.spy { background: linear-gradient(160deg, #5a1c22, #2b1418); border-color: var(--accent); }
.mycard.spy .cap-role { color: var(--muted); font-weight: 400; }
/* всплывающие окна */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 12, .72); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; width: 100%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.modal-box p { margin: 0 0 14px; white-space: pre-line; }
.modal-box input { margin-bottom: 14px; }
.modal-actions { justify-content: flex-end; }
.modal-box.wide { max-width: 860px; max-height: 88vh; overflow-y: auto; }
.vote { border-color: var(--accent2); }
.result.spy { border-color: var(--accent); } .result.civ { border-color: var(--ok); }

.chat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column;
  height: calc(100vh - 110px); position: sticky; top: 70px; }
.chat h3 { padding: 12px 14px 0; }
.log { flex: 1; overflow-y: auto; padding: 8px 14px; display: flex; flex-direction: column; gap: 4px; }
.msg b { color: var(--accent2); font-weight: 600; }
.msg.me b { color: var(--ok); }
.msg.sys { color: var(--muted); font-size: 13px; font-style: italic; }
.chat form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }

/* друзья, диалоги */
.list { display: grid; gap: 6px; }
.item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--panel2); border-radius: 8px; }
.dialogs { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; }
.dialogs .item { cursor: pointer; } .dialogs .item.on { outline: 1px solid var(--accent2); }
.thread { display: flex; flex-direction: column; height: calc(100vh - 150px); }
.bubble { max-width: 75%; padding: 6px 11px; border-radius: 12px; background: var(--panel2); align-self: flex-start; overflow-wrap: anywhere; }
.bubble.me { align-self: flex-end; background: #2c4a66; }
.bubble small { color: var(--muted); margin-left: 8px; font-size: 11px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* статистика */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.tile { background: var(--panel2); border-radius: 10px; padding: 12px; }
.tile b { display: block; font-size: 26px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll { overflow-x: auto; }

/* каталог локаций */
.catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.catalog .panel { margin: 0; }
.catalog .head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--panel2); border-radius: 12px; padding: 1px 9px; font-size: 13px; }
.rules p, .rules li { max-width: 72ch; }

/* аватары, ход вопросов */
.ava { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; flex: none;
  background: #34506b; color: #fff; font-weight: 700; font-size: 14px; overflow: hidden; }
.ava img { width: 100%; height: 100%; object-fit: cover; }
.ava.sm { width: 22px; height: 22px; font-size: 11px; }
.ava.xl { width: 96px; height: 96px; font-size: 40px; }
.who { display: inline-flex; align-items: center; gap: 6px; border: none; }
.turn { font-size: 18px; font-weight: 700; }
.msg.qa-q, .msg.qa-a { background: var(--panel2); border-left: 3px solid var(--accent2); border-radius: 6px; padding: 4px 8px; }
.msg.qa-a { border-left-color: var(--ok); }
.qa { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.or { text-align: center; color: var(--muted); margin: 12px 0 10px; font-size: 13px; }
button.tg { width: 100%; background: #2aabee; border-color: #2aabee; color: #fff; font-weight: 600; }
button.tg:hover { background: #3fb6f2; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 20; max-width: 340px; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--accent2); border-radius: 8px; padding: 10px 12px; }
.toast.bad { border-left-color: var(--accent); }

@media (max-width: 860px) {
  .room, .dialogs, .deal { grid-template-columns: minmax(0, 1fr); }
  .mycard { max-width: 300px; margin-left: auto; margin-right: auto; }
  .chat { height: 420px; position: static; }
  .thread { height: 60vh; }
  .timer { font-size: 34px; }
}
