/* ---------------------------------------------------------
   树洞 · 界面样式
   深色、安静、私密。所有值来自统一的设计变量。
--------------------------------------------------------- */

:root {
  /* 色板 */
  --ink-0: #050806;
  --ink-1: #070b09;
  --ink-2: #0b120e;
  --surface: rgba(233, 235, 225, 0.045);
  --surface-strong: rgba(233, 235, 225, 0.07);
  --line: rgba(233, 235, 225, 0.1);
  --line-soft: rgba(233, 235, 225, 0.06);
  --text: #e8e5da;
  --text-sub: #98a198;
  --text-faint: rgba(152, 161, 152, 0.6);
  --moss: #a9c3a0;
  --moss-dim: rgba(169, 195, 160, 0.16);
  --amber: #c9a97a;
  --amber-dim: rgba(201, 169, 122, 0.14);
  --danger: #d1867b;
  --danger-dim: rgba(209, 134, 123, 0.12);

  /* 字体 */
  --font-display: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "SimSun", Georgia, serif;
  --font-body: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", -apple-system, sans-serif;

  /* 尺寸 */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shell-w: 680px;

  /* 动效 */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(120% 70% at 50% -12%, rgba(126, 160, 120, 0.13), transparent 62%),
    radial-gradient(70% 50% at 92% 102%, rgba(201, 169, 122, 0.06), transparent 70%),
    linear-gradient(180deg, #0a110d 0%, var(--ink-1) 52%, var(--ink-0) 100%);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body[data-view="lock"] { overflow-y: auto; }

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

button { cursor: pointer; }

::selection { background: rgba(169, 195, 160, 0.28); }

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

/* ---------- 氛围层 ---------- */
.atmosphere {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.moonlight {
  position: absolute;
  top: -200px;
  left: 50%;
  width: 620px;
  height: 620px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(178, 203, 168, 0.14), rgba(178, 203, 168, 0.03) 45%, transparent 68%);
  filter: blur(6px);
}

.grain {
  position: absolute;
  inset: 0;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

/* ---------- 口令页 ---------- */
.lock {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px 88px;
}

.lock-inner {
  width: 100%;
  max-width: 340px;
  text-align: center;
  animation: fade-up 0.9s var(--ease) both;
}

.lock.is-leaving .lock-inner {
  animation: fade-out 0.3s var(--ease) both;
}

.brand-mark {
  display: inline-block;
  width: 40px;
  height: 40px;
  color: var(--moss);
  opacity: 0.85;
}

.brand-mark svg { width: 100%; height: 100%; }

.brand-title {
  margin: 18px 0 0;
  font-family: var(--font-display);
  font-size: 46px;
  font-weight: 400;
  letter-spacing: 0.24em;
  text-indent: 0.24em;
  color: #efede2;
}

.brand-sub {
  margin: 14px 0 0;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
}

.lock-form { margin-top: 46px; }

.field-label {
  display: block;
  margin-bottom: 14px;
  font-size: 12px;
  letter-spacing: 0.18em;
  color: var(--text-sub);
}

.code {
  position: relative;
  padding: 2px;
}

.code-cells {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.cell {
  height: 52px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.022);
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--text);
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.cell.is-filled {
  background: rgba(233, 235, 225, 0.055);
  border-color: rgba(233, 235, 225, 0.18);
}

.code.is-focused .cell.is-active {
  border-color: rgba(169, 195, 160, 0.7);
  box-shadow: 0 0 0 3px rgba(169, 195, 160, 0.08);
}

.code.is-error .cell {
  border-color: rgba(209, 134, 123, 0.6);
  animation: shake 0.42s var(--ease);
}

.code-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  background: transparent;
  font-size: 16px;
  letter-spacing: 4px;
  caret-color: transparent;
  cursor: text;
}

.lock-msg {
  min-height: 20px;
  margin: 12px 0 0;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--danger);
}

.enter-btn {
  width: 100%;
  height: 46px;
  margin-top: 18px;
  border: 1px solid rgba(211, 223, 203, 0.5);
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #d3dfcb, #b8cbaa);
  color: #0a100c;
  font-size: 13.5px;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  transition: filter 0.2s var(--ease), opacity 0.2s var(--ease), transform 0.2s var(--ease);
}

.enter-btn:hover:not(:disabled) { filter: brightness(1.06); }
.enter-btn:active:not(:disabled) { transform: translateY(1px); }
.enter-btn:disabled { opacity: 0.22; cursor: default; }

.lock-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(22px + env(safe-area-inset-bottom));
  margin: 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.12em;
  color: rgba(152, 161, 152, 0.32);
}

/* ---------- 内页骨架 ---------- */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: var(--shell-w);
  margin: 0 auto;
  animation: fade-in 0.5s var(--ease) both;
}

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 22px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(8, 13, 10, 0.92), rgba(8, 13, 10, 0.55) 70%, transparent);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.mini-mark {
  width: 26px;
  height: 26px;
  flex: none;
  color: var(--moss);
  opacity: 0.75;
}

.mini-mark svg { width: 100%; height: 100%; }

.topbar-text { min-width: 0; }

.app-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0.2em;
  line-height: 1.2;
  color: #efede2;
}

.app-sub {
  margin: 3px 0 0;
  font-size: 11.5px;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.identity {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11.5px;
  letter-spacing: 0.1em;
  color: var(--moss);
  background: rgba(169, 195, 160, 0.06);
}

.identity::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.identity.is-owner {
  color: var(--amber);
  background: var(--amber-dim);
  border-color: rgba(201, 169, 122, 0.28);
}

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--text-sub);
  transition: color 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.icon-btn svg { width: 17px; height: 17px; }

.icon-btn:hover {
  color: var(--text);
  background: rgba(233, 235, 225, 0.06);
  border-color: var(--line-soft);
}

/* ---------- 留言流 ---------- */
.stream-wrap {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 22px;
  scrollbar-width: thin;
  scrollbar-color: rgba(233, 235, 225, 0.14) transparent;
}

.stream-wrap::-webkit-scrollbar { width: 6px; }
.stream-wrap::-webkit-scrollbar-thumb { background: rgba(233, 235, 225, 0.14); border-radius: 3px; }

.stream {
  list-style: none;
  margin: 0;
  padding: 26px 0 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  position: relative;
  padding: 16px 18px 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: var(--surface);
  animation: card-in 0.5s var(--ease) both;
  transition: border-color 0.25s var(--ease), background 0.25s var(--ease);
}

.card:hover {
  background: rgba(233, 235, 225, 0.058);
  border-color: rgba(233, 235, 225, 0.12);
}

.card.is-leaving {
  animation: card-out 0.32s var(--ease) both;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  padding-right: 26px;
}

.sender {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  letter-spacing: 0.12em;
  color: var(--text-sub);
}

.sender::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--moss);
  opacity: 0.8;
}

.card--owner .sender { color: rgba(201, 169, 122, 0.85); }
.card--owner .sender::before { background: var(--amber); opacity: 0.85; }

.card-time {
  margin-left: auto;
  font-size: 11px;
  letter-spacing: 0.05em;
  font-variant-numeric: tabular-nums;
  color: rgba(152, 161, 152, 0.55);
}

.card-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.85;
  letter-spacing: 0.01em;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.card-gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 11px 0 2px;
}

.card-gallery.is-single { grid-template-columns: 1fr; }

.gallery-item {
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
  line-height: 0;
  cursor: zoom-in;
}

.gallery-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  transition: transform 0.5s var(--ease), opacity 0.3s var(--ease);
}

.card-gallery.is-single .gallery-item img {
  aspect-ratio: auto;
  max-height: 520px;
}

.gallery-item:hover img { transform: scale(1.015); opacity: 0.94; }

.delete-btn {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: rgba(152, 161, 152, 0.6);
  opacity: 0.32;
  transition: opacity 0.2s var(--ease), color 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease);
}

.delete-btn svg { width: 15px; height: 15px; }

.card:hover .delete-btn,
.delete-btn:focus-visible { opacity: 1; }

.delete-btn:hover {
  color: var(--danger);
  background: var(--danger-dim);
  border-color: rgba(209, 134, 123, 0.22);
}

/* ---------- 空状态 ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 72px 24px;
  text-align: center;
  animation: fade-in 0.6s var(--ease) both;
}

.empty-mark {
  width: 52px;
  height: 52px;
  color: var(--moss);
  opacity: 0.4;
}

.empty-mark svg { width: 100%; height: 100%; }

.empty-title {
  margin: 16px 0 0;
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.12em;
  color: rgba(232, 229, 218, 0.75);
}

.empty-sub {
  margin: 6px 0 0;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  color: var(--text-faint);
}

/* ---------- 输入区 ---------- */
.composer-wrap {
  flex: none;
  padding: 8px 22px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(7, 11, 9, 0), rgba(7, 11, 9, 0.88) 32%, rgba(7, 11, 9, 0.97));
}

.composer {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(11, 18, 14, 0.86);
  padding: 8px 8px 8px 6px;
  transition: border-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.composer:focus-within {
  border-color: rgba(169, 195, 160, 0.32);
  box-shadow: 0 0 0 3px rgba(169, 195, 160, 0.05);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.attach {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-sub);
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}

.attach svg { width: 18px; height: 18px; }

.attach:hover { color: var(--moss); background: rgba(169, 195, 160, 0.08); }

#msg-input {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  max-height: 132px;
  padding: 7px 2px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text);
  scrollbar-width: thin;
}

#msg-input::placeholder { color: rgba(152, 161, 152, 0.5); }

.send {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--moss);
  color: #0a100c;
  transition: opacity 0.2s var(--ease), transform 0.18s var(--ease), filter 0.2s var(--ease);
}

.send svg { width: 18px; height: 18px; }

.send:hover:not(:disabled) { filter: brightness(1.08); }
.send:active:not(:disabled) { transform: scale(0.94); }
.send:disabled { opacity: 0.2; cursor: default; }

.preview-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 2px 10px;
}

.preview {
  position: relative;
  width: 72px;
  height: 72px;
}

.preview img {
  display: block;
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.preview-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(233, 235, 225, 0.16);
  border-radius: 50%;
  background: #1a221d;
  color: var(--text);
}

.preview-remove svg { width: 11px; height: 11px; }

.composer-hint {
  margin: 8px 0 0;
  text-align: center;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: rgba(152, 161, 152, 0.34);
}

/* ---------- 弹层 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(3, 6, 4, 0.72);
  backdrop-filter: blur(6px);
  animation: fade-in 0.22s var(--ease) both;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 330px;
  padding: 24px 22px 20px;
  border: 1px solid rgba(233, 235, 225, 0.12);
  border-radius: var(--radius-lg);
  background: #111a14;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: modal-in 0.28s var(--ease) both;
}

.modal-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: var(--text);
}

.modal-text {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-faint);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.btn {
  flex: 1;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 13.5px;
  letter-spacing: 0.1em;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}

.btn.ghost {
  background: transparent;
  color: var(--text-sub);
}

.btn.ghost:hover {
  background: rgba(233, 235, 225, 0.05);
  color: var(--text);
}

.btn.danger {
  background: var(--danger-dim);
  border-color: rgba(209, 134, 123, 0.35);
  color: #e4a79e;
}

.btn.danger:hover {
  background: rgba(209, 134, 123, 0.2);
  color: #f0b8b0;
}

/* ---------- 图片查看 ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 5, 3, 0.94);
  cursor: zoom-out;
  animation: fade-in 0.22s var(--ease) both;
}

.lightbox img {
  max-width: 100%;
  max-height: 88dvh;
  border-radius: 8px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  animation: modal-in 0.28s var(--ease) both;
}

/* ---------- 轻提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 80;
  transform: translateX(-50%);
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(18, 27, 21, 0.96);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: rgba(232, 229, 218, 0.88);
  white-space: nowrap;
  animation: toast-in 0.28s var(--ease) both;
}

.toast.is-leaving { animation: toast-out 0.25s var(--ease) both; }

/* ---------- 动效 ---------- */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

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

@keyframes card-in {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes card-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-4px); }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(2px); }
}

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

/* 触屏设备：删除按钮常驻可见（弱化） */
@media (hover: none) {
  .delete-btn { opacity: 0.55; }
}

/* ---------- 小屏适配 ---------- */
@media (max-width: 480px) {
  .lock { padding: 32px 20px 76px; }
  .brand-title { font-size: 40px; }
  .stream-wrap { padding: 0 16px; }
  .composer-wrap { padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); }
  .topbar { padding-left: 16px; padding-right: 16px; }
  .card { padding: 14px 15px 12px; }
  .card-text { font-size: 14.5px; }
  .cell { height: 48px; }
}
