/* ============================================================
   闲话 · XIANHUA —— 京都茶室 × 奶油活页手账
   ============================================================ */

:root {
  --bg: #f3ece0;
  --bg-soft: #f8f3e8;
  --paper: #fbf6ea;
  --paper-raised: #fffdf8;
  --ink: #3c372f;
  --ink-soft: #6f6558;
  --ink-faint: #9b9082;
  --line: rgba(122, 106, 84, 0.16);
  --line-strong: rgba(122, 106, 84, 0.28);
  --matcha: #7d9b72;
  --matcha-deep: #4f6c49;
  --matcha-soft: rgba(125, 155, 114, 0.14);
  --hojicha: #b07a52;
  --hojicha-soft: rgba(176, 122, 82, 0.14);
  --sakura: #d9a09d;
  --sky: #93b3c3;
  --danger: #b5645a;
  --shadow-sm: 0 2px 6px rgba(92, 76, 54, 0.07);
  --shadow: 0 10px 26px rgba(92, 76, 54, 0.12);
  --shadow-lg: 0 22px 48px rgba(70, 58, 42, 0.2);
  --radius: 16px;
  --radius-sm: 10px;
  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "HarmonyOS Sans SC",
    "Segoe UI", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
}

[data-theme="dark"] {
  --bg: #1a1916;
  --bg-soft: #211f1b;
  --paper: #24221e;
  --paper-raised: #2b2823;
  --ink: #ece3d3;
  --ink-soft: #b6a996;
  --ink-faint: #8b7f6e;
  --line: rgba(236, 227, 211, 0.12);
  --line-strong: rgba(236, 227, 211, 0.22);
  --matcha: #8fae82;
  --matcha-deep: #b1cba4;
  --matcha-soft: rgba(143, 174, 130, 0.18);
  --hojicha: #c8976d;
  --hojicha-soft: rgba(200, 151, 109, 0.16);
  --sakura: #cf9a97;
  --sky: #96b7c7;
  --danger: #d08a80;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
*::selection { background: rgba(125, 155, 114, 0.32); }

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

body {
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(1200px 700px at 12% -10%, rgba(255, 255, 255, 0.55), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(125, 155, 114, 0.13), transparent 55%),
    radial-gradient(700px 500px at 50% 120%, rgba(176, 122, 82, 0.1), transparent 60%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[data-theme="dark"] body {
  background-image:
    radial-gradient(1100px 700px at 10% -10%, rgba(125, 155, 114, 0.12), transparent 60%),
    radial-gradient(900px 600px at 100% 0%, rgba(176, 122, 82, 0.08), transparent 55%);
}

button, input, textarea, select { font-family: inherit; color: inherit; }
button { cursor: pointer; }
.is-hidden { display: none !important; }

/* ───────────── PIN 门 ───────────── */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(700px 420px at 50% 30%, rgba(255, 253, 246, 0.85), transparent 70%),
    var(--bg);
  z-index: 100;
}

.gate::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    transparent 0 31px,
    rgba(122, 106, 84, 0.07) 31px 32px
  );
  pointer-events: none;
}

.gate-card {
  position: relative;
  width: min(380px, 100%);
  padding: 40px 30px 26px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.gate-card::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  width: 110px;
  height: 22px;
  transform: translateX(-50%) rotate(-2deg);
  background: repeating-linear-gradient(
    45deg,
    rgba(125, 155, 114, 0.55) 0 7px,
    rgba(125, 155, 114, 0.32) 7px 14px
  );
  border-radius: 2px;
  opacity: 0.85;
}

.gate-stamp {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 26px;
  color: #fff8ee;
  background: var(--hojicha);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255, 248, 238, 0.5);
}

.gate-title {
  font-family: var(--serif);
  font-size: 34px;
  letter-spacing: 0.18em;
  margin: 0 0 6px;
  color: var(--ink);
}

.gate-sub {
  margin: 0 0 26px;
  font-size: 12.5px;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
}

.gate-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gate-input {
  width: 100%;
  padding: 13px 16px;
  font-size: 17px;
  letter-spacing: 0.4em;
  text-align: center;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.gate-input:focus {
  border-color: var(--matcha);
  box-shadow: 0 0 0 3px var(--matcha-soft);
}

.gate-error {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--danger);
}

.gate-hint {
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

/* ───────────── 布局 ───────────── */

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: none;
  height: 62px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 78%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 18px;
  color: #fff8ee;
  background: linear-gradient(145deg, var(--matcha-deep), var(--matcha));
  border-radius: 11px;
  box-shadow: var(--shadow-sm);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong {
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 0.16em;
}
.brand-text span {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  white-space: nowrap;
}

.mode-switch {
  margin-left: auto;
  display: flex;
  gap: 3px;
  padding: 3px;
  background: var(--matcha-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.mode-btn {
  border: 0;
  background: transparent;
  padding: 7px 13px;
  font-size: 12.5px;
  color: var(--ink-soft);
  border-radius: 999px;
  white-space: nowrap;
  transition: background 0.18s, color 0.18s, box-shadow 0.18s;
}
.mode-btn:hover { color: var(--ink); }
.mode-btn.is-active {
  background: var(--paper-raised);
  color: var(--matcha-deep);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.top-actions { display: flex; gap: 4px; margin-left: auto; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-size: 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  transition: background 0.18s, transform 0.12s;
}
.icon-btn:hover { background: var(--matcha-soft); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0); }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

html[data-view="both"] .workspace { grid-template-columns: minmax(0, 1.02fr) minmax(0, 0.98fr); }
html[data-view="chat"] .notes-panel { display: none; }
html[data-view="notes"] .chat-panel { display: none; }

.panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}

.panel-head {
  flex: none;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-raised) 55%, transparent);
}

/* ───────────── 通用控件 ───────────── */

.btn {
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  color: var(--ink);
  padding: 9px 15px;
  font-size: 13px;
  border-radius: 10px;
  transition: transform 0.12s, box-shadow 0.18s, background 0.18s;
  white-space: nowrap;
}
.btn:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.small { padding: 7px 11px; font-size: 12.5px; }

.btn-primary {
  background: linear-gradient(160deg, var(--matcha), var(--matcha-deep));
  color: #fffaf2;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(79, 108, 73, 0.28);
}
.btn-primary:hover { box-shadow: 0 6px 16px rgba(79, 108, 73, 0.35); }

.btn-ghost { background: transparent; }

.btn-magic {
  background: linear-gradient(160deg, #d7a377, var(--hojicha));
  color: #fffaf2;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(176, 122, 82, 0.3);
  font-weight: 600;
}

.mini-btn {
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink-soft);
  font-size: 11.5px;
  padding: 5px 9px;
  border-radius: 999px;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  white-space: nowrap;
}
.mini-btn:hover { color: var(--matcha-deep); border-color: var(--matcha); background: var(--matcha-soft); }
.mini-btn.danger-text, .danger-text { color: var(--danger); }

.input, .select {
  width: 100%;
  padding: 10px 12px;
  font-size: 13.5px;
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
  color: var(--ink);
}
.input:focus, .select:focus {
  border-color: var(--matcha);
  box-shadow: 0 0 0 3px var(--matcha-soft);
}
textarea.input { resize: vertical; line-height: 1.65; }
.code-area { font-family: var(--mono); font-size: 12.5px; }

.chip {
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink-soft);
  font-size: 12px;
  padding: 6px 11px;
  border-radius: 999px;
  white-space: nowrap;
  transition: all 0.16s;
}
.chip:hover { border-color: var(--matcha); color: var(--matcha-deep); }
.chip.is-active {
  background: var(--matcha);
  border-color: var(--matcha);
  color: #fffaf2;
  box-shadow: var(--shadow-sm);
}

.row { display: flex; gap: 8px; align-items: center; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ───────────── 问答室 ───────────── */

.chat-head { display: flex; flex-direction: column; gap: 8px; }

.session-row { display: flex; gap: 6px; align-items: center; }
.session-row .select { flex: 1; min-width: 0; padding: 7px 10px; font-size: 12.5px; }

.context-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--hojicha);
  background: var(--hojicha-soft);
  border: 1px dashed color-mix(in srgb, var(--hojicha) 40%, transparent);
  border-radius: 9px;
}
.context-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 10px;
  background-image:
    repeating-linear-gradient(transparent 0 33px, rgba(122, 106, 84, 0.055) 33px 34px);
  background-position: 0 8px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar, .note-view::-webkit-scrollbar,
.sheet::-webkit-scrollbar, .tag-bar::-webkit-scrollbar { width: 7px; height: 6px; }
.messages::-webkit-scrollbar-thumb, .note-view::-webkit-scrollbar-thumb,
.sheet::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; }

.msg {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  position: relative;
  animation: fadeUp 0.25s ease both;
}
.msg.is-user { flex-direction: row-reverse; }

.avatar {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 16px;
  background: var(--matcha-soft);
  border: 1px solid var(--line);
  user-select: none;
}
.msg.is-user .avatar { background: var(--hojicha-soft); }

.msg-main { max-width: 86%; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.msg.is-user .msg-main { align-items: flex-end; }

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  font-size: 14.5px;
  line-height: 1.72;
  word-break: break-word;
  overflow-wrap: anywhere;
  position: relative;
}
.msg.is-user .bubble {
  background: color-mix(in srgb, var(--matcha) 18%, var(--paper-raised));
  border-color: color-mix(in srgb, var(--matcha) 32%, transparent);
  border-bottom-right-radius: 5px;
}
.msg.is-assistant .bubble { border-bottom-left-radius: 5px; }

.msg.is-selected .bubble {
  outline: 2px solid var(--matcha);
  outline-offset: 2px;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.18s;
  flex-wrap: wrap;
}
.msg:hover .msg-meta, .msg.is-selected .msg-meta { opacity: 1; }
.msg.is-user .msg-meta { justify-content: flex-end; }

.time { font-size: 10.5px; color: var(--ink-faint); }

.select-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  background: transparent;
  padding: 0;
  flex: none;
  align-self: flex-start;
  margin-top: 10px;
  position: relative;
  transition: all 0.15s;
}
.select-dot:hover { border-color: var(--matcha); }
.select-dot.is-on {
  background: var(--matcha);
  border-color: var(--matcha);
}
.select-dot.is-on::after {
  content: "✓";
  position: absolute;
  inset: 0;
  font-size: 10px;
  line-height: 12px;
  color: #fff;
}

.typing {
  display: inline-flex;
  gap: 5px;
  padding: 4px 2px;
}
.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--matcha);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }

.selection-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper-raised) 60%, transparent);
  flex-wrap: wrap;
}
.selection-info { font-size: 11.5px; color: var(--ink-faint); flex: 1; min-width: 120px; }
.selection-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.composer {
  flex: none;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.composer-input {
  width: 100%;
  min-height: 44px;
  max-height: 190px;
  resize: none;
  padding: 11px 14px;
  font-size: 14.5px;
  line-height: 1.6;
  border-radius: 13px;
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.composer-input:focus {
  border-color: var(--matcha);
  box-shadow: 0 0 0 3px var(--matcha-soft);
}
.composer-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.composer-hint { flex: 1; font-size: 11px; color: var(--ink-faint); text-align: right; }

.empty-state {
  height: 100%;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink-faint);
  text-align: center;
  padding: 30px 20px;
  font-size: 13px;
  line-height: 1.8;
}
.empty-state .big { font-size: 34px; opacity: 0.8; }
.empty-state p { margin: 0; max-width: 380px; }

/* ───────────── 笔记墙 ───────────── */

.notes-head { display: flex; flex-direction: column; gap: 9px; }
.search-row { display: flex; align-items: center; gap: 8px; }
.search-icon { font-size: 13px; opacity: 0.6; }
.search-input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  font-size: 13px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: var(--paper-raised);
  outline: none;
}
.search-input:focus { border-color: var(--matcha); box-shadow: 0 0 0 3px var(--matcha-soft); }

.tag-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
.tag-bar .chip { flex: none; }
.tag-count { opacity: 0.55; font-size: 10.5px; margin-left: 2px; }

.note-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px;
  columns: 2;
  column-gap: 14px;
  overscroll-behavior: contain;
}
.note-grid::-webkit-scrollbar { width: 7px; }
.note-grid::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 99px; }

.note-card {
  --accent: var(--matcha);
  break-inside: avoid;
  margin: 0 0 14px;
  padding: 20px 16px 14px 22px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: var(--shadow-sm);
  position: relative;
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.2s;
  overflow: hidden;
}
.note-card::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 12px;
  background-image: radial-gradient(circle at 5px 11px, var(--paper) 3.2px, transparent 3.6px);
  background-size: 12px 27px;
  background-repeat: repeat-y;
  opacity: 0.85;
  pointer-events: none;
}
.note-card::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 50%;
  width: 86px;
  height: 18px;
  transform: translateX(-50%) rotate(-2deg);
  border-radius: 2px;
  background: color-mix(in srgb, var(--accent) 46%, transparent);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  opacity: 0.9;
}
.note-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.note-card[data-theme="cream"] { --accent: #c9a87c; }
.note-card[data-theme="sakura"] { --accent: var(--sakura); }
.note-card[data-theme="sky"] { --accent: var(--sky); }
.note-card[data-theme="ink"] { --accent: #8a7a66; }
.note-card[data-theme="matcha"] { --accent: var(--matcha); }

.note-card-top { display: flex; align-items: flex-start; gap: 8px; }
.note-emoji {
  font-size: 22px;
  line-height: 1;
  margin-top: 1px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.08));
}
.note-title {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.45;
  margin: 0;
  flex: 1;
  word-break: break-word;
}
.note-pin { font-size: 12px; opacity: 0.7; }

.note-summary {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.66;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 10px;
}
.note-tag {
  font-size: 10.5px;
  color: color-mix(in srgb, var(--accent) 75%, var(--ink));
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
}

.note-foot {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 10.5px;
  color: var(--ink-faint);
}
.note-card-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.18s; }
.note-card:hover .note-card-actions, .note-card:focus-within .note-card-actions { opacity: 1; }

.fab {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 0;
  font-size: 22px;
  color: #fffaf2;
  background: linear-gradient(160deg, var(--matcha), var(--matcha-deep));
  box-shadow: 0 8px 20px rgba(79, 108, 73, 0.35);
  display: none;
}

/* ───────────── 覆盖层 / 抽屉 ───────────── */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(38, 32, 24, 0.38);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  justify-content: flex-end;
  animation: fadeIn 0.18s ease;
}
.overlay.center { justify-content: center; align-items: center; padding: 18px; }

.sheet {
  width: min(660px, 100%);
  height: 100%;
  background: var(--paper);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  animation: slideIn 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet-bar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.sheet-title { font-family: var(--serif); font-size: 17px; margin: 0; flex: 1; letter-spacing: 0.04em; }
.sheet-bar-actions { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.sheet-desc { font-size: 12px; color: var(--ink-faint); margin: 0 0 14px; line-height: 1.7; }

.modal {
  width: min(620px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  padding: 0 0 16px;
  animation: rise 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal .field, .modal .preset-row, .modal .modal-actions, .modal .status-line, .modal > .sheet-desc {
  margin-left: 18px;
  margin-right: 18px;
}
.modal > .sheet-desc { margin-top: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.field > span { font-size: 12px; color: var(--ink-soft); letter-spacing: 0.03em; }
.check-field { flex-direction: row; align-items: center; justify-content: space-between; }
.check-field input { width: 18px; height: 18px; accent-color: var(--matcha); }

.preset-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.status-line { min-height: 18px; margin-top: 10px; font-size: 12px; color: var(--ink-faint); line-height: 1.6; }
.status-line.ok { color: var(--matcha-deep); }
.status-line.err { color: var(--danger); }

/* 笔记阅读 */
.note-view { padding: 4px 0 40px; }
.note-view-inner { padding: 18px 26px 0; }

.note-hero { padding: 10px 26px 14px; border-bottom: 1px dashed var(--line); }
.note-hero .hero-emoji { font-size: 30px; }
.note-hero h1 {
  font-family: var(--serif);
  font-size: 25px;
  line-height: 1.45;
  margin: 6px 0 8px;
  letter-spacing: 0.02em;
}
.note-hero .hero-summary {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 10px;
  line-height: 1.7;
}
.note-hero .hero-meta { font-size: 11px; color: var(--ink-faint); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.md { font-size: 14.5px; line-height: 1.85; color: var(--ink); }
.md > :first-child { margin-top: 0; }
.md h1, .md h2, .md h3, .md h4 {
  font-family: var(--serif);
  line-height: 1.5;
  margin: 1.4em 0 0.55em;
  letter-spacing: 0.01em;
}
.md h1 { font-size: 22px; }
.md h2 { font-size: 18.5px; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.md h3 { font-size: 16px; }
.md h4 { font-size: 14.5px; }
.md p { margin: 0.6em 0; }
.md ul, .md ol { padding-left: 1.4em; margin: 0.6em 0; }
.md li { margin: 0.28em 0; }
.md li::marker { color: var(--matcha); }
.md a { color: var(--matcha-deep); text-underline-offset: 3px; }
.md mark { background: color-mix(in srgb, #e8c96a 55%, transparent); color: inherit; padding: 0 2px; border-radius: 3px; }
.md blockquote {
  margin: 0.8em 0;
  padding: 8px 14px;
  border-left: 3px solid var(--matcha);
  background: var(--matcha-soft);
  border-radius: 0 8px 8px 0;
  color: var(--ink-soft);
}
.md blockquote p { margin: 0.3em 0; }
.md hr { border: 0; border-top: 1px dashed var(--line-strong); margin: 1.4em 0; }
.md strong { font-weight: 650; color: var(--ink); }
.md code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: var(--matcha-soft);
  padding: 1.5px 5px;
  border-radius: 5px;
  color: var(--matcha-deep);
  word-break: break-word;
}
.md pre {
  position: relative;
  margin: 0.9em 0;
  padding: 14px 14px 12px;
  background: #2c2a25;
  color: #efe7d8;
  border-radius: 11px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.65;
}
.md pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
  white-space: pre;
}
.copy-btn {
  position: absolute;
  top: 7px;
  right: 7px;
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #efe7d8;
  opacity: 0;
  transition: opacity 0.15s;
}
.md pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: rgba(255, 255, 255, 0.2); }

.md table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.9em 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;
}
.md th, .md td {
  border: 1px solid var(--line-strong);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}
.md th { background: var(--matcha-soft); font-weight: 600; white-space: nowrap; }
.md tr:nth-child(even) td { background: color-mix(in srgb, var(--paper-raised) 60%, transparent); }
.md img { max-width: 100%; border-radius: 10px; margin: 0.5em 0; }

.md .task {
  list-style: none;
  margin-left: -1.25em;
  display: flex;
  align-items: flex-start;
  gap: 7px;
}
.md .task input {
  width: 15px;
  height: 15px;
  margin-top: 4px;
  accent-color: var(--matcha);
  flex: none;
}
.md .task.done > span { color: var(--ink-faint); text-decoration: line-through; text-decoration-color: var(--line-strong); }

.note-view-edit { padding: 16px 22px 40px; display: flex; flex-direction: column; gap: 10px; }
.note-view-edit label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--ink-soft); }

.note-continue {
  margin: 26px auto 0;
  display: flex;
  justify-content: center;
  padding: 0 22px;
}

/* 记忆 */
.memory-sheet { width: min(560px, 100%); padding-bottom: 30px; }
.memory-form { display: flex; flex-direction: column; gap: 8px; padding: 0 18px; margin-bottom: 16px; }
.memory-list { list-style: none; margin: 0; padding: 0 18px; display: flex; flex-direction: column; gap: 8px; }
.memory-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 11px;
  animation: fadeUp 0.2s ease;
}
.memory-item .mem-body { flex: 1; min-width: 0; }
.memory-item .mem-cat {
  display: inline-block;
  font-size: 10px;
  color: var(--hojicha);
  background: var(--hojicha-soft);
  border-radius: 999px;
  padding: 1px 7px;
  margin-bottom: 4px;
}
.memory-item p { margin: 0; font-size: 13px; line-height: 1.65; word-break: break-word; }
.memory-item .mem-actions { display: flex; gap: 3px; }
.memory-empty { font-size: 12.5px; color: var(--ink-faint); text-align: center; padding: 24px 0; }

/* Toast */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 120;
  pointer-events: none;
  width: min(92vw, 460px);
}
.toast {
  padding: 9px 16px;
  font-size: 12.5px;
  line-height: 1.5;
  color: #fffaf2;
  background: rgba(56, 50, 40, 0.94);
  border-radius: 999px;
  box-shadow: var(--shadow);
  animation: toastIn 0.22s ease, toastOut 0.3s ease 2.4s forwards;
  text-align: center;
}
.toast.err { background: rgba(150, 70, 60, 0.96); }
.toast.ok { background: rgba(79, 108, 73, 0.96); }

/* ───────────── 移动端 ───────────── */

.mobile-tabs { display: none; }

@media (max-width: 1079px) {
  html[data-view="both"] .workspace { grid-template-columns: 1fr; }
  html[data-view="both"] .notes-panel { display: none; }
  html[data-view="both"] .chat-panel { display: flex; }

  /* 手机上用底部标签切换，顶部不再放模式开关，避免挤爆宽度 */
  .mode-switch { display: none; }
  .topbar { gap: 8px; }
  .brand { flex: 1; min-width: 0; }
  .top-actions { margin-left: 0; }

  .workspace { padding: 10px 10px 76px; }
  .topbar { height: 56px; padding: 0 12px; }
  .brand-text span { display: none; }
  .mobile-tabs { width: 100%; }

  .mobile-tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--paper) 90%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
  }
  .tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    border: 0;
    background: transparent;
    font-size: 17px;
    color: var(--ink-soft);
    padding: 5px 0;
    border-radius: 10px;
  }
  .tab-btn span { font-size: 10px; letter-spacing: 0.06em; }
  .tab-btn.is-active { color: var(--matcha-deep); background: var(--matcha-soft); }

  .sheet {
    width: 100%;
    height: 92dvh;
    margin-top: auto;
    border-radius: 20px 20px 0 0;
    border-left: 0;
    border-top: 1px solid var(--line);
    animation: sheetUp 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .overlay { align-items: flex-end; }
  .overlay.center { align-items: center; padding: 12px; }
  .modal { max-height: 92dvh; border-radius: 16px; }

  .note-grid { columns: 1; padding: 12px; }
  .fab { display: grid; place-items: center; }

  .msg-main { max-width: 84%; }
  .note-view-inner, .note-hero { padding-left: 20px; padding-right: 20px; }

  .selection-bar { padding: 8px 10px; }
  .selection-info { display: none; }
  .selection-actions { flex: 1; justify-content: space-between; }
}

@media (min-width: 1080px) {
  html[data-view="both"] .tag-bar { flex-wrap: wrap; overflow-x: visible; }
  .mobile-tabs { display: none !important; }
}

@media (max-width: 420px) {
  .brand-text strong { font-size: 15px; }
  .mode-btn { padding: 6px 9px; font-size: 11px; }
  .note-card { padding-left: 18px; }
}

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

/* ───────────── 动画 ───────────── */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes slideIn {
  from { transform: translateX(30px); opacity: 0.4; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes sheetUp {
  from { transform: translateY(40px); opacity: 0.5; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }
