:root {
  --ink: #e9e4da;
  --dim: #9a9488;
  --warm: #ffb45e;
  --cold: #7fb2ff;
  --gold: #e8c46a;
  --red: #ff6b6b;
  --glass: rgba(10, 12, 18, .55);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: #05070b; color: var(--ink); overflow: hidden; }
body {
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none; -webkit-user-select: none;
}
#app { position: fixed; inset: 0; height: 100dvh; overflow: hidden; }

/* ---------- Фонҳо ---------- */
.bg { position: absolute; inset: 0; opacity: 0; transition: opacity 2.2s ease; }
.bg i { position: absolute; display: block; }
#app[data-scene="title"]    .bg-title,
#app[data-scene="home"]     .bg-home,
#app[data-scene="street"]   .bg-street,
#app[data-scene="price"]    .bg-price,
#app[data-scene="future"]   .bg-future,
#app[data-scene="end-good"] .bg-end-good,
#app[data-scene="end-mid"]  .bg-end-mid,
#app[data-scene="end-bad"]  .bg-end-bad { opacity: 1; }

.bg-title { background: radial-gradient(ellipse at 50% 30%, #1a2233 0%, #05070b 70%); }

.bg-home { background: linear-gradient(180deg, #1b130d 0%, #0b0806 70%); }
.bg-home .window {
  top: 12%; right: 10%; width: 38%; height: 30%;
  border: 3px solid #2a1f16; border-radius: 4px;
  background: linear-gradient(180deg, #0d1626, #111d30);
  box-shadow: inset 0 0 40px #000;
}
.bg-home .window::before, .bg-home .window::after { content: ""; position: absolute; background: #2a1f16; }
.bg-home .window::before { left: 50%; top: 0; bottom: 0; width: 3px; }
.bg-home .window::after  { top: 50%; left: 0; right: 0; height: 3px; }
.bg-home .lamp {
  left: -20%; bottom: -10%; width: 110%; height: 80%;
  background: radial-gradient(circle at 40% 60%, rgba(255,170,80,.45), rgba(255,140,50,.12) 35%, transparent 60%);
  animation: flicker 5s infinite;
}

.bg-street { background: linear-gradient(180deg, #070b14 0%, #0c1422 60%, #05070b 100%); }
.bg-street .streetlamp { left: 22%; top: 8%; width: 4px; height: 70%; background: linear-gradient(#222a36, #0d1119); }
.bg-street .streetlamp::before {
  content: ""; position: absolute; top: -4px; left: -18px; width: 40px; height: 10px;
  border-radius: 6px; background: #ffe3a8; box-shadow: 0 0 30px 10px rgba(255,210,140,.6);
  animation: flicker 7s infinite;
}
.bg-street .cone {
  left: calc(22% - 90px); top: 9%; width: 180px; height: 70%;
  background: linear-gradient(180deg, rgba(255,214,150,.35), rgba(255,214,150,.03));
  clip-path: polygon(45% 0, 55% 0, 100% 100%, 0 100%);
  filter: blur(4px); animation: flicker 7s infinite;
}
.bg-street .puddle {
  left: 0; right: 0; bottom: 0; height: 22%;
  background: radial-gradient(ellipse at 25% 20%, rgba(255,210,140,.25), transparent 50%),
              linear-gradient(180deg, rgba(40,60,90,.25), transparent);
  animation: shimmer 3s ease-in-out infinite alternate;
}

.bg-price { background: radial-gradient(ellipse at 50% 35%, #2b2110 0%, #0b0905 60%, #000 100%); }
.bg-price .gold {
  inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(232,196,106,.25) 0 2px, transparent 3px) 0 0/90px 110px,
    radial-gradient(circle at 70% 60%, rgba(232,196,106,.18) 0 1.5px, transparent 3px) 0 0/130px 90px;
  animation: drift 30s linear infinite;
}

.bg-future { background: linear-gradient(180deg, #0a1018 0%, #101a26 55%, #04060a 100%); }
.bg-future .fog {
  inset: -20%;
  background: radial-gradient(ellipse at 30% 60%, rgba(140,170,210,.14), transparent 50%),
              radial-gradient(ellipse at 75% 40%, rgba(140,170,210,.10), transparent 45%);
  animation: fog 18s ease-in-out infinite alternate;
}
.bg-future .figure {
  left: 50%; top: 18%; width: 70px; height: 190px; transform: translateX(-50%);
  background: linear-gradient(180deg, #0a0e14, #020305);
  border-radius: 35px 35px 8px 8px; opacity: .85;
  box-shadow: 0 0 60px 20px rgba(127,178,255,.08);
  filter: blur(1.5px);
}
.bg-future .figure::before {
  content: ""; position: absolute; top: -34px; left: 50%; transform: translateX(-50%);
  width: 38px; height: 42px; border-radius: 50%; background: #0a0e14;
}

.bg-end-good { background: linear-gradient(180deg, #ffcf8f 0%, #c27b4a 35%, #3b2419 75%, #120b08 100%); }
.bg-end-good::after { content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 30%, rgba(255,240,200,.6), transparent 50%); animation: breathe 6s ease-in-out infinite; }
.bg-end-mid { background: linear-gradient(180deg, #121a26 0%, #0b0f16 100%); }
.bg-end-mid::after { content: ""; position: absolute; left: 30%; top: 18%; width: 40%; height: 30%;
  border-radius: 4px; background: rgba(255,180,94,.35); box-shadow: 0 0 80px 20px rgba(255,180,94,.25);
  filter: blur(2px); animation: flicker 6s infinite; }
.bg-end-bad { background: radial-gradient(ellipse at 22% 15%, rgba(255,214,150,.2), transparent 40%), linear-gradient(#030407, #000); }

#rain { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#flash { position: absolute; inset: 0; background: #cfe0ff; opacity: 0; pointer-events: none; }
#flash.on { animation: lightning .9s ease-out; }
.vignette { position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0,0,0,.85) 100%); }
.grain { position: absolute; inset: -50%; pointer-events: none; opacity: .035;
  background-image: repeating-radial-gradient(circle at 17% 32%, #fff 0 1px, transparent 1px 3px);
  animation: grain 1s steps(4) infinite; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; top: calc(var(--safe-t) + 10px); left: 16px; right: 16px;
  display: flex; justify-content: space-between; align-items: center; z-index: 20;
  opacity: 0; transition: opacity 1s;
}
#app.playing #hud { opacity: 1; }
#memory {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 20px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font-size: 12px; color: var(--dim); border: 1px solid rgba(255,255,255,.06);
}
#memory .label { letter-spacing: .02em; }
#memDots { display: flex; gap: 3px; }
#memDots i { width: 6px; height: 6px; border-radius: 50%; background: var(--warm); box-shadow: 0 0 6px var(--warm); transition: all .8s; }
#memDots i.lost { background: #333; box-shadow: none; transform: scale(.7); }
#memCount { color: var(--ink); min-width: 1ch; }
#memory.hit { animation: hit .8s; }
#musicBtn {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid rgba(255,255,255,.12);
  background: var(--glass); color: var(--dim); font-size: 16px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#musicBtn.on { color: var(--warm); box-shadow: 0 0 14px rgba(255,180,94,.4); }
#musicBtn.off { opacity: .35; }

/* ---------- Экранҳо ---------- */
.screen { position: absolute; inset: 0; z-index: 10; opacity: 0; pointer-events: none; transition: opacity 1.2s ease; }
.screen.show { opacity: 1; pointer-events: auto; }

#title { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 0 24px; }
#title .pre { font-size: 12px; letter-spacing: .4em; text-transform: uppercase; color: var(--dim); margin-bottom: 18px; }
#title h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(42px, 13vw, 72px); line-height: 1.05;
  text-shadow: 0 0 30px rgba(127,178,255,.25); }
#title h1 span { color: var(--warm); font-style: italic; text-shadow: 0 0 30px rgba(255,180,94,.5); }
#title .sub { margin: 22px 0 40px; color: var(--dim); font-size: 15px; }
#title .hint { margin-top: 26px; font-size: 12px; color: #5d5950; }
.btn-main {
  padding: 15px 52px; border-radius: 40px; border: 1px solid rgba(255,180,94,.5);
  background: rgba(255,180,94,.08); color: var(--warm); font-size: 17px; letter-spacing: .1em;
  box-shadow: 0 0 30px rgba(255,180,94,.15); animation: breathe 3s ease-in-out infinite;
}

#card {
  position: absolute; inset: 0; z-index: 30; display: flex; flex-direction: column;
  justify-content: center; align-items: center; background: #000; opacity: 0; pointer-events: none;
  transition: opacity 1s ease;
}
#card.show { opacity: 1; pointer-events: auto; }
#card small { font-size: 11px; letter-spacing: .5em; color: var(--dim); margin-bottom: 14px; text-transform: uppercase; }
#card h2 { font-family: Georgia, serif; font-weight: 400; font-size: clamp(30px, 9vw, 48px); text-align: center; padding: 0 20px; }
#card.show h2 { animation: rise 2s ease both; }

#stage {
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: calc(var(--safe-t) + 70px) 16px calc(var(--safe-b) + 18px);
}
#lines { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; overflow-y: auto; max-height: 62dvh; padding-top: 24px;
  -webkit-mask-image: linear-gradient(transparent, #000 32px); mask-image: linear-gradient(transparent, #000 32px); scrollbar-width: none; }
.line { opacity: 0; transform: translateY(10px); animation: rise .9s ease forwards; font-size: 17px; line-height: 1.5; }
.line.narr { color: #d8d2c4; text-shadow: 0 1px 8px rgba(0,0,0,.9); font-style: italic; font-family: Georgia, serif; font-size: 16px; }
.line.say { padding: 12px 14px; border-radius: 14px; background: var(--glass);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-left: 2px solid var(--who, var(--warm)); }
.line .who { display: block; font-size: 11px; letter-spacing: .15em; text-transform: uppercase; color: var(--who, var(--warm)); margin-bottom: 3px; }
.line.endtitle { text-align: center; font-family: Georgia, serif; font-size: 28px; margin-top: 10px; color: var(--warm); }
#stage.fast .line, #stage.fast .choice { animation-delay: 0s !important; animation-duration: .2s; }

#choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  opacity: 0; animation: rise .8s ease forwards; text-align: left;
  padding: 15px 16px; border-radius: 14px; font-size: 16px; line-height: 1.35; color: var(--ink);
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.14);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: background .3s, border-color .3s, transform .15s;
}
.choice:active { transform: scale(.98); background: rgba(255,180,94,.15); border-color: var(--warm); }
.choice.picked { background: rgba(255,180,94,.18); border-color: var(--warm); }
.choice.fade { opacity: 0 !important; transition: opacity .5s; }
.choice.restart { text-align: center; color: var(--warm); border-color: rgba(255,180,94,.4); }

#toast {
  position: absolute; z-index: 25; left: 50%; top: calc(var(--safe-t) + 64px);
  transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; white-space: nowrap; max-width: 92vw;
  overflow: hidden; text-overflow: ellipsis; transition: all .6s ease;
  background: rgba(40,10,10,.75); border: 1px solid rgba(255,107,107,.4); color: #ffd0d0;
}
#toast.good { background: rgba(10,30,20,.75); border-color: rgba(120,220,160,.4); color: #d0ffe0; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Аниматсияҳо ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(12px); filter: blur(3px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes flicker { 0%,100% { opacity: 1; } 47% { opacity: 1; } 48% { opacity: .6; } 49% { opacity: 1; } 72% { opacity: .85; } 73% { opacity: 1; } }
@keyframes shimmer { from { opacity: .6; } to { opacity: 1; } }
@keyframes drift { to { background-position: 0 -440px, 0 -360px; } }
@keyframes fog { from { transform: translateX(-5%); } to { transform: translateX(5%); } }
@keyframes breathe { 0%,100% { opacity: .85; } 50% { opacity: 1; } }
@keyframes lightning { 0% { opacity: 0; } 8% { opacity: .55; } 14% { opacity: .05; } 22% { opacity: .35; } 100% { opacity: 0; } }
@keyframes grain { 0% { transform: translate(0,0); } 25% { transform: translate(-3%,2%); } 50% { transform: translate(2%,-3%); } 75% { transform: translate(-2%,-1%); } }
@keyframes hit { 0%,100% { transform: none; } 20% { transform: translateX(-4px); border-color: var(--red); } 40% { transform: translateX(4px); } 60% { transform: translateX(-2px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01s !important; animation-iteration-count: 1 !important; transition-duration: .2s !important; }
}
@media (min-width: 700px) {
  #stage { max-width: 560px; margin: 0 auto; }
}
