:root {
  --paper: #f7f3ea;
  --paper-deep: #f1ebdf;
  --card: #fffdf8;
  --ink: #26221a;
  --muted: #7c7263;
  --line: #e6ddcc;
  --accent: #a85d2e;
  --accent-strong: #8d4a20;
  --accent-ink: #fff8f0;
  --accent-soft: rgba(168, 93, 46, 0.1);
  --ring: rgba(168, 93, 46, 0.28);
  --danger: #a63d2c;
  --shadow: 0 1px 2px rgba(70, 52, 22, 0.04), 0 12px 28px -18px rgba(70, 52, 22, 0.35);
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17150f;
    --paper-deep: #1d1a14;
    --card: #211e18;
    --ink: #efe9dd;
    --muted: #9c9284;
    --line: #332e25;
    --accent: #d68c58;
    --accent-strong: #e6a276;
    --accent-ink: #24160c;
    --accent-soft: rgba(214, 140, 88, 0.12);
    --ring: rgba(214, 140, 88, 0.32);
    --danger: #e08a76;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 16px 32px -20px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 50% -12%, var(--accent-soft), transparent 62%),
    var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent-soft);
}

.page {
  width: 100%;
  max-width: 43rem;
  margin: 0 auto;
  padding: clamp(2.5rem, 7vw, 4.5rem) 1.25rem 3rem;
}

/* ---------- 页头 ---------- */

.masthead {
  text-align: center;
}

.eyebrow {
  margin: 0 0 0.9rem;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.36em;
  text-transform: uppercase;
}

.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.2rem, 6.5vw, 3rem);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-indent: 0.1em;
}

.lede {
  max-width: 24rem;
  margin: 0.9rem auto 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.8;
}

/* ---------- 写留言 ---------- */

.compose {
  margin-top: clamp(2rem, 5vw, 2.75rem);
  padding: 1.25rem 1.3rem 1.1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.compose:focus-within {
  border-color: var(--ring);
  box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft);
}

.field + .field {
  margin-top: 0.9rem;
}

.field label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
}

.field input,
.field textarea {
  display: block;
  width: 100%;
  padding: 0.65rem 0.85rem;
  color: var(--ink);
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  line-height: 1.6;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  background: var(--card);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.field textarea {
  min-height: 6rem;
  resize: vertical;
}

.compose-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.9rem;
}

.counter {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.counter.near {
  color: var(--accent);
}

.primary {
  padding: 0.62rem 1.25rem;
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.primary:hover:not(:disabled) {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.primary:active:not(:disabled) {
  transform: translateY(0);
}

.primary:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary.sending .label::after {
  content: "…";
}

.form-hint {
  min-height: 1.2rem;
  margin: 0.55rem 0 0;
  color: var(--danger);
  font-size: 0.8rem;
}

/* ---------- 留言墙 ---------- */

.wall {
  margin-top: clamp(2.5rem, 6vw, 3.5rem);
}

.wall-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.wall-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.12rem;
  font-weight: 500;
  letter-spacing: 0.08em;
}

.total {
  color: var(--muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.list {
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
}

.message {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr);
  gap: 0.85rem;
  padding: 0.95rem 1.05rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  animation: rise 0.35s ease both;
}

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

.avatar {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  font-size: 0.95rem;
  font-weight: 500;
  user-select: none;
}

.tone-0 { background: #efe3d2; color: #7a4a26; }
.tone-1 { background: #e3e8da; color: #4d5c3b; }
.tone-2 { background: #e8e0ee; color: #5c4a6d; }
.tone-3 { background: #eadfe0; color: #7a3f4a; }
.tone-4 { background: #dfe7ea; color: #3f5c66; }
.tone-5 { background: #f0e6cf; color: #6b5424; }

@media (prefers-color-scheme: dark) {
  .tone-0 { background: #3a2c1f; color: #e8c39d; }
  .tone-1 { background: #2b3325; color: #c3d3ae; }
  .tone-2 { background: #322a3a; color: #d3c0e3; }
  .tone-3 { background: #3a2a2d; color: #e3b8bf; }
  .tone-4 { background: #253138; color: #b6cfd8; }
  .tone-5 { background: #37301e; color: #ddc99a; }
}

.message-main {
  min-width: 0;
}

.message-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.message-name {
  overflow: hidden;
  font-size: 0.94rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-time {
  flex: none;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

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

/* 加载骨架 */

.skeleton {
  pointer-events: none;
}

.skeleton .avatar,
.skeleton .bar {
  background: var(--paper-deep);
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton .bar {
  height: 0.7rem;
  margin-top: 0.45rem;
  border-radius: 6px;
}

.skeleton .bar.short {
  width: 45%;
}

@keyframes shimmer {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* 空与错误 */

.empty {
  margin-top: 1rem;
  padding: 2.75rem 1.5rem;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.empty p {
  margin: 0;
}

.empty-sub {
  margin-top: 0.4rem !important;
  font-size: 0.85rem;
  opacity: 0.75;
}

.error {
  margin-top: 1rem;
  padding: 1.4rem;
  text-align: center;
  border: 1px dashed var(--danger);
  border-radius: 14px;
}

.error p {
  margin: 0 0 0.9rem;
  color: var(--danger);
  font-size: 0.9rem;
}

.more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 1.25rem;
}

.ghost {
  padding: 0.5rem 1.05rem;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  font: inherit;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.ghost:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.foot {
  margin-top: 3.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
  letter-spacing: 0.06em;
}

.foot p {
  margin: 0;
}

/* ---------- 提示条 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  z-index: 10;
  padding: 0.62rem 1.1rem;
  color: var(--paper);
  background: var(--ink);
  border-radius: 999px;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.5);
  font-size: 0.86rem;
  transform: translateX(-50%);
  animation: toast-in 0.25s ease both;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- 通用 ---------- */

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

@media (max-width: 30rem) {
  .page {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  .compose {
    padding: 1.1rem 1rem 1rem;
  }
  .message {
    padding: 0.85rem;
  }
}
