/* Стиль: светлая плоская иллюстрация в цветах Инжиниума — кремовый фон, тёмно-синяя обводка, «наклейки» */
:root {
  --bg: #f6ece4;
  --paper: #fffcf7;
  --ink: #2b255c;
  --text: #2b255c;
  --muted: #6d6890;
  --line: #2b255c;
  --gold: #fec347;
  --gold-d: #e9a21f;
  --blue: #3f63c8;
  --sky: #5685cb;
  --teal: #45c0a8;
  --red: #ea5160;
  --pink: #e34d69;
  --soft: #efe3d8;
  --radius: 18px;
  --bw: 2.5px;
  --shadow: 0 4px 0 var(--ink);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}
#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
.screen { position: relative; z-index: 1; min-height: 100%; }
[hidden] { display: none !important; }
b { font-weight: 800; }

/* --- Старт --- */
.start-wrap { max-width: 560px; margin: 0 auto; padding: 18px 16px calc(32px + var(--safe-b)); text-align: center; }
.hero { width: 100%; display: block; border: var(--bw) solid var(--line); border-radius: 22px; box-shadow: 0 6px 0 var(--ink); margin: 14px 0 6px; aspect-ratio: 1672/941; object-fit: cover; background: var(--soft); }
.badge { display: inline-block; font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink); background: var(--paper); border: 2px solid var(--line); padding: 5px 12px; border-radius: 99px; }
.title { font-size: 38px; line-height: 1.02; margin: 14px 0 6px; font-weight: 900; letter-spacing: -0.02em; color: var(--ink); }
.title span { color: var(--red); }
.lead { color: var(--muted); margin: 8px 0 18px; font-weight: 500; }
.lead b { color: var(--ink); }
.card { background: var(--paper); border: var(--bw) solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.start-card { text-align: left; display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-weight: 800; font-size: 14px; }
label small { color: var(--muted); font-weight: 500; }
input {
  width: 100%; font: inherit; font-size: 18px; color: var(--ink); font-weight: 600;
  background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
input::placeholder { color: #a9a3c4; font-weight: 500; }
input:focus { box-shadow: 0 0 0 4px rgba(254, 195, 71, .55); }
#group-code { letter-spacing: .4em; text-align: center; font-size: 26px; font-weight: 900; }
.error { color: var(--red); font-size: 14px; font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 800; color: var(--ink); cursor: pointer;
  background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 11px 16px;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .08s ease, box-shadow .08s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; box-shadow: none; }
.btn.primary { background: var(--gold); }
.btn.green { background: var(--teal); color: #fff; }
.btn.danger { background: #ffe1e4; color: var(--red); border-color: var(--red); box-shadow: 0 3px 0 var(--red); }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); }
.btn.big { padding: 15px; font-size: 18px; width: 100%; border-width: var(--bw); box-shadow: var(--shadow); }
.btn.big:active { transform: translateY(4px); }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 auto; }

/* --- Ёлка --- */
.tree-holder svg { display: block; overflow: visible; }
.tree-holder.big { width: 210px; margin: 8px auto 8px; }
.tree-holder.mini { width: 50px; flex: none; cursor: pointer; }
.lamp { transition: fill .4s; transform-box: fill-box; transform-origin: center; }
.lamp.on { animation: twinkle 2.4s ease-in-out infinite; }
.lamp.new { animation: pop 1s ease-out, twinkle 2.4s ease-in-out 1s infinite; }
.star { transition: fill .6s; transform-box: fill-box; transform-origin: center; }
.star.on { animation: spin 3s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: 1; } 50% { opacity: .7; } }
@keyframes pop { 0% { transform: scale(.2); } 60% { transform: scale(1.8); } 100% { transform: scale(1); } }
@keyframes spin { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* --- Шапка квеста --- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  padding: 8px 14px 0; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--paper);
  border-bottom: var(--bw) solid var(--line);
}
.topinfo { flex: 1; min-width: 0; }
.stage-name { font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.chip { font-size: 12px; font-weight: 800; padding: 2px 9px; border-radius: 99px; background: var(--soft); border: 1.5px solid var(--line); white-space: nowrap; }
#chip-key { background: var(--gold); }
.icon-btn { display: grid; place-items: center; padding: 0; background: #fff; border: 2px solid var(--line); border-radius: 12px; color: var(--ink); font-size: 22px; font-weight: 900; width: 42px; height: 42px; cursor: pointer; box-shadow: 0 3px 0 var(--ink); }

/* --- Лента --- */
.feed { max-width: 640px; margin: 0 auto; padding: 16px 12px calc(120px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; }
.msg { display: flex; gap: 8px; align-items: flex-end; animation: rise .35s ease-out; }
.msg .ava { width: 38px; height: 38px; flex: none; }
.msg .ava svg { width: 100%; height: 100%; display: block; }
.bubble { background: var(--paper); border: 2px solid var(--line); border-radius: 18px 18px 18px 6px; padding: 10px 14px; max-width: 86%; word-wrap: break-word; box-shadow: 0 3px 0 var(--ink); }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--sky); color: #fff; border-radius: 18px 18px 6px 18px; font-weight: 700; }
.msg.user.bad .bubble { background: #ffe1e4; color: var(--red); border-color: var(--red); box-shadow: 0 3px 0 var(--red); }
.msg.user.good .bubble { background: var(--teal); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.typing .bubble { display: flex; gap: 4px; padding: 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); animation: dot 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 100% { opacity: .3; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

.divider { align-self: center; margin: 16px 0 4px; font-size: 13px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; color: var(--ink); background: var(--gold); border: 2px solid var(--line); border-radius: 99px; padding: 4px 14px; box-shadow: 0 3px 0 var(--ink); }
.lamp-note { align-self: center; font-size: 14px; color: #fff; background: var(--teal); border: 2px solid var(--line); border-radius: 99px; padding: 4px 14px; font-weight: 800; animation: rise .4s; }

.widget { animation: rise .35s ease-out; margin-left: 46px; display: grid; gap: 10px; }
.widget.card { padding: 14px; }
.answer-row { display: flex; gap: 8px; }
.answer-row input { flex: 1; min-width: 0; }
.answer-row .btn { flex: none; }
.hint-box { background: #fff4d6; border: 2px dashed var(--gold-d); border-radius: 12px; padding: 10px 12px; font-size: 15px; }
.hint-link { background: none; border: 0; color: var(--blue); font: inherit; font-size: 14px; font-weight: 800; padding: 0; cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 3px; }
.hint-link:disabled { color: var(--muted); text-decoration: none; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.media-frame { position: relative; width: 100%; aspect-ratio: 16/9; border-radius: 14px; overflow: hidden; background: #000; border: 2px solid var(--line); }
.media-frame iframe, .media-frame video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.media-img { width: 100%; border-radius: 12px; display: block; border: 2px solid var(--line); }
.small { font-size: 13px; color: var(--muted); }
.small a { color: var(--blue); font-weight: 700; }

.voice { display: flex; align-items: center; gap: 12px; }
.voice .play { width: 52px; height: 52px; border-radius: 50%; border: 2px solid var(--line); box-shadow: 0 3px 0 var(--ink); font-size: 20px; background: var(--teal); color: #fff; cursor: pointer; flex: none; }
.voice .wave { flex: 1; height: 28px; display: flex; align-items: center; gap: 3px; }
.voice .wave i { flex: 1; background: #cfc6e6; border-radius: 2px; }
.voice.playing .wave i { animation: wave .8s ease-in-out infinite; background: var(--teal); }
@keyframes wave { 50% { transform: scaleY(.3); } }
details summary { cursor: pointer; color: var(--blue); font-size: 14px; font-weight: 700; }

/* генератор */
.art { width: 100%; aspect-ratio: 1; border-radius: 14px; background: #f3eee2; display: block; border: 2px solid var(--line); }
.art-wrap { position: relative; }
.art-wrap .loading { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255, 252, 247, .85); border-radius: 14px; font-weight: 800; text-align: center; padding: 20px; }

/* факты */
.facts-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.facts-grid span { aspect-ratio: 1; border-radius: 10px; display: grid; place-items: center; font-weight: 900; background: #fff; border: 2px solid var(--line); font-size: 14px; }
.facts-grid span.ok { background: var(--teal); color: #fff; }
.facts-grid span.no { background: var(--red); color: #fff; }
.fact-card { background: #fff4d6; color: var(--ink); border: 2px solid var(--line); border-radius: 14px; padding: 14px; font-weight: 700; }
.fact-card .small { color: var(--muted) !important; }
.fact-card .row { margin-top: 12px; }
.fact-card .btn { color: #fff; }
.tf-true { background: var(--teal) !important; }
.tf-false { background: var(--red) !important; }

/* ядро — золотой гранёный шар, как под потолком атриума */
.core-wrap { display: grid; place-items: center; padding: 20px 0; gap: 16px; }
.core {
  width: 200px; height: 200px; border-radius: 50%; cursor: pointer; color: var(--ink); font-weight: 900; font-size: 16px; padding: 32px;
  border: 3px solid var(--line);
  background:
    linear-gradient(60deg, transparent 48%, rgba(233, 162, 31, .55) 49%, rgba(233, 162, 31, .55) 51%, transparent 52%) 0 0 / 50px 50px,
    linear-gradient(-60deg, transparent 48%, rgba(233, 162, 31, .55) 49%, rgba(233, 162, 31, .55) 51%, transparent 52%) 0 0 / 50px 50px,
    radial-gradient(circle at 35% 30%, #fff3c4, #fec347 45%, #e9a21f 85%);
  box-shadow: 0 6px 0 var(--ink), 0 0 0 10px rgba(254, 195, 71, .25);
  animation: breathe 2s ease-in-out infinite;
}
.core.boom { animation: boom 1.6s ease-in forwards; }
@keyframes breathe { 50% { box-shadow: 0 6px 0 var(--ink), 0 0 0 22px rgba(254, 195, 71, .18); } }
@keyframes boom { 0% { transform: scale(1); } 40% { transform: scale(.85) rotate(-10deg); } 100% { transform: scale(6); opacity: 0; } }

/* финал */
.finale { text-align: center; display: grid; gap: 14px; justify-items: center; }
.finale h2 { font-size: 30px; margin: 0; font-weight: 900; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.stats div { background: var(--soft); border: 2px solid var(--line); border-radius: 14px; padding: 10px 4px; }
.stats b { display: block; font-size: 22px; color: var(--red); }
.stats small { color: var(--muted); font-size: 12px; font-weight: 700; }

/* шторки */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(43, 37, 92, .45); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet-card { width: 100%; max-width: 520px; background: var(--paper); border: var(--bw) solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + var(--safe-b)); display: grid; gap: 10px; animation: up .25s ease-out; max-height: 92vh; overflow: auto; }
.sheet-card h3 { margin: 0 0 4px; font-weight: 900; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.vr-alert { text-align: center; }
.vr-alert .big-emoji { font-size: 64px; animation: spin 1s ease-in-out infinite; }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); z-index: 30; background: var(--ink); color: #fff; font-weight: 800; padding: 12px 18px; border-radius: 14px; box-shadow: 0 4px 0 rgba(0, 0, 0, .25); animation: up .3s; max-width: 90vw; text-align: center; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 25; }

@media (min-width: 700px) {
  .title { font-size: 50px; }
  .tree-holder.big { width: 250px; }
}

/* --- Гирлянда --- */
.garland { flex: 1 0 100%; height: 50px; margin: 0 -14px; cursor: pointer; }
.garland svg, .garland-big svg { display: block; width: 100%; height: 100%; overflow: visible; }
.garland-big { width: 100%; height: 70px; margin: 6px 0 4px; }
.bulb { transform-box: fill-box; transform-origin: 50% 0; }
.bulb.on { animation: bulb 2.4s ease-in-out infinite; }
.bulb.on .halo { animation: halo 2.4s ease-in-out infinite; }
.bulb.new { animation: swing 1.2s ease-out, bulb 2.4s ease-in-out 1.2s infinite; }
@keyframes bulb { 0%, 100% { opacity: 1; } 50% { opacity: .82; } }
@keyframes halo { 50% { opacity: .05; } }
@keyframes swing { 0% { transform: rotate(0) scale(1.6); } 30% { transform: rotate(14deg) scale(1.2); } 60% { transform: rotate(-9deg); } 100% { transform: rotate(0); } }
.stage-list { text-align: left; display: grid; gap: 6px; }
.stage-list div { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.stage-list div.done { color: var(--ink); font-weight: 800; }
.stage-list i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); background: #cfc7c0; flex: none; }
.stage-list .done i { background: var(--gold); box-shadow: 0 0 0 4px rgba(254, 195, 71, .35); }
.vr-alert .big-emoji { width: 80px; height: 80px; margin: 0 auto; }
.vr-alert .big-emoji svg { width: 100%; height: 100%; }
.voice .play { display: grid; place-items: center; }

/* --- Генератор --- */
.mood-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.mood { font: inherit; font-size: 14px; font-weight: 800; color: var(--ink); background: #fff; border: 2px solid var(--line); border-radius: 99px; padding: 7px 13px; cursor: pointer; box-shadow: 0 2px 0 var(--ink); }
.mood.on { background: var(--gold); transform: translateY(2px); box-shadow: none; }
.art-wrap .loading { display: grid; place-content: center; justify-items: center; gap: 12px; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid var(--soft); border-top-color: var(--red); border-right-color: var(--gold); animation: rot 0.9s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.art-wrap:has(.art[hidden]) { aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 14px; }
.loading-text { text-align: center; padding: 0 14px; max-width: 300px; }
.loading-text { text-align: center; padding: 0 14px; max-width: 300px; }
