/* ────────────────────────────────────────────────────────────────
   heart.protocol — стили
   Холодный «терминал» в начале → тёплое сердце и письмо в конце.
   ──────────────────────────────────────────────────────────────── */

:root {
  --bg: #070407;
  --ink: #f8eaee;
  --ink-2: rgba(248, 234, 238, .66);
  --ink-3: rgba(248, 234, 238, .40);
  --ink-4: rgba(248, 234, 238, .17);
  --rose: #ff3d68;
  --rose-2: #ff7593;
  --blush: #ffc3d1;
  --mint: #8ff0c4;
  --line: rgba(255, 110, 145, .18);

  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --serif: "Cormorant Garamond", Cormorant, Georgia, "Times New Roman", serif;

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-io: cubic-bezier(.65, 0, .35, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --gutter: clamp(16px, 4.5vw, 32px);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--bg);
}

body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.6 var(--mono);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; color: inherit; }

/* ───────────── сцена и атмосфера ───────────── */

#stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.fx-glow {
  z-index: 0;
  background:
    radial-gradient(55% 42% at 50% 44%, rgba(150, 20, 55, .16), transparent 72%),
    radial-gradient(120% 60% at 50% 120%, rgba(90, 8, 35, .38), transparent 62%);
  opacity: .65;
  transition: opacity 2.6s var(--ease-io);
}
body.phase-heart .fx-glow { opacity: 1; }

/* строки развёртки старого монитора — только пока «терминал» */
.fx-scan {
  z-index: 2;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, .028) 0 1px, transparent 1px 3px);
  transition: opacity 1.8s var(--ease-io);
}
.fx-scan::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -32vh;
  height: 32vh;
  background: linear-gradient(to bottom, transparent, rgba(255, 80, 120, .045), transparent);
  animation: roll 7.5s linear infinite;
}
@keyframes roll { to { transform: translateY(164vh); } }
body.is-decrypting .fx-scan { opacity: 0; }

.fx-vignette {
  z-index: 2;
  background: radial-gradient(125% 95% at 50% 50%, transparent 50%, rgba(0, 0, 0, .62) 100%);
}

/* плёночное зерно */
.fx-grain {
  z-index: 2;
  inset: -100%;
  opacity: .06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1.5 -.55'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 1.1s steps(6) infinite;
}
@keyframes grain {
  0%   { transform: translate(0, 0); }
  20%  { transform: translate(-3%, 2%); }
  40%  { transform: translate(2%, -3%); }
  60%  { transform: translate(-2%, -1%); }
  80%  { transform: translate(3%, 3%); }
  100% { transform: translate(0, 0); }
}

.curtain {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000;
  pointer-events: none;
  animation: curtain 1.9s var(--ease-io) .15s forwards;
}
@keyframes curtain { to { opacity: 0; visibility: hidden; } }

/* ───────────── HUD по углам ───────────── */

.hud {
  position: fixed;
  z-index: 5;
  inset: calc(var(--safe-t) + 14px) var(--gutter) calc(var(--safe-b) + 14px);
  pointer-events: none;
  font-size: 10px;
  letter-spacing: .14em;
  color: var(--ink-3);
  opacity: 0;
  transition: opacity 1.4s var(--ease-io);
}
body.phase-type .hud { opacity: 1; }
body.is-decrypting .hud { opacity: 0; }

.hud > div {
  position: absolute;
  white-space: nowrap;
  line-height: 1;
}
.hud-tl { top: 5px; left: 18px; }
.hud-tr { top: 5px; right: 46px; }
.hud-bl { bottom: 5px; left: 18px; }
.hud-br { bottom: 5px; right: 18px; font-variant-numeric: tabular-nums; }
.hud .dim { color: var(--ink-4); }

.live {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 8px;
  border-radius: 50%;
  vertical-align: 1px;
  background: var(--rose);
  box-shadow: 0 0 8px var(--rose);
  animation: live 1.6s ease-in-out infinite;
}
@keyframes live { 50% { opacity: .25; } }

.corner {
  position: absolute;
  width: 11px;
  height: 11px;
  border: 0 solid var(--ink-4);
}
.corner.tl { top: 0; left: 0; border-top-width: 1px; border-left-width: 1px; }
.corner.tr { top: 0; right: 0; border-top-width: 1px; border-right-width: 1px; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 1px; border-left-width: 1px; }
.corner.br { bottom: 0; right: 0; border-bottom-width: 1px; border-right-width: 1px; }

/* ───────────── терминал ───────────── */

.term {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(24px, 5.5vh, 56px);
  padding: calc(var(--safe-t) + 52px) var(--gutter) calc(var(--safe-b) + 52px);
  transition: opacity 1s var(--ease-io), filter 1.1s var(--ease-io), transform 1.5s var(--ease-out);
}
body.is-decrypting .term {
  opacity: 0;
  filter: blur(10px);
  transform: scale(.96);
  pointer-events: none;
}

.term-lines {
  position: relative;
  width: min(100%, 500px);
  min-height: calc(8 * 1.8em);
  font-size: clamp(11.5px, 3.3vw, 14px);
  line-height: 1.8;
  color: var(--ink-2);
}
.term-lines::before {
  content: "";
  position: absolute;
  inset: -48px -64px;
  z-index: -1;
  background: radial-gradient(closest-side, rgba(7, 4, 7, .8), rgba(7, 4, 7, 0));
}

.ln {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: ln-in .5s var(--ease-out) both;
}
@keyframes ln-in { from { opacity: 0; transform: translateX(-6px); } }

.ln .pr { margin-right: 1ch; color: var(--rose); }
.ln .v { color: var(--ink); }
.ln .ok { color: var(--mint); }
.ln .warn { color: var(--blush); }
.ln .redact { color: var(--ink-4); }
.ln .dots { color: var(--ink-3); }
.ln .bar-on { color: var(--rose-2); text-shadow: 0 0 10px rgba(255, 61, 104, .65); }
.ln .bar-off { color: var(--ink-4); }

.caret {
  display: inline-block;
  width: .6em;
  height: 1.15em;
  margin-left: .25ch;
  vertical-align: -.22em;
  background: var(--rose-2);
  box-shadow: 0 0 10px rgba(255, 61, 104, .7);
  animation: blink 1.05s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ───────────── сканер отпечатка ───────────── */

.scan {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity 1.1s var(--ease-out), transform 1.3s var(--ease-out);
}
body.scan-ready .scan {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.scan-btn {
  position: relative;
  width: clamp(122px, 33vw, 150px);
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  touch-action: none;
  -webkit-touch-callout: none;
  transition: transform .5s var(--ease-out);
}
.scan-btn::before {
  content: "";
  position: absolute;
  inset: -24%;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(closest-side, rgba(255, 61, 104, .2), rgba(255, 61, 104, 0));
  animation: breathe 3.4s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(1.08); opacity: .5; } }
.scan-btn:focus { outline: none; }
.scan-btn:focus-visible { outline: 1px dashed var(--rose-2); outline-offset: 10px; }

.scan.is-holding .scan-btn { transform: scale(.965); }
.scan.is-holding .scan-btn::before { animation-duration: .9s; }

.scan-svg {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.ring-ticks {
  fill: none;
  stroke: rgba(255, 150, 175, .22);
  stroke-width: 2.4;
  stroke-dasharray: .6 6.57;
}
.ring-track {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.2;
}
.ring-prog {
  fill: none;
  stroke: var(--rose);
  stroke-width: 2.4;
  stroke-linecap: round;
  transition: stroke .5s;
}

.orbit {
  transform-origin: 70px 70px;
  animation: spin 7s linear infinite;
  transition: opacity .4s;
}
.orbit circle { fill: var(--rose-2); }
@keyframes spin { to { transform: rotate(360deg); } }
.scan.is-holding .orbit,
.scan.is-done .orbit { opacity: 0; }

.fp {
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.fp-base { stroke: rgba(255, 160, 184, .28); }
.fp-lit { stroke: #ffb3c5; transition: stroke .5s; }
.scan.is-done .fp-lit,
.scan.is-done .ring-prog { stroke: var(--mint); }

.beam,
.beam-halo { opacity: 0; }

.scan-label {
  min-height: 1.6em;
  margin: 0;
  font-size: 11px;
  letter-spacing: .14em;
  color: var(--ink-3);
  text-align: center;
  transition: color .4s;
}
.scan-label.is-hint { color: var(--blush); }
.scan-label.is-ok { color: var(--mint); }

/* ───────────── письмо ───────────── */

.letter {
  position: fixed;
  z-index: 4;
  left: var(--gutter);
  right: var(--gutter);
  bottom: calc(var(--safe-b) + clamp(20px, 4.5vh, 44px));
  max-height: calc(100% - var(--safe-t) - 40px);
  overflow-y: auto;
  scrollbar-width: none;
  text-align: center;
  visibility: hidden;
  pointer-events: none;
  -webkit-user-select: text;
  user-select: text;
}
.letter::-webkit-scrollbar { display: none; }
body.phase-letter .letter {
  visibility: visible;
  pointer-events: auto;
}

.l-eyebrow {
  margin: 0 0 clamp(6px, 1.4vh, 14px);
  font: 400 10px/1.4 var(--mono);
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.l-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-right: 10px;
  border-radius: 50%;
  vertical-align: 1px;
  background: var(--mint);
  box-shadow: 0 0 8px var(--mint);
}

.l-name {
  margin: 0 0 clamp(8px, 1.8vh, 18px);
  font: italic 400 clamp(54px, 15.5vw, 118px)/.95 var(--serif);
  letter-spacing: -.005em;
  color: var(--blush);
  text-shadow: 0 0 22px rgba(255, 61, 104, .5), 0 0 64px rgba(255, 61, 104, .28);
}
.l-name .ch {
  display: inline-block;
  --ty: .2em;
  --blur: 14px;
}

.l-body {
  max-width: 31em;
  margin: 0 auto;
  font: 500 clamp(17px, 4.4vw, 21px)/1.42 var(--serif);
  color: var(--ink);
  text-wrap: pretty;
}
.l-body p { margin: 0 0 .35em; }
.l-body .w { display: inline-block; }

.l-finale {
  margin: clamp(10px, 2vh, 20px) 0 0;
  font: italic 500 clamp(26px, 6.8vw, 34px)/1.15 var(--serif);
  color: var(--rose-2);
  text-shadow: 0 0 18px rgba(255, 61, 104, .55);
}

.l-sign {
  margin: 4px 0 0;
  font: italic 400 clamp(16px, 4vw, 19px)/1.3 var(--serif);
  color: var(--ink-2);
}

.l-days {
  margin: clamp(12px, 2.4vh, 22px) 0 0;
  font: 400 10.5px/1.5 var(--mono);
  letter-spacing: .16em;
  color: var(--ink-3);
}
.l-days b {
  font-weight: 500;
  color: var(--blush);
  font-variant-numeric: tabular-nums;
}

.l-replay {
  margin-top: clamp(12px, 2.4vh, 22px);
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 61, 104, .04);
  color: var(--ink-3);
  font: 400 10.5px/1 var(--mono);
  letter-spacing: .16em;
  cursor: pointer;
  transition: color .3s, border-color .3s, background-color .3s;
}
.l-replay:hover,
.l-replay:focus-visible {
  outline: none;
  color: var(--ink);
  border-color: rgba(255, 110, 145, .45);
  background: rgba(255, 61, 104, .1);
}

/* плавное проявление: прозрачность + размытие + лёгкий подъём */
.rv {
  opacity: 0;
  transform: translateY(var(--ty, 12px));
  filter: blur(var(--blur, 9px));
  transition:
    opacity 1.1s var(--ease-out) var(--d, 0s),
    transform 1.5s var(--ease-out) var(--d, 0s),
    filter 1.2s var(--ease-out) var(--d, 0s);
}
.letter.is-on .rv {
  opacity: 1;
  transform: none;
  filter: blur(0);
}

/* широкий экран: сердце слева, письмо справа */
@media (min-aspect-ratio: 6/5) and (min-width: 820px) {
  .letter {
    top: 50%;
    right: max(6vw, 40px);
    bottom: auto;
    left: auto;
    width: min(500px, 42vw);
    max-height: calc(100% - 64px);
    transform: translateY(-50%);
    text-align: left;
  }
  .l-name { font-size: clamp(64px, 7.4vw, 124px); }
  .l-body { margin: 0; font-size: clamp(18px, 1.55vw, 23px); }
}

/* невысокие экраны в портрете */
@media (max-height: 640px) and (max-aspect-ratio: 6/5) {
  .l-name { font-size: clamp(44px, 12vw, 80px); }
  .l-body { font-size: 16px; }
  .l-finale { font-size: 24px; }
}

/* ───────────── звук ───────────── */

.sound {
  position: fixed;
  z-index: 6;
  top: calc(var(--safe-t) + 4px);
  right: calc(var(--gutter) - 10px);
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ink-3);
  cursor: pointer;
  transition: color .3s;
}
.sound:hover,
.sound:focus-visible { outline: none; color: var(--ink); }
.sound svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sound .w1,
.sound .w2,
.sound .x { transition: opacity .3s; }
.sound .x { opacity: 0; }
.sound[aria-pressed="false"] .w1,
.sound[aria-pressed="false"] .w2 { opacity: 0; }
.sound[aria-pressed="false"] .x { opacity: 1; }

.noscript {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  background: var(--bg);
  color: var(--blush);
  font: italic 400 22px/1.4 var(--serif);
  text-align: center;
}

/* ───────────── меньше движения ───────────── */

@media (prefers-reduced-motion: reduce) {
  .fx-grain,
  .fx-scan::after,
  .scan-btn::before,
  .orbit,
  .live { animation: none; }
  .rv {
    transform: none;
    filter: none;
    transition: opacity .8s ease var(--d, 0s);
  }
}
