@font-face { font-family: 'Cormorant'; font-style: italic; font-weight: 300 700; font-display: swap; src: url(fonts/cormorant-italic-cyrillic.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Cormorant'; font-style: italic; font-weight: 300 700; font-display: swap; src: url(fonts/cormorant-italic-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Cormorant'; font-style: normal; font-weight: 300 700; font-display: swap; src: url(fonts/cormorant-cyrillic.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Cormorant'; font-style: normal; font-weight: 300 700; font-display: swap; src: url(fonts/cormorant-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 300 800; font-display: swap; src: url(fonts/nunito-cyrillic.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Nunito'; font-style: normal; font-weight: 300 800; font-display: swap; src: url(fonts/nunito-latin.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --ink: #f4efe6;
  --ink-soft: rgba(244, 239, 230, .72);
  --ink-dim: rgba(244, 239, 230, .48);
  --blue: #8fd3ff;
  --pink: #ffa9cf;
  --gold: #ffd98a;
  --glass: rgba(14, 20, 52, .55);
  --glass-edge: rgba(255, 255, 255, .12);
  --serif: 'Cormorant', 'Times New Roman', Georgia, serif;
  --sans: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  position: fixed; inset: 0; overflow: hidden;
  background: #070a1e;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }

#nebula, #sky { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#nebula { z-index: 0; }
#sky { z-index: 1; }
#veil { position: fixed; inset: 0; z-index: 2; background: #070a1e; pointer-events: none; transition: opacity 2.4s ease; }
#veil.gone { opacity: 0; }

/* Верх: заголовок */
#top {
  position: fixed; left: 0; right: 0; top: calc(var(--sat) + 26px); z-index: 5;
  text-align: center; padding: 0 22px; pointer-events: none;
  transition: opacity 1.2s ease, transform 1.2s ease;
  opacity: 0;
}
body.ready #top { opacity: 1; }
#title {
  margin: 0; font: italic 300 clamp(34px, 9vw, 58px)/1.05 var(--serif);
  letter-spacing: .01em; color: var(--ink);
  text-shadow: 0 0 24px rgba(255, 236, 200, .35), 0 2px 18px rgba(0, 0, 0, .5);
  opacity: 0; transform: translateY(10px);
  animation: rise 1.8s .6s ease forwards;
}
#lead {
  margin: 12px auto 0; max-width: 34ch; font-size: clamp(14px, 3.8vw, 17px); color: var(--ink-soft);
  text-shadow: 0 1px 12px rgba(0, 0, 0, .6);
  opacity: 0; animation: rise 1.8s 1.3s ease forwards;
}
@keyframes rise { to { opacity: 1; transform: none; } }
body.quiet #top { opacity: 0 !important; transform: translateY(-10px); pointer-events: none; }

/* Кнопка музыки */
#sound {
  position: fixed; top: calc(var(--sat) + 14px); right: 14px; z-index: 6;
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--glass-edge);
  background: rgba(10, 14, 40, .45); color: var(--ink-soft); cursor: pointer;
  display: grid; place-items: center; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: color .3s, background .3s, opacity 1.2s ease 1.6s;
  opacity: 0;
}
body.ready #sound { opacity: 1; }
#sound svg { fill: currentColor; }
#sound .off { stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
#sound[aria-pressed="true"] { color: var(--gold); }
#sound[aria-pressed="true"] .off { display: none; }

/* Кнопка волшебного режима: рядом с музыкой, на узком экране без подписи */
#mode {
  position: fixed; top: calc(var(--sat) + 14px); right: 64px; z-index: 6;
  height: 42px; padding: 0 16px 0 12px; border-radius: 999px; border: 1px solid var(--glass-edge);
  background: rgba(10, 14, 40, .45); color: var(--ink-soft); cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px; font: 600 13.5px/1 var(--sans); letter-spacing: .02em;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: color .3s, background .3s, opacity 1.2s ease 1.6s;
  opacity: 0;
}
body.ready #mode { opacity: 1; }
#mode[hidden] { display: none; }
#mode .ico { font-size: 17px; line-height: 1; }
#mode:hover { color: var(--ink); background: rgba(10, 14, 40, .6); }
#mode:disabled { opacity: .45; cursor: default; }
body.magic #mode { color: var(--gold); }
body.quiet #mode { opacity: 0; pointer-events: none; transition-delay: 0s; }
@media (max-width: 759px) {
  #mode { width: 42px; padding: 0; justify-content: center; }
  #mode .txt { display: none; }
}
/* Озеро: пока оно работает, обычные холсты не рисуются */
#lake { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 1; touch-action: none; }
body.magic #sky, body.magic #nebula { visibility: hidden; }
#veil.fast { transition-duration: .6s; }
body.quiet #after { opacity: 0; pointer-events: none; }

/* Панели */
.panel { position: fixed; left: 0; right: 0; z-index: 7; display: flex; flex-direction: column; align-items: center; padding: 0 18px; }
#cta { bottom: calc(var(--sab) + 172px); gap: 10px; transition: opacity .8s ease, transform .8s ease; opacity: 0; }
body.ready #cta { opacity: 1; transition-delay: 1.2s; }
#cta.hidden, body.quiet #cta { transition-delay: 0s; }
#cta.hidden, body.quiet #cta { opacity: 0 !important; pointer-events: none; transform: translateY(12px); }
#hint { margin: 0; font-size: 13.5px; color: var(--ink-dim); text-align: center; max-width: 32ch; text-shadow: 0 1px 8px rgba(0,0,0,.6); min-height: 1.4em; }

.btn {
  font: 600 16px/1 var(--sans); letter-spacing: .02em; color: #1a1430;
  background: linear-gradient(180deg, #fff2cf, #f6cd82); border: 0; border-radius: 999px;
  padding: 16px 30px; cursor: pointer;
  box-shadow: 0 0 0 1px rgba(255, 230, 170, .35), 0 8px 30px rgba(255, 200, 120, .25), 0 0 60px rgba(255, 200, 120, .15);
  transition: transform .25s ease, box-shadow .4s ease, filter .3s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 0 0 1px rgba(255, 230, 170, .5), 0 10px 34px rgba(255, 200, 120, .35), 0 0 70px rgba(255, 200, 120, .22); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn:disabled { filter: saturate(.4) brightness(.8); cursor: default; }
.btn.ghost { background: transparent; color: var(--ink-soft); box-shadow: inset 0 0 0 1px var(--glass-edge); }
.btn.ghost:hover { color: var(--ink); box-shadow: inset 0 0 0 1px rgba(255,255,255,.3); }

#light { animation: breathe 4s ease-in-out infinite; }
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 230, 170, .35), 0 8px 30px rgba(255, 200, 120, .25), 0 0 60px rgba(255, 200, 120, .12); }
  50% { box-shadow: 0 0 0 1px rgba(255, 230, 170, .5), 0 8px 34px rgba(255, 200, 120, .4), 0 0 90px rgba(255, 200, 120, .28); }
}

/* Форма: на телефоне шторка снизу, на большом экране карточка в центре */
#sheet { bottom: 0; padding: 0; z-index: 8; }
#sheet[hidden] { display: none; }
#form {
  width: 100%; max-width: 440px; margin: 0;
  background: var(--glass); border: 1px solid var(--glass-edge); border-bottom: 0;
  border-radius: 26px 26px 0 0; padding: 22px 22px calc(var(--sab) + 20px);
  backdrop-filter: blur(22px) saturate(1.3); -webkit-backdrop-filter: blur(22px) saturate(1.3);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .08);
  transform: translateY(30px); opacity: 0;
  animation: sheetIn .55s cubic-bezier(.2, .8, .2, 1) forwards;
}
@keyframes sheetIn { to { transform: none; opacity: 1; } }
#sheet.closing #form { animation: sheetOut .4s ease forwards; }
@keyframes sheetOut { to { transform: translateY(30px); opacity: 0; } }
@media (min-width: 760px) and (min-height: 600px) {
  #sheet { top: 0; justify-content: center; }
  #form { border-radius: 26px; border-bottom: 1px solid var(--glass-edge); padding: 28px 28px 26px; box-shadow: 0 30px 80px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255,255,255,.08); }
}
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--ink-dim); margin: 0 0 6px 4px; letter-spacing: .02em; }
.field small { float: right; font-size: 12px; opacity: .8; margin-right: 4px; }
.field input, .field textarea {
  width: 100%; font: 400 17px/1.4 var(--sans); color: var(--ink);
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .1); border-radius: 14px;
  padding: 12px 14px; outline: none; resize: none;
  transition: border-color .25s, background .25s, box-shadow .25s;
}
.field input::placeholder, .field textarea::placeholder { color: rgba(244, 239, 230, .32); }
.field input:focus, .field textarea:focus { border-color: rgba(255, 220, 160, .5); background: rgba(255, 255, 255, .08); box-shadow: 0 0 0 3px rgba(255, 210, 140, .12); }

.pick { border: 0; margin: 4px 0 6px; padding: 0; }
.pick legend { font-size: 13px; color: var(--ink-dim); margin: 0 0 8px 4px; padding: 0; letter-spacing: .02em; }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick legend { grid-column: 1 / -1; }
.opt { position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; cursor: pointer; border: 1px solid rgba(255, 255, 255, .1); background: rgba(255, 255, 255, .04); transition: border-color .3s, background .3s, box-shadow .3s; }
.opt[hidden] { display: none; }
.opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.opt b { font-weight: 600; font-size: 15px; color: var(--ink-soft); }
.opt i { width: 22px; height: 28px; border-radius: 9px 9px 11px 11px / 8px 8px 14px 14px; position: relative; flex: none; opacity: .55; transition: opacity .3s, box-shadow .3s; }
.opt i::before { content: ''; position: absolute; left: 50%; top: -5px; width: 8px; height: 5px; margin-left: -4px; border-radius: 3px 3px 0 0; background: inherit; filter: brightness(.7); }
.opt i::after { content: ''; position: absolute; left: 50%; bottom: 7px; width: 6px; height: 9px; margin-left: -3px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: #fff2c0; opacity: 0; transition: opacity .3s; }
.opt.blue i { background: var(--blue); }
.opt.pink i { background: var(--pink); }
.opt.gold i { background: var(--gold); }
.opt:hover { background: rgba(255, 255, 255, .07); }
.opt:has(input:checked) { border-color: rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .09); }
.opt:has(input:checked) b { color: var(--ink); }
.opt:has(input:checked) i { opacity: 1; }
.opt:has(input:checked) i::after { opacity: 1; }
.opt.blue:has(input:checked) i { box-shadow: 0 0 18px var(--blue), 0 0 40px rgba(143, 211, 255, .5); }
.opt.pink:has(input:checked) i { box-shadow: 0 0 18px var(--pink), 0 0 40px rgba(255, 169, 207, .5); }
.opt.gold:has(input:checked) i { box-shadow: 0 0 18px var(--gold), 0 0 40px rgba(255, 217, 138, .5); }
.opt:has(input:focus-visible) { outline: 2px solid rgba(255, 220, 160, .5); outline-offset: 2px; }

#err { min-height: 1.3em; margin: 6px 4px 8px; font-size: 13.5px; color: #ffb7a4; }
.row { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.row .btn { padding: 14px 24px; }

/* Подсказка к звезде */
#tip {
  position: fixed; z-index: 6; max-width: min(300px, 78vw); padding: 10px 14px 11px; pointer-events: none;
  background: rgba(10, 14, 40, .62); border: 1px solid var(--glass-edge); border-radius: 14px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
  transform: translate(-50%, -100%); opacity: 0; transition: opacity .25s ease;
  font-size: 14px; line-height: 1.35;
}
#tip.on { opacity: 1; }
#tip[hidden] { display: none; }
#tip b { display: block; font: 600 16px/1.2 var(--sans); color: var(--ink); overflow-wrap: anywhere; }
#tip span { display: block; margin-top: 3px; color: var(--ink-soft); overflow-wrap: anywhere; }
#tip span:empty { display: none; }
#tip em[hidden] { display: none; }
#tip em { display: block; margin-top: 5px; font-style: normal; font-size: 12px; color: var(--gold); letter-spacing: .04em; }
#tip.blue b { color: var(--blue); } #tip.pink b { color: var(--pink); } #tip.gold b { color: var(--gold); }

/* Подпись под сценой */
#caption {
  position: fixed; left: 0; right: 0; top: 30%; z-index: 6; padding: 0 24px; text-align: center; pointer-events: none;
  font: italic 300 clamp(26px, 7vw, 44px)/1.15 var(--serif); color: var(--ink);
  text-shadow: 0 0 30px rgba(255, 236, 200, .35), 0 2px 20px rgba(0, 0, 0, .6);
  opacity: 0; transition: opacity 1.2s ease;
}
#caption.on { opacity: 1; }

/* Низ: счёт, таймер, подпись */
#bottom {
  position: fixed; left: 0; right: 0; bottom: calc(var(--sab) + 14px); z-index: 5; text-align: center; pointer-events: none;
  padding: 0 18px; transition: opacity 1.4s ease 2s;
  opacity: 0;
}
body.ready #bottom { opacity: 1; }
body.quiet #bottom { opacity: 0; transition-delay: 0s; }
#counts { display: flex; justify-content: center; gap: 18px; font-size: 13.5px; color: var(--ink-dim); margin-bottom: 8px; }
#counts .c { display: inline-flex; align-items: center; gap: 7px; }
#counts .c[hidden] { display: none; }
#counts i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
#counts .blue i { background: var(--blue); box-shadow: 0 0 8px var(--blue); }
#counts .pink i { background: var(--pink); box-shadow: 0 0 8px var(--pink); }
#counts .gold i { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
#counts b { font-weight: 600; color: var(--ink-soft); }
#timer { display: flex; flex-direction: column; align-items: center; gap: 1px; }
#timerLabel { font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-dim); }
#timerValue { font: 400 clamp(22px, 5.6vw, 28px)/1.2 var(--serif); letter-spacing: .06em; color: var(--ink); font-variant-numeric: tabular-nums; text-shadow: 0 0 18px rgba(255, 236, 200, .25); }
#timerDate { font-size: 12.5px; color: var(--ink-dim); }
#sign { margin: 10px 0 0; font: italic 400 15px/1 var(--serif); letter-spacing: .12em; color: var(--ink-dim); }

.noscript { position: fixed; inset: auto 0 40% 0; text-align: center; color: var(--ink); z-index: 9; }

/* Кнопки, которые добавляет сцена после раскрытия */
#after { position: fixed; left: 0; right: 0; bottom: calc(var(--sab) + 112px); z-index: 7; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 0 18px; transition: opacity .8s; }
#after.hidden { opacity: 0; pointer-events: none; }
#after .btn { padding: 13px 24px; }
#after .btn.gold { background: linear-gradient(180deg, #fff6d8, #f5c86a); }
#after p { margin: 0; font-size: 13.5px; color: var(--ink-dim); text-align: center; max-width: 34ch; text-shadow: 0 1px 8px rgba(0,0,0,.6); }

@media (prefers-reduced-motion: reduce) {
  #light { animation: none; }
}
@media (max-height: 560px) {
  #top { top: calc(var(--sat) + 12px); }
  #lead { display: none; }
  #cta, #after { bottom: calc(var(--sab) + 120px); }
  #sign { display: none; }
}
/* На телефоне заголовок слева, луна справа */
@media (max-width: 759px), (max-height: 599px) {
  #top { text-align: left; padding: 0 30% 0 24px; }
  #lead { margin-left: 0; }
}
