:root {
  color-scheme: light;
  font-family: "Noto Serif SC", "Songti SC", "Microsoft YaHei", system-ui, sans-serif;
  --paper: #f4f0e8;
  --paper-deep: #e9e1d5;
  --ink: #272421;
  --muted: #756f68;
  --line: rgba(69, 62, 55, 0.17);
  --owner: #ded4c7;
  --other: #ffffff;
  --focus: #755f4c;
}

* {
  box-sizing: border-box;
}

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

body {
  min-width: 0;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(255, 255, 255, 0.78), transparent 34rem),
    linear-gradient(180deg, var(--paper), var(--paper-deep));
}

button,
input {
  font: inherit;
}

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

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 60%, transparent);
  outline-offset: 3px;
}

.eyebrow {
  margin: 0 0 0.7rem;
  color: var(--muted);
  font-family: "Microsoft YaHei", system-ui, sans-serif;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
}

.boundary-note,
.quiet-note {
  color: var(--muted);
  line-height: 1.75;
}

.credential-hint {
  margin: 1.35rem 0 0;
  padding: 0.85rem 0 0.85rem 1rem;
  border-left: 1px solid color-mix(in srgb, var(--focus) 42%, transparent);
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.75;
  background: linear-gradient(90deg, rgba(117, 95, 76, 0.055), transparent 80%);
}

.credential-hint span {
  display: block;
  margin-bottom: 0.18rem;
  color: var(--ink);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.login-panel {
  width: min(100%, 34rem);
  padding: clamp(1.35rem, 5vw, 2.8rem) clamp(0.35rem, 3vw, 1.4rem);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.login-panel h1,
.archive-header h1,
.empty-state h2 {
  margin: 0;
  font-weight: 500;
  letter-spacing: -0.035em;
}

.login-panel h1 {
  font-size: clamp(1.8rem, 7vw, 2.5rem);
}

.login-form {
  display: grid;
  gap: 0.62rem;
  margin-top: 1.45rem;
}

.login-form label {
  font-size: 0.88rem;
}

.login-form input {
  width: 100%;
  min-height: 3rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: var(--other);
}

.login-form button,
.load-older,
.logout-button {
  min-height: 2.9rem;
  border: 1px solid var(--ink);
  border-right: 0;
  border-left: 0;
  border-radius: 0;
  cursor: pointer;
}

.login-form button {
  margin-top: 0.5rem;
  color: var(--paper);
  background: var(--ink);
}

.form-error {
  padding: 0.8rem 0.9rem;
  border-left: 3px solid #965848;
  color: #703d34;
  background: rgba(150, 88, 72, 0.08);
  line-height: 1.55;
}

.quiet-note {
  margin: 1.25rem 0 0;
  font-size: 0.8rem;
}

.archive-shell {
  width: min(100%, 49rem);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(1.5rem, env(safe-area-inset-top)) max(1.25rem, env(safe-area-inset-right)) max(2rem, env(safe-area-inset-bottom)) max(1.25rem, env(safe-area-inset-left));
}

.archive-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2rem;
  padding: clamp(1.5rem, 5vw, 3.5rem) 0 1.5rem;
  border-bottom: 1px solid var(--line);
}

.archive-header > div {
  min-width: 0;
}

.archive-header h1 {
  overflow-wrap: anywhere;
  font-size: clamp(2rem, 7vw, 3.5rem);
}

.archive-header .boundary-note {
  max-width: 38rem;
  margin: 1rem 0 0;
}

.logout-button {
  flex: 0 0 auto;
  min-height: 2.5rem;
  padding: 0.5rem 0.9rem;
  color: var(--ink);
  background: transparent;
}

.archive-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.9rem 0;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
}

.archive-content {
  min-width: 0;
  padding: 1.5rem 0 2rem;
}

.empty-state {
  padding: clamp(2rem, 9vw, 5rem) clamp(1rem, 5vw, 3rem);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.empty-state h2 {
  font-size: clamp(1.35rem, 5vw, 2rem);
}

.empty-state p {
  max-width: 34rem;
  margin: 1rem auto 0;
  color: var(--muted);
  line-height: 1.75;
}

.message-list {
  display: flex;
  min-width: 0;
  margin: 0;
  padding: 0;
  flex-direction: column;
  list-style: none;
}

.day-marker {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 2.8rem 0 0.65rem;
  color: var(--muted);
  font-size: 0.74rem;
}

.day-marker::after {
  height: 1px;
  flex: 1;
  content: "";
  background: var(--line);
}

.day-marker span {
  padding: 0;
}

.message {
  display: block;
  min-width: 0;
  margin: 0;
}

.message-card {
  display: grid;
  min-width: 0;
  max-width: none;
  grid-template-columns: minmax(5.2rem, 7.2rem) minmax(0, 1fr);
  gap: 1rem 1.35rem;
  padding: 1.15rem 0 1.25rem;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.message--owner .message-card {
  background: linear-gradient(90deg, rgba(117, 95, 76, 0.045), transparent 64%);
}

.message--system .message-card {
  display: block;
  max-width: 100%;
  padding-block: 1rem;
  border: 0;
  color: var(--muted);
  text-align: center;
  background: transparent;
  box-shadow: none;
}

.message-card header {
  display: flex;
  grid-column: 1;
  align-items: flex-start;
  flex-direction: column;
  gap: 0.18rem;
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
}

.message-card time {
  white-space: nowrap;
}

.message-text {
  grid-column: 2;
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 1rem;
  line-height: 1.7;
}

.message-media {
  grid-column: 2;
  margin: 0.45rem 0 0;
}

.message-media img,
.message-video {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: min(70vh, 42rem);
  border-radius: 0.6rem;
  object-fit: contain;
}

.message-audio {
  grid-column: 2;
  display: block;
  width: min(100%, 20rem);
  margin-top: 0.45rem;
}

.message-file {
  grid-column: 2;
  display: inline-block;
  margin-top: 0.45rem;
  color: inherit;
  overflow-wrap: anywhere;
}

.load-older {
  display: block;
  width: 100%;
  margin: 0 auto 1.35rem;
  padding: 0.55rem 1.15rem;
  color: var(--ink);
  background: transparent;
}

.load-older[hidden] {
  display: none;
}

.load-older[disabled] {
  cursor: wait;
  opacity: 0.62;
}

.archive-footer {
  padding: 1.5rem 0 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.6;
  text-align: center;
}

.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;
}

@media (max-width: 480px) {
  .login-shell {
    place-items: start stretch;
    padding-top: max(1rem, env(safe-area-inset-top));
  }

  .login-panel {
    align-self: center;
    margin-block: auto;
    padding-block: 1.25rem;
  }

  .login-panel h1 {
    font-size: 1.7rem;
  }

  .boundary-note {
    margin-bottom: 0;
    font-size: 0.83rem;
  }

  .login-form {
    margin-top: 1.15rem;
  }

  .quiet-note {
    margin-top: 0.95rem;
  }

  .archive-shell {
    padding-right: max(0.75rem, env(safe-area-inset-right));
    padding-left: max(0.75rem, env(safe-area-inset-left));
  }

  .archive-header {
    display: grid;
    gap: 1rem;
    padding-top: 1.5rem;
  }

  .logout-button {
    min-height: 2.75rem;
  }

  .message-card {
    grid-template-columns: 4rem minmax(0, 1fr);
    gap: 0.75rem;
    padding: 1rem 0 1.08rem;
  }

  .message-text {
    font-size: 1rem;
    line-height: 1.68;
  }
}

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

/* The login remains a neutral security boundary, with the same dusk-to-paper
   visual language as the letter outside it. */
:root {
  --paper: #f5ede2;
  --paper-deep: #e8d8cd;
  --ink: #2d2428;
  --muted: #766b70;
  --line: rgba(91, 64, 72, 0.16);
  --owner: #e4d4cd;
  --other: #fffaf4;
  --focus: #9f6270;
  --rose: #ca8994;
  --apricot: #dfad86;
  --lilac: #9d95b7;
}

body {
  background:
    radial-gradient(circle at 13% 7%, rgba(255, 255, 255, 0.9), transparent 30rem),
    radial-gradient(circle at 88% 18%, rgba(202, 137, 148, 0.14), transparent 28rem),
    radial-gradient(circle at 20% 90%, rgba(157, 149, 183, 0.1), transparent 26rem),
    linear-gradient(155deg, var(--paper), var(--paper-deep));
}

.login-shell {
  position: relative;
  isolation: isolate;
}

.login-shell::before {
  position: fixed;
  z-index: -1;
  top: 50%;
  left: 50%;
  width: min(78vw, 42rem);
  aspect-ratio: 1.7;
  border: 1px solid rgba(159, 98, 112, 0.09);
  border-radius: 50%;
  content: "";
  transform: translate(-50%, -50%) rotate(-8deg);
}

.login-shell::after {
  position: fixed;
  z-index: -1;
  top: calc(50% - 2px);
  left: calc(50% - min(39vw, 21rem));
  width: 5px;
  height: 5px;
  border-radius: 50%;
  content: "";
  background: var(--rose);
  box-shadow:
    0 0 18px rgba(202, 137, 148, 0.42),
    min(78vw, 42rem) 0 0 0 var(--apricot);
}

.login-panel {
  position: relative;
  padding: clamp(1.7rem, 5vw, 3.2rem);
  border: 1px solid rgba(100, 72, 79, 0.12);
  border-radius: 4px;
  background:
    linear-gradient(145deg, rgba(255, 252, 247, 0.78), rgba(244, 230, 221, 0.68)),
    repeating-linear-gradient(-35deg, transparent 0 14px, rgba(104, 72, 77, 0.018) 14px 15px);
  box-shadow:
    0 34px 100px rgba(91, 59, 64, 0.13),
    inset 0 1px rgba(255, 255, 255, 0.76);
  backdrop-filter: blur(16px);
  animation: login-arrive 760ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.login-panel::before {
  position: absolute;
  top: -1px;
  left: 8%;
  width: 24%;
  height: 2px;
  content: "";
  background: linear-gradient(90deg, var(--rose), var(--apricot));
}

@keyframes login-arrive {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-panel .eyebrow {
  color: rgba(159, 98, 112, 0.82);
}

.login-panel h1 {
  color: #2c2227;
  font-size: clamp(2.15rem, 7vw, 3rem);
}

.boundary-note {
  max-width: 29em;
  margin-top: 1.15rem;
}

.credential-hint {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.55rem 1rem;
  margin: 1.7rem 0 0;
  padding: 1.15rem 1.2rem;
  border: 1px solid rgba(159, 98, 112, 0.2);
  border-left: 3px solid var(--rose);
  border-radius: 3px;
  color: var(--muted);
  background:
    radial-gradient(circle at 92% 14%, rgba(223, 173, 134, 0.14), transparent 34%),
    linear-gradient(110deg, rgba(202, 137, 148, 0.12), rgba(255, 250, 244, 0.48));
  box-shadow: 0 12px 34px rgba(112, 71, 78, 0.07);
}

.credential-hint__title {
  grid-column: 1 / -1;
  margin-bottom: 0.14rem;
  color: #5f3d49;
  font-family: "Microsoft YaHei", system-ui, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.credential-hint p {
  display: contents;
}

.credential-hint b,
.credential-hint strong {
  line-height: 1.7;
}

.credential-hint b {
  color: rgba(78, 55, 62, 0.64);
  font-family: "Microsoft YaHei", system-ui, sans-serif;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.12em;
}

.credential-hint strong {
  color: #3d2d33;
  font-size: 0.9rem;
  font-weight: 600;
}

.login-form {
  gap: 0.68rem;
  margin-top: 1.65rem;
}

.login-form label {
  color: rgba(61, 45, 51, 0.76);
  font-family: "Microsoft YaHei", system-ui, sans-serif;
  font-size: 0.76rem;
  letter-spacing: 0.08em;
}

.login-form input {
  min-height: 3.25rem;
  border-color: rgba(100, 72, 79, 0.18);
  border-radius: 3px;
  background: rgba(255, 252, 248, 0.78);
  box-shadow: inset 0 1px 2px rgba(85, 58, 64, 0.025);
  transition:
    border-color 260ms ease,
    box-shadow 260ms ease,
    background 260ms ease;
}

.login-form input::placeholder {
  color: rgba(91, 72, 78, 0.38);
}

.login-form input:focus {
  border-color: rgba(159, 98, 112, 0.48);
  background: #fffaf5;
  box-shadow: 0 0 0 4px rgba(202, 137, 148, 0.08);
}

.login-form button {
  min-height: 3.2rem;
  margin-top: 0.72rem;
  border: 1px solid #34272d;
  border-radius: 999px;
  background: linear-gradient(110deg, #30242a, #4a303a);
  box-shadow: 0 14px 34px rgba(61, 40, 47, 0.16);
  transition:
    transform 160ms ease,
    background 360ms ease,
    box-shadow 360ms ease;
}

.login-form button:hover,
.login-form button:focus-visible {
  background: linear-gradient(110deg, #3c2932, #6f4451);
  box-shadow: 0 18px 42px rgba(91, 51, 64, 0.2);
}

.login-form button:active {
  transform: scale(0.992);
}

.quiet-note {
  text-align: center;
}

@media (max-width: 520px) {
  .login-shell {
    place-items: start center;
    padding: max(1rem, env(safe-area-inset-top)) 0.8rem max(1rem, env(safe-area-inset-bottom));
  }

  .login-panel {
    margin-top: min(8svh, 3.5rem);
    padding: 1.55rem 1.15rem 1.6rem;
  }

  .credential-hint {
    padding: 1rem;
  }

  .login-shell::before {
    width: 130vw;
  }

  .login-shell::after {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .login-panel {
    animation: none;
  }
}
