:root {
  --bg: #0f171c;
  --bg2: #142028;
  --surface: #18252d;
  --surface2: #1f2f38;
  --line: #2b3d47;
  --ice: #cfe3ea;
  --ice-dim: #8ea7b1;
  --text: #eef3f4;
  --muted: #93a7ae;
  --paper: #f3ead8;
  --paper-ink: #2a2620;
  --red: #c0462a;
  --red-hi: #dd5a3b;
  --gold: #d9a441;
  --green: #6fbf8e;
  --radius: 16px;
  --font-display: "Forum", Georgia, serif;
  --font: "Manrope", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; overflow-x: hidden; }
a { color: var(--ice); }
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; letter-spacing: .01em; margin: 0 0 .4em; line-height: 1.15; }
h1 { font-size: 2.6rem; }
h2 { font-size: 1.7rem; }
h3 { font-size: 1.25rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.mono { font-family: var(--mono); }
.pre { white-space: pre-wrap; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ---------- Загрузка ---------- */
.loader { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.loader-peak { width: 0; height: 0; border-left: 34px solid transparent; border-right: 34px solid transparent; border-bottom: 46px solid var(--ice-dim); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .35; transform: translateY(-4px); } }

/* ---------- Кнопки, поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 12px 22px; border-radius: 999px; border: 0; background: var(--red); color: #fff; font-weight: 700; cursor: pointer; text-decoration: none; transition: transform .15s, background .15s, opacity .15s; }
.btn:hover { background: var(--red-hi); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.block { display: flex; width: 100%; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn.ghost:hover { background: var(--surface2); }
.btn.ice { background: var(--ice); color: #10202a; }
.btn.small { min-height: 38px; padding: 8px 14px; font-size: .9rem; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
label.f { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
input, textarea, select { width: 100%; font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--ice-dim); outline-offset: 0; border-color: transparent; }
textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
input[type=file] { padding: 9px; }
input[type=checkbox] { width: auto; }

/* ---------- Каркас приложения ---------- */
.shell { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + var(--safe-b)); }
.top { position: sticky; top: 0; z-index: 20; background: linear-gradient(var(--bg) 70%, transparent); padding: 14px 0 12px; display: flex; align-items: center; gap: 12px; }
.top .brand { font-family: var(--font-display); font-size: 1.45rem; flex: 1; }
.alt-chip { font-family: var(--mono); font-size: .82rem; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; white-space: nowrap; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface2); display: grid; place-items: center; font-weight: 700; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin: 14px 0; }
.card.paper { background: var(--paper); color: var(--paper-ink); border-color: #d9ccb2; }
.card.paper .muted { color: #6f6656; }
.card h3 { margin-bottom: .3em; }
.tag { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; padding: 3px 9px; border-radius: 999px; background: var(--surface2); color: var(--ice); }
.tag.red { background: rgba(192,70,42,.18); color: #f0a08c; }
.tag.green { background: rgba(111,191,142,.16); color: var(--green); }
.tag.gold { background: rgba(217,164,65,.16); color: var(--gold); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgba(15,23,28,.94); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabs-in { max-width: 640px; margin: 0 auto; display: flex; }
.tab { flex: 1; background: none; border: 0; padding: 9px 2px 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .72rem; font-weight: 600; cursor: pointer; position: relative; }
.tab .ic { font-size: 1.25rem; line-height: 1.2; }
.tab.on { color: var(--text); }
.tab.on::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 2px; background: var(--red); border-radius: 2px; }
.tab .dot { position: absolute; top: 7px; right: calc(50% - 18px); width: 8px; height: 8px; border-radius: 50%; background: var(--red); }

/* ---------- Лендинг ---------- */
.hero { position: relative; min-height: 78vh; display: flex; align-items: flex-end; background: #0b1216 url(/img/hero.jpg) center 30%/cover no-repeat; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(15,23,28,.15) 0%, rgba(15,23,28,.35) 45%, var(--bg) 100%); }
.hero-in { position: relative; z-index: 1; max-width: 640px; margin: 0 auto; padding: 0 16px 28px; width: 100%; }
.hero h1 { font-size: clamp(2.8rem, 11vw, 4.4rem); margin-bottom: .1em; text-shadow: 0 2px 24px rgba(0,0,0,.4); }
.hero .lead { font-size: 1.12rem; max-width: 30em; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 18px 0; }
.fact { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.fact b { display: block; font-family: var(--font-display); font-size: 1.5rem; font-weight: 400; line-height: 1.1; }
.fact span { font-size: .8rem; color: var(--muted); }
.login-box { display: grid; gap: 12px; justify-items: center; padding: 6px 0; }
.landing-route li { margin-bottom: 8px; }
.countdown { font-family: var(--mono); font-size: 1.6rem; font-weight: 700; letter-spacing: .02em; }
.countdown small { font-size: .7rem; color: var(--muted); font-weight: 500; margin-right: 6px; }

/* ---------- Карта восхождения ---------- */
.summit-head { position: relative; border-radius: var(--radius); overflow: hidden; background: linear-gradient(180deg, #1b2b35, #142028); border: 1px solid var(--line); padding: 18px; margin-top: 6px; }
.summit-head svg { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 70px; opacity: .55; }
.summit-head .in { position: relative; }
.meter { height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--ice-dim), var(--ice)); border-radius: 99px; transition: width .8s; }
.route { position: relative; margin: 18px 0 8px; padding-left: 74px; }
.route::before { content: ""; position: absolute; left: 92px; top: 18px; bottom: 18px; width: 2px; background: repeating-linear-gradient(var(--line) 0 6px, transparent 6px 11px); }
.step { position: relative; display: flex; gap: 14px; align-items: flex-start; padding: 10px 0; cursor: pointer; }
.step .alt { position: absolute; left: -74px; top: 18px; width: 62px; text-align: right; font-family: var(--mono); font-size: .72rem; color: var(--muted); }
.step .node { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface2); border: 2px solid var(--line); font-size: 1rem; z-index: 1; }
.step .body { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 13px; }
.step .body b { display: block; font-weight: 600; }
.step .body .sub { font-size: .84rem; color: var(--muted); }
.step.done .node { background: var(--ice); border-color: var(--ice); color: #10202a; }
.step.active .node { background: var(--red); border-color: var(--red-hi); color: #fff; box-shadow: 0 0 0 6px rgba(192,70,42,.18); animation: pulse 2s infinite; }
.step.active .body { border-color: rgba(192,70,42,.55); }
.step.waiting .node { border-color: var(--gold); color: var(--gold); }
.step.locked { opacity: .5; }
.step.locked .body { filter: blur(.3px); }
.step.missed { opacity: .6; }
.step.missed .node { border-style: dashed; }
.step .opt { font-size: .7rem; color: var(--gold); margin-left: 6px; font-weight: 600; }
@keyframes pulse { 50% { box-shadow: 0 0 0 11px rgba(192,70,42,.05); } }

/* ---------- Конверт ---------- */
.envelope-stage { display: grid; justify-items: center; padding: 0 0 4px; }
.envelope { position: relative; width: min(100%, 360px); aspect-ratio: 14 / 9; perspective: 900px; margin-top: 64px; }
.envelope .back { position: absolute; inset: 0; background: #cdb894; border-radius: 10px; box-shadow: 0 18px 40px rgba(0,0,0,.45); }
.envelope .letter { position: absolute; left: 6%; right: 6%; top: 12%; height: 82%; background: #fffcf4; border-radius: 6px; padding: 12px 14px; color: var(--paper-ink); transition: transform .9s cubic-bezier(.2,.8,.2,1); z-index: 2; visibility: hidden; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.envelope .letter .ph { height: 46%; border-radius: 4px; background: url(/img/poster.jpg) center/cover; }
.envelope .letter b { display: block; font-family: var(--font-display); font-size: 1.25rem; font-weight: 400; margin-top: 6px; }
.envelope .letter i { display: block; height: 5px; border-radius: 3px; background: #ddd6c8; margin-top: 7px; }
.envelope .front { position: absolute; inset: 0; z-index: 3; border-radius: 10px; background: #e3d3b3; clip-path: polygon(0 34%, 50% 72%, 100% 34%, 100% 100%, 0 100%); }
.envelope .front::after { content: ""; position: absolute; inset: 0; background: linear-gradient(160deg, rgba(255,255,255,.12), transparent 60%); }
.envelope .flap { position: absolute; left: 0; right: 0; top: 0; height: 60%; z-index: 4; transform-origin: top center; transition: transform .7s ease-in-out, z-index 0s .35s; transform-style: preserve-3d; }
.envelope .flap::before { content: ""; position: absolute; inset: 0; background: #d9c6a0; clip-path: polygon(0 0, 100% 0, 50% 100%); border-radius: 10px 10px 0 0; backface-visibility: hidden; }
.envelope .flap::after { content: ""; position: absolute; inset: 0; background: #c2ab83; clip-path: polygon(0 0, 100% 0, 50% 100%); transform: rotateX(180deg); backface-visibility: hidden; }
.seal { -webkit-appearance: none; appearance: none; border-radius: 50%; position: absolute; left: 50%; top: 60%; width: 78px; height: 78px; margin: -39px 0 0 -39px; z-index: 5; border: 0; padding: 0; background: none; cursor: pointer; }
.seal .half { position: absolute; inset: 0; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #e0684a, #b3341e 55%, #84230f); box-shadow: 0 4px 10px rgba(0,0,0,.35), inset 0 -3px 6px rgba(0,0,0,.3); display: grid; place-items: center; font-family: var(--font-display); font-size: 2.1rem; color: #f3c9b8; transition: transform .6s cubic-bezier(.3,.6,.4,1), opacity .6s; }
.seal .half.l { clip-path: polygon(0 0, 52% 0, 44% 30%, 56% 52%, 42% 74%, 50% 100%, 0 100%); }
.seal .half.r { clip-path: polygon(52% 0, 100% 0, 100% 100%, 50% 100%, 42% 74%, 56% 52%, 44% 30%); }
.seal::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; border: 2px solid rgba(221,90,59,.5); animation: ring 1.8s ease-out infinite; }
@keyframes ring { from { transform: scale(.85); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }
.envelope.shake .seal { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: rotate(-7deg) scale(1.05); } 40%, 80% { transform: rotate(7deg) scale(1.05); } }
.envelope.broken .seal::after { display: none; }
.envelope.broken .seal .l { transform: translate(-46px, 60px) rotate(-38deg); opacity: 0; }
.envelope.broken .seal .r { transform: translate(46px, 70px) rotate(34deg); opacity: 0; }
.envelope.open .flap { transform: rotateX(180deg); z-index: 1; }
.envelope.open .letter { visibility: visible; transition-delay: 0s; }
.envelope.out .letter { transform: translateY(-58%); }
.envelope.locked .seal { cursor: default; }
.envelope.locked .seal::after { display: none; }
.envelope-hint { margin-top: 18px; color: var(--muted); font-size: .9rem; text-align: center; }
.video-wrap { border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; margin: 10px 0; }
.video-wrap video { width: 100%; height: 100%; display: block; }
.letter-text { font-family: var(--font-display); font-size: 1.22rem; line-height: 1.5; white-space: pre-wrap; }
.reveal { animation: rise .6s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ---------- Задание ---------- */
.steps-nav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin: 10px 0; scrollbar-width: none; }
.steps-nav button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 13px; font-size: .84rem; cursor: pointer; color: var(--muted); }
.steps-nav button.on { background: var(--ice); color: #10202a; border-color: var(--ice); font-weight: 700; }
.steps-nav button.filled:not(.on) { color: var(--text); }
.steps-nav button.filled::after { content: " ✓"; color: var(--green); }
.editor { min-height: 260px; font-size: 1.02rem; background: #fffcf4; color: var(--paper-ink); border-color: #d9ccb2; }
.editor.big { min-height: 52vh; }
.save-state { font-size: .8rem; color: var(--muted); min-height: 1.2em; }
.part { border: 1px solid var(--line); border-radius: 14px; padding: 13px; margin: 10px 0; background: var(--surface); }
.part.locked { opacity: .55; }
.part.done { border-color: rgba(111,191,142,.45); }
.part.current { border-color: rgba(192,70,42,.6); }
.part-h { display: flex; gap: 10px; align-items: baseline; }
.part-h .n { font-family: var(--mono); color: var(--muted); font-size: .85rem; }
.upload-done { font-size: .88rem; padding: 10px 12px; border-radius: 12px; background: rgba(111,191,142,.12); color: #bfe6cd; margin: 8px 0; word-break: break-word; }

/* ---------- Значки ---------- */
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.badge { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.badge .bi { font-size: 1.9rem; line-height: 1.2; }
.badge b { display: block; font-size: .92rem; margin-top: 4px; }
.badge .pts { font-family: var(--mono); font-size: .78rem; color: var(--gold); }
.badge .d { font-size: .76rem; color: var(--muted); margin-top: 4px; }
.badge.off { opacity: .38; filter: grayscale(1); }
.rank { width: 100%; border-collapse: collapse; font-size: .92rem; }
.rank td, .rank th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.rank th { font-size: .75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.rank tr.me td { background: rgba(207,227,234,.07); }
.rank .num { font-family: var(--mono); text-align: right; }
.prize { text-align: center; padding: 26px 18px; background: radial-gradient(circle at 50% 0%, rgba(217,164,65,.25), transparent 70%), var(--surface); border-color: rgba(217,164,65,.45); }

/* ---------- Штаб ---------- */
.subtabs { display: flex; gap: 6px; overflow-x: auto; margin: 8px 0 4px; scrollbar-width: none; }
.subtabs button { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 12px; font-size: .84rem; cursor: pointer; color: var(--muted); }
.subtabs button.on { background: var(--surface2); color: var(--text); border-color: var(--ice-dim); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-family: var(--mono); font-size: 1.45rem; }
.stat span { font-size: .78rem; color: var(--muted); }
.ulist { display: grid; gap: 8px; }
.urow { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; text-align: left; width: 100%; color: var(--text); }
.urow:hover { border-color: var(--ice-dim); }
.urow .nm { flex: 1; min-width: 0; }
.urow .nm b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.urow .marks { font-size: .9rem; white-space: nowrap; }
.chk { display: flex; gap: 8px; align-items: center; padding: 6px 0; font-size: .92rem; cursor: pointer; }
.script-view { background: #fffcf4; color: var(--paper-ink); border-radius: 12px; padding: 14px; white-space: pre-wrap; font-size: .95rem; max-height: 50vh; overflow: auto; }
.revs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.revs button { border: 1px solid var(--line); background: var(--bg2); color: var(--muted); border-radius: 8px; padding: 4px 8px; font-size: .75rem; cursor: pointer; font-family: var(--mono); }
.revs button.on { color: var(--text); border-color: var(--ice-dim); }

/* ---------- Модалка и тост ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5,10,13,.72); display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-box { position: relative; background: var(--bg2); border: 1px solid var(--line); border-radius: 20px 20px 0 0; width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; padding: 22px 16px calc(22px + var(--safe-b)); animation: rise .25s ease; }
@media (min-width: 700px) { .modal { align-items: center; } .modal-box { border-radius: 20px; } }
.modal-x { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--surface2); font-size: 1.4rem; cursor: pointer; }
.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--ice); color: #10202a; font-weight: 600; padding: 11px 18px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: calc(100% - 32px); text-align: center; }
.toast.on { opacity: 1; transform: translateX(-50%); }
.toast.err { background: #f0a08c; }
.badge-pop { text-align: center; padding: 10px 0; }
.badge-pop .bi { font-size: 4rem; animation: pop .6s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(.2) rotate(-20deg); opacity: 0; } }

@media (min-width: 700px) {
  .facts { grid-template-columns: repeat(4, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
