:root {
  --ink: #050506;
  --paper: #f3f1ea;
  --mute: #8d8d96;
  --display: "Dela Gothic One", "Arial Black", sans-serif;
  --body: "Onest", system-ui, sans-serif;
  --top: calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --bottom: calc(var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + var(--tg-content-safe-area-inset-bottom, 0px));
  --blob: 28px 22px 30px 20px / 22px 30px 20px 28px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--ink); }
body { font: 600 15px/1.4 var(--body); color: var(--paper); user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #9fe8ff; outline-offset: 2px; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 40; }
#flash.go { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }

/* ---------- заставка з літерами з самої 3D-моделі ---------- */
#splash { position: fixed; inset: 0; z-index: 30; display: grid; place-content: center; justify-items: center; gap: 28px; background: var(--ink); transition: opacity .55s ease, transform .55s ease, filter .55s ease; }
#splash.gone { opacity: 0; transform: scale(1.35); filter: blur(10px); pointer-events: none; }
#splash-logo { width: min(82vw, 420px); aspect-ratio: 49 / 36; }
#splash-logo svg { width: 100%; height: auto; overflow: visible; color: var(--paper); }
#splash-logo path { transform-box: fill-box; transform-origin: 50% 100%; opacity: 0; animation: letter .78s cubic-bezier(.2, 1.7, .4, 1) forwards, jelly 2.4s ease-in-out infinite; }
@keyframes letter {
  0% { opacity: 0; transform: translateY(-14px) scale(.2, 1.9) rotate(-18deg); }
  55% { opacity: 1; transform: translateY(0) scale(1.28, .72) rotate(4deg); }
  100% { opacity: 1; transform: none; }
}
@keyframes jelly { 0%, 70%, 100% { translate: 0 0; scale: 1 1; } 78% { translate: 0 -.7px; scale: .95 1.08; } 86% { translate: 0 0; scale: 1.05 .95; } }
#splash-note { color: var(--mute); font-size: 12px; letter-spacing: .24em; text-transform: uppercase; }

/* ---------- верхня панель ---------- */
#topbar { position: fixed; z-index: 10; top: calc(var(--top) + 10px); left: 14px; right: 14px; display: flex; align-items: center; gap: 8px; transition: opacity .35s, transform .35s; }
#mini-logo { width: 62px; margin-right: auto; }
#mini-logo svg { width: 100%; height: auto; }
#demo-badge { font: 400 10px var(--display); letter-spacing: .1em; padding: 5px 9px; border-radius: 99px; background: #ffd84d; color: #000; }
.pill { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 99px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.13); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); font-size: 12.5px; }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: #666; }
.pill.on i { background: #6dffa8; box-shadow: 0 0 10px #6dffa8; }
.round { width: 38px; height: 38px; flex: none; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.13); }
.round svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.round.dark { background: rgba(0,0,0,.06); border-color: rgba(0,0,0,.14); color: var(--ink); }
#btn-sound .cross, #btn-sound.muted .wave { display: none; }
#btn-sound.muted .cross { display: block; }

body[data-view="boot"] #topbar, body[data-view="print"] #topbar, body[data-view="flight"] #topbar { opacity: 0; transform: translateY(-16px); pointer-events: none; }

/* ---------- HUD друку ---------- */
#print-hud { position: fixed; z-index: 8; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s; }
body[data-view="print"] #print-hud { opacity: 1; }
#print-hud > * { position: absolute; left: 22px; right: 22px; }
#print-hud .layer { top: calc(var(--top) + 22px); font-size: 12px; letter-spacing: .2em; color: var(--mute); }
#print-hud .layer b { font: 400 34px var(--display); color: var(--paper); letter-spacing: 0; margin-left: 6px; font-variant-numeric: tabular-nums; }
#print-hud .layer i { font-style: normal; }
#print-hud h2 { bottom: calc(var(--bottom) + 122px); font: 400 clamp(21px, 6.4vw, 30px)/1.12 var(--display); text-wrap: balance; }
#print-hud p { bottom: calc(var(--bottom) + 94px); color: var(--mute); }
#print-hud .bar { bottom: calc(var(--bottom) + 74px); height: 5px; border-radius: 9px; background: rgba(255,255,255,.12); overflow: hidden; }
#print-hud .bar i { display: block; height: 100%; width: 100%; transform-origin: left; transform: scaleX(0); background: var(--paper); box-shadow: 0 0 14px #fff; transition: transform .12s linear; }
#btn-skip { position: absolute; left: auto !important; right: 14px !important; bottom: calc(var(--bottom) + 18px); padding: 10px; color: var(--mute); font-size: 13px; pointer-events: auto; }
body:not([data-view="print"]) #btn-skip { pointer-events: none; }

/* ---------- головний екран ---------- */
#home { position: fixed; z-index: 9; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: flex-end; }
#home > * { transition: opacity .4s, transform .5s cubic-bezier(.2, 1.2, .35, 1); }
body:not([data-view="home"]) #home > * { opacity: 0; transform: translateY(50px); pointer-events: none !important; visibility: hidden; transition: opacity .25s, transform .3s, visibility 0s .3s; }
#tools { display: flex; justify-content: center; gap: 8px; padding: 0 12px 12px; pointer-events: auto; }
#tools button { display: flex; align-items: center; gap: 6px; padding: 9px 12px; border-radius: 99px; background: rgba(255,255,255,.065); border: 1px solid rgba(255,255,255,.11); font-size: 12px; white-space: nowrap; }
#tools svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tools button[aria-pressed="true"] { background: var(--paper); color: var(--ink); }
#home-panel { padding: 0 18px calc(var(--bottom) + 18px); text-align: center; pointer-events: auto; }
#home h1 { font: 400 clamp(19px, 6.2vw, 30px)/1.1 var(--display); white-space: nowrap; }
.wavy b { display: inline-block; font-weight: 400; white-space: pre; animation: wave 2.8s ease-in-out infinite; animation-delay: calc(var(--i) * 75ms); }
@keyframes wave { 0%, 62%, 100% { transform: translateY(0) scaleY(1); } 74% { transform: translateY(-5px) scaleY(1.2); } 86% { transform: translateY(1px) scaleY(.92); } }
#home-status { margin: 8px auto 16px; color: var(--mute); font-size: 13.5px; min-height: 19px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 440px; }

.big { position: relative; width: 100%; max-width: 440px; min-height: 62px; display: block; margin: 0 auto; padding: 0 18px; background: var(--paper); color: var(--ink); border-radius: var(--blob); font: 400 clamp(14px, 4.3vw, 18px) var(--display); overflow: hidden; isolation: isolate; animation: blob 5s ease-in-out infinite; transition: transform .18s cubic-bezier(.3, 2, .5, 1); box-shadow: 0 0 0 0 rgba(255,255,255,.35), 0 10px 40px rgba(255,255,255,.14); }
.big::after { content: ""; position: absolute; inset: -40% auto -40% -35%; width: 26%; background: linear-gradient(90deg, transparent, rgba(0,0,0,.17), transparent); transform: skewX(-20deg); animation: shine 3.2s ease-in-out infinite; z-index: -1; }
.big:active { transform: scale(.955, .93); }
.big:disabled { opacity: .45; cursor: not-allowed; }
@keyframes blob { 0%, 100% { border-radius: 28px 22px 30px 20px / 22px 30px 20px 28px; } 50% { border-radius: 20px 32px 22px 30px / 31px 21px 31px 22px; } }
@keyframes shine { 0%, 45% { left: -35%; } 85%, 100% { left: 135%; } }
.ghost { padding: 12px 20px; color: var(--mute); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- шторка: біла, як перший варіант лого ---------- */
#scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.45); }
#sheet { position: fixed; z-index: 16; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 520px; max-height: calc(100% - var(--top) - 46px); display: flex; flex-direction: column; background: var(--paper); color: var(--ink); border-radius: 34px 30px 0 0 / 30px 36px 0 0; transform: translateY(105%); visibility: hidden; transition: transform .48s cubic-bezier(.22, 1.18, .36, 1), visibility 0s .48s; box-shadow: 0 -20px 60px rgba(0,0,0,.55); }
#sheet.open { transform: translateY(0); visibility: visible; transition: transform .48s cubic-bezier(.22, 1.18, .36, 1); }
.grip { width: 42px; height: 5px; border-radius: 9px; background: rgba(0,0,0,.18); margin: 10px auto 4px; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 4px 16px 10px; }
.sheet-head h2 { flex: 1; text-align: center; font: 400 17px/1.15 var(--display); text-wrap: balance; }
#sheet-back.invisible { visibility: hidden; }
#sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px calc(var(--bottom) + 18px); }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; padding-top: 4px; }
.grid .tile:first-child, .grid .tile:nth-child(2) { grid-column: span 2; }
.tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 92px; background: var(--ink); color: var(--paper); border-radius: var(--blob); font-size: 12.5px; animation: pop .55s cubic-bezier(.2, 1.7, .4, 1) backwards; animation-delay: calc(var(--i) * 38ms + 60ms); transition: transform .16s; }
.tile:active { transform: scale(.92) rotate(-3deg); }
.tile svg { width: 31px; height: 31px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
@keyframes pop { from { opacity: 0; transform: translateY(26px) scale(.5) rotate(8deg); } }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; margin: 0 0 5px 4px; color: #5b5b63; }
.input { display: flex; align-items: center; gap: 6px; background: #fff; border: 2px solid var(--ink); border-radius: 18px; padding: 0 6px 0 14px; }
.input:focus-within { box-shadow: 0 0 0 4px rgba(5,5,6,.13); }
.input b { color: #77777f; }
.input input, .input textarea { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: 13px 0; font: 600 16px var(--body); color: var(--ink); user-select: text; -webkit-user-select: text; }
.input textarea { resize: none; height: 108px; }
.input button { flex: none; padding: 8px 11px; border-radius: 12px; background: var(--ink); color: var(--paper); font-size: 12px; }
.field.bad .input, .field.bad .drop { border-color: #d3123f; animation: shake .4s; }
@keyframes shake { 20%, 60% { translate: -7px 0; } 40%, 80% { translate: 7px 0; } }
.error { color: #b80f36; font-size: 13px; margin: -4px 4px 12px; }

.drop { display: grid; place-items: center; gap: 6px; min-height: 118px; padding: 16px; text-align: center; border: 2.5px dashed var(--ink); border-radius: var(--blob); background: #fff; cursor: pointer; position: relative; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.drop small { color: #66666e; }
.file-list { list-style: none; margin-top: 10px; display: grid; gap: 7px; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; background: #fff; border-radius: 14px; border: 1px solid rgba(0,0,0,.13); animation: pop .45s cubic-bezier(.2, 1.7, .4, 1) backwards; }
.file-list .thumb { width: 38px; height: 38px; flex: none; border-radius: 10px; object-fit: cover; display: grid; place-items: center; background: var(--ink); color: var(--paper); font: 400 10px var(--display); }
.file-list div { flex: 1; min-width: 0; }
.file-list strong { display: block; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.file-list small { color: #66666e; }
.file-list button { width: 30px; height: 30px; font-size: 18px; }

.hint { font-size: 12.5px; line-height: 1.45; color: #4f4f57; background: rgba(0,0,0,.055); border-radius: 14px; padding: 9px 12px; margin-bottom: 12px; }
#sheet .big { background: var(--ink); color: var(--paper); box-shadow: 0 10px 28px rgba(0,0,0,.3); }
#sheet .big::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.3), transparent); }

.card { border: 2px solid var(--ink); border-radius: var(--blob); background: #fff; padding: 14px; margin-bottom: 12px; }
.card h3 { font: 400 15px var(--display); letter-spacing: .06em; }
.card p { font-size: 13px; color: #55555d; margin: 4px 0 10px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips button { padding: 8px 12px; border-radius: 12px; background: var(--ink); color: var(--paper); font-size: 12px; }
.chips button.light { background: rgba(0,0,0,.08); color: var(--ink); }
.claim { display: flex; gap: 8px; }
.claim .input { flex: 1; }
.card .big { min-height: 54px; }
.claim > button { padding: 0 18px; border-radius: 18px; background: var(--ink); color: var(--paper); }

/* ---------- під час польоту ---------- */
#flight-hud, #result { position: fixed; z-index: 11; inset: 0; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .3s, visibility 0s .3s; }
body[data-view="flight"] #flight-hud, body[data-view="result"] #result { opacity: 1; visibility: visible; transition: opacity .3s; }
#flight-hud { display: flex; flex-direction: column; justify-content: space-between; text-align: center; }
.flight-top { padding: calc(var(--top) + 20px) 22px 24px; background: linear-gradient(rgba(5,5,6,.85), rgba(5,5,6,0)); }
.flight-top h2 { font: 400 clamp(20px, 6.2vw, 30px)/1.12 var(--display); text-wrap: balance; }
.flight-top h2.in { animation: title .55s cubic-bezier(.2, 1.7, .4, 1); }
@keyframes title { from { opacity: 0; transform: scale(.7) rotate(-4deg); } }
.flight-top p { margin: 8px auto 0; max-width: 330px; color: #b4b4bd; font-size: 13.5px; text-wrap: balance; }
.flight-bottom { display: grid; justify-items: center; gap: 4px; padding: 20px 22px calc(var(--bottom) + 14px); background: linear-gradient(rgba(5,5,6,0), rgba(5,5,6,.85)); }
.flight-bottom > * { pointer-events: auto; }
body:not([data-view="flight"]) .flight-bottom > * { pointer-events: none; }
#flight-percent { font: 400 56px/1.1 var(--display); font-variant-numeric: tabular-nums; text-shadow: 0 0 30px rgba(255,255,255,.45); }
#flight-percent small { font-size: .42em; margin-left: 2px; }
#flight-percent.idle { opacity: 0; height: 0; overflow: hidden; }

#result { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; text-align: center; padding: 0 20px calc(var(--bottom) + 18px); }
#result h2 { font: 400 clamp(36px, 12.4vw, 62px)/1.02 var(--display); text-wrap: balance; }
#result h2 b { display: inline-block; font-weight: 400; white-space: pre; animation: slam .7s cubic-bezier(.18, 1.9, .4, 1) backwards, wave 2.8s ease-in-out 1.4s infinite; animation-delay: calc(var(--i) * 48ms), calc(1.4s + var(--i) * 75ms); text-shadow: -2px 0 rgba(0,229,255,.75), 2px 0 rgba(255,40,170,.7), 0 0 34px rgba(255,255,255,.4); }
#result h2 .word { display: inline-block; white-space: nowrap; }
#result.failed h2 { font-size: clamp(29px, 9.4vw, 48px); }
@keyframes slam { from { opacity: 0; transform: translateY(-46px) scale(2.6) rotate(16deg); } }
#result p { margin: 12px 0 18px; max-width: 360px; color: #c4c4cc; text-wrap: balance; overflow-wrap: anywhere; }
#result-actions { width: 100%; display: grid; justify-items: center; gap: 6px; pointer-events: auto; }
body:not([data-view="result"]) #result-actions { pointer-events: none; }

#toast { position: fixed; z-index: 50; left: 50%; top: calc(var(--top) + 62px); width: max-content; max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 18px; background: var(--paper); color: var(--ink); font-size: 13.5px; text-align: center; transform: translate(-50%, -14px); opacity: 0; pointer-events: none; transition: .3s cubic-bezier(.2, 1.5, .4, 1); box-shadow: 0 12px 34px rgba(0,0,0,.5); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 640px) {
  #home-status { margin: 5px auto 9px; }
  .big { min-height: 52px; }
  #flight-percent { font-size: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  .big, .big::after, .wavy b, #splash-logo path { animation-iteration-count: 1 !important; animation-duration: .01s !important; }
}
