:root {
  color-scheme: light;
  --paper: #f1ede8;
  --paper-light: #fffdf9;
  --fog: #ded4d6;
  --mist: #d9c4c5;
  --ink: #403b3f;
  --muted: #82777b;
  --line: #cfc4c6;
  --accent: #66565d;
  --danger: #85525b;
  --shadow: rgba(66, 49, 57, 0.1);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
}

button,
input,
textarea {
  font: inherit;
}

button,
.photo-button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.photo-button:focus-within,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.ambient-circle {
  position: fixed;
  z-index: 0;
  top: 8vh;
  right: max(-7rem, -8vw);
  width: clamp(13rem, 25vw, 24rem);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--mist);
  opacity: 0.72;
  pointer-events: none;
}

.site-shell {
  position: relative;
  z-index: 1;
  width: min(100% - 40px, 920px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px 0 48px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
  border-bottom: 1px solid rgba(119, 100, 108, 0.22);
}

.wordmark,
.page-number,
.eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.wordmark {
  color: var(--ink);
  text-decoration: none;
}

.page-number,
.eyebrow {
  color: var(--muted);
}

.auth-view {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: clamp(48px, 10vw, 120px);
  align-items: center;
  min-height: calc(100vh - 110px);
  padding: 72px 0;
}

.auth-copy {
  max-width: 560px;
}

h1,
.message-body,
.quiet-note,
.empty-state p {
  font-family: Georgia, "Songti SC", "STSong", serif;
  font-weight: 400;
}

h1 {
  max-width: 680px;
  margin: 14px 0 24px;
  font-size: clamp(3.2rem, 8vw, 6.6rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.intro {
  max-width: 33rem;
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.85;
}

.door-form {
  align-self: end;
  margin-bottom: 12vh;
}

.door-form > label {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.answer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  border-bottom: 1px solid var(--accent);
}

.answer-row input {
  min-width: 0;
  height: 50px;
  border: 0;
  color: var(--ink);
  background: rgba(255, 253, 249, 0.48);
  padding: 0 14px;
}

.answer-row button,
.send-button {
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: 2px;
  color: var(--paper-light);
  background: var(--accent);
  padding: 0 18px;
  cursor: pointer;
}

.answer-row button {
  border-bottom: 0;
}

.answer-row button:hover,
.send-button:hover {
  background: #55464d;
}

.auth-error {
  margin: 14px 0 0;
  border-left: 2px solid var(--danger);
  color: var(--danger);
  background: rgba(217, 196, 197, 0.48);
  padding: 10px 12px;
  font-family: Georgia, "Songti SC", serif;
}

.door-form.is-wrong {
  animation: wrong-answer 240ms ease-out;
}

.quiet-note {
  position: absolute;
  bottom: 42px;
  left: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.chat-view {
  padding: 64px 0 0;
}

.chat-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 32px;
  margin-bottom: 46px;
}

.chat-heading h1 {
  margin: 8px 0 0;
  font-size: clamp(3rem, 7vw, 5.6rem);
}

.identity-block {
  display: flex;
  align-items: center;
  gap: 18px;
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.identity-block strong {
  color: var(--ink);
  font-weight: 600;
}

.text-button,
#remove-image {
  border: 0;
  border-bottom: 1px solid currentColor;
  color: var(--muted);
  background: transparent;
  padding: 2px 0;
  cursor: pointer;
}

.timeline {
  width: min(100%, 720px);
  margin: 0 auto;
}

.date-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 15px;
  align-items: center;
  margin: 36px 0 24px;
  color: var(--muted);
  font-size: 0.72rem;
}

.date-divider::before,
.date-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.message {
  width: min(82%, 520px);
  margin: 0 0 24px;
  border: 1px solid rgba(126, 106, 114, 0.14);
  border-radius: 3px;
  background: var(--paper-light);
  box-shadow: 8px 8px 0 var(--fog);
  padding: 18px 20px;
}

.message.is-mine {
  margin-left: auto;
  background: #e7ddde;
  box-shadow: -8px 8px 0 #d5c8ca;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.message-body {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 1rem;
  line-height: 1.75;
}

.message-image-link {
  display: block;
  margin-top: 14px;
}

.message-image {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: cover;
  border: 1px solid rgba(126, 106, 114, 0.2);
}

.empty-state {
  margin: 84px auto 110px;
  text-align: center;
  color: var(--muted);
}

.empty-state p {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 1.35rem;
}

.empty-state span {
  font-size: 0.82rem;
}

.composer {
  position: sticky;
  bottom: 18px;
  width: min(100%, 760px);
  margin: 70px auto 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 253, 249, 0.96);
  box-shadow: 0 16px 45px var(--shadow);
  padding: 16px;
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 92px;
  resize: vertical;
  border: 0;
  color: var(--ink);
  background: transparent;
  padding: 8px;
  line-height: 1.65;
}

.composer textarea::placeholder {
  color: #a29699;
}

.composer-actions {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  border-top: 1px solid rgba(126, 106, 114, 0.15);
  padding-top: 12px;
}

.photo-button {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  color: var(--accent);
  font-size: 0.8rem;
  cursor: pointer;
}

.photo-button span {
  margin-right: 6px;
  font-size: 1.15rem;
}

.photo-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.composer-status {
  margin: 0;
  color: var(--danger);
  font-size: 0.76rem;
  text-align: center;
}

.send-button {
  min-width: 112px;
}

.send-button:disabled,
.answer-row button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.image-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 8px 12px;
  padding: 10px;
  background: var(--paper);
}

.image-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
}

#remove-image {
  font-size: 0.76rem;
}

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

@keyframes wrong-answer {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-5px); }
  70% { transform: translateX(5px); }
}

@media (max-width: 720px) {
  .site-shell {
    width: min(100% - 28px, 920px);
    padding-top: 18px;
  }

  .ambient-circle {
    top: 11vh;
    right: -6rem;
  }

  .auth-view {
    display: block;
    min-height: calc(100vh - 72px);
    padding: 72px 0 100px;
  }

  h1 {
    font-size: clamp(3.15rem, 16vw, 5.2rem);
  }

  .door-form {
    margin: 72px 0 0;
  }

  .quiet-note {
    bottom: 28px;
  }

  .chat-view {
    padding-top: 44px;
  }

  .chat-heading {
    display: block;
    margin-bottom: 36px;
  }

  .identity-block {
    justify-content: space-between;
    margin-top: 18px;
  }

  .message {
    width: calc(100% - 22px);
    padding: 16px;
  }

  .composer {
    bottom: 8px;
    margin-top: 52px;
  }

  .composer-actions {
    grid-template-columns: 1fr auto;
  }

  .composer-status {
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
