:root {
  --bg: #0e1120; --panel: #161a2c; --panel2: #1d2237; --panel3: #242a44; --line: #2a3050;
  --text: #e9ecf5; --muted: #8e95ad; --accent: #f16529; --accent2: #e44d26;
  --ok: #51cf66; --bad: #ff6b6b; --warn: #ffd43b; --gold: #ffd43b;
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
  --pixel: "Press Start 2P", var(--mono);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; -webkit-font-smoothing: antialiased; }
a { color: #74c0fc; }
h2, h3 { margin: 0; font-weight: 700; }
h3 { font-size: 1rem; margin-bottom: 10px; }
code { font-family: var(--mono); background: #2b3152; padding: 1px 5px; border-radius: 4px; font-size: .92em; color: #ffd8a8; white-space: nowrap; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85em; margin: -4px 0 10px; }
.brand { font-family: var(--pixel); font-size: 13px; letter-spacing: .5px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.brand.big { font-size: clamp(16px, 3.4vw, 26px); line-height: 1.5; margin-bottom: 16px; }

.btn { border: 1px solid var(--line); background: var(--panel3); color: var(--text); padding: 10px 18px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; transition: transform .1s, background .15s, opacity .15s; }
.btn:hover { background: #2c3358; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent2); color: #fff; box-shadow: 0 4px 0 #b53a17; }
.btn.primary:hover { background: #ff7a3d; }
.btn.primary:active { box-shadow: 0 1px 0 #b53a17; transform: translateY(3px); }
.btn.primary.busy { animation: pulse 1s infinite; }
.btn.big { padding: 14px 26px; font-size: 1.05em; width: 100%; }
.btn.ghost { background: transparent; border-color: var(--ok); color: var(--ok); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.icon { background: transparent; border: 1px solid transparent; font-size: 18px; cursor: pointer; padding: 4px 6px; border-radius: 8px; color: var(--text); text-decoration: none; line-height: 1; }
.icon:hover { background: var(--panel3); }
@keyframes pulse { 50% { opacity: .7; } }

/* ---------- Вход ---------- */
.screen.join { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 40px 40px; background-position: center; }
.join-card { width: min(560px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 32px; box-shadow: 0 20px 60px rgba(0,0,0,.45); text-align: center; }
.tagline { color: var(--muted); margin: 0 0 16px; }
.join-stats { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; font-size: .9em; color: var(--muted); margin-bottom: 18px; min-height: 22px; }
.join-card form { text-align: left; }
.join-card label { display: block; font-weight: 600; margin: 14px 0 6px; }
.join-card input, .key-box input, .admin input, .admin textarea { width: 100%; padding: 12px 14px; font: inherit; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); outline: 0; }
.join-card input:focus, .key-box input:focus, .admin input:focus { border-color: var(--accent); }
.avatars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-bottom: 18px; }
.av-btn { font-size: 24px; padding: 6px 0; background: var(--panel2); border: 2px solid transparent; border-radius: 10px; cursor: pointer; line-height: 1.3; }
.av-btn:hover { background: var(--panel3); }
.av-btn.sel { border-color: var(--accent); background: #3a2416; }
.form-error { color: var(--bad); min-height: 22px; margin-top: 8px; font-size: .95em; }
.fine { color: var(--muted); font-size: .85em; margin: 16px 0 0; }
.key-box { margin-top: 14px; text-align: left; color: var(--muted); font-size: .9em; }
.key-box summary { cursor: pointer; }
.key-box form { display: flex; gap: 8px; margin-top: 8px; }
.key-box form .btn { padding: 8px 14px; }

/* ---------- Шапка ---------- */
.top { display: flex; align-items: center; gap: 14px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.progress { flex: 1; min-width: 180px; display: flex; align-items: center; gap: 10px; }
.progress .bar { flex: 1; height: 14px; background: var(--panel3); border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.progress .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent2), var(--warn)); transition: width .6s cubic-bezier(.2,.8,.2,1); border-radius: 8px; }
.ptext { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; font-size: .9em; }
.progress.big .bar { height: 22px; }
.online { white-space: nowrap; color: var(--muted); }
.online b { color: var(--text); }
.me { display: flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; background: var(--panel2); border: 2px solid var(--me, var(--line)); font-weight: 600; white-space: nowrap; }
.me.done { box-shadow: 0 0 12px rgba(255, 212, 59, .5); border-color: var(--gold); }
.my-progress { color: var(--muted); font-weight: 400; font-size: .85em; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); display: inline-block; box-shadow: 0 0 6px var(--bad); }
.conn.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }

/* ---------- Раскладка ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(340px, 1fr); gap: 16px; padding: 16px; align-items: start; }
.work { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }

/* ---------- Шаги ---------- */
.steps { display: flex; gap: 6px; flex-wrap: wrap; }
.step { width: 52px; height: 52px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 0; font: inherit; transition: transform .1s, border-color .15s; }
.step:hover { transform: translateY(-2px); border-color: var(--muted); }
.step-n { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.step-i { font-size: 18px; line-height: 1; }
.step.done { background: rgba(81, 207, 102, .15); border-color: rgba(81, 207, 102, .5); }
.step.done .step-i { color: var(--ok); font-weight: 700; }
.step.locked { opacity: .5; }
.step.next { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.step.active { background: var(--accent); border-color: var(--accent2); transform: translateY(-2px); }
.step.active .step-n { color: #fff; }

/* ---------- Задание ---------- */
.mission { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.m-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.m-icon { font-size: 28px; line-height: 1; }
.m-title { font-size: 1.25rem; flex: 1; min-width: 200px; }
.m-badge { font-size: .8em; padding: 3px 10px; border-radius: 20px; background: var(--panel3); color: var(--muted); white-space: nowrap; }
.m-badge.done { background: rgba(81, 207, 102, .15); color: var(--ok); }
.m-badge.open { background: rgba(241, 101, 41, .15); color: #ffa07a; }
.m-brief { margin: 10px 0 6px; font-size: 1.02em; }
.m-who { min-height: 24px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: .9em; color: var(--muted); margin-bottom: 8px; }
.who-l { margin-right: 4px; }
.who-av { position: relative; font-size: 18px; line-height: 1; }
.who-av i { position: absolute; right: -6px; top: -6px; font-size: 10px; font-style: normal; }
.who-first { color: var(--warn); }
.who-more { margin-left: 6px; }
.m-details { background: var(--panel2); border-radius: 10px; padding: 10px 14px; margin: 8px 0 12px; }
.m-details summary { cursor: pointer; font-weight: 600; color: #ffd8a8; }
.theory { margin-top: 8px; color: #d6d9e6; }
.theory p { margin: 8px 0; }
.theory h4 { margin: 16px 0 4px; font-size: 1rem; color: #ffd8a8; }
.theory h4:first-child { margin-top: 6px; }
.theory ul { margin: 6px 0; padding-left: 22px; }
.theory li { margin: 4px 0; }
.theory code { white-space: normal; overflow-wrap: anywhere; }
.theory pre.mini { background: #0c0f1a; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 13px; line-height: 1.5; overflow: auto; margin: 8px 0; white-space: pre; }
.theory pre.mini code { background: none; padding: 0; color: #d6d9e6; white-space: inherit; font-size: inherit; }
.m-details.intro { border: 1px solid rgba(241, 101, 41, .35); }
.m-details.intro summary { color: #ffb38a; }
.checks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.chk { display: grid; grid-template-columns: 22px 1fr; column-gap: 8px; padding: 7px 10px; border-radius: 8px; background: var(--panel2); align-items: start; transition: background .2s; }
.chk-i { font-weight: 700; color: var(--muted); text-align: center; }
.chk.ok { background: rgba(81, 207, 102, .12); }
.chk.ok .chk-i { color: var(--ok); }
.chk.bad { background: rgba(255, 107, 107, .12); }
.chk.bad .chk-i { color: var(--bad); }
.chk-d { grid-column: 2; color: #ffa8a8; font-size: .88em; }
.chk-d:empty { display: none; }
.broken { margin-top: 10px; background: rgba(255, 212, 59, .1); border: 1px solid rgba(255, 212, 59, .4); border-radius: 8px; padding: 10px 12px; font-size: .92em; }
.broken ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Редактор и предпросмотр ---------- */
.editor-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 760px) { .editor-wrap { grid-template-columns: 1fr; } }
.pane { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-width: 0; overflow: hidden; min-height: 420px; }
.pane-title { padding: 8px 12px; font-size: .82em; color: var(--muted); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.pane-title .hint { opacity: .7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor { position: relative; flex: 1; font-family: var(--mono); font-size: 14px; line-height: 1.55; tab-size: 2; min-height: 380px; background: #0c0f1a; }
.editor pre, .editor textarea { margin: 0; padding: 12px 14px; font: inherit; line-height: inherit; tab-size: inherit; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-all; position: absolute; inset: 0; overflow: auto; border: 0; }
.editor pre { pointer-events: none; color: #d6d9e6; }
.editor pre code { background: none; padding: 0; color: inherit; font-size: inherit; white-space: inherit; }
.editor textarea { background: transparent; color: transparent; caret-color: #fff; outline: 0; resize: none; z-index: 1; }
.editor textarea::placeholder { color: #4a5175; }
.editor textarea::selection { background: rgba(241, 101, 41, .35); }
.tk-t { color: #ff9f6b; } .tk-p { color: #8e95ad; } .tk-a { color: #a5d8ff; } .tk-v { color: #c0eb75; } .tk-c { color: #6c7591; font-style: italic; } .tk-d { color: #b197fc; } .tk-e { color: #ffd43b; }
#preview { width: 100%; flex: 1; border: 0; background: #fff; min-height: 380px; }
.actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.verdict { flex: 1; min-width: 200px; font-weight: 600; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: #ffa8a8; }

/* ---------- Стена ---------- */
.wall { display: grid; grid-template-columns: repeat(var(--wall-w, 30), 1fr); gap: 2px; width: 100%; max-width: 400px; margin: 0 auto; aspect-ratio: var(--wall-w, 30) / var(--wall-h, 38); }
.wall .cell { background: var(--c); opacity: .07; border-radius: 1px; transition: opacity .5s; min-width: 0; }
.wall .cell.empty { background: transparent; opacity: 0; }
.wall .cell.on { opacity: 1; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--o, #fff) 60%, transparent); }
.wall .cell.on.hl { outline: 2px solid var(--o); z-index: 1; opacity: 1; }
.wall:hover .cell.on:not(.hl) { opacity: .75; }
.wall .cell.pop { animation: pop .85s cubic-bezier(.2, .9, .3, 1.4); }
@keyframes pop { 0% { transform: scale(2.4); filter: brightness(2.2); } 100% { transform: scale(1); filter: none; } }
.wall-tip { min-height: 22px; text-align: center; color: var(--muted); font-size: .9em; margin-top: 8px; }
.wall-stats { text-align: center; color: var(--muted); font-size: .9em; }
.wall-stats b { color: var(--text); }

/* ---------- Лента ---------- */
.feed { display: flex; flex-direction: column; gap: 4px; font-size: .9em; }
body.board .feed { max-height: 320px; overflow: auto; }
.ev { display: flex; gap: 8px; padding: 5px 8px; border-radius: 6px; background: var(--panel2); align-items: baseline; }
.ev.new { animation: slide .35s ease-out; }
@keyframes slide { from { transform: translateY(-8px); opacity: 0; } }
.ev-t { color: var(--muted); font-family: var(--mono); font-size: .85em; white-space: nowrap; }
.ev-solved { border-left: 3px solid var(--ok); }
.ev-join { border-left: 3px solid #4dabf7; }
.ev-house, .ev-milestone { border-left: 3px solid var(--gold); background: rgba(255, 212, 59, .08); }
.ev-done { border-left: 3px solid var(--gold); background: rgba(255, 212, 59, .18); font-weight: 700; }
.ev-admin { border-left: 3px solid var(--accent); background: rgba(241, 101, 41, .1); }
.ev-empty { color: var(--muted); }

/* ---------- Город ---------- */
.city { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; --s: .2; }
.city.empty::after { content: 'Пока ни одного дома'; color: var(--muted); }
.house { background: var(--panel2); border: 1px solid var(--line); border-top: 3px solid var(--pc, var(--line)); border-radius: 10px; overflow: hidden; cursor: pointer; transition: transform .15s, box-shadow .15s; }
.house:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.house.me { outline: 2px solid var(--accent); }
.house.done { border-color: var(--gold); border-top-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(255, 212, 59, .25); }
.house:not(.online) { opacity: .55; }
.house .screen { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: #fff; }
.house .screen iframe { width: 800px; height: 600px; border: 0; transform-origin: 0 0; transform: scale(var(--s)); pointer-events: none; background: #fff; display: block; }
.house .typing { position: absolute; top: 4px; right: 4px; opacity: 0; transition: opacity .2s; font-size: 14px; background: rgba(0,0,0,.55); border-radius: 6px; padding: 2px 5px; }
.house.typing-on .typing { opacity: 1; animation: wiggle .6s infinite; }
@keyframes wiggle { 50% { transform: rotate(-12deg) translateY(-1px); } }
.house .empty-note { display: none; position: absolute; inset: 0; align-items: center; justify-content: center; color: #aaa; font-size: .8em; background: #f5f5f7; }
.house.blank .empty-note { display: flex; }
.meta { display: flex; align-items: center; gap: 6px; padding: 6px 8px 2px; font-size: .82em; }
.meta .av { font-size: 16px; }
.meta .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.dots { display: flex; gap: 2px; flex-wrap: wrap; max-width: 46px; justify-content: flex-end; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: #3a4160; display: block; }
.dots i.on { background: var(--ok); }
.house .st { color: var(--muted); font-size: .75em; padding: 0 8px 6px; }

/* ---------- Модалки, тосты, баннер ---------- */
.modal { position: fixed; inset: 0; background: rgba(5, 7, 15, .75); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { width: min(1100px, 100%); max-height: 92vh; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; }
.modal-card.small { width: min(520px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-weight: 600; gap: 10px; }
.modal-head .av { font-size: 20px; }
.modal-body { display: grid; grid-template-columns: 1.2fr 1fr; gap: 0; min-height: 0; flex: 1; }
.modal-body.col { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
@media (max-width: 800px) { .modal-body { grid-template-columns: 1fr; overflow: auto; } }
.modal-preview { background: #fff; min-height: 300px; }
.modal-preview iframe { width: 100%; height: 100%; min-height: 420px; border: 0; display: block; }
.modal-code { margin: 0; padding: 14px; overflow: auto; font-family: var(--mono); font-size: 13px; line-height: 1.5; background: #0c0f1a; border-left: 1px solid var(--line); max-height: 70vh; white-space: pre-wrap; overflow-wrap: anywhere; }
.modal-code code { background: none; padding: 0; color: #d6d9e6; white-space: inherit; }
.key-value { display: block; white-space: normal; word-break: break-all; padding: 10px; background: #0c0f1a; font-size: 14px; user-select: all; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--panel3); border: 1px solid var(--line); border-left: 4px solid var(--ok); padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: slide .3s ease-out; font-size: .92em; }
.toast.out { opacity: 0; transition: opacity .4s; }
.toast.bad { border-left-color: var(--bad); }
.toast.gold { border-left-color: var(--gold); }
.toast.join { border-left-color: #4dabf7; }
.toast.admin { border-left-color: var(--accent); }
.banner { position: fixed; top: 20%; left: 50%; transform: translateX(-50%); background: linear-gradient(135deg, #f16529, #ffd43b); color: #1a1004; font-family: var(--pixel); font-size: clamp(12px, 2.2vw, 22px); line-height: 1.6; padding: 22px 30px; border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.6); z-index: 70; text-align: center; max-width: 90vw; animation: bannerIn .5s cubic-bezier(.2,.9,.3,1.3); }
@keyframes bannerIn { from { transform: translateX(-50%) scale(.6); opacity: 0; } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; }

/* ---------- Экран проектора ---------- */
body.board { overflow-x: hidden; }
body.board .top { padding: 12px 24px; }
body.board .brand { font-size: 16px; }
.stats { display: flex; gap: 18px; white-space: nowrap; color: var(--muted); }
.stats b { color: var(--text); font-size: 1.1em; }
.board-layout { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(320px, .9fr); gap: 18px; padding: 18px 24px; }
.board-layout .wall-box .wall { max-width: 560px; }
.board-layout .feed { max-height: 320px; font-size: 1em; }
.side-col { display: flex; flex-direction: column; gap: 18px; }
.leaders { margin: 0; padding-left: 26px; display: flex; flex-direction: column; gap: 6px; }
.leaders li { padding: 4px 8px; border-radius: 6px; background: var(--panel2); }
.leaders .lb-n { color: var(--muted); float: right; font-variant-numeric: tabular-nums; }
.ticker { grid-column: 1 / -1; font-size: 1.15em; padding: 12px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 50px; display: flex; align-items: center; gap: 12px; }
.ticker .ev-t { color: var(--muted); font-family: var(--mono); }
.city-box.wide { grid-column: 1 / -1; }
.city-box.wide .city { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
@media (max-width: 900px) { .board-layout { grid-template-columns: 1fr; } }

/* ---------- Админка ---------- */
.admin { max-width: 960px; margin: 0 auto; padding: 24px 16px; display: flex; flex-direction: column; gap: 16px; }
.admin .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.admin input { width: auto; flex: 1; min-width: 160px; }
.admin table { width: 100%; border-collapse: collapse; font-size: .92em; }
.admin th, .admin td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.admin th { color: var(--muted); font-weight: 600; }
.admin .btn.sm { padding: 5px 10px; font-size: .85em; }
.admin .ok { color: var(--ok); }
