:root {
  --table: #E4DCCB; --grid: rgba(60, 40, 20, .07); --paper: #F7F2E7; --ink: #231C15; --muted: #74685A;
  --line: rgba(35, 28, 21, .16); --token: #FBF7EE; --accent: #C8402F; --accent-edge: #8E2A1E; --gold: #E2B33C; --green: #2F7D4F;
  --f-display: "Rubik", "Trebuchet MS", system-ui, sans-serif; --f-text: "Alegreya", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh; min-height: 100dvh; color: var(--ink); background-color: var(--table);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 36px 36px; font: 17px/1.5 var(--f-text); -webkit-font-smoothing: antialiased; padding-bottom: 90px;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.wrap { max-width: 1040px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }

/* header */
.top { padding-top: 18px; }
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; font: 800 21px var(--f-display); letter-spacing: -.02em; }
.mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #FFF7EA; display: grid; place-items: center; font: 900 21px var(--f-display); transform: rotate(-8deg); box-shadow: 0 3px 0 var(--accent-edge); }
.top-right { display: flex; align-items: center; gap: 8px; }
.phase { font: 700 14px var(--f-display); color: var(--muted); font-variant-numeric: tabular-nums; }
.pill { font: 700 14px var(--f-display); min-height: 40px; padding: 0 16px; border: 0; border-radius: 999px; background: var(--token); box-shadow: 0 4px 0 var(--line), inset 0 0 0 1.5px var(--line); }
.pill.ghost { background: transparent; box-shadow: none; color: var(--muted); }

/* generic */
h1 { font: 900 clamp(40px, 7vw, 76px)/.98 var(--f-display); letter-spacing: -.045em; margin: 0; }
h1 em { font-style: normal; color: var(--accent); }
h2 { font: 800 clamp(26px, 4vw, 40px)/1.08 var(--f-display); letter-spacing: -.03em; margin: 0; text-wrap: balance; }
.lead { color: var(--muted); font-size: 20px; margin: 14px 0 0; max-width: 34ch; }
.lbl { font: 600 12px var(--f-display); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.paper { background: var(--paper); border-radius: 16px; padding: 22px; box-shadow: 0 6px 0 var(--line), 0 30px 40px -24px rgba(0,0,0,.35); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 0 24px; border: 0; border-radius: 12px;
  font: 800 18px var(--f-display); background: var(--accent); color: #FFF7EA; box-shadow: 0 5px 0 var(--accent-edge); transition: transform .1s, box-shadow .1s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--accent-edge); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.alt { background: var(--token); color: var(--ink); box-shadow: 0 5px 0 var(--line), inset 0 0 0 1.5px var(--line); }
.btn.block { width: 100%; }
.err { color: var(--accent); min-height: 1.4em; margin: 10px 0 0; font-weight: 500; }
input.field { width: 100%; height: 50px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; padding: 0 16px; outline: none; font-size: 18px; }
input.field:focus { border-color: var(--accent); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 18px; }

/* home */
.home { display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: center; padding: clamp(28px, 6vw, 70px) 0 20px; }
.avatars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 8px; }
.avatars button { padding: 0; border: 0; border-radius: 50%; aspect-ratio: 1; overflow: hidden; opacity: .5; outline: 2.5px solid transparent; outline-offset: 2px; background: #ddd; }
.avatars button.on { opacity: 1; outline-color: var(--accent); }
.avatars img { width: 100%; height: 100%; object-fit: cover; display: block; }
.invite { background: rgba(200, 64, 47, .1); color: var(--accent-edge); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-weight: 500; }
.tg-row { margin-top: 14px; text-align: center; color: var(--muted); font-size: 15px; }
.tg-row a { color: #1C86BD; font-weight: 600; }
.steps { color: var(--muted); padding-left: 20px; margin: 18px 0 0; }

/* players */
.people { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.person { display: inline-flex; align-items: center; gap: 8px; padding: 5px 14px 5px 5px; border-radius: 999px; background: var(--token); box-shadow: 0 3px 0 var(--line), inset 0 0 0 1.5px var(--line); font: 600 15px var(--f-display); }
.person img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.person.off { opacity: .45; }
.person .host { color: var(--gold); }
.person .ok { color: var(--green); font-weight: 800; }
.bk-tg { vertical-align: -2px; }

/* lobby */
.lobby { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; padding-top: 34px; }
.copy { display: flex; gap: 8px; margin-top: 14px; }
.copy input { flex: 1; min-width: 0; height: 46px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; padding: 0 12px; font-size: 14px; color: var(--muted); }
.opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--line); font: 600 15px var(--f-display); }
.opt:last-child { border-bottom: 0; }
.opt small { display: block; font: 400 13px var(--f-text); color: var(--muted); }
.step { display: inline-flex; align-items: center; border-radius: 10px; background: var(--token); box-shadow: inset 0 0 0 1.5px var(--line); }
.step button { width: 38px; height: 38px; border: 0; background: none; font: 800 18px var(--f-display); }
.step button:disabled { opacity: .3; }
.step span { min-width: 46px; text-align: center; font-variant-numeric: tabular-nums; }
.switch { width: 50px; height: 30px; border-radius: 99px; border: 0; background: #D9CFBD; position: relative; transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(20px); }
.switch:disabled { opacity: .6; cursor: default; }

/* question */
.stage { padding-top: 28px; }
.qcard {
  position: relative; background: var(--accent); color: #FFF7EA; border-radius: 18px; padding: clamp(26px, 5vw, 46px) clamp(22px, 5vw, 44px);
  box-shadow: 0 8px 0 var(--accent-edge), 0 30px 40px -18px rgba(0,0,0,.4); transform: rotate(-.6deg);
}
.qcard .lbl { color: rgba(255, 247, 234, .75); }
.qcard h2 { color: #FFF7EA; margin-top: 10px; font-size: clamp(28px, 5vw, 48px); }
.timer { position: absolute; right: 18px; top: 16px; font: 800 18px var(--f-display); font-variant-numeric: tabular-nums; background: rgba(0,0,0,.18); border-radius: 999px; padding: 4px 12px; }
.timer.hurry { background: #FFF7EA; color: var(--accent); }
.vote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; margin-top: 30px; }
.vote {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 16px 10px 14px; border: 0; border-radius: 14px;
  background: var(--paper); box-shadow: 0 5px 0 var(--line), inset 0 0 0 1.5px var(--line); transition: transform .15s, box-shadow .15s; font: 700 15px var(--f-display);
}
.vote img { width: 76px; height: 76px; border-radius: 50%; object-fit: cover; }
.vote span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vote:hover { transform: translateY(-3px); }
.vote.on { box-shadow: 0 5px 0 var(--accent-edge), inset 0 0 0 3px var(--accent); transform: translateY(-3px); }
.vote.on::after { content: "✓"; position: absolute; top: 8px; right: 10px; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 15px; }
.vote:disabled { cursor: default; opacity: .55; transform: none; }
.status { margin-top: 20px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; }

/* reveal */
.bars { display: grid; gap: 12px; margin-top: 26px; }
.bar { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.bar > img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.bar .track { position: relative; height: 44px; border-radius: 10px; background: rgba(35, 28, 21, .07); overflow: hidden; }
.bar .fill { position: absolute; inset: 0 auto 0 0; background: #D9CFBD; border-radius: 10px; animation: grow .7s cubic-bezier(.2,.8,.2,1) both; }
.bar.top .fill { background: var(--gold); }
@keyframes grow { from { width: 0 !important; } }
.bar .name { position: absolute; left: 14px; top: 0; bottom: 0; display: flex; align-items: center; gap: 8px; font: 700 16px var(--f-display); }
.bar .who { display: flex; }
.bar .who img { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--paper); margin-left: -8px; object-fit: cover; }
.bar .n { font: 800 20px var(--f-display); min-width: 28px; text-align: right; }
.crown { font-size: 18px; }
.plus { display: inline-block; font: 800 13px var(--f-display); color: var(--green); background: rgba(47, 125, 79, .12); padding: 2px 8px; border-radius: 99px; }

/* scores */
.scores { display: grid; gap: 8px; margin-top: 14px; }
.score { display: grid; grid-template-columns: 28px 38px minmax(0, 1fr) auto; gap: 10px; align-items: center; font: 600 16px var(--f-display); }
.score img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.score .pos { color: var(--muted); text-align: center; }
.score b { font-size: 20px; }
.score.win b, .score.win .pos { color: var(--accent); }
.side-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 24px; margin-top: 28px; align-items: start; }
.history { display: grid; gap: 10px; margin-top: 12px; }
.history div { padding: 10px 0; border-top: 1px dashed var(--line); }
.history small { color: var(--muted); display: block; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; transition: .2s; pointer-events: none; z-index: 60;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 10px; font: 600 15px var(--f-display); max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 820px) { body.in-game #igroteka-back { display: none !important; } }
.conn { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); background: var(--accent); color: #fff; padding: 6px 14px; border-radius: 99px; font: 700 13px var(--f-display); z-index: 60; }

@media (max-width: 820px) {
  .home, .lobby, .side-grid { grid-template-columns: 1fr; gap: 22px; }
  .home { padding-top: 24px; }
  .vote-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
  .vote img { width: 58px; height: 58px; }
  .vote { font-size: 13px; padding: 12px 6px; }
  .top-right .phase { display: none; }
  .logo { font-size: 17px; white-space: nowrap; }
  .pill { padding: 0 12px; }
}
@media (max-width: 420px) { .avatars { gap: 4px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
