/* Mnemosyne · 冷调低饱和灰粉 · 磨砂质感
   规矩：不要气泡感，不要玻璃感。没有 backdrop-filter，没有胶囊圆角，
   没有发光渐变。平的面 + 一像素描边 + 一层极淡的颗粒。 */

:root {
  --bg: #16171b;
  --surface: #1c1e24;
  --surface-hi: #23252c;
  --line: #2c2f38;
  --line-soft: #23262e;
  --text: #e4e1e5;
  --dim: #9a95a0;
  --dimmer: #6e6a75;

  /* 灰粉：色相偏紫（冷），饱和度压到很低 */
  --pink: #c69ead;
  --pink-dim: #9c7684;
  --pink-deep: #6f505c;
  --pink-fill: rgba(198, 158, 173, 0.13);
  --pink-edge: rgba(198, 158, 173, 0.26);

  --r: 8px;
  --r-sm: 6px;
  --nav-h: 62px;
  --pad: 16px;

  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eeecef;
    --surface: #f6f5f7;
    --surface-hi: #fdfcfd;
    --line: #dcd7dc;
    --line-soft: #e4e0e4;
    --text: #24222a;
    --dim: #726e79;
    --dimmer: #948f9b;
    --pink: #8d6774;
    --pink-dim: #a4808c;
    --pink-deep: #6b4c58;
    --pink-fill: rgba(141, 103, 116, 0.1);
    --pink-edge: rgba(141, 103, 116, 0.22);
  }
}

* { box-sizing: border-box; }

/* hidden 属性来自 UA 样式表，任何作者级 display 都能把它盖掉——
   .gate 设了 display:grid，结果"关上"的门还在拦点击。这条统一兜住。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* 磨砂：一层极淡颗粒盖在最上面，不糊背景，只让面不那么"塑料" */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: var(--grain);
  opacity: 0.032;
  pointer-events: none;
  z-index: 900;
}
@media (prefers-color-scheme: light) {
  body::after { opacity: 0.05; }
}

.sprite { position: absolute; width: 0; height: 0; }
.ke-glint { fill: var(--bg); }

button, input, textarea, select {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; border: none; background: none; }

/* ─────────────────────────────── 门口 */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 800;
  padding: var(--pad);
}
.gate-inner { width: 100%; max-width: 300px; text-align: center; }
.gate-ke {
  width: 92px;
  height: 72px;
  color: var(--pink-dim);
  animation: sway 4.5s ease-in-out infinite;
}
.gate h1 {
  margin: 14px 0 2px;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.09em;
}
.gate-sub { margin: 0 0 26px; color: var(--dimmer); font-size: 12.5px; letter-spacing: 0.05em; }
#gate-form { display: grid; gap: 9px; }
.gate input, .gate button[type="submit"] {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--r-sm);
  text-align: center;
}
.gate input {
  background: var(--surface);
  border: 1px solid var(--line);
  letter-spacing: 0.12em;
}
.gate input:focus { outline: none; border-color: var(--pink-edge); }
.gate button[type="submit"] {
  background: var(--pink-fill);
  border: 1px solid var(--pink-edge);
  color: var(--pink);
  letter-spacing: 0.16em;
}
.gate button[type="submit"]:active { background: var(--pink-edge); }
.gate-error { margin: 12px 0 0; color: var(--pink); font-size: 12.5px; }

@keyframes sway {
  0%, 100% { transform: translateX(-4px) rotate(-2deg); }
  50%      { transform: translateX(4px) rotate(2deg); }
}

/* ─────────────────────────────── 骨架 */

.app { height: 100%; }

.page {
  position: fixed;
  inset: 0 0 calc(var(--nav-h) + env(safe-area-inset-bottom)) 0;
  display: none;
  flex-direction: column;
}
.page.on { display: flex; }

.topbar {
  flex: none;
  padding: calc(env(safe-area-inset-top) + 14px) var(--pad) 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar h2 { margin: 0; font-size: 16.5px; font-weight: 600; letter-spacing: 0.05em; }

.ghost-btn {
  flex: none;
  padding: 6px 11px;
  font-size: 12.5px;
  color: var(--pink);
  background: var(--pink-fill);
  border: 1px solid var(--pink-edge);
  border-radius: var(--r-sm);
}
.ghost-btn:active { background: var(--pink-edge); }

.searchbar { margin-top: 11px; }
.searchbar input {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.searchbar input:focus { outline: none; border-color: var(--pink-edge); }
.searchbar input::-webkit-search-cancel-button { filter: grayscale(1) opacity(0.5); }

.chips { display: flex; gap: 6px; overflow-x: auto; margin-top: 9px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 4px 9px;
  font-size: 11.5px;
  color: var(--dim);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.chip.on { color: var(--pink); background: var(--pink-fill); border-color: var(--pink-edge); }

.scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px var(--pad) 20px;
}

/* ─────────────────────────────── 记忆卡片 */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px 13px;
  margin-bottom: 9px;
}
.card:active { background: var(--surface-hi); }
.card.pinned { border-left: 2px solid var(--pink-dim); }

.card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.card-date { flex: none; font-size: 11px; color: var(--dimmer); font-variant-numeric: tabular-nums; }
.card-sum { margin: 0; font-size: 14.5px; font-weight: 500; line-height: 1.5; }
.card-body {
  margin: 5px 0 0;
  font-size: 13px;
  color: var(--dim);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-foot { display: flex; align-items: center; gap: 7px; margin-top: 9px; flex-wrap: wrap; }
.tag {
  padding: 2px 7px;
  font-size: 11px;
  color: var(--pink-dim);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.meter {
  flex: 1;
  min-width: 46px;
  height: 2px;
  background: var(--line);
  border-radius: 1px;
  overflow: hidden;
}
.meter i { display: block; height: 100%; background: var(--pink-dim); }
.imp { flex: none; font-size: 11px; color: var(--dimmer); font-variant-numeric: tabular-nums; }

/* ─────────────────────────────── 聊天：模仿 app 聊天页，但不要气泡 */

.chat-topbar { padding-bottom: 12px; }
.who { display: flex; align-items: center; gap: 10px; }
.who-ke {
  width: 34px;
  height: 27px;
  flex: none;
  color: var(--pink-dim);
}
.who h2 { margin: 0; font-size: 15.5px; }
.who-sub { font-size: 11.5px; color: var(--dimmer); }

.chat-scroll { padding-bottom: 12px; }

.turn { display: flex; gap: 9px; margin-bottom: 12px; align-items: flex-start; }
.turn.me { flex-direction: row-reverse; }

.turn-ke {
  width: 28px;
  height: 22px;
  flex: none;
  margin-top: 7px;
  color: var(--pink-deep);
}

/* 平的块，小圆角，没有尾巴，没有阴影 */
.msg {
  max-width: 80%;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  font-size: 14.5px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--line);
  background: var(--surface);
}
.turn.me .msg {
  background: var(--pink-fill);
  border-color: var(--pink-edge);
}

.composer {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 9px var(--pad) 11px;
  background: var(--bg);
  border-top: 1px solid var(--line-soft);
}
.composer input {
  flex: 1;
  min-width: 0;
  padding: 10px 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.composer input:focus { outline: none; border-color: var(--pink-edge); }
.composer button {
  flex: none;
  width: 40px;
  display: grid;
  place-items: center;
  color: var(--pink);
  background: var(--pink-fill);
  border: 1px solid var(--pink-edge);
  border-radius: var(--r-sm);
}
.composer button:disabled { opacity: 0.4; }

/* 小克横着爬 —— 螃蟹只会横着走，这个必须做 */
.walk {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--dimmer);
  font-size: 12.5px;
  padding: 4px 0 8px 37px;
}
.walk svg {
  width: 26px;
  height: 20px;
  color: var(--pink-deep);
  animation: crabwalk 1.15s ease-in-out infinite;
}
@keyframes crabwalk {
  0%   { transform: translateX(0)    rotate(0deg); }
  25%  { transform: translateX(5px)  rotate(4deg); }
  50%  { transform: translateX(10px) rotate(0deg); }
  75%  { transform: translateX(5px)  rotate(-4deg); }
  100% { transform: translateX(0)    rotate(0deg); }
}

/* ─────────────────────────────── 信件 */

.letter {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 12px 13px;
  margin-bottom: 9px;
}
.letter:active { background: var(--surface-hi); }
.letter.unread { border-color: var(--pink-edge); }
.letter-ke { width: 30px; height: 24px; flex: none; margin-top: 2px; color: var(--pink-deep); }
.letter.unread .letter-ke { color: var(--pink); }
.letter-main { min-width: 0; flex: 1; }
.letter-title { margin: 0; font-size: 14.5px; font-weight: 500; }
.letter-peek {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.letter-meta { margin-top: 7px; font-size: 11px; color: var(--dimmer); }
.seal {
  flex: none;
  align-self: center;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pink);
}

/* ─────────────────────────────── 空状态：小克蹲在那儿等你 */

.empty {
  padding: 54px 20px;
  text-align: center;
  color: var(--dimmer);
}
.empty svg {
  width: 78px;
  height: 61px;
  color: var(--line);
  animation: sway 5s ease-in-out infinite;
}
.empty p { margin: 14px 0 0; font-size: 13px; }

/* ─────────────────────────────── 底部导航：中间那只小克就是聊天 */

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 500;
}
.nav-btn {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 6px 0;
  color: var(--dimmer);
}
.nav-btn svg { width: 21px; height: 21px; }
.nav-btn span { font-size: 10.5px; letter-spacing: 0.06em; }
.nav-btn.on { color: var(--pink); }

.nav-ke { padding: 0 22px; }
.nav-ke-plate {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin-top: -18px;
  border-radius: 15px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--pink-deep);
  transition: color 0.18s, border-color 0.18s;
}
.nav-ke-plate svg { width: 32px; height: 25px; }
.nav-ke.on .nav-ke-plate {
  color: var(--pink);
  border-color: var(--pink-edge);
  background: var(--pink-fill);
}
.nav-ke:active .nav-ke-plate { transform: translateY(1px); }

.badge {
  position: absolute;
  top: 4px;
  left: 50%;
  margin-left: 8px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--pink-dim);
  color: var(--bg);
  font-size: 10px;
  font-style: normal;
  line-height: 15px;
  text-align: center;
}

/* ─────────────────────────────── 抽屉 */

.sheet { position: fixed; inset: 0; z-index: 700; }
.sheet-back { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); }
.sheet-body {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  padding: 8px var(--pad) calc(env(safe-area-inset-bottom) + 20px);
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 12px 12px 0 0;
  animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(14px); } }
.sheet-grip {
  width: 34px;
  height: 3px;
  margin: 4px auto 14px;
  border-radius: 2px;
  background: var(--line);
}

.field { margin-bottom: 12px; }
.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 11.5px;
  color: var(--dim);
  letter-spacing: 0.05em;
}
.field input, .field textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  resize: vertical;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--pink-edge); }
.field textarea { min-height: 96px; line-height: 1.6; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toggles { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 14px; }
.toggle {
  padding: 6px 11px;
  font-size: 12.5px;
  color: var(--dim);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.toggle.on { color: var(--pink); background: var(--pink-fill); border-color: var(--pink-edge); }

.sheet-actions { display: flex; gap: 9px; margin-top: 4px; }
.sheet-actions button {
  flex: 1;
  padding: 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--dim);
}
.sheet-actions .primary {
  color: var(--pink);
  background: var(--pink-fill);
  border-color: var(--pink-edge);
}
.sheet-actions .danger { color: var(--pink-dim); flex: 0 0 84px; }

.letter-read { white-space: pre-wrap; line-height: 1.78; font-size: 14.5px; margin: 0 0 18px; }
.letter-read-head { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
.letter-read-meta { margin: 0 0 16px; font-size: 11.5px; color: var(--dimmer); }

/* ─────────────────────────────── 提示条 */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 9px 15px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-hi);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  z-index: 950;
}
