@font-face {
  font-family: "Zpix";
  src: url("../fonts/zpix.ttf") format("truetype");
  font-display: swap;
}

:root {
  --ink: #f4f4f4;
  --line: #e6e6e6;
  --bg: #05060c;
  --panel: #07070f;
  --mine: #3c4458;
  --select: #5c6578;
  --pixel: "Zpix", "SimSun", monospace;
}

* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; background: #000; color: var(--ink); }

body {
  font-family: var(--pixel);
  font-size: 16px;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  text-rendering: optimizeSpeed;
  font-smooth: never;
}

button, textarea { font-family: inherit; color: inherit; }

#main {
  height: 100dvh;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
}

#main::-webkit-scrollbar,
.log::-webkit-scrollbar { display: none; }

.cover, .chat {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
}

.cover {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.cover__field {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  display: none;
}

.cover__frame {
  position: relative;
  z-index: 1;
  width: min(100%, calc(100dvh * 576 / 1024));
  aspect-ratio: 576 / 1024;
  container-type: size;
}

.cover__art,
.cover__stars {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.cover__art {
  object-fit: fill;
  display: block;
}

.cover__stars { z-index: 1; pointer-events: none; }

.cover__title {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 6.4%;
  width: 92%;
  margin: 0;
  transform: translateX(-50%) scale(0.42);
  transform-origin: center center;
  text-align: center;
  color: #f3efe4;
  font-weight: 400;
  pointer-events: none;
  opacity: 0;
  animation: come-forward 2.1s steps(7, end) both;
}

.cover__en,
.cover__zh {
  display: block;
  font-family: "Zpix", monospace;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-smooth: never;
  text-rendering: optimizeSpeed;
  line-height: 1;
}

.cover__en {
  font-size: 42px;
  letter-spacing: 2px;
}

.cover__zh {
  font-size: 30px;
  letter-spacing: 4px;
  margin-top: 14px;
  animation: breathe 3.4s ease-in-out 2.1s infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.38; }
}

@keyframes come-forward {
  from { opacity: 0; transform: translateX(-50%) scale(0.42); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}

.cover__arrow {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 1.8%;
  transform: translateX(-50%);
  width: 5.2cqw;
  height: 6.6cqw;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.cover__arrow svg {
  width: 100%;
  height: 100%;
  display: block;
  fill: #f3efe4;
  animation: blink 1.05s steps(1, end) infinite;
}

@keyframes blink {
  0%, 45% { opacity: 1; }
  46%, 100% { opacity: 0; }
}

.chat { background: var(--bg); }

.chat__sky {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.chat__bar,
.log,
.dock { position: relative; z-index: 1; }

.chat__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 16px 8px;
}

.chat__avatar {
  position: relative;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  background: #000;
  flex-shrink: 0;
  cursor: pointer;
  overflow: visible;
}

.chat__avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
  transform-origin: 50% 70%;
}

.chat__avatar.is-pat img {
  animation: pat 0.42s steps(3, end);
}

.chat__avatar.is-drowsy img {
  animation: drowsy 0.36s steps(3, end) forwards;
}

.chat__avatar.is-wake img {
  animation: wake 0.56s steps(3, end);
}

.chat__avatar.is-wake.is-pat img {
  animation: wake 0.56s steps(3, end), pat 0.42s steps(3, end);
}

.zzz {
  position: absolute;
  left: 8px;
  top: -18px;
  width: 42px;
  height: 36px;
  pointer-events: none;
  opacity: 0;
}

.chat__avatar.is-tired .zzz,
.chat__avatar.is-wake .zzz { opacity: 1; }

.zzz i {
  position: absolute;
  right: 0;
  bottom: 0;
  font-style: normal;
  line-height: 1;
  color: #f7f4ea;
  animation: floatz 2.4s steps(5, end) infinite;
}

.zzz i:nth-child(1) { font-size: 12px; animation-delay: 0s; }
.zzz i:nth-child(2) { font-size: 14px; right: 8px; animation-delay: -0.8s; }
.zzz i:nth-child(3) { font-size: 18px; right: 16px; animation-delay: -1.6s; }

@keyframes pat {
  0% { transform: none; }
  34% { transform: translateY(3px) rotate(-8deg) scale(0.94, 1.06); }
  67% { transform: translateY(-2px) rotate(7deg) scale(1.06, 0.94); }
  100% { transform: none; }
}

@keyframes drowsy {
  0% { transform: none; }
  50% { transform: translateY(2px) rotate(8deg); }
  100% { transform: translateY(3px) rotate(4deg); }
}

@keyframes wake {
  0% { filter: brightness(0.62); }
  45% { filter: brightness(1.55); }
  100% { filter: brightness(1); }
}

@keyframes floatz {
  0% { opacity: 0; transform: translate(0, 12px); }
  20% { opacity: 1; transform: translate(-2px, 4px); }
  70% { opacity: 1; transform: translate(-6px, -12px); }
  100% { opacity: 0; transform: translate(-8px, -22px); }
}

.chat__name {
  display: flex;
  align-items: center;
  font-size: 24px;
  letter-spacing: 2px;
  line-height: 1;
  white-space: nowrap;
}

.chat__name > span {
  display: flex;
  align-items: center;
  height: 1em;
  font-size: inherit;
  line-height: 1;
  letter-spacing: inherit;
}

.dream {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  transition: opacity 0.55s steps(5, end), max-width 0.55s steps(5, end);
}

.chat__name.is-dream .dream {
  max-width: 5em;
  opacity: 1;
}

.chat {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.log {
  flex: 1;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px;
  padding: 18px 16px 132px;
}

.msg {
  box-sizing: border-box;
  width: fit-content;
  max-width: calc(100vw - 64px);
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  position: relative;
}

.msg--user {
  align-self: flex-end;
  background: var(--mine);
  max-width: min(78vw, 280px);
}

.msg--bot { align-self: flex-start; }

.msg--card {
  padding: 8px;
  background: #000;
}

.msg--card img {
  display: block;
  width: min(220px, 68vw);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.msg--sheet,
.msg--qr {
  padding: 8px;
}

.msg--sheet { background: #111; }
.msg--qr { background: #1c1c28; }

.msg--sheet img,
.msg--qr img {
  display: block;
  height: auto;
}

.msg--sheet img { width: min(260px, 74vw); }
.msg--qr img { width: min(220px, 64vw); }

.rainbow {
  background-image: linear-gradient(
    90deg,
    #ff4d6d,
    #ff9f1c,
    #ffe66d,
    #7ae582,
    #4cc9f0,
    #b388ff,
    #ff4d6d
  );
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: #ffe66d;
  animation: hue 2.8s linear infinite;
}

@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .rainbow { color: transparent; }
}

@keyframes hue {
  from { background-position: 0% 50%; }
  to { background-position: 220% 50%; }
}

.msg--bot::after,
.msg--user::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  background: inherit;
  border-right: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  transform: rotate(45deg);
  bottom: -7px;
}

.msg--bot::after { left: 22px; }
.msg--user::after { right: 18px; }

.caret {
  display: inline-block;
  width: 10px;
  height: 16px;
  background: #fff;
  vertical-align: -2px;
  margin-left: 2px;
  animation: blink 1.05s steps(1, end) infinite;
}

.dock {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 2;
}

.picker {
  margin-bottom: 8px;
  border: 2px solid var(--line);
  background: #050508;
}

.picker[hidden] { display: none; }

.picker button {
  display: block;
  width: 100%;
  text-align: center;
  padding: 14px 12px;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: transparent;
  font-size: 16px;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.picker button:last-child { border-bottom: 0; }

.picker button:active:not(:has(.rainbow)) {
  background: var(--select);
}

.picker button:active:has(.rainbow) {
  background-color: var(--select);
}

@media (hover: hover) and (pointer: fine) {
  .picker button:hover:not(:has(.rainbow)) {
    background: var(--select);
  }

  .picker button:hover:has(.rainbow),
  .picker button:active:has(.rainbow) {
    background-color: var(--select);
  }
}

.picker button.is-asked { color: rgba(244, 244, 244, 0.45); }

.composer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 0 16px;
  border: 2px solid var(--line);
  background: #0a0a10;
  font-size: 16px;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.composer .chev {
  width: 28px;
  height: 16px;
  fill: var(--ink);
  flex-shrink: 0;
}

.composer.is-open .chev { transform: rotate(180deg); }

@media (min-width: 960px) {
  .cover__field { display: block; }

  .chat__bar,
  .log {
    width: min(680px, calc(100% - 96px));
    margin-inline: auto;
  }

  .dock {
    left: 50%;
    right: auto;
    width: min(680px, calc(100% - 96px));
    transform: translateX(-50%);
  }

  .chat__avatar {
    width: 96px;
    height: 96px;
  }

  .zzz {
    left: 16px;
    top: -20px;
    width: 52px;
    height: 46px;
  }

  .zzz i:nth-child(1) { font-size: 16px; }
  .zzz i:nth-child(2) { font-size: 18px; }
  .zzz i:nth-child(3) { font-size: 22px; }

  .chat__name { font-size: 36px; }

  .log {
    gap: 22px;
    padding: 28px 4px 168px;
  }

  .msg {
    max-width: 100%;
    padding: 18px 22px;
    font-size: 24px;
  }

  .msg--user { max-width: 68%; }

  .msg--card img { width: 280px; }
  .msg--sheet img { width: 340px; }
  .msg--qr img { width: 290px; }

  .caret {
    width: 14px;
    height: 22px;
  }

  .picker button,
  .composer {
    font-size: 24px;
  }

  .composer { min-height: 64px; }

  .picker button { padding: 16px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .cover__arrow svg, .caret, .cover__title, .cover__zh, .chat__avatar img, .rainbow, .zzz i, .dream { animation: none; }
  .dream { transition: none; }
  .zzz i { opacity: 1; transform: none; }
  .zzz i:nth-child(1) { bottom: 0; }
  .zzz i:nth-child(2) { bottom: 14px; }
  .zzz i:nth-child(3) { bottom: 28px; }
  .cover__title { opacity: 1; transform: translateX(-50%) scale(1); }
  .cover__zh { opacity: 1; }
  #main { scroll-behavior: auto; }
}
