:root {
  --ink: #0e1713;
  --ink-2: #16211b;
  --panel: rgba(22, 36, 29, 0.72);
  --line: rgba(180, 210, 190, 0.14);
  --text: #eef5f0;
  --muted: #93a89b;
  --accent: #6fbf8c;
  --accent-2: #c4a574;
  --danger: #c97878;
  --danger-soft: #8f4a4a;
  --ok-soft: #3d6b52;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Syne", "Manrope", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--ink);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

.bg-orbit {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(111, 191, 140, 0.18), transparent 55%),
    radial-gradient(700px 420px at -10% 30%, rgba(196, 165, 116, 0.12), transparent 50%),
    radial-gradient(600px 600px at 50% 120%, rgba(80, 40, 40, 0.2), transparent 55%),
    linear-gradient(165deg, #132019 0%, #0e1713 45%, #101816 100%);
}

#app {
  position: relative;
  z-index: 1;
  max-width: 430px;
  margin: 0 auto;
  min-height: var(--app-h, 100vh);
  padding: 1.1rem 1rem calc(1.4rem + env(safe-area-inset-bottom));
}

.view { display: grid; gap: 1rem; }
.view.enter { animation: rise .35s ease both; }
.hidden { display: none !important; }

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

.brand {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(2.8rem, 12vw, 3.6rem);
  line-height: 0.95;
  letter-spacing: -0.03em;
  margin: 0.2rem 0 0.8rem;
}
.screen-title {
  font-family: var(--display);
  font-size: 1.85rem;
  margin: 0;
  letter-spacing: -0.02em;
}
.screen-title.tight { margin-bottom: 0; }
.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--accent-2);
  font-weight: 700;
}
.lead { color: var(--muted); line-height: 1.45; margin: 0; }
.lead.soft { font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.88rem; line-height: 1.4; margin: 0; }
.hint.tight { margin-top: 0.15rem; }

.hero { padding: 1.4rem 0 0.4rem; }
.stack { display: grid; gap: 0.7rem; }

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.95rem 1.2rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary {
  background: linear-gradient(135deg, #7ecf98, #4f9f6f);
  color: #0c1711;
  box-shadow: 0 10px 30px rgba(79, 159, 111, 0.28);
}
.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}
.btn.soft-green {
  background: rgba(79, 159, 111, 0.16);
  border-color: rgba(79, 159, 111, 0.35);
  color: #b7e2c6;
}
.btn.soft-red {
  background: rgba(201, 120, 120, 0.14);
  border-color: rgba(201, 120, 120, 0.35);
  color: #efc0c0;
}
.sticky-cta { margin-top: 0.4rem; position: sticky; bottom: 0.6rem; }

.back {
  justify-self: start;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  padding: 0;
  cursor: pointer;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  padding: 0.3rem;
  border-radius: 999px;
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--line);
}
.mode {
  border: 0;
  border-radius: 999px;
  padding: 0.75rem;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.mode.active {
  background: rgba(111, 191, 140, 0.18);
  color: var(--text);
}

.block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.8rem;
}
.block h3 { margin: 0; font-size: 1rem; }
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.field { display: grid; gap: 0.4rem; }
.field label { color: var(--muted); font-size: 0.82rem; font-weight: 600; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.28);
  color: var(--text);
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  font: inherit;
  outline: none;
}
input:focus, textarea:focus { border-color: rgba(111, 191, 140, 0.45); }
.code-input {
  font-family: var(--display);
  font-size: 1.8rem;
  letter-spacing: 0.28em;
  text-align: center;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(0,0,0,0.28);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.2rem;
}
.step {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 999px;
  border: 0;
  background: rgba(111, 191, 140, 0.16);
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
}
.step-value, #count-input {
  min-width: 2rem;
  text-align: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
#count-input {
  width: 2.6rem;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  -moz-appearance: textfield;
}
#count-input::-webkit-outer-spin-button,
#count-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.roster {
  display: grid;
  gap: 0.65rem;
}
.seat {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.7rem;
  align-items: center;
  padding: 0.55rem;
  border-radius: 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.04);
}
.seat-avatar {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #0e1713;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.15);
}
.seat input {
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
}
.seat-remove {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 1.8rem;
  height: 1.8rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: rgba(111, 191, 140, 0.16);
  font-weight: 800;
  font-size: 0.85rem;
}

.pack-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 0.55rem;
}
.pack {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.22);
  color: var(--text);
  border-radius: 14px;
  padding: 0.8rem;
  cursor: pointer;
  font: inherit;
}
.pack strong { display: block; font-size: 0.95rem; }
.pack span { color: var(--muted); font-size: 0.78rem; }
.pack.active {
  border-color: rgba(111, 191, 140, 0.55);
  background: rgba(111, 191, 140, 0.12);
}

.lobby-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.code-pill {
  background: rgba(196, 165, 116, 0.12);
  border: 1px solid rgba(196, 165, 116, 0.28);
  border-radius: 14px;
  padding: 0.55rem 0.75rem;
  text-align: right;
}
.code-pill span {
  display: block;
  font-size: 0.68rem;
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.code-pill strong {
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: 0.12em;
}

/* PASS + CARD — top-anchored (no vertical center / dvh jump in Telegram) */
.pass-screen, .card-screen {
  display: grid;
  justify-items: center;
  align-content: start;
  text-align: center;
  gap: 0.85rem;
  padding-top: 1.5rem;
  min-height: 0;
  transform: translateZ(0);
}
.pass-avatar {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 800;
  color: #0e1713;
  margin-top: 0.25rem;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}
.pass-name {
  font-family: var(--display);
  font-size: 2.2rem;
  margin: 0;
  letter-spacing: -0.02em;
  min-height: 2.6rem;
  line-height: 1.15;
}
.pass-help { color: var(--muted); margin: 0 0 0.6rem; line-height: 1.45; }
.progress { color: var(--muted); font-weight: 700; letter-spacing: 0.08em; }

.card-stage {
  width: min(86vw, 320px);
  perspective: 1200px;
  margin: 0.5rem auto 1rem;
}
.flip-card {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4.2;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(.2,.8,.2,1);
  cursor: pointer;
}
.flip-card.is-flipped { transform: rotateY(180deg); }
.flip-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 22px;
  display: grid;
  place-items: center;
  padding: 1.2rem;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow);
}
.flip-back {
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.08), transparent 40%),
    linear-gradient(160deg, #24352c, #152019);
}
.flip-back .seal {
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px dashed rgba(238, 245, 240, 0.28);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.35;
}
.flip-front {
  transform: rotateY(180deg);
  align-content: center;
  gap: 0.35rem;
  text-align: center;
}
.flip-front.civilian {
  background:
    radial-gradient(circle at 50% 0%, rgba(111, 191, 140, 0.22), transparent 45%),
    linear-gradient(165deg, #2a4336 0%, #1a2c24 55%, #15231d 100%);
  border-color: rgba(111, 191, 140, 0.28);
}
.flip-front.spy {
  background:
    radial-gradient(circle at 50% 0%, rgba(201, 120, 120, 0.22), transparent 45%),
    linear-gradient(165deg, #3a2626 0%, #271a1a 55%, #1c1414 100%);
  border-color: rgba(201, 120, 120, 0.28);
}
.card-art {
  width: 5.5rem;
  height: 5.5rem;
  margin: 0 auto 0.4rem;
}
.card-art svg { width: 100%; height: 100%; display: block; }
.card-role {
  margin: 0;
  font-family: var(--display);
  font-size: 1.7rem;
  letter-spacing: -0.02em;
}
.card-loc-label {
  margin: 0.7rem 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(238,245,240,0.55);
  font-weight: 700;
}
.card-loc {
  margin: 0.35rem 0 0;
  font-family: var(--display);
  font-size: clamp(1.55rem, 6.5vw, 2.05rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: #fff;
  padding: 0.65rem 0.85rem;
  border-radius: 14px;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  text-shadow: 0 1px 0 rgba(0,0,0,0.25);
}
.flip-front.civilian .card-loc {
  background: rgba(111, 191, 140, 0.22);
  border-color: rgba(183, 226, 198, 0.45);
  color: #eafff2;
}
.flip-front.spy .card-loc {
  background: rgba(201, 120, 120, 0.2);
  border-color: rgba(239, 192, 192, 0.4);
  color: #ffe8e8;
}
.card-tip {
  margin: 0.9rem 0 0;
  color: rgba(238,245,240,0.72);
  font-size: 0.92rem;
  line-height: 1.4;
  max-width: 16rem;
}

.play-hero { padding-top: 0.6rem; }
.locs {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.locs summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--text);
}
.chip-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}
.chip {
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  color: var(--muted);
}

.finish-hero { text-align: center; padding: 2rem 0 1rem; }
.finish-hero.win-spies .screen-title { color: #efc0c0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(20, 28, 24, 0.95);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: 999px;
  z-index: 20;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

.step-value.wide { min-width: 4.2rem; }
.center { text-align: center; justify-self: center; }

.confirm-view {
  min-height: 78dvh;
  align-content: center;
  gap: 1.1rem;
}
.confirm-avatars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem 0.7rem;
  padding: 0.4rem 0 1.4rem;
  min-height: 5.2rem;
  align-content: flex-start;
}
.confirm-avatars .ava {
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #0e1713;
  position: relative;
  box-shadow: var(--shadow);
}
.confirm-avatars .ava small {
  position: absolute;
  left: 50%;
  bottom: -1.15rem;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
  max-width: 4.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
}
.confirm-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.45rem;
  margin-top: 0.2rem;
}
.lobby-edit-row {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}
.lobby-edit-row:first-of-type {
  border-top: 0;
  padding-top: 0.35rem;
}
.confirm-stats .stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem 0.5rem;
  text-align: center;
}
.confirm-stats .stat span {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.25rem;
}
.confirm-stats .stat strong {
  font-family: var(--display);
  font-size: 1.05rem;
}
.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 0.55rem;
  margin-top: 0.6rem;
}
.code-pill.big {
  text-align: center;
  padding: 1rem;
  border-radius: 18px;
}
.code-pill.big strong {
  font-size: 2rem;
  letter-spacing: 0.2em;
  display: block;
}

.play-view { gap: 0.85rem; }
.timer-wrap { display: grid; place-items: center; padding: 0.4rem 0 0.2rem; }
.timer-ring {
  position: relative;
  width: 9.5rem;
  height: 9.5rem;
}
.timer-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.timer-ring .track {
  fill: none;
  stroke: rgba(255,255,255,0.08);
  stroke-width: 8;
}
.timer-ring .prog {
  fill: none;
  stroke: #6fbf8c;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.4s linear, stroke 0.3s ease;
}
.timer-ring.urgent .prog { stroke: #c97878; }
.timer-readout {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
}
.timer-readout strong {
  font-family: var(--display);
  font-size: 1.7rem;
  letter-spacing: 0.04em;
}
.timer-readout span {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.pass-screen, .card-screen { transition: opacity .2s ease; }
.pass-screen.is-leaving, .card-screen.is-leaving { opacity: 0; pointer-events: none; }

.role-card {
  border-radius: 18px;
  border: 1px solid var(--line);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.role-card-inner {
  padding: 1rem 1rem 1.1rem;
  text-align: center;
  display: grid;
  gap: 0.25rem;
  justify-items: center;
}
.role-card-inner.civilian {
  background: linear-gradient(165deg, #2a4336 0%, #1a2c24 100%);
  border-top: 3px solid rgba(111, 191, 140, 0.45);
}
.role-card-inner.spy {
  background: linear-gradient(165deg, #3a2626 0%, #271a1a 100%);
  border-top: 3px solid rgba(201, 120, 120, 0.45);
}
.role-art { width: 3.6rem; height: 3.6rem; }
.role-art svg { width: 100%; height: 100%; }
.role-title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.2rem;
  opacity: 0.92;
}
.role-meta {
  margin: 0.15rem 0 0;
  width: 100%;
}
.role-meta-label {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(238,245,240,0.55);
  font-weight: 700;
  margin-bottom: 0.35rem;
}
.role-meta-word {
  display: block;
  font-family: var(--display);
  font-size: clamp(1.45rem, 6vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: #fff;
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
}
.role-card-inner.civilian .role-meta-word {
  background: rgba(111, 191, 140, 0.22);
  border-color: rgba(183, 226, 198, 0.45);
  color: #eafff2;
}
.role-card-inner.spy .role-meta-word {
  background: rgba(201, 120, 120, 0.2);
  border-color: rgba(239, 192, 192, 0.4);
  color: #ffe8e8;
}
.role-tip { margin: 0.45rem 0 0; color: var(--muted); font-size: 0.86rem; line-height: 1.35; }

.finish-spies {
  margin-top: 1rem;
  display: grid;
  gap: 0.45rem;
  justify-items: center;
}
#finish-loc {
  margin-top: 0.85rem;
  width: min(100%, 20rem);
  justify-self: center;
}
#finish-loc .finish-loc-word,
#finish-loc .role-meta-word {
  margin-top: 0.2rem;
}
.finish-spies .spy-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: rgba(201, 120, 120, 0.14);
  border: 1px solid rgba(201, 120, 120, 0.35);
  color: #efc0c0;
  font-weight: 700;
}
.pack.voted {
  border-color: rgba(196, 165, 116, 0.55);
  background: rgba(196, 165, 116, 0.12);
}
.pack .vote-count {
  display: block;
  margin-top: 0.25rem;
  color: var(--accent-2);
  font-size: 0.75rem;
  font-weight: 700;
}
.vote-panel {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.25rem;
}
.vote-targets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.vote-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  border-radius: 14px;
  padding: 0.7rem 0.6rem;
  font: inherit;
  font-weight: 700;
  text-align: center;
}
.vote-btn.active {
  border-color: rgba(126, 207, 152, 0.55);
  background: rgba(126, 207, 152, 0.14);
}
.vote-btn.mine {
  border-color: rgba(196, 165, 116, 0.55);
  background: rgba(196, 165, 116, 0.12);
}
.vote-live {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.72);
}
.vote-live .row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.vote-live .tally {
  font-weight: 700;
  color: #efc0c0;
}


