/* ==========================================================================
   Сайт-визитка с резиновым лицом
   1 Токены · 2 База · 3 Фон · 4 Каркас · 5 Лицо · 6 Подсказка · 7 Эмоции ·
   8 Текст · 9 Ссылки · 10 Счётчик · 11 Подвал · 12 Холст · 13 Облачко ·
   14 Звук · 15 Состояния · 16 Десктоп · 17 Анимации · 18 Меньше движения
   ========================================================================== */


/* 1. Токены
   -------------------------------------------------------------------------- */

:root {
  /* цвета */
  --bg: #2747F5;
  --cream: #FFF5E1;
  --sun: #FFD43B;
  --ink: #121212;
  --paper: #FFFFFF;
  --dot: rgba(255, 255, 255, .09);
  --glow: rgba(150, 172, 255, .78);
  --glow-soft: rgba(112, 140, 255, .36);
  --vignette: rgba(9, 20, 118, .4);
  --cream-90: rgba(255, 245, 225, .9);
  --cream-75: rgba(255, 245, 225, .75);
  --cream-55: rgba(255, 245, 225, .55);

  /* шрифты */
  --font-display: "Unbounded", system-ui, sans-serif;
  --font-body: "Onest", system-ui, sans-serif;
  --font-hand: "Caveat", system-ui, sans-serif;
  --font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;

  /* отступы */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;
  --gutter: 16px;

  /* стикерный стиль */
  --line: 2px solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --shadow-sm: 3px 3px 0 var(--ink);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);

  /* размер лица: желаемая высота и потолок */
  --vh: 1vh;
  --face-h: calc(54 * var(--vh));
  --face-max: 500px;
  --face-w: calc(min(var(--face-h), var(--face-max)) * 409 / 537);
}

@supports (height: 1svh) {
  :root { --vh: 1svh; }
}


/* 2. База
   -------------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden; /* для старых браузеров без clip */
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: calc(100 * var(--vh));
  display: grid;
  grid-template-rows: 1fr auto;
  overflow-x: clip;
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

::selection {
  background: var(--sun);
  color: var(--ink);
}

:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: 3px;
}


/* 3. Фон: кобальт, сетка точек, виньетка
   -------------------------------------------------------------------------- */

body {
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--dot) 1.5px, transparent 2px);
  background-size: 22px 22px;
  background-position: 11px 11px;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(130% 100% at 50% 42%, transparent 55%, var(--vignette) 100%);
}


/* 4. Каркас
   -------------------------------------------------------------------------- */

.hero {
  position: relative;
  z-index: 1; /* весь контент ниже холста с лицом (z-index: 5) */
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding:
    max(var(--sp-4), env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    var(--sp-7)
    max(var(--gutter), env(safe-area-inset-left));
}

.hero__inner {
  width: 100%;
  max-width: 1360px;
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  row-gap: var(--sp-7);
}

.stage {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 64px; /* место для подсказки над лицом */
}


/* 5. Лицо: слот, запасная картинка, свечение
   -------------------------------------------------------------------------- */

.stage__face {
  position: relative;
  width: min(100%, 90vw, var(--face-w));
}

/* мягкое свечение за головой */
.stage__face::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 54%;
  width: 170%;
  aspect-ratio: 1;
  translate: -50% -50%;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--glow), var(--glow-soft) 45%, rgba(110, 138, 255, 0) 100%);
  pointer-events: none;
}

.face-slot {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 409 / 537;
  border-radius: 32px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Без рамки фокуса. Фокус с клавиатуры (Tab) видно по тёплому свечению за головой. */
.face-slot:focus,
.face-slot:focus-visible {
  outline: none;
}

.stage__face:has(.face-slot:focus-visible)::before {
  background: radial-gradient(closest-side, rgba(255, 212, 59, .55), rgba(255, 212, 59, .18) 45%, rgba(255, 212, 59, 0) 100%);
}

.face-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: contain;
  object-position: 50% 100%;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 16px 22px rgba(9, 20, 110, .38));
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.face-slot.is-live .face-fallback {
  visibility: hidden;
}

.face-fallback.is-shaking {
  animation: face-jelly .58s var(--ease-out);
}


/* 6. Подсказка «хватай и тяни!»
   -------------------------------------------------------------------------- */

.hint {
  --nudge-x: 3px;
  position: absolute;
  top: -46px;
  left: 6%;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  color: var(--sun);
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: clamp(27px, 2.4vw, 36px);
  line-height: 1;
  white-space: nowrap;
  rotate: -7deg;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity .35s ease, translate .35s var(--ease-out);
}

.hint.is-hidden {
  opacity: 0;
  translate: 0 10px;
  pointer-events: none;
}

.hint__arrow {
  width: 56px;
  height: auto;
  margin: 0 0 0 28px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  scale: -1 1; /* на телефоне стрелка смотрит вниз-вправо */
}


/* 7. Эмоции
   -------------------------------------------------------------------------- */

.emotes {
  --emote: 46px;
  display: grid;
  grid-template-columns: repeat(4, var(--emote));
  justify-content: center;
  gap: 12px 14px;
  margin-top: var(--sp-3);
}

.emote {
  display: grid;
  place-items: center;
  width: var(--emote);
  height: var(--emote);
  padding: 0;
  border: var(--line);
  border-radius: 50%;
  background: var(--cream);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-emoji);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition:
    background-color .15s ease,
    box-shadow .15s ease,
    transform .15s var(--ease-spring);
}

@media (hover: hover) {
  .emote:hover {
    background: var(--sun);
  }
}

.emote:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
  transition-duration: .05s;
}


/* 8. Текст: привет, имя, о себе
   -------------------------------------------------------------------------- */

.intro {
  min-width: 0;
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.kicker {
  display: inline-block;
  margin: 0 0 var(--sp-5);
  padding: 8px 14px 9px;
  border: var(--line);
  border-radius: 999px;
  background: var(--sun);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(13px, 1.05vw, 16px);
  line-height: 1;
  rotate: -3deg;
}

.name {
  margin: 0;
  color: var(--cream);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(46px, 7.2vw, 108px);
  /* не шире колонки: «Фамилия» ≈ 6.3em. Длинная фамилия — уменьши 15.5cqi */
  font-size: clamp(46px, min(7.2vw, 15.5cqi), 108px);
  line-height: .95;
  letter-spacing: -.02em;
  overflow-wrap: anywhere;
}

.name__last {
  position: relative;
  display: inline-block;
}

/* жёлтая «от руки» волна под фамилией */
.squiggle {
  position: absolute;
  left: -.03em;
  bottom: -.3em;
  width: calc(100% + .06em);
  height: .28em;
  max-width: none;
  overflow: visible;
  fill: none;
  stroke: var(--sun);
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.role {
  max-width: 32ch;
  margin: calc(var(--sp-6) + .2em) 0 0;
  color: var(--cream-90);
  font-size: clamp(17px, 1.45vw, 21px);
  line-height: 1.5;
  text-wrap: pretty;
}


/* 9. Ссылки-таблетки
   -------------------------------------------------------------------------- */

.links {
  width: 100%;
  margin-top: var(--sp-6);
}

/* узкая колонка — сетка 2×2, широкая — одна строка (см. @container ниже) */
.links__list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  max-width: 360px;
  margin: 0 auto;
  padding: 0;
  list-style: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  padding: 12px 20px 12px 17px;
  border: var(--line);
  border-radius: 999px;
  background: var(--cream);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition:
    transform .2s var(--ease-spring),
    box-shadow .2s ease,
    background-color .2s ease;
}

@media (hover: hover) {
  .pill:hover {
    background: var(--sun);
    box-shadow: 6px 6px 0 var(--ink);
    transform: translateY(-2px) rotate(-1.5deg);
  }
}

.pill:active {
  box-shadow: 1px 1px 0 var(--ink);
  transform: translate(3px, 3px);
  transition-duration: .06s;
}

.pill:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: 4px;
}

.pill__icon {
  flex: none;
  width: 20px;
  height: 20px;
  fill: currentColor;
}


/* 10. Счётчик
   -------------------------------------------------------------------------- */

.stat {
  margin: var(--sp-6) 0 0;
  color: var(--cream-75);
  font-size: 15px;
  font-weight: 500;
}

.stat b {
  display: inline-block;
  color: var(--sun);
  font-family: var(--font-display);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* число подпрыгивает, когда кто-то (ты или другой гость) потянул лицо */
@media (prefers-reduced-motion: no-preference) {
  .stat b.is-bumped {
    animation: count-bump .4s cubic-bezier(.3, 1.6, .5, 1);
  }
}

@keyframes count-bump {
  40% { transform: scale(1.35) rotate(-4deg); }
}


/* 11. Подвал
   -------------------------------------------------------------------------- */

.footer {
  position: relative;
  z-index: 1;
  padding:
    var(--sp-4)
    max(var(--gutter), env(safe-area-inset-right))
    max(var(--sp-4), env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
  color: var(--cream-55);
  font-size: 13px;
  text-align: center;
}

.footer p {
  margin: 0;
}


/* 12. Холст движка (поверх страницы, клики проходят насквозь)
   -------------------------------------------------------------------------- */

#face-canvas {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Пока движок не показал лицо (или упал и потерял WebGL-контекст), холст
   прячем: Chrome рисует на месте потерянного контекста белую заглушку */
body:not(:has(.face-slot.is-live)) #face-canvas {
  visibility: hidden;
}


/* 13. Облачко с репликой
   left/top (из app.js) — это кончик хвоста. Хвост внизу слева,
   облачко рисуется вверх-вправо; .bubble--flip — зеркально.
   -------------------------------------------------------------------------- */

.bubble {
  --tail-x: 4px;   /* кончик хвоста левее края облачка */
  --tail-y: 18px;  /* и ниже его нижней кромки */
  --bubble-bg: var(--paper);
  --pop-from: -10deg;
  --pop-mid: 3deg;
  --shift: translate(var(--tail-x), calc(-100% - var(--tail-y)));
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  width: max-content;
  max-width: min(260px, calc(100vw - 32px));
  padding: 10px 16px 11px;
  border: 3px solid var(--ink);
  border-radius: 22px 22px 22px 6px;
  background: var(--bubble-bg);
  color: var(--ink);
  filter: drop-shadow(4px 4px 0 var(--ink));
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(16px, 2vw, 24px);
  line-height: 1.15;
  letter-spacing: -.01em;
  text-align: left;
  overflow-wrap: break-word;
  opacity: 0;
  pointer-events: none;
  transform: var(--shift) scale(.6);
  transform-origin: calc(-1 * var(--tail-x)) calc(100% + var(--tail-y));
  transition: opacity .16s ease, transform .16s ease;
}

.bubble__text {
  display: block;
  text-wrap: balance;
}

/* хвост: чёрный треугольник + треугольник цвета облачка поверх */
.bubble::before,
.bubble::after {
  content: "";
  position: absolute;
  top: calc(100% - 2px);
  left: -11px;
  width: 56px;
  height: 28px;
  pointer-events: none;
}

.bubble::before {
  background: var(--ink);
  clip-path: polygon(18px 2px, 52px 2px, 4px 23px);
}

.bubble::after {
  background: var(--bubble-bg);
  clip-path: polygon(22.3px 1px, 46.8px 1px, 12.2px 16.2px);
}

.bubble.is-visible {
  opacity: 1;
  transform: var(--shift);
  animation: bubble-pop .26s both;
}

.bubble--flip {
  --shift: translate(calc(-100% - var(--tail-x)), calc(-100% - var(--tail-y)));
  --pop-from: 10deg;
  --pop-mid: -3deg;
  border-radius: 22px 22px 6px 22px;
  transform-origin: calc(100% + var(--tail-x)) calc(100% + var(--tail-y));
}

.bubble--flip::before,
.bubble--flip::after {
  left: auto;
  right: -11px;
  transform: scaleX(-1);
}

.bubble--shout {
  --bubble-bg: var(--sun);
  max-width: min(320px, calc(100vw - 32px));
  font-size: clamp(20px, 2.8vw, 34px);
  font-weight: 800;
}

.bubble--shout.is-visible {
  animation:
    bubble-pop .26s both,
    bubble-jitter .1s linear .26s infinite;
}


/* 14. Кнопка звука
   -------------------------------------------------------------------------- */

.sound-toggle {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 30;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: var(--line);
  border-radius: 50%;
  background: var(--cream);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-emoji);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  transition:
    background-color .15s ease,
    box-shadow .15s ease,
    transform .15s var(--ease-spring);
}

@media (hover: hover) {
  .sound-toggle:hover {
    box-shadow: 4px 5px 0 var(--ink);
    transform: translateY(-2px) rotate(-8deg);
  }
}

.sound-toggle:active {
  box-shadow: 1px 1px 0 var(--ink);
  transform: translate(2px, 2px);
  transition-duration: .05s;
}

.sound-toggle[aria-pressed="true"] {
  background: var(--sun);
}

.sound-toggle__icon {
  grid-area: 1 / 1;
}

.sound-toggle:not([aria-pressed="true"]) .sound-toggle__icon--on,
.sound-toggle[aria-pressed="true"] .sound-toggle__icon--off {
  display: none;
}


/* 15. Состояния
   -------------------------------------------------------------------------- */

html.is-grabbing,
html.is-grabbing * {
  cursor: grabbing !important;
  user-select: none;
  -webkit-user-select: none;
}


/* 16. Планшет и десктоп
   -------------------------------------------------------------------------- */

@media (min-width: 480px) {
  .emotes {
    grid-template-columns: repeat(8, var(--emote));
    gap: 10px;
  }
}

@container (min-width: 560px) {
  .links__list {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px 16px;
    max-width: none;
  }

  .pill {
    width: auto;
  }
}

@media (min-width: 900px) {
  :root {
    --gutter: clamp(24px, 4vw, 64px);
    --face-h: calc(76 * var(--vh));
    --face-max: 660px;
  }

  .hero {
    padding-top: max(clamp(48px, 8vh, 80px), env(safe-area-inset-top));
    padding-bottom: clamp(12px, 2vh, 32px);
  }

  .footer {
    padding-top: var(--sp-3);
    padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom));
  }

  /* колонка лица = лицо + воздух по бокам, остальное — тексту */
  .hero__inner {
    grid-template-columns: minmax(0, min(calc(var(--face-w) + 48px), 50%)) minmax(0, 1fr);
    column-gap: clamp(32px, 5vw, 96px);
  }

  .stage {
    padding-top: 0;
  }

  /* подсказка над макушкой справа, стрелка вниз-влево — кончик у волос */
  .hint {
    --nudge-x: -3px;
    top: max(-60px, calc(8.5% - 97px));
    left: 72.5%;
  }

  .hint__arrow {
    width: 64px;
    margin: 0 0 0 -30px;
    scale: 1 1;
  }

  .emotes {
    --emote: clamp(40px, 4.4vw, 46px);
    gap: clamp(6px, .8vw, 10px);
    margin-top: clamp(8px, 1.5vh, 16px);
  }

  .intro {
    align-items: flex-start;
    text-align: left;
  }

  .links__list {
    justify-content: flex-start;
    margin-inline: 0;
  }
}


/* 17. Анимации
   -------------------------------------------------------------------------- */

@keyframes bubble-pop {
  0% {
    opacity: 0;
    transform: var(--shift) rotate(var(--pop-from)) scale(.4);
    animation-timing-function: cubic-bezier(.2, .9, .35, 1.15);
  }
  40% {
    opacity: 1;
  }
  62% {
    transform: var(--shift) rotate(var(--pop-mid)) scale(1.08);
    animation-timing-function: cubic-bezier(.45, 0, .4, 1);
  }
  100% {
    opacity: 1;
    transform: var(--shift) rotate(0deg) scale(1);
  }
}

@keyframes bubble-jitter {
  0%, 100% { translate: 0 0; }
  25% { translate: -1.5px 1px; }
  50% { translate: 1px -1.5px; }
  75% { translate: 1.5px 1px; }
}

@keyframes face-jelly {
  0%   { transform: none; }
  14%  { transform: scale(1.08, .92) rotate(-2deg); }
  30%  { transform: scale(.94, 1.06) rotate(2deg); }
  46%  { transform: scale(1.04, .96) rotate(-1deg); }
  62%  { transform: scale(.98, 1.02) rotate(.5deg); }
  80%  { transform: scale(1.01, .99); }
  100% { transform: none; }
}

@keyframes face-nudge {
  0%, 100% { transform: none; }
  40%      { transform: scale(1.02, .98); }
}

@keyframes hint-nudge {
  0%, 62%, 100% { translate: 0 0; }
  74% { translate: var(--nudge-x) 4px; }
  86% { translate: 0 0; }
}

@keyframes emote-bounce {
  0%   { translate: 0 0; rotate: 0deg; }
  30%  { translate: 0 -7px; rotate: -8deg; }
  55%  { translate: 0 0; rotate: 4deg; }
  75%  { translate: 0 -2px; rotate: -2deg; }
  100% { translate: 0 0; rotate: 0deg; }
}

@keyframes squiggle-draw {
  from { clip-path: inset(0 100% 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}

/* декоративное движение — только если человек не просил его убрать */
@media (prefers-reduced-motion: no-preference) {
  .hint__arrow {
    animation: hint-nudge 2.6s ease-in-out 1.2s infinite;
  }

  .squiggle {
    animation: squiggle-draw .9s cubic-bezier(.65, 0, .35, 1) .35s backwards;
  }

  @media (hover: hover) {
    .emote:hover {
      animation: emote-bounce .55s var(--ease-out);
    }
  }
}


/* 18. Меньше движения
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .bubble,
  .hint,
  .pill,
  .emote,
  .sound-toggle {
    transition-duration: .01ms;
  }

  .bubble.is-visible,
  .bubble--shout.is-visible {
    animation: none;
  }

  .pill:hover,
  .sound-toggle:hover {
    transform: none;
  }

  .face-fallback.is-shaking {
    animation: face-nudge .3s ease-out;
  }
}
