:root {
  --bg: #0a0a0b;
  --ink: #f3efe8;
  --muted: #8f8b85;
  --line: rgba(243, 239, 232, .14);
  --accent: #d0503f;
  --card: #141416;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Manrope', system-ui, sans-serif;
  --ease: cubic-bezier(.22, .8, .2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 300 17px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }

#wave {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0; opacity: .9; transition: opacity 1.2s;
}
body[data-screen="story"] #wave, body[data-screen="letter"] #wave { opacity: .28; }
.preview-badge {
  position: fixed; z-index: 40; left: 12px; top: max(10px, env(safe-area-inset-top));
  font: 500 11px/1 var(--sans); letter-spacing: .06em; padding: 7px 10px; border-radius: 999px;
  background: #2b3a2e; color: #a9dcb3; pointer-events: none;
}
.grain {
  position: fixed; inset: -50%; z-index: 1; pointer-events: none; opacity: .06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1.2s steps(6) infinite;
}
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-4%, 3%); }
  40% { transform: translate(3%, -5%); } 60% { transform: translate(-6%, -2%); }
  80% { transform: translate(5%, 4%); } 100% { transform: translate(0, 0); }
}

/* ── Экраны ── */
#app { position: relative; z-index: 2; height: 100%; }
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; text-align: center;
  padding: max(28px, env(safe-area-inset-top)) 22px max(110px, calc(env(safe-area-inset-bottom) + 96px));
  opacity: 0; visibility: hidden; transform: translateY(14px);
  transition: opacity .9s var(--ease), transform .9s var(--ease), visibility 0s .9s;
}
.screen.on { opacity: 1; visibility: visible; transform: none; transition-delay: .15s, .15s, 0s; }
.screen.scroll { justify-content: flex-start; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; }
.screen.scroll::-webkit-scrollbar { display: none; }

.eyebrow { font-size: 12px; letter-spacing: .32em; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.serif { font-family: var(--serif); font-weight: 400; }
.big { font-size: clamp(44px, 11vw, 92px); line-height: 1.02; letter-spacing: -.01em; }
.mid { font-size: clamp(28px, 6.4vw, 44px); line-height: 1.15; }
.lead { font-size: 18px; color: var(--ink); max-width: 30ch; }
.fine { font-size: 13px; color: var(--muted); letter-spacing: .04em; }

.btn {
  margin-top: 6px;
  padding: 14px 30px; border: 1px solid var(--ink); border-radius: 999px;
  font-size: 15px; letter-spacing: .08em; font-weight: 500;
  transition: background .35s, color .35s, transform .2s;
}
.btn:hover, .btn:focus-visible { background: var(--ink); color: var(--bg); outline: none; }
.btn:active { transform: scale(.97); }
.btn.small { padding: 10px 20px; }
.btn.ghost { border-color: var(--line); color: var(--muted); }
.link { color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 4px; }

/* ── Отсчёт ── */
.count { display: flex; gap: clamp(14px, 4vw, 34px); margin: 8px 0; }
.count div { display: flex; flex-direction: column; align-items: center; min-width: 58px; }
.count b { font: 400 clamp(40px, 10vw, 72px)/1 var(--serif); font-variant-numeric: tabular-nums; }
.count span { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); margin-top: 8px; }
.teaser { font: italic 400 22px/1.35 var(--serif); max-width: 26ch; min-height: 2.7em; }

/* ── Вступление: печатная машинка ── */
.type { min-height: 2.1em; }
.type::after { content: '|'; margin-left: 2px; animation: blink 1s steps(1) infinite; color: var(--muted); font-weight: 300; }
.type.done::after { display: none; }
@keyframes blink { 50% { opacity: 0; } }
.type-late { opacity: 0; transform: translateY(8px); transition: opacity 1s var(--ease), transform 1s var(--ease); }
.type-late.show { opacity: 1; transform: none; }

/* ── Квест ── */
.progress { display: flex; gap: 8px; }
.progress i { width: 26px; height: 2px; background: var(--line); border-radius: 2px; transition: background .5s; }
.progress i.done { background: var(--ink); }
.progress i.cur { background: var(--accent); }

.card { position: relative; width: min(440px, 100%); perspective: 1600px; }
.face {
  width: 100%; padding: 30px 24px; border: 1px solid var(--line); border-radius: 22px;
  background: rgba(20, 20, 22, .82); backdrop-filter: blur(6px);
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  backface-visibility: hidden; transition: transform 1s var(--ease);
}
.face.back { position: absolute; inset: 0; transform: rotateY(180deg); padding: 16px 16px 24px; }
.face.back .photo { aspect-ratio: auto; height: min(50vh, 440px); }
.card.flip .front { position: absolute; inset: 0; transform: rotateY(-180deg); }
.card.flip .back { position: relative; transform: rotateY(0); }

#qForm { display: flex; gap: 10px; width: 100%; }
#qInput {
  flex: 1; min-width: 0; background: transparent; color: var(--ink);
  border: 0; border-bottom: 1px solid var(--line); padding: 10px 2px;
  font: 400 22px var(--serif); outline: none; transition: border-color .3s;
}
#qInput:focus { border-color: var(--ink); }
#qInput::placeholder { color: #55534f; font-style: italic; }
.card.shake .front { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.reaction { min-height: 1.4em; color: var(--muted); font-size: 15px; }
.reaction.hint { color: var(--ink); font-style: italic; font-family: var(--serif); font-size: 19px; }
.peek { font-size: 12px; color: #6fae7c; font-family: monospace; }

.photo {
  width: 100%; aspect-ratio: 4 / 5; border-radius: 14px; overflow: hidden;
  background: linear-gradient(135deg, #1c1b1f, #2a2224 60%, #1a1a1c);
  display: flex; align-items: center; justify-content: center;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo.empty::after { content: '♡'; font: 64px var(--serif); color: rgba(243, 239, 232, .18); }
.caption { font: italic 400 21px/1.35 var(--serif); }

/* ── Наша история ── */
.story-head { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 12vh 0 6vh; }
.together { font: italic 400 22px/1.4 var(--serif); max-width: 28ch; }
.together b { font-style: normal; font-variant-numeric: tabular-nums; }
.timeline { list-style: none; width: min(560px, 100%); position: relative; padding-left: 26px; text-align: left; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 8px; bottom: 8px; width: 1px; background: var(--line); }
.timeline li {
  position: relative; padding-bottom: 54px;
  opacity: 0; transform: translateY(30px); transition: opacity 1s var(--ease), transform 1s var(--ease);
}
.timeline li.seen { opacity: 1; transform: none; }
.timeline li::before {
  content: ''; position: absolute; left: -26px; top: 7px; width: 11px; height: 11px;
  border-radius: 50%; border: 1px solid var(--ink); background: var(--bg);
}
.timeline li.seen::before { background: var(--accent); border-color: var(--accent); transition: background .6s .4s; }
.timeline time { font-size: 12px; letter-spacing: .24em; text-transform: uppercase; color: var(--muted); }
.timeline h3 { font: 400 32px/1.15 var(--serif); margin: 6px 0 10px; }
.timeline p { color: #cfcac2; }
.timeline .photo { margin-top: 16px; aspect-ratio: 4 / 3; }
.story-end { padding: 4vh 0 14vh; }

/* ── I wanna be yours: тишина → песня с текстом ── */
#yours { gap: 18px; }
.stage { position: relative; width: min(680px, 100%); height: min(60vh, 540px); }
.stage > * { position: absolute; inset: 0; transition: opacity 1.4s var(--ease), filter 1.4s var(--ease), transform 1.4s var(--ease); }

.prelude, .song-head, .yours-final {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  opacity: 0; filter: blur(8px); transform: scale(.98); pointer-events: none;
}
.prelude { font: italic 400 clamp(30px, 7.4vw, 50px)/1.2 var(--serif); }
.prelude.show { opacity: 1; filter: none; transform: none; }

.song-head span { font: italic 500 clamp(40px, 10vw, 72px)/1.05 var(--serif); }
.song-head small { margin-top: 14px; font-size: 12px; letter-spacing: .32em; text-transform: uppercase; color: var(--muted); }
.stage.singing .song-head { opacity: 1; filter: none; transform: none; transition-delay: .4s; }
.stage.sung .song-head { opacity: 0; filter: blur(10px); transform: scale(1.03); transition-delay: 0s; }

.lyrics {
  overflow: hidden; opacity: 0;
  -webkit-mask-image: linear-gradient(transparent, #000 24%, #000 76%, transparent);
  mask-image: linear-gradient(transparent, #000 24%, #000 76%, transparent);
}
.stage.sung .lyrics { opacity: 1; }
.lyrics-track { position: absolute; left: 0; right: 0; top: 0; transition: transform 1.15s cubic-bezier(.25, .9, .25, 1); }
.ly {
  font: italic 500 clamp(27px, 6.8vw, 46px)/1.18 var(--serif); padding: 12px 8px;
  color: rgba(243, 239, 232, .5); opacity: .16; filter: blur(2.5px); transform: scale(.93);
  transition: opacity .9s var(--ease), filter .9s var(--ease), transform .9s var(--ease);
}
.ly[data-d="1"] { opacity: .38; filter: blur(.7px); transform: scale(.96); }
.ly[data-d="0"] {
  opacity: 1; filter: drop-shadow(0 0 22px rgba(208, 80, 63, .38)); transform: none;
  /* строка «заливается» светом по мере пения */
  background: linear-gradient(90deg, var(--ink) var(--p, 0%), rgba(243, 239, 232, .5) calc(var(--p, 0%) + 14%));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.ly.gap { letter-spacing: .5em; font-size: 26px; }

.yours-final { font: italic 400 clamp(38px, 9.5vw, 66px)/1.1 var(--serif); padding: 0 8px; }
.stage.done .lyrics, .stage.done .song-head { opacity: 0; filter: blur(10px); }
.stage.done .yours-final { opacity: 1; filter: none; transform: none; transition-delay: 1s; }

.song-bar { width: min(220px, 60%); height: 1px; background: var(--line); overflow: hidden; }
.song-bar i { display: block; height: 100%; background: var(--ink); transform: scaleX(0); transform-origin: left; }
.yours-next { opacity: 0; pointer-events: none; transition: opacity 1.2s; text-decoration: none; font-size: 14px; letter-spacing: .08em; }
.yours-next.show { opacity: 1; pointer-events: auto; }

/* ── Письмо ── */
.paper { width: min(580px, 100%); text-align: left; padding: 12vh 0 4vh; }
#letterBody p { font: 400 21px/1.55 var(--serif); margin-bottom: 1em; color: #e9e4dc; }
#letterBody p:first-child { font-size: clamp(38px, 9vw, 58px); line-height: 1.05; font-style: italic; color: var(--ink); }
.sign { font-style: italic; font-size: 24px; text-align: right; color: var(--muted); }

.scratch-wrap { display: flex; flex-direction: column; align-items: center; gap: 18px; width: min(460px, 100%); padding: 6vh 0 14vh; }
.scratch {
  position: relative; width: 100%; min-height: 190px; border-radius: 20px; overflow: hidden;
  display: flex; align-items: center; justify-content: center; padding: 28px;
  background: radial-gradient(circle at 30% 20%, #3a2321, #18171a 70%); border: 1px solid var(--line);
}
.scratch p { position: relative; }
#scratchCanvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; transition: opacity 1s; }
.scratch.clear #scratchCanvas { opacity: 0; pointer-events: none; }

/* ── Меню повторного визита ── */
.menu { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.menu button {
  font: italic 400 clamp(24px, 6vw, 32px)/1.3 var(--serif); padding: 6px 12px; color: #cfcac2;
  transition: color .3s, letter-spacing .4s var(--ease);
}
.menu button:hover, .menu button:focus-visible { color: var(--ink); letter-spacing: .02em; outline: none; }

/* ── Плеер: пластинка + громкость ── */
.player {
  position: fixed; z-index: 10; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 12px; padding: 7px 18px 7px 7px; border-radius: 999px;
  background: rgba(20, 20, 22, .85); border: 1px solid var(--line); backdrop-filter: blur(8px);
  transition: border-color .3s;
}
.player:hover { border-color: rgba(243, 239, 232, .32); }
.disc-btn { display: block; border-radius: 50%; flex: none; line-height: 0; }
.disc-btn .disc { display: block; }
.disc-btn:focus-visible { outline: 1px solid var(--ink); outline-offset: 3px; }
.disc {
  width: 46px; height: 46px; border-radius: 50%; flex: none; position: relative;
  background: repeating-radial-gradient(circle, #111 0 1.5px, #1d1d1f 1.5px 3px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
  animation: spin 2.6s linear infinite; animation-play-state: paused;
}
.disc::after { content: ''; position: absolute; inset: 0; border-radius: 50%; background: linear-gradient(130deg, transparent 40%, rgba(255, 255, 255, .12) 50%, transparent 60%); }
.label { position: absolute; inset: 15px; border-radius: 50%; background: var(--accent); }
.label::after { content: ''; position: absolute; inset: 6px; border-radius: 50%; background: var(--bg); }
.player.playing .disc { animation-play-state: running; }
.label { transition: background .4s; }
.player.muted .label { background: #4a4743; }
@keyframes spin { to { transform: rotate(360deg); } }
.player-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; width: 118px; }
.player-text b, .player-text i { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-text b { font-weight: 500; font-size: 13px; }
.player-text i { font-style: normal; font-size: 11px; color: var(--muted); }

/* Ползунок громкости: тонкая линия, заливка до точки */
.vol {
  -webkit-appearance: none; appearance: none; width: 104px; height: 28px; background: transparent;
  cursor: pointer; touch-action: none; --v: 45%;
}
.vol:focus { outline: none; }
.vol::-webkit-slider-runnable-track {
  height: 3px; border-radius: 3px;
  background: linear-gradient(90deg, var(--ink) var(--v), rgba(243, 239, 232, .16) var(--v));
}
.vol::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5.5px; border-radius: 50%;
  background: var(--ink); box-shadow: 0 0 0 5px rgba(243, 239, 232, .07); transition: transform .25s var(--ease), box-shadow .25s;
}
.vol:active::-webkit-slider-thumb, .vol:focus-visible::-webkit-slider-thumb { transform: scale(1.3); box-shadow: 0 0 0 7px rgba(208, 80, 63, .22); }
.vol::-moz-range-track { height: 3px; border-radius: 3px; background: rgba(243, 239, 232, .16); }
.vol::-moz-range-progress { height: 3px; border-radius: 3px; background: var(--ink); }
.vol::-moz-range-thumb { width: 14px; height: 14px; border: 0; border-radius: 50%; background: var(--ink); }

.sound-hint {
  position: fixed; z-index: 11; left: 50%; bottom: max(86px, calc(env(safe-area-inset-bottom) + 80px));
  transform: translateX(-50%); padding: 10px 18px; border-radius: 999px; white-space: nowrap;
  background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 500; letter-spacing: .02em;
  animation: hint 2.6s ease-in-out infinite;
}
@keyframes hint { 50% { transform: translateX(-50%) translateY(-4px); box-shadow: 0 10px 30px rgba(208, 80, 63, .25); } }

/* Блестки финала */
.spark { position: fixed; z-index: 30; width: 2px; border-radius: 2px; background: var(--ink); pointer-events: none; }

@media (max-width: 420px) {
  .player-text { display: none; }
  .player { padding: 6px 16px 6px 6px; gap: 10px; }
  .disc { width: 40px; height: 40px; }
  .label { inset: 13px; }
  .count div { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .grain, .disc, .sound-hint { animation: none; }
  .screen, .timeline li, .stage > *, .ly { transition-duration: .01s; }
}
