:root {
  --blue: #2f7cf6;
  --blue-deep: #1d6ae0;
  --blue-soft: #e8f2ff;
  --ink: #1b2430;
  --body: #5f6b7c;
  --muted: #98a2b3;
  --line: #eef2f6;
  --bg: #f4f7fb;
  --card: #ffffff;
  --shadow: 0 8px 24px rgba(36, 64, 110, 0.06);
  --danger: #e25454;
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background: #dbe4f0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font-family: inherit; }
button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid #b9d4ff;
  outline-offset: 2px;
}
::selection { background: #d6e7ff; }

.app {
  width: min(480px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
}
.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.3px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #8b95a7;
  display: grid;
  place-items: center;
}
.icon-btn:active { background: rgba(47, 124, 246, 0.08); }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 16px 12px;
  height: 44px;
  padding: 0 14px;
  background: var(--card);
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(30, 50, 80, 0.04);
  color: var(--muted);
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 16px;
  color: var(--ink);
}
.search input::placeholder { color: #b0b8c6; }

.folder-bar {
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 0 8px 0 6px;
  position: relative;
  z-index: 5;
}
.folders {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.folders::-webkit-scrollbar { display: none; }
.folders button {
  flex: none;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #8d97a8;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 10px 8px;
}
.folders button span {
  margin-left: 4px;
  font-size: 12px;
}
.folders button.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}
.folders .add-folder {
  color: var(--blue);
  font-size: 22px;
  line-height: 1;
  padding: 2px 10px 6px;
  border-bottom: 0;
}
.folder-manage {
  position: relative;
  flex: none;
}
.folder-manage > button {
  height: 100%;
  border: 0;
  background: transparent;
  color: #667084;
  font-size: 13px;
  font-weight: 600;
  padding: 0 8px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 16px 12px;
  position: relative;
  z-index: 4;
}
.chips { display: flex; gap: 4px; }
.chip {
  border: 0;
  background: transparent;
  color: #8d97a8;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 600;
}
.chip.active {
  background: var(--blue-soft);
  color: var(--blue);
}
.sort-wrap { position: relative; }
.sort-btn {
  border: 0;
  background: transparent;
  color: #8d97a8;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 6px 0 6px 8px;
  white-space: nowrap;
}

.menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 168px;
  padding: 6px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(20, 40, 80, 0.16);
  z-index: 6;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  border-radius: 10px;
  padding: 11px 12px;
}
.menu button:active,
.menu button.active { background: #f4f7fb; }
.menu button.danger { color: var(--danger); }

.status {
  margin: 0 16px 10px;
  color: #c05621;
  background: #fff4eb;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
}

.view { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px;
}

.card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
}
.card.is-pinned {
  box-shadow: inset 3px 0 0 var(--blue), var(--shadow);
}
.card.menu-open { z-index: 5; }
.card-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.card-head h2 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 16px;
  line-height: 1.45;
  word-break: break-word;
}
.card-head h2 svg {
  vertical-align: -2px;
  margin-right: 4px;
}
.card-tools {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.badge {
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
}
.more-btn {
  width: 32px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #b0b8c4;
  display: grid;
  place-items: center;
}
.more-btn:active { background: #f3f5f8; }
.card-tools .menu { top: 32px; }

.card-body {
  margin: 8px 0 0;
  color: var(--body);
  font-size: 14px;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
}
.card-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.card-tab {
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--blue);
  background: var(--blue-soft);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
}
.card-foot time {
  color: var(--muted);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.card-actions { display: flex; gap: 8px; }
.card-actions button {
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: #f3f5f8;
  color: #4b5568;
  padding: 0 10px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.card-actions button:active { background: #e7ebf0; }
.card-actions button.copied {
  background: #e8f8f0;
  color: #1f9d6a;
}

.pager {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 4px 0 8px;
}
.pager button {
  margin-top: 8px;
  border: 0;
  background: #fff;
  color: var(--blue);
  font-weight: 700;
  border-radius: 999px;
  height: 40px;
  padding: 0 22px;
  box-shadow: var(--shadow);
}
.pager button:disabled { color: var(--muted); }

.empty {
  margin: 28px 8px;
  text-align: center;
  color: var(--muted);
}
.empty-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 20px;
  background: #fff;
  color: var(--blue);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}
.empty strong {
  display: block;
  color: var(--ink);
  font-size: 16px;
  margin-bottom: 6px;
}
.empty p { margin: 0; font-size: 13px; line-height: 1.6; }

.skeleton {
  height: 112px;
  border-radius: var(--radius);
  background: linear-gradient(90deg, #fff 25%, #f3f6fb 37%, #fff 63%);
  background-size: 400% 100%;
  animation: shine 1.2s ease infinite;
}
@keyframes shine {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

.fab {
  position: fixed;
  z-index: 21;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 10px 24px rgba(47, 124, 246, 0.38);
  display: grid;
  place-items: center;
  right: max(18px, calc((100% - 480px) / 2 + 18px));
  bottom: calc(74px + env(safe-area-inset-bottom));
}
.fab:active { background: var(--blue-deep); }

.tabbar {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(480px, 100%);
  display: flex;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid #e8edf4;
  padding: 6px 28px calc(6px + env(safe-area-inset-bottom));
}
.tabbar button {
  flex: 1;
  border: 0;
  background: transparent;
  color: #98a2b3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 0;
}
.tabbar button.active { color: var(--blue); }

.editor-bar {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  padding: 10px 8px;
  position: sticky;
  top: 0;
  background: rgba(244, 247, 251, 0.94);
  backdrop-filter: blur(10px);
  z-index: 5;
}
.editor-bar h2 {
  margin: 0;
  text-align: center;
  font-size: 16px;
}
.editor-bar button {
  border: 0;
  background: transparent;
  color: #667084;
  font-size: 15px;
  padding: 8px;
}
#save-btn {
  color: var(--blue);
  font-weight: 700;
  text-align: right;
}
#save-btn:disabled { color: #9eb8e2; }
.editor-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
}
#draft-title {
  border: 0;
  background: transparent;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  outline: none;
  padding: 8px 2px;
}
#draft-title::placeholder { color: #c0c7d2; font-weight: 600; }
#draft-content {
  border: 0;
  outline: none;
  resize: vertical;
  min-height: 240px;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  padding: 14px;
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
}
.switch {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  font-size: 15px;
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i {
  width: 44px;
  height: 26px;
  background: #d5dbe6;
  border-radius: 999px;
  position: relative;
  transition: background 0.15s ease;
}
.switch i::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(20, 40, 80, 0.2);
  transition: transform 0.15s ease;
}
.switch input:checked + i { background: var(--blue); }
.switch input:checked + i::after { transform: translateX(18px); }
.ghost-btn,
.text-danger {
  border: 0;
  background: #fff;
  border-radius: 14px;
  height: 46px;
  font-size: 15px;
  box-shadow: var(--shadow);
}
.ghost-btn { color: var(--blue); font-weight: 700; }
.text-danger { color: var(--danger); }

.panel {
  background: #fff;
  border-radius: var(--radius);
  margin: 4px 16px 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel .row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  text-align: left;
}
.panel .row:last-child { border-bottom: 0; }
.panel .row span { color: var(--muted); }
.info-row,
.help p {
  margin: 0;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
}
.info-row:last-child { border-bottom: 0; }
.info-row strong { font-weight: 600; }
.help { padding-bottom: 4px; }
.help h3 {
  margin: 0;
  padding: 16px 16px 0;
  font-size: 14px;
}
.help p {
  display: block;
  color: var(--body);
  line-height: 1.65;
  font-size: 13px;
  border-bottom: 0;
  padding-top: 8px;
}

body.lock { overflow: hidden; }

.composer { z-index: 40; }
.composer-card {
  width: min(440px, 100%);
  max-height: min(86dvh, 680px);
  overflow: auto;
  background: var(--bg);
  border-radius: 20px;
  padding: 6px 14px 16px;
  box-shadow: 0 20px 50px rgba(20, 40, 80, 0.22);
}
.composer-bar {
  display: grid;
  grid-template-columns: 64px 1fr 64px;
  align-items: center;
  position: sticky;
  top: 0;
  background: var(--bg);
  padding: 6px 0 8px;
}
.composer-bar h2 {
  margin: 0;
  text-align: center;
  font-size: 16px;
}
.composer-bar button {
  border: 0;
  background: transparent;
  color: #667084;
  font-size: 15px;
  padding: 8px 0;
}
#compose-save {
  color: var(--blue);
  font-weight: 700;
  text-align: right;
}
#compose-save:disabled { color: #9eb8e2; }
#compose-title {
  border: 0;
  outline: none;
  background: transparent;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  padding: 8px 2px;
}
#compose-title::placeholder { color: #c0c7d2; font-weight: 600; }
.compose-label {
  display: block;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.compose-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 2px;
  scrollbar-width: none;
}
.compose-tabs::-webkit-scrollbar { display: none; }
.compose-tabs button {
  flex: none;
  border: 0;
  background: #fff;
  color: #667084;
  border-radius: 999px;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.compose-tabs button.active {
  background: var(--blue-soft);
  color: var(--blue);
}
.compose-tabs .add {
  width: 32px;
  padding: 0;
  color: var(--blue);
  font-size: 18px;
}
.composer .text-danger { width: 100%; margin-top: 8px; }
#folder-modal { z-index: 45; }
#modal { z-index: 46; }
#folder-name {
  width: 100%;
  margin-top: 14px;
  border: 0;
  outline: none;
  background: var(--bg);
  border-radius: 12px;
  height: 44px;
  padding: 0 12px;
  font-size: 16px;
  color: var(--ink);
}

#compose-content {
  width: 100%;
  min-height: 120px;
  max-height: 40dvh;
  border: 0;
  outline: none;
  resize: vertical;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  padding: 14px;
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
}
.composer .switch,
.composer .ghost-btn { margin-top: 12px; }
.composer .ghost-btn { width: 100%; }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: min(420px, calc(100% - 32px));
  background: #1c2430;
  color: #fff;
  border-radius: 999px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
body[data-view="editor"] .toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
.toast button {
  border: 0;
  background: transparent;
  color: #8cbcff;
  font-weight: 700;
  padding: 0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(20, 30, 50, 0.42);
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal-card {
  width: min(320px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 20px 18px 16px;
}
.modal-card h3 { margin: 0 0 8px; font-size: 17px; }
.modal-card p { margin: 0; color: var(--body); font-size: 14px; line-height: 1.5; word-break: break-word; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-actions button {
  border: 0;
  background: #f3f5f8;
  color: var(--ink);
  border-radius: 10px;
  height: 36px;
  padding: 0 14px;
  font-size: 14px;
}
.modal-actions .danger {
  background: var(--danger);
  color: #fff;
}
.modal-actions .primary {
  background: var(--blue);
  color: #fff;
}

@media (min-width: 520px) {
  body { background: #d5e0ee; }
  .app {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7), 0 18px 50px rgba(30, 50, 90, 0.12);
  }
}
