/* ============================================================
   纸间 · 移动端设计系统
   纸感暖调：米白纸底 / 墨色正文 / 一点朱红
   结构：430px 应用画布，屏幕内滚动，底部标签栏 + 悬浮新建
   ============================================================ */

:root {
  --paper:        #F6F1E7;
  --paper-deep:   #EFE8D9;
  --card:         #FDFBF6;
  --card-raised:  #FFFEFB;
  --ink:          #2A2622;
  --ink-2:        #57504A;
  --muted:        #776D5F;
  --line:         #E5DBCB;
  --line-soft:    #EFE7D9;
  --accent:       #B04A2C;
  --accent-deep:  #8F3A21;
  --accent-soft:  #F5E3DA;
  --moss:         #4C6357;
  --moss-soft:    #E4EBE5;

  --serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif;
  --sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
           "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;

  --shadow-sm: 0 1px 2px rgba(42, 38, 34, .05);
  --shadow-md: 0 2px 4px rgba(42, 38, 34, .04), 0 16px 28px -22px rgba(42, 38, 34, .5);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

::selection { background: var(--accent-soft); color: var(--accent-deep); }

/* 纸张颗粒 */
.grain {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .38;
  mix-blend-mode: multiply;
  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='.82' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='.16'/%3E%3C/svg%3E");
}

/* ============================ 应用画布 ============================ */

.app {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 430px;
  background:
    radial-gradient(420px 260px at 84% -6%, #FCF6EA 0%, rgba(252, 246, 234, 0) 70%),
    linear-gradient(178deg, #F7F2E9 0%, #F5EFE4 60%, #F6F1E7 100%);
  overflow: hidden;
  z-index: 1;
}

.screen {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-top) + 16px) 18px calc(136px + var(--safe-bottom));
  display: none;
}
.screen.is-active {
  display: block;
  animation: screenIn .3s cubic-bezier(.22, .61, .36, 1) both;
}
@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- 顶部问候 ---------- */

.screen-head { padding: 4px 2px 16px; }

.dateline {
  margin: 0 0 9px;
  font-size: 10.5px;
  letter-spacing: .18em;
  color: var(--accent);
  text-transform: uppercase;
}

.greet {
  margin: 0;
  font-family: var(--serif);
  font-size: 27px;
  line-height: 1.32;
  font-weight: 600;
  letter-spacing: -.01em;
}

.greet-sub {
  margin: 9px 0 0;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--muted);
}

/* ---------- 搜索 ---------- */

.search {
  display: flex;
  align-items: center;
  gap: 9px;
  height: 46px;
  padding: 0 13px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  transition: border-color .2s ease, box-shadow .2s ease;
}
.search svg { width: 16px; height: 16px; color: var(--muted); flex: 0 0 auto; }
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
}
.search input::placeholder { color: #A99D8C; }
.search input::-webkit-search-cancel-button { display: none; }
.search:focus-within {
  border-color: #DCC4B2;
  box-shadow: 0 0 0 3px rgba(176, 74, 44, .08);
}
.search-clear {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--paper-deep);
  color: var(--muted);
  flex: 0 0 auto;
}
.search-clear svg { width: 12px; height: 12px; }

/* ---------- 笔记卡片 ---------- */

.cards { display: flex; flex-direction: column; gap: 10px; }

.card-note {
  width: 100%;
  display: block;
  text-align: left;
  padding: 15px 16px 13px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  font-family: inherit;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .22s ease, border-color .22s ease;
  animation: cardIn .34s cubic-bezier(.22, .61, .36, 1) both;
}
.card-note:active {
  transform: scale(.985);
  box-shadow: var(--shadow-md);
  border-color: #DCCBB6;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: none; }
}

.card-title {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 5px;
  font-family: var(--serif);
  font-size: 16.5px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--ink);
}
.card-title em {
  font-style: normal;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pin-dot {
  flex: 0 0 auto;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.card-snippet {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.72;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: .02em;
}
.card-meta .sep { opacity: .45; }

/* ---------- 空状态 ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 52vh;
  padding: 30px 20px 60px;
  text-align: center;
}
.empty svg { width: 118px; height: 118px; }
.empty p {
  margin: 0;
  font-family: var(--serif);
  font-size: 13px;
  line-height: 1.95;
  color: var(--muted);
}

/* ---------- 底部渐隐，避免悬浮按钮压住文字 ---------- */

.bottom-scrim {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(58px + var(--safe-bottom));
  height: 62px;
  pointer-events: none;
  z-index: 4;
  background: linear-gradient(180deg, rgba(246, 241, 231, 0) 0%, rgba(246, 241, 231, .72) 58%, rgba(246, 241, 231, .95) 100%);
}

/* ---------- 悬浮新建 ---------- */

.fab {
  position: absolute;
  right: 18px;
  bottom: calc(72px + var(--safe-bottom));
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border: 0;
  border-radius: 19px;
  background: linear-gradient(160deg, #BC5330, #98391F);
  color: #FCF8EF;
  box-shadow: 0 16px 28px -14px rgba(143, 58, 33, .95), inset 0 1px 0 rgba(255, 255, 255, .18);
  transition: transform .18s cubic-bezier(.34, 1.4, .64, 1), box-shadow .2s ease;
  z-index: 5;
}
.fab svg { width: 24px; height: 24px; }
.fab:active {
  transform: scale(.93);
  box-shadow: 0 8px 16px -10px rgba(143, 58, 33, .9);
}

/* ---------- 底部标签栏 ---------- */

.tabbar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: calc(58px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(250, 246, 238, .88);
  backdrop-filter: blur(16px) saturate(1.1);
  -webkit-backdrop-filter: blur(16px) saturate(1.1);
  border-top: 1px solid var(--line);
  z-index: 6;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 10.5px;
  letter-spacing: .06em;
  transition: color .2s ease;
}
.tab svg { width: 22px; height: 22px; transition: transform .2s ease; }
.tab.is-active { color: var(--accent); }
.tab.is-active svg { transform: translateY(-1px); stroke-width: 1.9; }

/* ============================ 编辑器 ============================ */

.editor {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 430px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #FBF7EF 0%, #F7F2E8 100%);
  transform: translateY(100%);
  transition: transform .34s cubic-bezier(.32, .72, 0, 1), visibility 0s linear .34s;
  visibility: hidden;
}
.editor.is-open {
  transform: none;
  visibility: visible;
  transition: transform .34s cubic-bezier(.32, .72, 0, 1), visibility 0s;
}

.editor-bar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  height: calc(54px + var(--safe-top));
  padding-top: var(--safe-top);
  border-bottom: 1px solid var(--line-soft);
  flex: 0 0 auto;
}
.bar-btn {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border: 0;
  background: none;
  color: var(--ink-2);
}
.bar-btn svg { width: 20px; height: 20px; }
.bar-btn:active { color: var(--accent); }

.save-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: .02em;
}
.save-state .dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--moss);
  box-shadow: 0 0 0 3px var(--moss-soft);
  transition: background .2s ease, box-shadow .2s ease;
}
.save-state .dot.is-saving {
  background: #C08A2E;
  box-shadow: 0 0 0 3px #F6ECD8;
  animation: pulse 1.1s ease-in-out infinite;
}
.save-state .dot.is-error { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
@keyframes pulse { 50% { opacity: .4; } }

.editor-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 22px 0;
}
.editor-title {
  width: 100%;
  flex: 0 0 auto;
  padding: 6px 0 2px;
  border: 0;
  outline: 0;
  background: none;
  font-family: var(--serif);
  font-size: 25px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--ink);
}
.editor-title::placeholder,
.editor-body::placeholder { color: #B2A594; }

.editor-body {
  flex: 1;
  width: 100%;
  min-height: 56vh;
  padding: 8px 0 28px;
  border: 0;
  outline: 0;
  background: none;
  resize: none;
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.95;
  color: var(--ink-2);
}

.editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
  padding: 10px 22px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .02em;
  background: rgba(251, 247, 239, .7);
}

/* ============================ 登录 / 注册 ============================ */

.gate {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 430px;
  z-index: 40;
  display: flex;
  align-items: center;
  overflow-y: auto;
  padding: calc(var(--safe-top) + 34px) 26px calc(var(--safe-bottom) + 34px);
  background:
    radial-gradient(360px 240px at 76% 4%, #FCF6EA 0%, rgba(252, 246, 234, 0) 72%),
    linear-gradient(178deg, #F8F3EA 0%, #F5EFE4 100%);
}
.gate-inner { width: 100%; }

.gate-brand { text-align: center; margin-bottom: 30px; }
.seal {
  width: 54px; height: 54px;
  margin: 0 auto 15px;
  display: grid; place-items: center;
  border-radius: 15px;
  background: linear-gradient(160deg, #33302B, #221F1B);
  color: #F7F2E7;
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 12px 24px -14px rgba(42, 38, 34, .9), inset 0 1px 0 rgba(255, 255, 255, .13);
}
.gate-brand h1 {
  margin: 0 0 7px;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: .16em;
  text-indent: .16em;
}
.gate-brand p {
  margin: 0;
  font-size: 12px;
  letter-spacing: .08em;
  color: var(--muted);
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 22px;
  border-radius: 13px;
  background: var(--paper-deep);
}
.seg-item {
  padding: 9px 0;
  border: 0;
  border-radius: 10px;
  background: none;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink-2);
  transition: background .2s ease, box-shadow .2s ease;
}
.seg-item.is-active {
  background: var(--card-raised);
  color: var(--ink);
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.gate-form { display: block; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  margin: 0 0 7px 2px;
  font-size: 11.5px;
  letter-spacing: .05em;
  color: var(--muted);
}
.field input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #FFFDF8;
  font-family: inherit;
  font-size: 16px;
  color: var(--ink);
  outline: 0;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.field input::placeholder { color: #AFA290; }
.field input:focus {
  border-color: #D9BFAF;
  box-shadow: 0 0 0 3px rgba(176, 74, 44, .09);
}

.btn-primary {
  width: 100%;
  height: 50px;
  margin-top: 4px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(165deg, #B8502F, #9D3F23);
  color: #FCF8EF;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .04em;
  box-shadow: 0 16px 26px -16px rgba(143, 58, 33, .95), inset 0 1px 0 rgba(255, 255, 255, .16);
  transition: transform .16s ease, opacity .2s ease;
}
.btn-primary:active { transform: scale(.985); }
.btn-primary:disabled { opacity: .55; }

.gate-error {
  margin: 0 0 12px;
  padding: 10px 13px;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 12.5px;
  line-height: 1.6;
}
.gate-hint {
  margin: 16px 0 0;
  text-align: center;
  font-size: 11px;
  line-height: 1.75;
  color: var(--muted);
}

/* ============================ 我的 ============================ */

.me-head { text-align: center; padding: 28px 0 24px; }
.me-avatar {
  width: 72px; height: 72px;
  margin: 0 auto 15px;
  display: grid; place-items: center;
  border-radius: 24px;
  background: var(--accent-soft);
  color: #4A3B31;
  font-family: var(--serif);
  font-size: 29px;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(42, 38, 34, .06), 0 12px 24px -18px rgba(42, 38, 34, .8);
}
.me-name {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .01em;
}
.me-account { margin: 7px 0 0; font-size: 12px; color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--line);
  overflow: hidden;
}
.stat { padding: 14px 6px; text-align: center; background: var(--card); }
.stat strong {
  display: block;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.stat span { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); letter-spacing: .04em; }

.menu {
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--card);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.menu button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 17px 16px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: none;
  font-family: inherit;
  font-size: 14.5px;
  color: var(--ink);
  text-align: left;
}
.menu button:last-child { border-bottom: 0; }
.menu button:active { background: var(--paper); }
.menu button svg { width: 16px; height: 16px; color: #A2947E; }
.menu button.danger { color: var(--accent); }

.me-foot {
  margin: 24px 0 0;
  text-align: center;
  font-size: 11px;
  line-height: 1.8;
  color: var(--muted);
}

/* ============================ 底部操作面板 ============================ */

.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(42, 38, 34, .34);
  backdrop-filter: blur(2px);
  animation: fade .2s ease both;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  width: 100%;
  max-width: 430px;
  padding: 8px 10px calc(10px + var(--safe-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--paper);
  box-shadow: 0 -20px 40px -30px rgba(42, 38, 34, .6);
  animation: sheetUp .3s cubic-bezier(.32, .72, 0, 1) both;
}
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to   { transform: none; }
}
.sheet button {
  width: 100%;
  padding: 16px;
  border: 0;
  border-radius: 13px;
  background: none;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
}
.sheet button:active { background: rgba(42, 38, 34, .05); }
.sheet button.danger { color: var(--accent); }
.sheet .sheet-cancel {
  margin-top: 6px;
  border-top: 1px solid var(--line-soft);
  border-radius: 0 0 13px 13px;
  color: var(--muted);
  font-size: 14px;
}

/* ============================ 确认框 ============================ */

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(42, 38, 34, .34);
  backdrop-filter: blur(3px);
  animation: fade .18s ease both;
}
.modal {
  width: min(330px, 100%);
  padding: 22px 22px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: 0 30px 60px -30px rgba(42, 38, 34, .7);
  animation: modalIn .24s cubic-bezier(.22, .61, .36, 1) both;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.96) translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.modal h3 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
}
.modal p {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.75;
  color: var(--muted);
}
.modal-actions { display: flex; gap: 8px; }
.btn-ghost, .btn-danger {
  flex: 1;
  height: 44px;
  border: 0;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
}
.btn-ghost { background: var(--paper-deep); color: var(--ink-2); }
.btn-danger { background: var(--accent); color: #FFF8F2; }
.btn-ghost:active, .btn-danger:active { transform: scale(.985); }

/* ============================ 提示 ============================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  z-index: 70;
  transform: translateX(-50%);
  max-width: min(84vw, 340px);
  padding: 11px 17px;
  border-radius: 12px;
  background: #2C2823;
  color: #F7F2E7;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 18px 34px -16px rgba(42, 38, 34, .9);
  animation: toastIn .26s cubic-bezier(.22, .61, .36, 1) both;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ============================ 桌面端：居中成一块屏 ============================ */

@media (min-width: 700px) and (min-height: 640px) {
  body {
    background:
      radial-gradient(700px 420px at 22% 0%, #EFE7D8 0%, rgba(239, 231, 216, 0) 62%),
      #E9E1D2;
  }
  .app, .gate, .editor {
    top: 24px;
    bottom: 24px;
    border-radius: 28px;
    box-shadow: 0 0 0 1px rgba(42, 38, 34, .07), 0 44px 80px -46px rgba(42, 38, 34, .55);
  }
  .app, .gate { overflow: hidden; }
  .screen { border-radius: 28px; }
  .tabbar { border-radius: 0 0 28px 28px; }
  .fab { bottom: calc(84px + var(--safe-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
