:root {
  --bg: #2a2140; --panel: #fff8ec; --ink: #2d2433; --muted: #7d7186;
  --accent: #ff8a5c; --accent-ink: #fff; --line: #eadfce; --good: #4bb36b; --bad: #e0506a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', sans-serif; overscroll-behavior: none; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.overlay-screen { background: rgba(28, 20, 46, .88); z-index: 30; }
#home { background: radial-gradient(circle at 30% 20%, #4a3a70, var(--bg) 70%); }
#lobby { background: radial-gradient(circle at 70% 20%, #3f4f80, var(--bg) 70%); }

.home-card { display: flex; background: var(--panel); border-radius: 28px; overflow: hidden; max-width: 820px; width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.45); margin: auto; }
.cover { width: 44%; object-fit: cover; object-position: center 30%; min-height: 480px; }
.home-main { flex: 1; padding: 28px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
h1 { margin: 0; font-size: 44px; line-height: 1; letter-spacing: -1px; }
h2 { margin: 0; font-size: 26px; }
.tagline { margin: 0 0 6px; color: var(--muted); font-style: italic; }
.profile-row { display: flex; gap: 12px; align-items: center; background: #fff; border: 2px solid var(--line); border-radius: 18px; padding: 8px 12px; }
.lvl-line { display: flex; justify-content: space-between; }
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffb02e, var(--accent)); border-radius: 99px; transition: width .4s; }
.bar.big { height: 16px; border: 2px solid rgba(255,255,255,.7); background: rgba(0,0,0,.35); }
.bar.big i { background: linear-gradient(90deg, #6ac36a, #b6e36a); }
small { color: var(--muted); }

input { font: inherit; padding: 13px 16px; border-radius: 14px; border: 2px solid var(--line); background: #fff; color: var(--ink); width: 100%; outline: none; min-width: 0; }
input:focus { border-color: var(--accent); }
#codeInput { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 800; }
.join-row { display: flex; gap: 8px; }
.join-row .btn { flex: 1; white-space: nowrap; }

.btn { font: inherit; font-weight: 700; padding: 13px 18px; border-radius: 14px; border: 0; background: #e9dfd0; color: var(--ink); cursor: pointer; transition: transform .08s, filter .15s; position: relative; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 0 #d66a3f; }
.btn.ghost { background: transparent; border: 2px solid var(--line); }
.btn.small { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.badge { position: absolute; top: -6px; right: -6px; background: var(--bad); color: #fff; font-style: normal; font-size: 12px; border-radius: 99px; min-width: 20px; padding: 1px 6px; }
.error { color: var(--bad); margin: 0; min-height: 1.4em; font-weight: 600; }
.hint { color: var(--muted); margin: 6px 0; text-align: center; }

.panel { background: var(--panel); border-radius: 24px; padding: 22px; width: 100%; max-width: 560px; margin: auto; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.45); }
.panel.wide { max-width: 760px; }
.lobby-head { display: flex; align-items: center; gap: 10px; }
.lobby-head > div { flex: 1; }
.code { font-size: 38px; font-weight: 900; letter-spacing: 8px; line-height: 1; }

.players { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.pcard { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 6px 4px 8px; text-align: center; font-weight: 700; font-size: 14px; position: relative; overflow: hidden; }
.pcard canvas { display: block; margin: 0 auto; }
.pcard small { display: block; font-weight: 500; }
.pcard.me { border-color: var(--accent); }
.pcard.liar { border-color: var(--bad); background: #ffe9ec; }
.pcard .crown { position: absolute; top: 4px; left: 6px; }
.colors { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.colors button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; padding: 0; }
.colors button.active { box-shadow: 0 0 0 3px var(--ink); }
.colors button:disabled { opacity: .25; cursor: default; }

.chat { border: 2px solid var(--line); border-radius: 14px; background: #fff; overflow: hidden; }
.chat-log { height: 110px; overflow-y: auto; padding: 8px 12px; font-size: 14px; display: flex; flex-direction: column; gap: 3px; }
.chat-log .sys { color: var(--muted); font-style: italic; }
.chat-log .ghost { opacity: .55; }
.chat form { display: flex; border-top: 2px solid var(--line); }
.chat form input { border: 0; border-radius: 0; padding: 10px 12px; }
.chat form .btn { border-radius: 0; }

/* Игра */
#game { padding: 0; background: #1b1530; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.hud-tasks { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); width: min(260px, 60vw); color: #fff; pointer-events: none; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.hud-tasks ul { list-style: none; margin: 8px 0 0; padding: 8px 10px; background: rgba(20,14,36,.55); border-radius: 12px; font-size: 14px; display: flex; flex-direction: column; gap: 3px; }
.hud-tasks li.done { color: #9be59b; text-decoration: line-through; }
.role-tag { margin-top: 6px; font-weight: 800; font-size: 14px; }
.role-tag.liar { color: #ff8fa3; }
.toast { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); background: rgba(20,14,36,.85); color: #fff; padding: 10px 18px; border-radius: 99px; font-weight: 700; z-index: 5; text-align: center; max-width: 90vw; }

.actions { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: flex-end; }
.act { width: 88px; height: 88px; border-radius: 50%; border: 4px solid rgba(255,255,255,.85); font-size: 30px; line-height: 1; color: #fff; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; box-shadow: 0 6px 16px rgba(0,0,0,.4); font-family: inherit; }
.act span { font-size: 11px; font-weight: 800; margin-top: 3px; }
.act:active { transform: scale(.93); }
.act.use { background: #4aa3f0; }
.act.report { background: #f5a04a; }
.act.kill { background: #e0506a; }
.act.cool { filter: grayscale(.8) brightness(.7); }
.act b { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 30px; text-shadow: 0 2px 4px #000; }

.joy { position: absolute; left: max(24px, env(safe-area-inset-left)); bottom: max(24px, env(safe-area-inset-bottom)); width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,.12); border: 3px solid rgba(255,255,255,.3); display: none; touch-action: none; }
.joy i { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; border-radius: 50%; background: rgba(255,255,255,.55); }
@media (pointer: coarse) { .joy { display: block; } }

.overlay { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: #fff; text-align: center; padding: 20px; animation: fade .3s; }
.overlay.chubrik { background: radial-gradient(circle, #3d6fb0, #15203a); }
.overlay.liar { background: radial-gradient(circle, #a8324a, #2a0f18); }
.overlay h2 { font-size: 46px; }
.overlay p { margin: 0; max-width: 460px; font-size: 18px; opacity: .9; }
@keyframes fade { from { opacity: 0; } }

/* Модалки */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(20,14,36,.7); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 22px; padding: 16px; width: min(380px, 100%); max-height: 100%; overflow-y: auto; }
.modal-card.sheet { width: min(520px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 18px; }
#taskCanvas { width: 100%; aspect-ratio: 1; border-radius: 16px; border: 2px solid var(--line); touch-action: none; display: block; }

/* Собрание */
.meet-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.timer:empty { display: none; }
.timer { font-weight: 900; font-size: 22px; background: var(--ink); color: #fff; border-radius: 99px; padding: 4px 14px; min-width: 62px; text-align: center; }
#drawStage { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.word-box { text-align: center; background: #fff; border: 2px dashed var(--accent); border-radius: 16px; padding: 8px 20px; }
.word-box b { display: block; font-size: 28px; text-transform: uppercase; letter-spacing: 1px; }
.word-box.liar { border-color: var(--bad); background: #ffe9ec; }
.pad { width: min(320px, 70vw, 42vh); aspect-ratio: 1; border-radius: 16px; border: 3px solid var(--ink); touch-action: none; background: #fffdf7; cursor: crosshair; }
.palette { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; }
.pen { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; padding: 0; }
.pen.active { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.12); }
#voteStage { display: flex; flex-direction: column; gap: 12px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.gcard { background: #fff; border: 3px solid var(--line); border-radius: 16px; padding: 6px; text-align: center; font-weight: 700; font-size: 14px; cursor: pointer; position: relative; font-family: inherit; color: var(--ink); }
.gcard canvas { width: 100%; aspect-ratio: 1; border-radius: 10px; display: block; background: #fffdf7; }
.gcard.dead { opacity: .4; cursor: default; }
.gcard.picked { border-color: var(--accent); background: #fff0e6; }
.gcard .voted { position: absolute; top: 8px; right: 8px; background: var(--good); color: #fff; border-radius: 99px; font-size: 11px; padding: 2px 7px; }
.gcard .tally { color: var(--bad); font-weight: 900; }
.gcard.me-card::after { content: 'это ты'; position: absolute; top: 8px; left: 8px; font-size: 11px; background: var(--ink); color: #fff; border-radius: 99px; padding: 2px 7px; }
.result { text-align: center; padding: 20px 0; }
.result h3 { font-size: 28px; margin: 8px 0; }
.rewards { background: #fff; border: 2px solid var(--line); border-radius: 16px; padding: 12px 16px; display: grid; gap: 4px; }
.rewards .row { display: flex; justify-content: space-between; }
.rewards .total { font-weight: 900; font-size: 18px; border-top: 2px solid var(--line); padding-top: 6px; margin-top: 4px; }
.levelup { text-align: center; font-weight: 900; color: var(--accent); font-size: 20px; }

/* Гардероб и навыки */
.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.item { background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 6px; text-align: center; font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit; color: var(--ink); }
.item canvas { display: block; margin: 0 auto; }
.item.active { border-color: var(--accent); background: #fff0e6; }
.item.locked { opacity: .55; }
.item small { display: block; }
.skill { display: flex; gap: 12px; align-items: center; background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; }
.skill .icon { font-size: 30px; }
.pips { letter-spacing: 3px; color: var(--accent); }
.rules li { margin-bottom: 6px; }

@media (max-width: 700px) {
  .home-card { flex-direction: column; }
  .cover { width: 100%; min-height: 0; height: 200px; object-position: center 25%; }
  .home-main { padding: 18px; }
  h1 { font-size: 34px; }
  .act { width: 74px; height: 74px; font-size: 26px; }
}
@media (max-height: 520px) {
  .hud-tasks ul { font-size: 12px; }
  .chat-log { height: 64px; }
  .panel { padding: 14px; gap: 8px; }
}
