:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-soft: #1e222b;
  --bg-hover: #252a35;
  --border: #2b3140;
  --text: #e8ecf4;
  --text-dim: #98a2b3;
  --text-faint: #6b7688;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --danger: #f0616d;
  --warn: #f0b23c;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-elevated: #ffffff;
    --bg-soft: #eef1f7;
    --bg-hover: #e4e9f2;
    --border: #dbe1ec;
    --text: #1a1f2b;
    --text-dim: #5c6678;
    --text-faint: #8b95a7;
    --accent: #2f6bed;
    --accent-soft: rgba(47, 107, 237, 0.1);
    --danger: #d93a48;
    --warn: #b57708;
    --shadow: 0 10px 30px rgba(20, 30, 50, 0.1);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei',
    'Hiragino Sans GB', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

.hidden {
  display: none !important;
}

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

/* ---------- 通用按钮 ---------- */

.btn {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 15px;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, transform 0.06s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: var(--danger);
}

.btn.tiny {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 8px;
}

.btn.icon {
  padding: 6px 10px;
  border: none;
  font-size: 16px;
  line-height: 1;
}

.btn.block {
  width: 100%;
}

/* ---------- 登录 ---------- */

.auth-screen {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 20%, var(--accent-soft), transparent 55%),
    radial-gradient(circle at 80% 80%, var(--accent-soft), transparent 55%), var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 26px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0.5px;
}

.auth-brand p {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(140deg, var(--accent), #8a5bff);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 21px;
  flex: none;
}

.brand-mark.small {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  font-size: 15px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field span {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  outline: none;
  transition: border-color 0.16s, box-shadow 0.16s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-error {
  min-height: 20px;
  font-size: 13px;
  color: var(--danger);
  margin-bottom: 8px;
}

.auth-actions {
  display: flex;
  gap: 10px;
}

.auth-actions .btn {
  flex: 1;
  padding: 11px;
}

.auth-tip {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------- 主布局 ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 268px 1fr;
}

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 14px;
  gap: 14px;
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px;
}

.sidebar-title {
  font-weight: 650;
  letter-spacing: 0.4px;
}

.search-box input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 11px;
  border: none;
  background: transparent;
  border-radius: 9px;
  cursor: pointer;
  color: var(--text-dim);
  text-align: left;
}

.nav-item:hover {
  background: var(--bg-soft);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.count {
  font-size: 12px;
  color: var(--text-faint);
}

.nav-item.active .count {
  color: var(--accent);
}

.tag-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
}

.section-label {
  font-size: 12px;
  color: var(--text-faint);
  padding-left: 11px;
  letter-spacing: 0.6px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-y: auto;
  padding: 0 2px 4px;
}

.tag-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text-dim);
  cursor: pointer;
}

.tag-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tag-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  font-size: 12px;
  color: var(--text-faint);
}

.foot-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}

.sync-state {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sync-state::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #3ecf8e;
}

.sync-state.busy::before {
  background: var(--warn);
}

.sync-state.offline::before {
  background: var(--danger);
}

.main {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 0;
  min-width: 0;
}

.mobile-head {
  display: none;
}

/* ---------- 列表 ---------- */

.list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
}

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 18px 16px 10px;
  gap: 8px;
}

.list-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.list-meta {
  font-size: 12px;
  color: var(--text-faint);
  white-space: nowrap;
}

.memo-list {
  overflow-y: auto;
  padding: 0 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 1;
}

.memo-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 13px;
  cursor: pointer;
  transition: border-color 0.16s, background 0.16s;
  position: relative;
}

.memo-card:hover {
  border-color: var(--accent);
}

.memo-card.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.memo-card.overdue {
  border-left: 3px solid var(--danger);
}

.memo-card-title {
  font-weight: 600;
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.memo-card-title .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}

.memo-card-snippet {
  font-size: 13px;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.memo-card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--text-faint);
  flex-wrap: wrap;
}

.mini-tag {
  background: var(--bg-soft);
  padding: 1px 7px;
  border-radius: 6px;
  color: var(--text-dim);
}

.remind-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.remind-badge.due {
  color: var(--warn);
}

.remind-badge.overdue {
  color: var(--danger);
  font-weight: 600;
}

.pin-badge {
  font-size: 11px;
  opacity: 0.85;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-faint);
  padding: 40px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 34px;
  opacity: 0.5;
}

/* ---------- 编辑器 ---------- */

.editor-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  min-width: 0;
}

.editor-empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--text-faint);
}

.editor-empty-inner {
  text-align: center;
}

.editor {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  padding: 0 26px 18px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 4px;
}

#btn-back {
  display: none;
}

.save-hint {
  font-size: 12px;
  color: var(--text-faint);
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  gap: 2px;
}

#btn-pin.on {
  color: var(--accent);
}

.memo-title-input {
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  font-size: 24px;
  font-weight: 700;
  padding: 6px 0 12px;
  letter-spacing: -0.2px;
}

.memo-title-input::placeholder,
.memo-content-input::placeholder {
  color: var(--text-faint);
  font-weight: 500;
}

.meta-row {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.meta-label {
  font-size: 12px;
  color: var(--text-faint);
  margin-right: 8px;
}

.tag-editor {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 200px;
}

.tags-wrap {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 20px;
  padding: 3px 8px 3px 10px;
  font-size: 12px;
}

.tag-pill button {
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  opacity: 0.7;
}

.tag-pill button:hover {
  opacity: 1;
}

#tag-input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  min-width: 90px;
  padding: 3px 0;
}

.remind-editor,
.done-editor {
  display: flex;
  align-items: center;
  gap: 8px;
}

.remind-editor input[type='datetime-local'] {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 13px;
  outline: none;
}

.done-editor {
  cursor: pointer;
}

.done-editor input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.memo-content-input {
  flex: 1;
  min-height: 120px;
  width: 100%;
  border: none;
  background: transparent;
  outline: none;
  resize: none;
  font-size: 15px;
  line-height: 1.75;
  padding: 12px 0;
}

.images-section {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.images-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.upload-btn {
  cursor: pointer;
}

.image-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.image-thumb {
  position: relative;
  width: 86px;
  height: 86px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: zoom-in;
  background: var(--bg-soft);
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-thumb .remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.16s;
}

.image-thumb:hover .remove {
  opacity: 1;
}

/* ---------- 浮层 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 20px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  max-width: 86vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  display: grid;
  place-items: center;
  z-index: 90;
  cursor: zoom-out;
  padding: 20px;
}

.viewer img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

/* ---------- 移动端 ---------- */

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 274px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .mobile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    grid-column: 1;
    grid-row: 1;
  }

  .mobile-head span {
    font-weight: 600;
    font-size: 15px;
  }

  .list-pane {
    border-right: none;
    grid-column: 1;
    grid-row: 2;
  }

  .editor-pane {
    grid-column: 1;
    grid-row: 1 / span 2;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 0.22s ease;
    padding-top: env(safe-area-inset-top);
  }

  .editor-pane.mobile-open {
    transform: translateX(0);
  }

  .editor {
    padding: 0 16px calc(14px + env(safe-area-inset-bottom));
  }

  #btn-back {
    display: grid;
  }

  .list-head {
    padding: 14px 14px 8px;
  }

  .memo-title-input {
    font-size: 20px;
  }

  .image-thumb {
    width: 74px;
    height: 74px;
  }
}
