/* Knobs for the mockup. Scene copy lives in js/scenarios.js. */
:root {
  --violet-950: #100814;
  --violet-900: #1a0d24;
  --plum-800: #3c2158;
  --plum-600: #6e458c;
  --gold-400: #e4c27a;
  --gold-200: #f6e6bf;
  --cream: #fff6ea;
  --skin: #f0c2a4;
  --skin-deep: #d49878;
  --eye: #6a3a26;
  --online: #8fd4a4;

  --bubble-alpha: 0.34;
  --bubble-user-alpha: 0.4;
  --scrim-strength: 0.86;
  --fade-duration: 360ms;

  --nera-scale: 1;
  --nera-offset-x: 0px;
  --nera-offset-y: 0px;
  --nera-top: 2.5%;
  --nera-width: 100%;
  --nera-height: 62%;

  --tg-safe-top: 0px;
  --tg-safe-right: 0px;
  --tg-safe-bottom: 0px;
  --tg-safe-left: 0px;
  --vv-offset: 0px;
  --app-height: 100dvh;
  /* 1 design pixel on a 390px-wide phone, so chat text stays a normal size and still scales with the screen. */
  --px: calc(100vw / 390);
  --px: calc(100dvw / 390);

  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-top));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-right));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-left));

  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: #07040d;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--cream);
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}

img {
  max-width: 100%;
}

.app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: var(--app-height);
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--violet-950);
  transform: translateY(var(--vv-offset));
  font-size: calc(16 * var(--px));
}

@media (min-width: 560px) {
  .app {
    --frame: min(96dvh, 960px, calc((100vw - 48px) * 16 / 9));
    --px: calc(var(--frame) * 9 / 16 / 390);
    width: calc(var(--frame) * 9 / 16);
    height: var(--frame);
    max-height: none;
    border-radius: calc(28 * var(--px));
    box-shadow:
      0 0 0 calc(1 * var(--px)) rgba(228, 194, 122, 0.28),
      0 calc(30 * var(--px)) calc(80 * var(--px)) rgba(0, 0, 0, 0.48);
  }
}

/* Scene */
.app.is-booting > :not(.loader) {
  visibility: hidden;
}

.loader {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: var(--violet-950);
}

.app:not(.is-booting) .loader {
  display: none;
}

.loader-spin {
  width: calc(44 * var(--px));
  height: calc(44 * var(--px));
  border-radius: 50%;
  border: calc(3 * var(--px)) solid rgba(228, 194, 122, 0.28);
  border-top-color: var(--gold-400);
  animation: spin 0.8s linear infinite;
}

.loader-note {
  margin: 0;
  max-width: 16em;
  padding: 0 calc(24 * var(--px));
  text-align: center;
  font-size: calc(15 * var(--px));
  line-height: 1.4;
  color: var(--cream);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.room,
.bg-photo {
  position: absolute;
  inset: 0;
}

.room {
  background:
    radial-gradient(ellipse at 50% 0%, rgba(92, 62, 140, 0.45), transparent 52%),
    linear-gradient(180deg, #2a1844 0%, #1a1028 42%, #140c18 100%);
}

.bg-photo {
  z-index: 1;
  background: url("../assets/background.webp") center top / contain no-repeat;
}

.moon-glow {
  position: absolute;
  top: -6%;
  left: 50%;
  width: 78%;
  height: 46%;
  transform: translateX(-50%);
  background: radial-gradient(circle at 50% 42%, rgba(255, 236, 206, 0.34), rgba(146, 112, 196, 0.16) 34%, transparent 68%);
}

.window {
  position: absolute;
  top: 8%;
  right: 8%;
  width: 34%;
  height: 22%;
  border-radius: calc(14 * var(--px)) calc(14 * var(--px)) calc(6 * var(--px)) calc(6 * var(--px));
  border: calc(7 * var(--px)) solid rgba(228, 198, 150, 0.38);
  background:
    radial-gradient(circle at 38% 46%, #f8edd0 0 calc(11 * var(--px)), rgba(248, 237, 208, 0.35) calc(13 * var(--px)), transparent calc(16 * var(--px))),
    linear-gradient(180deg, #24345c, #4a3568 70%, #2a1c3c);
  box-shadow:
    0 0 calc(36 * var(--px)) rgba(186, 160, 230, 0.28),
    inset 0 0 calc(18 * var(--px)) rgba(0, 0, 0, 0.35);
}

.window::before,
.window::after {
  content: "";
  position: absolute;
  background: rgba(228, 198, 150, 0.32);
}

.window::before {
  left: 50%;
  top: 0;
  bottom: 0;
  width: calc(5 * var(--px));
  transform: translateX(-50%);
}

.window::after {
  top: 42%;
  left: 0;
  right: 0;
  height: calc(5 * var(--px));
}

.stars {
  position: absolute;
  top: 9%;
  left: 18%;
  width: calc(2 * var(--px));
  height: calc(2 * var(--px));
  border-radius: 50%;
  background: #fff;
  box-shadow:
    calc(12 * var(--px)) calc(18 * var(--px)) 0 rgba(255, 255, 255, 0.8),
    calc(40 * var(--px)) calc(6 * var(--px)) 0 rgba(255, 244, 214, 0.9),
    calc(70 * var(--px)) calc(28 * var(--px)) 0 rgba(255, 255, 255, 0.55),
    calc(110 * var(--px)) calc(10 * var(--px)) 0 rgba(255, 236, 200, 0.7),
    calc(150 * var(--px)) calc(24 * var(--px)) 0 rgba(255, 255, 255, 0.45),
    calc(28 * var(--px)) calc(40 * var(--px)) 0 rgba(255, 255, 255, 0.35);
}

.shelf {
  position: absolute;
  top: 31%;
  left: 5%;
  width: 18%;
  height: 18%;
  display: flex;
  align-items: flex-end;
  gap: calc(3 * var(--px));
  padding: 0 calc(3 * var(--px)) calc(4 * var(--px));
  border-bottom: calc(3 * var(--px)) solid rgba(228, 194, 122, 0.42);
  background: linear-gradient(to top, rgba(36, 18, 28, 0.35), transparent 70%);
}

.book {
  display: block;
  width: 22%;
  border-radius: calc(2 * var(--px)) calc(2 * var(--px)) 0 0;
}

.book-a { height: 68%; background: #7a3d58; }
.book-b { height: 88%; background: #3d2a68; }
.book-c { height: 58%; background: #c6a56e; }
.book-d { height: 76%; background: #4e2d5c; }

.candle {
  position: absolute;
  top: 46%;
  width: calc(8 * var(--px));
  height: calc(28 * var(--px));
  border-radius: calc(2 * var(--px));
  background: linear-gradient(#f6e7c8, #c9a36a);
}

.candle-left { left: 7%; }
.candle-right { right: 8%; }

.candle i {
  position: absolute;
  left: 50%;
  top: calc(-16 * var(--px));
  width: calc(12 * var(--px));
  height: calc(18 * var(--px));
  transform: translateX(-50%);
  background: radial-gradient(circle at 50% 70%, #fff6d2, #f0a040 42%, transparent 72%);
  animation: flame 1.5s ease-in-out infinite;
}

.candle-right i { animation-delay: -0.6s; }

.floor {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42%;
  background: linear-gradient(to top, rgba(18, 8, 16, 0.72), rgba(42, 22, 40, 0.18) 55%, transparent);
}

@keyframes flame {
  0%,
  100% { transform: translateX(-50%) scale(1); opacity: 0.9; }
  50% { transform: translateX(-50%) scale(1.08, 1.15); opacity: 1; }
}

.character {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: var(--nera-top);
  width: var(--nera-width);
  height: var(--nera-height);
  transform:
    translateX(calc(-50% + var(--nera-offset-x)))
    translateY(var(--nera-offset-y))
    scale(var(--nera-scale));
  transform-origin: center top;
}

.sprite,
.silhouette {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity var(--fade-duration) ease;
}

.sprite {
  object-fit: contain;
  object-position: center top;
}

.sprite:not([src]) {
  visibility: hidden;
}

.sprite.is-visible,
.silhouette.is-visible {
  opacity: 1;
}

.silhouette.is-visible.is-dim {
  opacity: 0;
}

.silhouette svg {
  display: block;
  width: 100%;
  height: 100%;
}

.face-expr { opacity: 0; }
.silhouette[data-emotion="neutral"] .expr-neutral,
.silhouette[data-emotion="happy"] .expr-happy,
.silhouette[data-emotion="empathetic"] .expr-empathetic,
.silhouette[data-emotion="excited"] .expr-excited {
  opacity: 1;
}

.blush { opacity: 0.28; }
.silhouette[data-emotion="happy"] .blush { opacity: 0.42; }
.silhouette[data-emotion="excited"] .blush { opacity: 0.55; }
.silhouette[data-emotion="empathetic"] .blush { opacity: 0.16; }

.foreground {
  position: absolute;
  z-index: 3;
  inset: 0;
  background: url("../assets/foreground.webp") center top / contain no-repeat;
}

.sparkles {
  position: absolute;
  z-index: 4;
  inset: 0;
  opacity: 0;
  transition: opacity var(--fade-duration) ease;
}

.app.show-sparkles .sparkles {
  opacity: 1;
}

.sparkles i {
  position: absolute;
  width: calc(6 * var(--px));
  height: calc(6 * var(--px));
  border-radius: 50%;
  background: radial-gradient(circle, #fff8dc, #e4c27a 55%, transparent 72%);
  animation: twinkle 1.8s ease-in-out infinite;
}

.sparkles i:nth-child(1) { top: 16%; left: 22%; }
.sparkles i:nth-child(2) { top: 12%; left: 70%; animation-delay: -0.4s; }
.sparkles i:nth-child(3) { top: 24%; left: 80%; animation-delay: -1s; }
.sparkles i:nth-child(4) { top: 20%; left: 14%; width: calc(4 * var(--px)); height: calc(4 * var(--px)); animation-delay: -1.3s; }
.sparkles i:nth-child(5) { top: 30%; left: 74%; width: calc(4 * var(--px)); height: calc(4 * var(--px)); animation-delay: -0.8s; }

@keyframes twinkle {
  0%,
  100% { transform: scale(0.7); opacity: 0.35; }
  50% { transform: scale(1.15); opacity: 1; }
}

.scrim {
  position: absolute;
  z-index: 5;
  inset: 0;
  background: linear-gradient(
    to top,
    rgba(14, 6, 22, calc(var(--scrim-strength) * 0.94)) 0%,
    rgba(16, 8, 26, calc(var(--scrim-strength) * 0.62)) 24%,
    rgba(18, 8, 28, calc(var(--scrim-strength) * 0.28)) 42%,
    rgba(18, 8, 28, 0) 62%
  );
}

/* Chrome */
.header,
.chat,
.composer,
.indicator,
.arrow,
.menu,
.modal,
.toast {
  position: relative;
  z-index: 6;
}

.header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: calc(8 * var(--px));
  min-height: calc(56 * var(--px));
  padding: calc(6 * var(--px) + var(--safe-top)) calc(8 * var(--px) + var(--safe-right)) calc(8 * var(--px)) calc(8 * var(--px) + var(--safe-left));
  background: linear-gradient(to bottom, rgba(12, 6, 20, 0.55), rgba(12, 6, 20, 0));
}

.identity {
  display: flex;
  align-items: center;
  gap: calc(10 * var(--px));
  min-width: 0;
  flex: 1;
}

.avatar {
  flex: 0 0 auto;
  width: calc(36 * var(--px));
  height: calc(36 * var(--px));
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #6a4588, #2a1840);
  box-shadow: 0 0 0 calc(1 * var(--px)) rgba(228, 194, 122, 0.45);
}

.avatar svg {
  display: block;
  width: calc(20 * var(--px));
  height: calc(20 * var(--px));
}

.titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.name {
  font-size: calc(16 * var(--px));
  font-weight: 650;
  letter-spacing: 0.01em;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: calc(6 * var(--px));
  margin-top: calc(2 * var(--px));
  font-size: calc(12 * var(--px));
  color: rgba(255, 246, 234, 0.78);
}

.status i {
  width: calc(7 * var(--px));
  height: calc(7 * var(--px));
  border-radius: 50%;
  background: var(--online);
  box-shadow: 0 0 calc(6 * var(--px)) rgba(143, 212, 164, 0.8);
}

.icon-btn {
  flex: 0 0 auto;
  width: calc(44 * var(--px));
  height: calc(44 * var(--px));
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--gold-200);
}

.icon-btn svg {
  display: block;
  width: calc(22 * var(--px));
  height: calc(22 * var(--px));
}

#menu-btn svg,
#send svg {
  width: calc(20 * var(--px));
  height: calc(20 * var(--px));
}

.icon-btn:hover {
  background: rgba(255, 246, 234, 0.08);
}

.indicator {
  position: absolute;
  z-index: 7;
  top: auto;
  bottom: calc(68 * var(--px) + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: calc(3 * var(--px)) calc(10 * var(--px));
  border-radius: 999px;
  border: calc(1 * var(--px)) solid rgba(228, 194, 122, 0.24);
  background: rgba(18, 8, 28, 0.4);
  backdrop-filter: blur(calc(8 * var(--px)));
  font-size: calc(12 * var(--px));
  line-height: 1.3;
  letter-spacing: 0.01em;
  color: var(--gold-200);
  white-space: nowrap;
  pointer-events: none;
  text-shadow: 0 calc(1 * var(--px)) calc(8 * var(--px)) rgba(8, 2, 16, 0.75);
}

.arrow {
  position: absolute;
  z-index: 7;
  top: clamp(calc(108 * var(--px)), 33%, 42%);
  width: calc(42 * var(--px));
  height: calc(42 * var(--px));
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--gold-200);
  background: rgba(16, 8, 24, 0.32);
  border: calc(1 * var(--px)) solid rgba(228, 194, 122, 0.28);
  backdrop-filter: blur(calc(8 * var(--px)));
  box-shadow: 0 calc(8 * var(--px)) calc(20 * var(--px)) rgba(0, 0, 0, 0.18);
}

.arrow svg {
  display: block;
  width: calc(18 * var(--px));
  height: calc(18 * var(--px));
}

.arrow-prev { left: calc(8 * var(--px) + var(--safe-left)); }
.arrow-next { right: calc(8 * var(--px) + var(--safe-right)); }

.arrow:hover { background: rgba(16, 8, 24, 0.5); }

.chat {
  --fade-start: 0px;
  --fade-end: 0px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
  padding-bottom: calc(4 * var(--px));
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0,
    transparent var(--fade-start),
    #000 var(--fade-end),
    #000 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0,
    transparent var(--fade-start),
    #000 var(--fade-end),
    #000 100%
  );
}

.chat-spacer {
  display: none;
}

.chat.is-swapping .bubble-list {
  opacity: 0;
}

.bubble-list {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: calc(8 * var(--px));
  width: 100%;
  margin: 0;
  margin-top: auto;
  padding: var(--fade-end) calc(12 * var(--px)) calc(40 * var(--px));
  transition: opacity calc(var(--fade-duration) * 0.55) ease;
}

.bubble {
  max-width: 88%;
  padding: calc(10 * var(--px)) calc(14 * var(--px));
  border-radius: calc(18 * var(--px));
  border: calc(1 * var(--px)) solid rgba(246, 226, 176, 0.22);
  box-shadow: 0 calc(10 * var(--px)) calc(24 * var(--px)) rgba(10, 4, 18, 0.22);
  backdrop-filter: blur(calc(12 * var(--px)));
  -webkit-backdrop-filter: blur(calc(12 * var(--px)));
}

.bubble p {
  margin: 0;
  font-size: calc(15 * var(--px));
  line-height: 1.35;
  color: var(--cream);
  opacity: 1;
  overflow-wrap: anywhere;
}

.bubble-nera {
  border-bottom-left-radius: calc(6 * var(--px));
  background: rgba(98, 58, 138, var(--bubble-alpha));
}

.bubble-user {
  align-self: flex-end;
  border-bottom-right-radius: calc(6 * var(--px));
  background: rgba(122, 78, 48, var(--bubble-user-alpha));
  border-color: rgba(240, 210, 150, 0.32);
}

.bubble.is-new {
  animation: rise 280ms ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(calc(6 * var(--px))); }
  to { opacity: 1; transform: none; }
}

.boot-note {
  margin: calc(12 * var(--px)) calc(16 * var(--px));
  font-size: calc(13 * var(--px));
  line-height: 1.4;
  color: rgba(255, 246, 234, 0.8);
}

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: calc(6 * var(--px));
  padding: calc(8 * var(--px)) calc(10 * var(--px) + var(--safe-right)) calc(10 * var(--px) + var(--safe-bottom)) calc(10 * var(--px) + var(--safe-left));
  background: linear-gradient(to top, rgba(12, 6, 18, 0.62), rgba(12, 6, 18, 0.12));
}

.composer input {
  flex: 1 1 auto;
  min-width: 0;
  height: calc(44 * var(--px));
  padding: 0 calc(14 * var(--px));
  border-radius: 999px;
  border: calc(1 * var(--px)) solid rgba(228, 194, 122, 0.24);
  background: rgba(255, 246, 234, 0.1);
  color: var(--cream);
  font-size: calc(15 * var(--px));
  outline: none;
}

.composer input::placeholder {
  color: rgba(255, 246, 234, 0.62);
}

.composer input:focus {
  border-color: rgba(228, 194, 122, 0.55);
  background: rgba(255, 246, 234, 0.14);
}

.send[disabled] {
  opacity: 0.4;
  cursor: default;
}

.send:not([disabled]) {
  background: rgba(228, 194, 122, 0.18);
}

.menu {
  position: absolute;
  z-index: 20;
  top: calc(52 * var(--px) + var(--safe-top));
  right: calc(10 * var(--px) + var(--safe-right));
  min-width: calc(196 * var(--px));
  padding: calc(6 * var(--px));
  border-radius: calc(14 * var(--px));
  border: calc(1 * var(--px)) solid rgba(228, 194, 122, 0.28);
  background: rgba(28, 16, 42, 0.94);
  box-shadow: 0 calc(16 * var(--px)) calc(40 * var(--px)) rgba(0, 0, 0, 0.35);
}

.menu[hidden],
.modal[hidden] {
  display: none !important;
}

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: calc(10 * var(--px)) calc(12 * var(--px));
  border-radius: calc(10 * var(--px));
  color: var(--cream);
  font-size: calc(15 * var(--px));
}

.menu button:hover { background: rgba(255, 246, 234, 0.08); }

.modal {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(24 * var(--px));
  background: rgba(8, 4, 14, 0.5);
}

.modal-card {
  width: min(100%, calc(360 * var(--px)));
  max-height: min(80%, calc(520 * var(--px)));
  overflow: auto;
  padding: calc(20 * var(--px)) calc(18 * var(--px)) calc(16 * var(--px));
  border-radius: calc(18 * var(--px));
  border: calc(1 * var(--px)) solid rgba(228, 194, 122, 0.3);
  background: rgba(28, 16, 44, 0.96);
  box-shadow: 0 calc(24 * var(--px)) calc(60 * var(--px)) rgba(0, 0, 0, 0.4);
}

.modal-card h2 {
  margin: 0 0 calc(10 * var(--px));
  font-size: calc(18 * var(--px));
  font-weight: 650;
  color: var(--gold-200);
}

.modal-card p {
  margin: 0 0 calc(10 * var(--px));
  font-size: calc(14.5 * var(--px));
  line-height: 1.45;
  color: var(--cream);
}

.modal-close {
  margin-top: calc(6 * var(--px));
  min-height: calc(40 * var(--px));
  padding: calc(8 * var(--px)) calc(16 * var(--px));
  border-radius: 999px;
  background: rgba(228, 194, 122, 0.18);
  border: calc(1 * var(--px)) solid rgba(228, 194, 122, 0.35);
  color: var(--gold-200);
}

.toast {
  position: absolute;
  z-index: 25;
  left: 50%;
  bottom: calc(74 * var(--px) + var(--safe-bottom));
  max-width: calc(100% - 32 * var(--px));
  padding: calc(8 * var(--px)) calc(12 * var(--px));
  border-radius: 999px;
  background: rgba(20, 10, 30, 0.9);
  border: calc(1 * var(--px)) solid rgba(228, 194, 122, 0.24);
  color: var(--cream);
  font-size: calc(13 * var(--px));
  line-height: 1.35;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(8 * var(--px)));
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-on {
  opacity: 1;
  transform: translate(-50%, 0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: calc(2 * var(--px)) solid var(--gold-400);
  outline-offset: calc(2 * var(--px));
}

.chat::-webkit-scrollbar { width: calc(8 * var(--px)); }
.chat::-webkit-scrollbar-thumb {
  background: rgba(228, 194, 122, 0.35);
  border-radius: 99px;
}

@media (prefers-reduced-motion: reduce) {
  :root { --fade-duration: 0ms; }

  .candle i,
  .sparkles i,
  .bubble.is-new,
  .loader-spin {
    animation: none;
  }
}
