:root {
  --black: #1c1f21;
  --white: #ffffff;
  --red: #eb4247;
  --red-soft: rgba(235, 66, 71, 0.1);
  --grey: #ebeae6;
  --glass: rgba(255, 255, 255, 0.66);
  --glass-blur: 20px;
  --glass-fallback: rgba(255, 255, 255, 0.92);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --app-h: 100dvh;
  --shell-inset: 120px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  background: #fff;
  color: var(--black);
  font-family: Manrope, sans-serif;
  font-weight: 500;
}

body {
  min-height: 100dvh;
}

/* Chat stays viewport-locked; home can grow and scroll the page */
body:has(.app[data-view="chat"]) {
  height: 100%;
  overflow: hidden;
}

button,
a {
  font-family: inherit;
}

[hidden] {
  display: none !important;
}

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

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

.bg-bubble-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: var(--z, 1);
  margin-left: calc(var(--mx, 0) * var(--shift, 40px));
  margin-top: calc(var(--my, 0) * var(--shift, 40px));
}

.bg-bubble {
  position: absolute;
  top: 72vh;
  aspect-ratio: 900 / 528;
  z-index: var(--z, 1);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  animation: bubble-crawl var(--duration, 54s) linear infinite;
  animation-delay: var(--delay, 0s);
}

.bg-bubble--tail-left,
.bg-bubble--tail-right {
  right: auto;
  left: var(--x, -40px);
  width: calc(min(70vw, 900px) * var(--scale, 1));
}

.bg-bubble--tail-left {
  background-image: url("../images/bubble_2.svg");
}

.bg-bubble--tail-right {
  background-image: url("../images/bubble_1.svg?v=2");
}

@keyframes bubble-crawl {
  0% {
    top: 72vh;
    opacity: 0;
  }
  5% {
    opacity: 1;
  }
  92% {
    opacity: 1;
  }
  100% {
    top: -78vh;
    opacity: 0;
  }
}

.app {
  position: relative;
  z-index: 1;
  min-height: var(--app-h, 100dvh);
  overflow: visible;
}

.app[data-view="chat"] {
  height: var(--app-h, 100dvh);
  min-height: var(--app-h, 100dvh);
  overflow: hidden;
}

.shell {
  position: relative;
  display: grid;
  grid-template-columns: 500px minmax(0, 1fr);
  /* min-content floor: grow with home copy instead of letting it paint over the footer */
  grid-template-rows: minmax(min-content, 1fr) 60px;
  grid-template-areas:
    "main hero"
    "foot hero";
  column-gap: 100px;
  width: min(1200px, calc(100% - 240px));
  min-height: var(--app-h, 100dvh);
  margin: 0 auto;
  min-width: 0;
  overflow: visible;
}

.app[data-view="chat"] .shell {
  height: 100%;
  min-height: 0;
  max-height: 100%;
  /* visible: T-rex may paint past the shell; the window clips it */
  overflow: visible;
  grid-template-rows: minmax(0, 1fr) 60px;
}

.app[data-view="chat"] .col-main {
  min-height: 0;
  height: 100%;
  overflow: hidden;
  grid-template-rows: 60px minmax(0, 1fr);
}

.app[data-view="chat"] .view-chat {
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.col-main {
  grid-area: main;
  position: relative;
  display: grid;
  grid-template-rows: 60px minmax(min-content, 1fr);
  min-width: 0;
}

.top {
  grid-row: 1;
}

.view-home,
.view-chat {
  grid-row: 2;
  grid-column: 1;
}

.app[data-view="chat"] .view-chat {
  min-height: 0;
}

.view-home {
  z-index: 1;
}

.view-chat {
  z-index: 0;
}

.col-hero {
  grid-area: hero;
  position: relative;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  overflow: visible;
}

.foot {
  grid-area: foot;
}

.top,
.foot {
  flex: 0 0 60px;
  display: flex;
  align-items: center;
}

.logo {
  display: block;
  width: 120px;
  height: 24px;
}

.logo img {
  width: 120px;
  height: 24px;
}

.foot {
  font-size: 15px;
  line-height: 20px;
  color: rgba(28, 31, 33, 0.5);
}

.view-home {
  display: flex;
  flex-direction: column;
  /* safe: when the column is shorter than the stack, fall back to start
     so the title cannot slide under the 60px .top / logo row */
  justify-content: safe center;
  padding-top: 16px;
}

.hero-title {
  margin: 0;
  font-size: 84px;
  line-height: 83px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.hero-copy {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 10px 0 20px;
}

.hero-lead {
  margin: 0;
  font-size: 20px;
  line-height: 1.35;
  font-weight: 500;
}

.btn {
  appearance: none;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  border-radius: 12px;
  transition: transform 0.2s var(--ease), background-color 0.2s var(--ease), opacity 0.2s var(--ease);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0) scale(0.99);
}

.btn-primary {
  width: 100%;
  height: 64px;
  background: var(--red);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}

.btn-primary:hover {
  background: #de353a;
}

.btn-ghost {
  width: 250px;
  height: 48px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 15px;
  font-weight: 700;
}

.support {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px;
  border-radius: 12px;
}

.support-text {
  margin: 0;
  width: 400px;
  max-width: 100%;
  font-size: 15px;
  line-height: 20px;
  text-align: center;
  color: rgba(28, 31, 33, 0.5);
}

.character {
  position: relative;
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  height: var(--trex-h, 90dvh);
  overflow: visible;
  animation: float 5.6s ease-in-out infinite;
}

.character-img {
  width: auto;
  height: 100%;
  max-width: none;
  object-fit: contain;
  object-position: left bottom;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-22px);
  }
}

.view-chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-card {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
  padding: 20px;
  border-radius: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(28, 31, 33, 0.18) transparent;
}

.support,
.chat-card {
  position: relative;
  background: var(--glass-fallback);
}

@supports ((backdrop-filter: blur(20px)) or (-webkit-backdrop-filter: blur(20px))) {
  .support,
  .chat-card {
    background: var(--glass);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
  }
}

.chat-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: auto;
}

.row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
}

.row--bot {
  padding-right: 40px;
}

.row--user,
.row--action {
  justify-content: flex-end;
  padding-left: 40px;
}

.ava {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 100px;
  overflow: hidden;
  background: var(--red);
}

.ava img {
  width: 30px;
  height: 30px;
  object-fit: cover;
}

.ava--photo {
  background: #2b2b2b;
}

.ava--letter {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.bubble {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 10px;
  border-radius: 10px;
  background: var(--grey);
  overflow: visible;
}

.bubble::before {
  content: "";
  position: absolute;
  left: -11px;
  bottom: 0;
  width: 20px;
  height: 20px;
  background: url("../images/chat-tail.svg") right bottom / 17.1756px 17.1756px no-repeat;
  pointer-events: none;
}

.bubble-name {
  margin: 0;
  font-size: 13px;
  line-height: 18px;
  font-weight: 700;
  color: var(--red);
}

.bubble-text {
  margin: 0;
  font-size: 15px;
  line-height: 18px;
  font-weight: 500;
}

.bubble-time {
  margin: 0;
  font-size: 13px;
  line-height: 18px;
  color: rgba(28, 31, 33, 0.5);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  width: 100%;
}

.chip {
  appearance: none;
  background: transparent;
  border: 1px solid var(--black);
  border-radius: 100px;
  padding: 5px 10px;
  font-size: 15px;
  line-height: 20px;
  font-weight: 500;
  color: var(--black);
  cursor: pointer;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease), transform 0.2s var(--ease);
}

.chip:hover {
  background: var(--black);
  color: #fff;
}

.chip.is-picked,
.user-pill {
  border: 0;
  background: var(--black);
  color: #fff;
  border-radius: 100px;
  padding: 5px 10px;
  font-size: 15px;
  line-height: normal;
  font-weight: 500;
}

.rate {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--red-soft);
  border-radius: 10px;
  padding: 5px 10px 10px;
}

.rate-title {
  margin: 0 0 4px;
  font-size: 15px;
  line-height: 20px;
  font-weight: 700;
  color: var(--red);
}

.rate-stickers {
  display: flex;
  gap: 10px;
}

.sticker {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  width: 90px;
  height: 90px;
  cursor: pointer;
  transition: transform 0.2s var(--ease);
}

.sticker img {
  width: 90px;
  height: 90px;
}

.sticker:hover {
  transform: scale(1.06) rotate(-3deg);
}

.picked-sticker {
  width: 90px;
  height: 90px;
}

.picked-sticker img {
  width: 90px;
  height: 90px;
}

.cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;
  text-align: center;
}

.cta-avatars {
  display: flex;
  align-items: center;
}

.cta-avatars .ava {
  width: 60px;
  height: 60px;
  flex-basis: 60px;
}

.cta-avatars .ava img {
  width: 60px;
  height: 60px;
}

.cta-avatars .ava + .ava {
  margin-left: -8px;
}

.cta-title {
  margin: 8px 0 0;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 700;
}

.cta-text {
  margin: 10px 0 0;
  font-size: 20px;
  line-height: 1.35;
  font-weight: 500;
}

.cta .btn-primary {
  margin-top: 20px;
}

.typing {
  display: flex;
  gap: 4px;
  padding: 4px 2px 2px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(28, 31, 33, 0.35);
  animation: blink 1s infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

.appear {
  animation: appear 0.7s var(--ease) both;
  animation-delay: var(--d, 0ms);
}

.msg-in {
  animation: msg-in 0.45s var(--ease) both;
  animation-delay: var(--d, 0ms);
}

.msg-in-right {
  animation: msg-in-right 0.45s var(--ease) both;
  animation-delay: var(--d, 0ms);
}

@keyframes appear {
  from {
    opacity: 0;
    transform: translateY(22px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes msg-in-right {
  from {
    opacity: 0;
    transform: translateX(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.app[data-leaving="home"] .view-home,
.app[data-leaving="chat"] .view-chat {
  animation: view-out 0.4s ease both;
  pointer-events: none;
}

.app[data-view="chat"] .character {
  animation: float 5.6s ease-in-out infinite, hero-settle 0.7s var(--ease) both;
}

@keyframes view-out {
  to {
    opacity: 0;
  }
}

@keyframes hero-settle {
  from {
    opacity: 0.7;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 1099px) {
  :root {
    --shell-inset: 40px;
  }

  .shell {
    width: calc(100% - 80px);
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(200px, 1fr) 60px;
    grid-template-areas:
      "main"
      "hero"
      "foot";
    column-gap: 0;
  }

  .view-home {
    justify-content: flex-start;
    padding-bottom: 8px;
  }

  .col-hero {
    padding: 0;
    min-height: 0;
    overflow: visible;
    align-items: flex-end;
    justify-content: center;
  }

  .character {
    width: auto;
    max-width: 100%;
    height: calc(100% - 24px);
    max-height: calc(100% - 24px);
    min-height: 0;
    aspect-ratio: 487 / 800;
  }

  .character-img {
    width: auto;
    height: 100%;
    max-width: 100%;
    object-fit: contain;
    object-position: bottom center;
  }

  .app[data-view="home"] .shell {
    display: flex;
    flex-direction: column;
    grid-template-rows: none;
    grid-template-areas: none;
    min-height: var(--app-h, 100dvh);
  }

  .app[data-view="home"] .col-main {
    order: 1;
    flex: 0 0 auto;
  }

  /* Height = leftover to the window bottom (--trex-h); footer overlays */
  .app[data-view="home"] .col-hero {
    order: 2;
    flex: 0 0 auto;
    height: var(--trex-h, 40dvh);
    min-height: 200px;
  }

  .app[data-view="home"] .foot {
    order: 3;
    grid-area: auto;
    position: fixed;
    left: var(--shell-inset);
    right: var(--shell-inset);
    bottom: 0;
    z-index: 2;
    height: 60px;
    flex: 0 0 0;
    margin: 0;
  }

  .hero-title {
    font-size: 60px;
    line-height: 58px;
  }

  .bg-bubble--tail-left {
    left: var(--x, -30px);
    width: calc(min(96vw, 684px) * var(--scale, 1));
  }

  .bg-bubble--tail-right {
    left: auto;
    right: max(var(--x, 40px), calc(var(--x, 40px) * -1));
    width: calc(min(92vw, 640px) * var(--scale, 1));
  }

  .app[data-view="chat"] .col-hero {
    display: none;
  }

  .app[data-view="chat"] .shell {
    height: 100%;
    min-height: 0;
    max-height: 100%;
    grid-template-rows: minmax(0, 1fr) 60px;
    grid-template-areas:
      "main"
      "foot";
  }

}

@media (max-width: 600px) {
  :root {
    --shell-inset: 16px;
  }

  .shell {
    width: calc(100% - 32px);
  }

  .hero-title {
    font-size: 48px;
    line-height: 47px;
  }

  .hero-lead,
  .cta-text {
    font-size: 18px;
  }

  .hero-copy {
    gap: 16px;
    padding: 8px 0 12px;
  }

  .btn-primary {
    height: 56px;
  }

  .support {
    padding: 10px;
    gap: 10px;
  }

  .support-text {
    width: 100%;
  }

  .btn-ghost {
    width: min(250px, 100%);
  }

  .row--bot,
  .row--user,
  .row--action {
    padding-left: 0;
    padding-right: 0;
  }

  .chips {
    flex-direction: column;
    align-items: flex-end;
  }

  .cta-title {
    font-size: 24px;
  }
}

@media (max-width: 1099px) and (max-height: 760px) {
  .hero-title {
    font-size: 48px;
    line-height: 47px;
  }

  .hero-copy {
    gap: 12px;
    padding: 6px 0 10px;
  }

  .support {
    padding: 10px;
    gap: 10px;
  }
}

@media (max-width: 420px) {
  .hero-title {
    font-size: 48px;
    line-height: 47px;
  }

  .chip,
  .user-pill {
    white-space: normal;
    text-align: left;
  }
}

html[data-page-hidden] .bg-bubble,
html[data-page-hidden] .character {
  animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .appear,
  .msg-in,
  .msg-in-right {
    opacity: 1;
    transform: none;
  }

  .character {
    transform: none;
  }
}
