:root {
  --pearl: #f6f3ef;
  --paper: rgba(255, 252, 249, 0.82);
  --ink: #2c2830;
  --soft: #6f6876;
  --faint: #9a93a3;
  --line: rgba(120, 100, 140, 0.16);
  --lavender: #7d6aa3;
  --lavender-deep: #6a588f;
  --wash: #efe8f6;
  --rose: #8d4d5c;
  --shadow: 0 24px 60px rgba(70, 50, 80, 0.07);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC",
    "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(72rem 36rem at -10% -20%, rgba(196, 182, 216, 0.38), transparent 58%),
    radial-gradient(48rem 28rem at 110% -10%, rgba(232, 214, 220, 0.55), transparent 52%),
    var(--pearl);
}

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

button { cursor: pointer; }

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

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

.gate {
  width: min(440px, calc(100% - 32px));
  margin: max(6vh, 28px) auto 40px;
  padding: 42px 32px 28px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.portrait {
  position: relative;
  width: 112px;
  height: 112px;
  margin: 0 auto 18px;
}

.portrait img,
.portrait .fallback,
.mini {
  border-radius: 50%;
  object-fit: cover;
  background: #f4eef8;
}

.portrait img {
  position: relative;
  z-index: 1;
  width: 112px;
  height: 112px;
  box-shadow: 0 0 0 1px rgba(125, 106, 163, 0.35), 0 12px 28px rgba(80, 60, 100, 0.08);
}

.portrait .fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--lavender);
  font-family: "Iowan Old Style", Palatino, "Songti SC", "Noto Serif SC", serif;
  font-size: 42px;
}

.portrait img.is-missing { display: none; }

.eyebrow {
  margin: 0;
  text-align: center;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  font-size: 11px;
  color: var(--lavender);
}

h1 {
  margin: 6px 0 0;
  text-align: center;
  font-family: "Iowan Old Style", Palatino, "Songti SC", "Noto Serif SC", "STSong", serif;
  font-weight: 500;
  font-size: 52px;
  letter-spacing: 0.22em;
  text-indent: 0.22em;
}

.tagline {
  margin: 8px 0 26px;
  text-align: center;
  color: var(--soft);
  font-size: 15px;
}

form label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--soft);
}

input, textarea {
  width: 100%;
  border: 1px solid rgba(120, 100, 140, 0.22);
  background: #fffcf9;
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px;
  line-height: 1.5;
}

input { letter-spacing: 0.08em; }

input:focus, textarea:focus {
  outline: 2px solid rgba(125, 106, 163, 0.45);
  outline-offset: 1px;
  border-color: transparent;
}

button[type="submit"], .composer button {
  display: block;
  width: 100%;
  margin-top: 14px;
  height: 48px;
  border: 0;
  border-radius: 999px;
  background: var(--lavender-deep);
  color: #fbf8f4;
  letter-spacing: 0.12em;
}

button[type="submit"]:disabled, .composer button:disabled {
  opacity: 0.55;
  cursor: default;
}

.error {
  min-height: 1.2em;
  margin: 12px 0 0;
  text-align: center;
  color: var(--rose);
  font-size: 13px;
}

.quiet {
  margin: 22px 0 0;
  text-align: center;
  color: var(--faint);
  font-size: 12px;
}

.room {
  width: min(720px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 12px;
}

.mini {
  width: 40px;
  height: 40px;
  box-shadow: 0 0 0 1px rgba(125, 106, 163, 0.28);
  flex: 0 0 auto;
}

.who { min-width: 0; }

.who strong {
  display: block;
  font-family: "Iowan Old Style", Palatino, "Songti SC", "Noto Serif SC", serif;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.14em;
}

.who span {
  display: block;
  margin-top: 2px;
  color: var(--soft);
  font-size: 12px;
}

#starmap-link,
#leave {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--soft);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  text-decoration: none;
}

#starmap-link { margin-left: auto; }

#leave { margin-left: 8px; }

#log {
  flex: 1;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 8px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--faint);
  font-size: 14px;
  padding: 48px 12px;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: min(82%, 34rem);
}

.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; }

.msg p {
  margin: 0;
  padding: 12px 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user p {
  background: var(--wash);
  border-radius: 18px 18px 6px 18px;
}

.msg.assistant p {
  background: rgba(255, 252, 249, 0.94);
  border: 1px solid var(--line);
  border-radius: 18px 18px 18px 6px;
}

.msg.notice p {
  background: transparent;
  border-style: dashed;
  color: var(--soft);
}

.voice {
  align-self: flex-start;
  margin: 6px 0 0 2px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--lavender);
  font-size: 13px;
}

.voice:disabled { color: var(--faint); }

.composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(246, 243, 239, 0.92);
  border-top: 1px solid var(--line);
}

.composer textarea {
  flex: 1;
  margin: 0;
  resize: none;
  max-height: 140px;
  border-radius: 16px;
}

.composer button {
  width: auto;
  min-width: 76px;
  margin: 0;
  padding: 0 18px;
  flex: 0 0 auto;
}

@media (max-width: 640px) {
  .gate { padding: 32px 22px 22px; }
  h1 { font-size: 44px; }
}

@media (min-width: 900px) {
  html:has(#room:not([hidden])) { overflow: hidden; }
  .room {
    height: calc(100dvh - 64px);
    min-height: 0;
    margin: 24px auto;
    background: rgba(255, 252, 249, 0.5);
    border: 1px solid var(--line);
    border-radius: 28px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
}
