/* ═══════════════════════════════════════════════════════════
   Мафия — тёмная нуар-тема: приглушённый уголь, ламповое золото,
   кровь для опасного, индиго для ночи.
   ═══════════════════════════════════════════════════════════ */

:root {
  --bg:        #0A0B0F;
  --surface:   #14161D;
  --surface-2: #191C25;
  --surface-3: #20242F;
  --line:      #272C38;
  --line-soft: rgba(255,255,255,.07);

  --text:  #E9E7E2;
  --muted: #878C9B;
  --dim:   #5C6270;

  --gold:      #E3B462;
  --gold-deep: #C08F3C;
  --red:       #D04A44;
  --teal:      #4FB89A;
  --violet:    #9B7BE0;
  --indigo:    #6C74C4;

  --ava-ph: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235C6270' stroke-width='1.6' stroke-linecap='round'><circle cx='12' cy='8' r='3.6'/><path d='M5 20c.5-3.7 3.4-6 7-6s6.5 2.3 7 6'/></svg>");

  --r-sm: 10px;
  --r:    14px;
  --r-lg: 20px;

  --shadow: 0 18px 40px -24px rgba(0,0,0,.9);
  --ring: 0 0 0 1px var(--line), inset 0 1px 0 rgba(255,255,255,.04);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Атрибут hidden обязан побеждать любые display в правилах ниже,
   иначе скрытые элементы (бейдж Premium, кнопки) остаются на экране */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  background-image:
    radial-gradient(120% 70% at 50% -10%, rgba(227,180,98,.13), transparent 60%),
    radial-gradient(90% 60% at 90% 110%, rgba(108,116,196,.12), transparent 65%);
  background-attachment: fixed;
  min-height: 100vh;
  padding: 0 16px calc(28px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* Плёночное зерно — убирает «пластиковость» плоского фона */
.grain {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .04;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
}

.sprite { display: none; }

.screen { display: none; position: relative; z-index: 1; max-width: 620px; margin: 0 auto; }
.screen.active { display: block; }

/* ── иконки ── */
.ic { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor;
      stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ic-s  { width: .95em; height: .95em; }
.ic-xl { width: 44px; height: 44px; stroke-width: 1.3; }

/* ── типографика ── */
h1, h2, h3, .display { font-family: Unbounded, Inter, sans-serif; font-weight: 600; letter-spacing: -.01em; }

.hero { padding: 12vh 0 40px; text-align: center; }
.hero-mark {
  width: 84px; height: 84px; margin: 0 auto 22px; display: grid; place-items: center;
  color: var(--gold); border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, rgba(227,180,98,.18), rgba(227,180,98,.03));
  box-shadow: 0 0 0 1px rgba(227,180,98,.28), 0 0 60px -12px rgba(227,180,98,.5);
}
.hero-title {
  font-size: clamp(38px, 13vw, 60px); font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; line-height: 1;
  background: linear-gradient(180deg, #F6E5C0 10%, var(--gold-deep) 95%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero-sub {
  margin: 14px 0 30px; color: var(--dim); font-size: 12px;
  letter-spacing: .22em; text-transform: uppercase;
}

/* ── панели ── */
.panel {
  background: linear-gradient(180deg, var(--surface), var(--surface) 60%, #12141A);
  border-radius: var(--r-lg); box-shadow: var(--ring), var(--shadow);
  padding: 16px; margin-bottom: 14px; text-align: left;
}
.panel-flush { padding: 16px 0; }
.panel-flush > .panel-head, .panel-flush > .composer, .panel-flush > .ai-answer { padding-left: 16px; padding-right: 16px; }
.panel-accent { box-shadow: 0 0 0 1px rgba(227,180,98,.24), var(--shadow); }

.panel-head { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; color: var(--gold); }
.panel-head h2 { font-size: 12px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); flex: 1; }
.panel-head .icon-btn { margin-left: auto; }

/* ── кнопки ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 20px; border: 0; border-radius: var(--r);
  font: 600 15px/1 Inter, sans-serif; color: var(--text);
  background: var(--surface-3); cursor: pointer;
  transition: transform .12s ease, filter .15s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary {
  color: #1A1408; background: linear-gradient(140deg, #F0CE85, var(--gold-deep));
  box-shadow: 0 10px 26px -14px rgba(227,180,98,.9);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-gold { background: transparent; color: var(--gold); box-shadow: inset 0 0 0 1px rgba(227,180,98,.45); }
.btn-danger { background: rgba(208,74,68,.14); color: #F0918C; box-shadow: inset 0 0 0 1px rgba(208,74,68,.3); }
.btn-sm { height: 36px; padding: 0 14px; font-size: 13px; border-radius: var(--r-sm); }

.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; flex: none;
  border: 0; border-radius: 12px; background: var(--surface-2); color: var(--muted);
  cursor: pointer; transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-3); }
.icon-btn.accent { color: #1A1408; background: linear-gradient(140deg, #F0CE85, var(--gold-deep)); }
.icon-btn.ghost { background: transparent; }

/* ── поля ── */
.field {
  flex: 1; min-width: 0; height: 46px; padding: 0 14px;
  border: 0; border-radius: var(--r); outline: none;
  background: #0E1016; color: var(--text); font: 400 15px Inter, sans-serif;
  box-shadow: inset 0 0 0 1px var(--line);
  transition: box-shadow .15s;
}
.field::placeholder { color: var(--dim); }
.field:focus { box-shadow: inset 0 0 0 1px rgba(227,180,98,.5); }
.field-xs { flex: 0 0 78px; text-transform: uppercase; }

.row { display: flex; gap: 8px; }
.mt { margin-top: 14px; }

/* ── шапка ── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0 12px; margin-bottom: 4px;
  background: linear-gradient(180deg, var(--bg) 62%, transparent);
}
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ava { width: 38px; height: 38px; border-radius: 50%; object-fit: cover;
       background: var(--surface-3) var(--ava-ph) center/62% no-repeat;
       box-shadow: 0 0 0 1px var(--line-soft); }
.me-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.me-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border-radius: 999px; background: var(--surface-2); color: var(--gold);
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
  box-shadow: inset 0 0 0 1px var(--line-soft);
}
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 10px;
       font-weight: 600; letter-spacing: .1em; text-transform: uppercase; }
.tag-gold { color: var(--gold); background: rgba(227,180,98,.13); }

/* ── вкладки ── */
.tabs {
  position: sticky; top: 62px; z-index: 19;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
  padding: 4px; margin-bottom: 16px; border-radius: var(--r);
  background: rgba(16,18,24,.86); backdrop-filter: blur(12px);
  box-shadow: var(--ring);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 9px 2px; border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--dim); cursor: pointer;
  font: 500 11px Inter, sans-serif; transition: color .15s, background .15s;
}
.tab span { letter-spacing: .02em; }
.tab:hover { color: var(--muted); }
.tab.active { color: var(--gold); background: rgba(227,180,98,.1); }

.tabpane[hidden] { display: none; }

/* ── список комнат ── */
.rooms { display: flex; flex-direction: column; gap: 8px; }
.room {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  border-radius: var(--r); background: var(--surface-2); cursor: pointer;
  box-shadow: inset 0 0 0 1px var(--line-soft); transition: background .15s, box-shadow .15s;
}
.room:hover { background: var(--surface-3); box-shadow: inset 0 0 0 1px rgba(227,180,98,.3); }
.room-ic { width: 36px; height: 36px; display: grid; place-items: center; flex: none;
           border-radius: 11px; background: rgba(227,180,98,.1); color: var(--gold); }
.room-name { font-weight: 600; font-size: 14px; }
.room-meta { color: var(--dim); font-size: 12px; margin-top: 1px; }
.room-count { margin-left: auto; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.empty { display: flex; align-items: center; gap: 8px; padding: 18px 2px; color: var(--dim); font-size: 13px; }

/* ── карточки игроков ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.grid-game { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }

.pcard {
  position: relative; padding: 12px 8px 10px; border-radius: var(--r);
  background: var(--surface-2); text-align: center; cursor: default;
  box-shadow: inset 0 0 0 1px var(--line-soft);
  transition: box-shadow .15s, transform .12s, background .15s;
}
.pcard.pick { cursor: pointer; }
.pcard.pick:hover { background: var(--surface-3); }
.pcard.selected { box-shadow: inset 0 0 0 1.5px var(--gold), 0 0 24px -8px rgba(227,180,98,.7); transform: translateY(-1px); }
.pcard img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover;
             background: var(--surface-3) var(--ava-ph) center/62% no-repeat;
             box-shadow: 0 0 0 1px var(--line-soft); }
.pcard .nm { display: block; margin-top: 8px; font-size: 12px; font-weight: 500;
             white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .host { position: absolute; top: 7px; right: 7px; color: var(--gold); }
.pcard.dead { opacity: .42; }
.pcard.dead img { filter: grayscale(1); }
.pcard .tomb { position: absolute; top: 7px; left: 7px; color: var(--red); }

.rbadge {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 7px;
  padding: 3px 8px; border-radius: 999px; font-size: 10px; font-weight: 600;
  letter-spacing: .04em;
}
.t-mafia { color: #F09A95; background: rgba(208,74,68,.16); }
.t-city  { color: #79D6BC; background: rgba(79,184,154,.14); }
.t-solo  { color: #C0A6F0; background: rgba(155,123,224,.16); }
.t-dead  { color: var(--muted); background: rgba(255,255,255,.06); }

/* ── фаза ── */
.modal { position: fixed; inset: 0; z-index: 40; overflow-y: auto;
         background: rgba(6,7,10,.9); backdrop-filter: blur(8px); padding: 14px; }
.modal[hidden] { display: none; }
.game { max-width: 620px; margin: 0 auto; padding-bottom: 24px; }

.phase {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  border-radius: var(--r-lg); margin-bottom: 14px;
  background: linear-gradient(135deg, rgba(227,180,98,.16), rgba(227,180,98,.03));
  box-shadow: inset 0 0 0 1px rgba(227,180,98,.22);
}
.phase.is-night {
  background: linear-gradient(135deg, rgba(108,116,196,.2), rgba(108,116,196,.04));
  box-shadow: inset 0 0 0 1px rgba(108,116,196,.3);
}
.phase-l { display: flex; align-items: center; gap: 12px; min-width: 0; }
.phase-ic { width: 42px; height: 42px; display: grid; place-items: center; flex: none;
            border-radius: 13px; background: rgba(227,180,98,.14); color: var(--gold); }
.phase.is-night .phase-ic { background: rgba(108,116,196,.18); color: #A9B0F0; }
.phase-name { font-family: Unbounded, sans-serif; font-size: 15px; font-weight: 600; }
.phase-hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

.timer { position: relative; width: 46px; height: 46px; margin-left: auto; flex: none; }
.ring { width: 46px; height: 46px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 2.6; }
.ring-bg { stroke: rgba(255,255,255,.09); }
.ring-fg { stroke: var(--gold); stroke-linecap: round;
           stroke-dasharray: 98; stroke-dashoffset: 0; transition: stroke-dashoffset 1s linear; }
.phase.is-night .ring-fg { stroke: #A9B0F0; }
.timer span { position: absolute; inset: 0; display: grid; place-items: center;
              font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── карточка роли ── */
.rolecard {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  border-radius: var(--r-lg); margin-bottom: 14px; background: var(--surface);
  box-shadow: var(--ring), var(--shadow);
}
.rolecard:empty { display: none; }
.rolecard .medal {
  width: 50px; height: 50px; display: grid; place-items: center; flex: none;
  border-radius: 16px; background: rgba(255,255,255,.05);
}
.rolecard.m-mafia .medal { background: rgba(208,74,68,.16); color: #F09A95; }
.rolecard.m-city  .medal { background: rgba(79,184,154,.14); color: #79D6BC; }
.rolecard.m-solo  .medal { background: rgba(155,123,224,.16); color: #C0A6F0; }
.rolecard .medal .ic { width: 27px; height: 27px; }
.rolecard .rl { font-family: Unbounded, sans-serif; font-size: 15px; font-weight: 600; }
.rolecard .rd { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.rolecard .mates { margin-top: 6px; font-size: 12px; color: #F09A95; }

/* ── действия ── */
.actions { margin: 14px 0; }
.actions:empty { display: none; }
.hint { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 2px; }
.hint.ok { color: var(--teal); }

/* ── чат ── */
.chatwrap { margin-bottom: 14px; }
.chat { max-height: 210px; overflow-y: auto; padding: 0 16px; display: flex; flex-direction: column; gap: 7px; }
.chat::-webkit-scrollbar { width: 4px; }
.chat::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.msg { font-size: 13.5px; word-wrap: break-word; }
.msg b { color: var(--gold); font-weight: 600; }
.msg.sys { display: flex; align-items: flex-start; gap: 7px; color: var(--muted); font-size: 13px; }
.msg.sys .ic { margin-top: 2px; width: 15px; height: 15px; }
.msg.sys.k-kill   { color: #F09A95; }
.msg.sys.k-exile  { color: #F0CE85; }
.msg.sys.k-save   { color: #79D6BC; }
.msg.sys.k-revive { color: #79D6BC; }
.msg.sys.k-ai     { color: var(--violet); }
.composer { display: flex; gap: 8px; margin-top: 12px; }
.ai-answer { margin-top: 10px; padding: 12px 14px; border-radius: var(--r);
             background: rgba(155,123,224,.08); color: #CDBCF5; font-size: 13px;
             box-shadow: inset 0 0 0 1px rgba(155,123,224,.2); }

/* ── боевой пропуск ── */
.bar { height: 7px; border-radius: 999px; background: #0E1016; overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--gold-deep), #F0CE85); transition: width .4s ease; }
.bar-legend { display: flex; justify-content: space-between; margin: 8px 0 14px; color: var(--muted); font-size: 12px; }
.bar-legend b { color: var(--text); }
.rewards { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
.rw { display: grid; grid-template-columns: 52px 1fr 1fr; gap: 10px; align-items: center;
      padding: 9px 12px; border-radius: var(--r-sm); background: var(--surface-2); font-size: 12.5px; }
.rw-t { color: var(--dim); font-weight: 600; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.rw-p { color: var(--gold); display: flex; align-items: center; gap: 5px; }
.rw.locked .rw-p { opacity: .38; }

/* ── кланы ── */
.clan { padding: 14px; border-radius: var(--r); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-soft); }
.clan-top { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.clan-tag { padding: 3px 8px; border-radius: 7px; background: rgba(227,180,98,.13);
            color: var(--gold); font-size: 11px; font-weight: 700; letter-spacing: .06em; }
.clan-name { font-family: Unbounded, sans-serif; font-size: 14px; font-weight: 600; }
.clan-meta { color: var(--dim); font-size: 12px; }

/* ── роли: справочник ── */
.team-head { display: flex; align-items: center; gap: 8px; margin: 18px 4px 10px; }
.team-head h3 { font-size: 12px; letter-spacing: .16em; text-transform: uppercase; }
.team-head .line { flex: 1; height: 1px; background: var(--line); }
.team-head.mafia { color: #F09A95; } .team-head.city { color: #79D6BC; }
.team-head.solo  { color: #C0A6F0; } .team-head.dead { color: var(--muted); }
.rrow { display: flex; align-items: center; gap: 12px; padding: 11px 13px; margin-bottom: 6px;
        border-radius: var(--r); background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line-soft); }
.rrow .medal { width: 38px; height: 38px; display: grid; place-items: center; flex: none;
               border-radius: 12px; background: rgba(255,255,255,.05); }
.rrow .medal .ic { width: 21px; height: 21px; }
.rrow.m-mafia .medal { background: rgba(208,74,68,.15); color: #F09A95; }
.rrow.m-city  .medal { background: rgba(79,184,154,.13); color: #79D6BC; }
.rrow.m-solo  .medal { background: rgba(155,123,224,.15); color: #C0A6F0; }
.rrow.m-dead  .medal { color: var(--muted); }
.rrow .rn { font-size: 13.5px; font-weight: 600; }
.rrow .rd { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ── таблица лидеров ── */
.lb { display: flex; flex-direction: column; gap: 6px; }
.lb-row { display: flex; align-items: center; gap: 11px; padding: 9px 12px;
          border-radius: var(--r-sm); background: var(--surface-2); font-size: 13px; }
.lb-n { width: 20px; color: var(--dim); font-weight: 700; font-size: 12px; font-variant-numeric: tabular-nums; }
.lb-row.top .lb-n { color: var(--gold); }
.lb-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-w { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ── прочее ── */
.alert {
  display: flex; align-items: flex-start; gap: 10px; padding: 13px 15px; margin-bottom: 16px;
  border-radius: var(--r); text-align: left; font-size: 13px; color: #F0918C;
  background: rgba(208,74,68,.1); box-shadow: inset 0 0 0 1px rgba(208,74,68,.28);
}
.alert[hidden] { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60; max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 9px; padding: 12px 18px; border-radius: 999px;
  background: #1C202B; color: var(--text); font-size: 13.5px; font-weight: 500;
  box-shadow: 0 0 0 1px var(--line), 0 20px 40px -18px #000;
  animation: pop .22s ease;
}
.toast[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (max-width: 380px) {
  .tab span { font-size: 10px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
}
