@font-face { font-family: Nunito; src: url(/fonts/nunito-cyrillic.woff2) format('woff2'); font-weight: 200 1000; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: Nunito; src: url(/fonts/nunito-latin.woff2) format('woff2'); font-weight: 200 1000; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+2000-206F, U+20AC, U+2122; }
@font-face { font-family: Comfortaa; src: url(/fonts/comfortaa-cyrillic.woff2) format('woff2'); font-weight: 300 700; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: Comfortaa; src: url(/fonts/comfortaa-latin.woff2) format('woff2'); font-weight: 300 700; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+2000-206F, U+20AC, U+2122; }

:root {
  color-scheme: light;
  --bg-base: #fde9dd;
  --bg: radial-gradient(ellipse 120% 70% at 50% 0%, #fffbea 0%, transparent 65%),
        radial-gradient(ellipse 80% 55% at 0% 70%, #ffd9d6 0%, transparent 70%),
        radial-gradient(ellipse 80% 55% at 100% 85%, #e6dcfb 0%, transparent 70%),
        linear-gradient(180deg, #fff6df, #fde6da);
  --text: #5f3f33;
  --soft: #876455;
  --accent: #c4607a;
  --card: rgba(255, 253, 249, .86);
  --card-line: #fff;
  --shadow: 0 14px 34px -14px rgba(170, 95, 70, .38);
  --main: linear-gradient(135deg, #ffd978, #ffb48f);
  --main-text: #5a3524;
  --hug: linear-gradient(135deg, #ffe0e6, #ffcbd8);
  --share: linear-gradient(135deg, #efe7ff, #ddd2fb);
  --cloud: #fff;
  --floater: #ee9aa6;
  --arm: #ffcb66;
  --arm-edge: #e99f45;
  --focus: #8a3f62;
}
:root[data-theme="night"] {
  color-scheme: dark;
  --bg-base: #1d1a3a;
  --bg: radial-gradient(ellipse 120% 70% at 50% 0%, #3d3470 0%, transparent 65%),
        radial-gradient(ellipse 80% 55% at 0% 75%, #4a2f5c 0%, transparent 70%),
        radial-gradient(ellipse 80% 55% at 100% 90%, #25406a 0%, transparent 70%),
        linear-gradient(180deg, #1d1a3a, #2a2147);
  --text: #f8ecf2;
  --soft: #cdbfdc;
  --accent: #ffb7c8;
  --card: rgba(58, 48, 98, .82);
  --card-line: rgba(205, 188, 255, .22);
  --shadow: 0 16px 38px -16px rgba(5, 3, 20, .75);
  --main: linear-gradient(135deg, #ffe3a1, #ffbfa8);
  --main-text: #43283a;
  --hug: linear-gradient(135deg, #7d456b, #693a66);
  --share: linear-gradient(135deg, #52498a, #433c76);
  --cloud: #6f63a8;
  --floater: #d9c8ff;
  --arm: #f3e7bf;
  --arm-edge: #bfae8c;
  --focus: #ffe3a1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html {
  background: var(--bg-base);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  color: var(--text);
  font: 400 17px/1.5 Nunito, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  text-align: center;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
  isolation: isolate;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* ---------- Небо ---------- */
.sky { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; background: var(--bg); }

.cloud {
  position: absolute;
  left: 0;
  width: 150px; height: 44px;
  border-radius: 44px;
  background: var(--cloud);
  opacity: .62;
  animation: drift 70s linear infinite;
}
.cloud::before, .cloud::after { content: ''; position: absolute; border-radius: 50%; background: inherit; }
.cloud::before { width: 70px; height: 70px; left: 28px; bottom: 6px; }
.cloud::after { width: 48px; height: 48px; right: 26px; bottom: 10px; }
.cloud-1 { top: 11%; animation-delay: -22s; }
.cloud-2 { top: 44%; scale: .65; opacity: .42; animation-duration: 105s; animation-delay: -80s; }
.cloud-3 { top: 79%; scale: .9; opacity: .46; animation-duration: 90s; animation-delay: -50s; }
[data-theme="night"] .cloud { opacity: .2; }

#stars { position: absolute; inset: 0; display: none; }
[data-theme="night"] #stars { display: block; }
#stars i { position: absolute; border-radius: 50%; background: #fff6d6; animation: twinkle 5s ease-in-out infinite; }

#floaters span {
  position: absolute;
  top: 100%;
  color: var(--floater);
  opacity: 0;
  animation: rise 26s linear infinite;
}

/* ---------- Переключатель темы ---------- */
.theme-toggle {
  position: absolute;
  z-index: 2;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--card-line);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 19px;
  line-height: 1;
}

/* ---------- Главный экран ---------- */
.hero {
  width: min(100%, 460px);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.8svh, 18px);
  padding:
    calc(14px + env(safe-area-inset-top))
    calc(16px + env(safe-area-inset-right))
    calc(14px + env(safe-area-inset-bottom))
    calc(16px + env(safe-area-inset-left));
}
header { padding: 0 38px; }
h1, .signature strong { font-family: Comfortaa, Nunito, system-ui, sans-serif; }
h1 { font-size: clamp(25px, 8vw, 38px); font-weight: 700; line-height: 1.2; letter-spacing: -.01em; white-space: nowrap; }
.subtitle { color: var(--soft); font-size: clamp(14px, 4vw, 17px); text-wrap: balance; }

.gift {
  background: var(--card);
  border: 1px dashed var(--accent);
  color: var(--accent);
  border-radius: 18px;
  padding: 5px 14px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  text-wrap: balance;
  animation: appear .6s ease-out;
}
.gift.gone { visibility: hidden; }

/* ---------- Солнышко и луна ---------- */
.buddy {
  border: 0;
  background: none;
  border-radius: 50%;
  width: clamp(130px, min(58vw, 29svh), 250px);
  aspect-ratio: 1;
  flex: none;
  animation: bob 5s ease-in-out infinite;
  user-select: none;
  -webkit-user-select: none;
}
.buddy svg { display: block; width: 100%; height: 100%; overflow: visible; }
.only-night { display: none; }
[data-theme="night"] .only-night { display: inline; }
[data-theme="night"] .only-day { display: none; }

.glow, .rays, .body, .eyes, .tw, .arms { transform-box: view-box; transform-origin: 100px 100px; }
.glow { animation: glow 4s ease-in-out infinite; }
.rays { animation: spin 48s linear infinite; }
.eyes { transform-origin: 100px 95px; animation: blink 5.5s infinite; }
.tw { transform-box: fill-box; transform-origin: center; animation: twinkle 3.6s ease-in-out infinite; }
.tw2 { animation-delay: -1s; } .tw3 { animation-delay: -2s; } .tw4 { animation-delay: -2.8s; }

.eyes-joy, .mouth-joy { opacity: 0; }
.arms { opacity: 0; }
.arm-edge { stroke: var(--arm-edge); }
.arm-fill { stroke: var(--arm); }

.buddy.happy .body, .buddy.hugging .body { animation: squish .7s ease-out; }
.buddy.happy .eyes-joy, .buddy.happy .mouth-joy,
.buddy.hugging .eyes-joy, .buddy.hugging .mouth-joy { opacity: 1; }
.buddy.happy .eyes-open, .buddy.happy .mouth,
.buddy.hugging .eyes-open, .buddy.hugging .mouth { opacity: 0; }
.buddy.hugging .arms-open { animation: arms-open 2.6s ease-in-out forwards; }
.buddy.hugging .arms-hug { animation: arms-hug 2.6s ease-in-out forwards; }
.buddy.hugging .glow { animation: glow 1s ease-in-out 2; }

/* ---------- Карточка ---------- */
.card {
  position: relative;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 14px 18px;
}
.card::before {
  content: '♡';
  position: absolute;
  top: -15px; left: 50%;
  translate: -50% 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--hug);
  color: var(--accent);
  font: 700 17px/29px system-ui, sans-serif;
}
/* Высота постоянная: кнопки не прыгают при смене посланий */
.card-inner {
  height: clamp(112px, 19svh, 170px);
  overflow: auto;
  display: flex;
  flex-direction: column;
}
#message {
  margin: auto 0;
  font-size: clamp(18px, 5.2vw, 22px);
  font-weight: 600;
  line-height: 1.42;
  text-wrap: pretty;
  overflow-wrap: break-word;
  transition: opacity .22s ease, transform .22s ease;
}
#message.leaving { opacity: 0; transform: translateY(-8px); }

/* ---------- Кнопки ---------- */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.btn {
  min-height: 54px;
  border: 1px solid var(--card-line);
  border-radius: 24px;
  padding: 8px 12px;
  font-weight: 800;
  font-size: clamp(14px, 4.2vw, 17px);
  line-height: 1.25;
  box-shadow: var(--shadow);
  transition: transform .15s ease, filter .15s ease;
}
.btn-main { grid-column: 1 / -1; background: var(--main); color: var(--main-text); min-height: 58px; font-size: clamp(17px, 5vw, 19px); }
.btn-hug { background: var(--hug); }
.btn-share { background: var(--share); }
@media (hover: hover) { .btn:hover, .theme-toggle:hover { filter: brightness(1.05); transform: translateY(-2px); } }
.btn:active { transform: scale(.96); }

/* ---------- Подвал ---------- */
footer {
  padding: 36px calc(20px + env(safe-area-inset-right)) calc(36px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.signature { font-size: 17px; }
.signature strong { font-size: 21px; color: var(--accent); }
.telegram {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 20px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-line);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.telegram svg { color: #3d9fd6; flex: none; }
.promise { color: var(--soft); font-size: 14px; max-width: 34em; }
.noscript { color: var(--soft); }

/* ---------- Сообщения ---------- */
.toast {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 32px);
  translate: -50% 0;
  padding: 12px 18px;
  border-radius: 20px;
  background: var(--text);
  color: var(--bg-base);
  font-weight: 700;
  font-size: 15px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s, visibility .3s;
}
.toast.visible { opacity: 1; visibility: visible; }

dialog {
  margin: auto;
  width: min(92vw, 400px);
  border: 0;
  border-radius: 26px;
  padding: 22px;
  background: var(--bg-base);
  color: var(--text);
  text-align: center;
}
dialog::backdrop { background: rgba(40, 20, 40, .45); }
dialog input { width: 100%; margin: 14px 0; padding: 12px; font: inherit; font-size: 16px; border-radius: 14px; border: 1px solid var(--soft); background: var(--card); color: inherit; }
dialog .btn { width: 100%; }
.offscreen { position: fixed; top: 0; left: -9999px; }

/* ---------- Частицы ---------- */
.burst, .shower {
  position: fixed;
  z-index: 4;
  pointer-events: none;
  font-size: var(--size);
  line-height: 1;
  will-change: transform, opacity;
}
.burst { animation: burst .95s ease-out forwards; }
.shower { opacity: 0; animation: shower var(--time) cubic-bezier(.2, .6, .4, 1) var(--delay) forwards; }

/* ---------- Низкие и широкие экраны ---------- */
@media (max-height: 620px) {
  .buddy { width: clamp(108px, 24svh, 150px); }
  .subtitle { font-size: 13px; }
  .card { padding: 10px 16px; border-radius: 22px; }
  .card-inner { height: 100px; }
  #message { font-size: 17px; }
  .btn { min-height: 48px; }
  .btn-main { min-height: 50px; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .hero { width: min(100%, 780px); display: grid; grid-template-columns: 200px 1fr; grid-template-areas: 'head head' 'gift gift' 'buddy card' 'buddy actions'; align-content: center; justify-items: center; column-gap: 20px; }
  header { grid-area: head; }
  .gift { grid-area: gift; }
  .buddy { grid-area: buddy; width: 180px; align-self: center; }
  .card { grid-area: card; }
  .actions { grid-area: actions; }
}

/* ---------- Движение ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bob { 50% { translate: 0 -8px; } }
@keyframes glow { 0%, 100% { opacity: .65; transform: scale(.94); } 50% { opacity: 1; transform: scale(1.06); } }
@keyframes blink { 0%, 43%, 49%, 100% { transform: scaleY(1); } 46% { transform: scaleY(.08); } }
@keyframes twinkle { 0%, 100% { opacity: .25; scale: .8; } 50% { opacity: 1; scale: 1.1; } }
@keyframes drift { from { transform: translateX(-220px); } to { transform: translateX(calc(100vw + 60px)); } }
@keyframes rise {
  0% { transform: translate(0, 0) rotate(-12deg); opacity: 0; }
  12% { opacity: .55; }
  50% { transform: translate(22px, -55vh) rotate(12deg); }
  88% { opacity: .45; }
  100% { transform: translate(-6px, -108vh) rotate(-10deg); opacity: 0; }
}
@keyframes squish {
  25% { transform: scale(1.1, .9); }
  50% { transform: scale(.94, 1.08); }
  75% { transform: scale(1.04, .97); }
}
@keyframes arms-open {
  0% { opacity: 0; transform: scale(.7); }
  10% { opacity: 1; transform: scale(1); }
  24% { opacity: 1; transform: scale(1.09); }
  34% { opacity: 1; transform: scale(.9); }
  35%, 88% { opacity: 0; }
  89% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.75); }
}
@keyframes arms-hug {
  0%, 34% { opacity: 0; transform: scale(1.15); }
  35% { opacity: 1; transform: scale(1.1); }
  48% { opacity: 1; transform: scale(.97); }
  60% { transform: scale(1.03); }
  72% { transform: scale(.97); }
  88% { opacity: 1; transform: scale(1); }
  89%, 100% { opacity: 0; }
}
@keyframes burst {
  0% { transform: translate(-50%, -50%) scale(.4); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1); opacity: 0; }
}
@keyframes shower {
  0% { transform: translate(0, 0) scale(.6); opacity: 0; }
  10% { opacity: 1; }
  75% { opacity: .9; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1.1) rotate(20deg); opacity: 0; }
}
@keyframes appear { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  #floaters { display: none; }
  .cloud-1 { left: 4%; } .cloud-2 { left: 70%; } .cloud-3 { left: 30%; }
  #stars i { opacity: .7; }
  /* без движения объятие всё равно видно */
  .buddy.hugging .arms-hug { opacity: 1; }
}
