:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --text: #1f1f1d;
  --text-2: #6b6a65;
  --border: rgba(0, 0, 0, 0.1);
  --accent: #b7791f;
  --accent-bg: #f7c948;
  --accent-text: #3b2a05;
  --danger: #c0392b;
  --c-default: #ffffff;
  --c-yellow: #fff3c4;
  --c-green: #dff3d9;
  --c-blue: #d9ebfb;
  --c-pink: #fbdfe9;
  --c-purple: #e8e1fa;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161614;
    --surface: #222220;
    --text: #efede8;
    --text-2: #a3a199;
    --border: rgba(255, 255, 255, 0.12);
    --accent: #f0b429;
    --danger: #ff7b6b;
    --c-default: #222220;
    --c-yellow: #4a3f16;
    --c-green: #25402a;
    --c-blue: #1f3a52;
    --c-pink: #4f2a3a;
    --c-purple: #3a3260;
  }
}

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

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  padding-bottom: calc(132px + var(--safe-b));
}

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: calc(10px + var(--safe-t)) 16px 8px;
  border-bottom: 0.5px solid var(--border);
}

.topbar-row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }

h1 { font-size: 22px; font-weight: 600; margin: 0; }

.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.icon-btn svg { fill: var(--text-2); }
.icon-btn:active { background: var(--border); }

.text-btn {
  border: 0; background: transparent; color: var(--accent);
  min-height: 44px; padding: 0 12px; border-radius: 10px; font-size: 15px;
}
.text-btn:active { background: var(--border); }
.text-btn.danger { color: var(--danger); }

.search-wrap input {
  width: 100%; height: 40px; border-radius: 12px; border: 0.5px solid var(--border);
  background: var(--surface); padding: 0 14px; outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }

.tag-bar { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.tag-bar::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 0.5px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 4px 14px; font-size: 14px; min-height: 32px;
}
.chip.active { background: var(--accent-bg); color: var(--accent-text); border-color: transparent; }

.list { columns: 2; column-gap: 12px; padding: 14px 16px 0; }

.card {
  break-inside: avoid;
  display: block;
  width: 100%;
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--c-default);
  text-align: left;
  position: relative;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.card.c-yellow { background: var(--c-yellow); }
.card.c-green { background: var(--c-green); }
.card.c-blue { background: var(--c-blue); }
.card.c-pink { background: var(--c-pink); }
.card.c-purple { background: var(--c-purple); }
.card:active { transform: scale(0.985); }

.card-title { font-weight: 600; font-size: 16px; margin: 0 0 4px; padding-right: 28px; }
.card-body {
  font-size: 14px; color: var(--text); opacity: 0.88; white-space: pre-wrap;
  display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden;
}
.pin-mark { position: absolute; top: 10px; right: 10px; font-size: 11px; color: var(--accent); border: 0.5px solid var(--accent); border-radius: 6px; padding: 0 5px; line-height: 18px; }

.card-items { list-style: none; margin: 4px 0 0; padding: 0; font-size: 14px; }
.card-items li { display: flex; gap: 8px; align-items: flex-start; padding: 2px 0; }
.card-items input { margin: 5px 0 0; flex: 0 0 auto; width: 16px; height: 16px; accent-color: var(--accent); }
.card-items .done span { text-decoration: line-through; color: var(--text-2); }
.more-items { font-size: 13px; color: var(--text-2); padding-top: 2px; }

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 12px; padding: 0 8px; border-radius: 999px; background: rgba(127, 127, 127, 0.18); line-height: 20px; }
.card-remind { margin-top: 8px; font-size: 12px; color: var(--text-2); }
.card-remind.due { color: var(--danger); }

.card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card-actions button {
  flex: 1; min-height: 40px; border: 0.5px solid var(--border); background: var(--surface);
  border-radius: 10px; font-size: 14px;
}
.card-actions .danger { color: var(--danger); }

.empty { text-align: center; color: var(--text-2); padding: 64px 24px; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

.fab {
  position: fixed; right: 18px; bottom: calc(76px + var(--safe-b));
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--accent-bg); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center; z-index: 20;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.fab:active { transform: scale(0.95); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; background: var(--surface); border-top: 0.5px solid var(--border);
  padding-bottom: var(--safe-b);
}
.tab { flex: 1; min-height: 56px; border: 0; background: transparent; color: var(--text-2); font-size: 15px; }
.tab.active { color: var(--accent); font-weight: 600; }

.menu {
  position: fixed; top: calc(56px + var(--safe-t)); right: 12px; z-index: 40;
  background: var(--surface); border: 0.5px solid var(--border); border-radius: 12px;
  min-width: 170px; padding: 6px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; min-height: 44px; padding: 0 12px; border-radius: 8px; }
.menu button:active { background: var(--border); }

.editor {
  position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow-y: auto;
  padding-top: var(--safe-t); padding-bottom: var(--safe-b);
}
.editor.c-yellow { background: var(--c-yellow); }
.editor.c-green { background: var(--c-green); }
.editor.c-blue { background: var(--c-blue); }
.editor.c-pink { background: var(--c-pink); }
.editor.c-purple { background: var(--c-purple); }

.editor-panel { max-width: 720px; margin: 0 auto; padding: 8px 16px 48px; }
.editor-bar { display: flex; justify-content: space-between; align-items: center; margin: 0 -8px; }
.editor-bar-right { display: flex; }

.title-input {
  width: 100%; border: 0; background: transparent; outline: none;
  font-size: 22px; font-weight: 600; padding: 10px 0;
}
.body-input {
  width: 100%; border: 0; background: transparent; outline: none; resize: none;
  min-height: 38vh; padding: 4px 0; line-height: 1.7;
}

.mode-switch { display: inline-flex; border: 0.5px solid var(--border); border-radius: 10px; overflow: hidden; margin: 4px 0 10px; }
.seg { border: 0; background: transparent; min-height: 36px; padding: 0 18px; font-size: 14px; }
.seg.active { background: var(--accent-bg); color: var(--accent-text); }

.items-wrap { margin-bottom: 8px; }
.item-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.item-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex: 0 0 auto; }
.item-row input[type="text"] { flex: 1; min-width: 0; border: 0; border-bottom: 0.5px solid var(--border); background: transparent; outline: none; min-height: 40px; }
.item-row.done input[type="text"] { text-decoration: line-through; color: var(--text-2); }
.item-row .rm { border: 0; background: transparent; color: var(--text-2); width: 40px; height: 40px; font-size: 18px; }

.field { margin-top: 18px; }
.field > label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field input[type="text"], .field input[type="datetime-local"] {
  width: 100%; height: 42px; border-radius: 10px; border: 0.5px solid var(--border);
  background: var(--surface); padding: 0 12px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.remind-row { display: flex; gap: 8px; align-items: center; }
.remind-row input { flex: 1; min-width: 0; }

.colors { display: flex; gap: 12px; flex-wrap: wrap; }
.swatch {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid var(--border);
  position: relative;
}
.swatch.s-default { background: var(--c-default); }
.swatch.s-yellow { background: var(--c-yellow); }
.swatch.s-green { background: var(--c-green); }
.swatch.s-blue { background: var(--c-blue); }
.swatch.s-pink { background: var(--c-pink); }
.swatch.s-purple { background: var(--c-purple); }
.swatch[aria-checked="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

.meta-info { margin-top: 24px; font-size: 12px; color: var(--text-2); }

.dialog-back { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; padding: 20px; }
.dialog-back[hidden] { display: none; }
.dialog { background: var(--surface); border-radius: 16px; padding: 20px; max-width: 420px; width: 100%; }
.dialog h2 { margin: 0 0 10px; font-size: 18px; }
.dialog ul { margin: 0 0 16px; padding-left: 20px; font-size: 14px; color: var(--text-2); }
.dialog li { margin-bottom: 6px; }
.primary-btn { width: 100%; min-height: 44px; border: 0; border-radius: 10px; background: var(--accent-bg); color: var(--accent-text); font-weight: 600; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(140px + var(--safe-b));
  max-width: 88vw; background: #2b2b29; color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; z-index: 80;
}

[hidden] { display: none !important; }

@media (min-width: 700px) {
  .list { columns: 3; }
}
@media (min-width: 1000px) {
  .list { columns: 4; max-width: 1100px; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Notes PWA v2 enhancements ---------- */
.toolbar-row { display:flex; align-items:center; gap:8px; padding-top:8px; }
.toolbar-row select, .full-select, .full-input { min-height:40px; border:0.5px solid var(--border); border-radius:10px; background:var(--surface); color:var(--text); padding:0 10px; }
.toolbar-row select { flex:1; min-width:0; }
.full-select, .full-input { width:100%; }
.folder-label { margin-top:8px; font-size:12px; color:var(--text-2); }
.markdown-tools { display:flex; flex-wrap:wrap; gap:2px; margin:4px 0 6px; border-bottom:1px solid var(--border); }
.markdown-tools .text-btn { min-height:34px; padding:0 9px; font-size:13px; }
.markdown-preview { min-height:38vh; padding:8px 0; overflow-wrap:anywhere; }
.markdown-preview h1,.markdown-content h1 { font-size:1.45em; }
.markdown-preview h2,.markdown-content h2 { font-size:1.25em; }
.markdown-preview h3,.markdown-content h3 { font-size:1.1em; }
.markdown-preview code,.markdown-content code { background:rgba(127,127,127,.18); padding:2px 5px; border-radius:5px; }
.markdown-preview blockquote,.markdown-content blockquote { border-left:3px solid var(--accent); margin:8px 0; padding:2px 10px; color:var(--text-2); }
.calendar-wrap { margin:14px 16px 12px; padding:14px; border:1px solid var(--border); border-radius:16px; background:var(--surface); }
.calendar-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; }
.calendar-head strong { font-size:17px; }
.calendar-grid { display:grid; grid-template-columns:repeat(7,minmax(0,1fr)); gap:4px; }
.weekday { text-align:center; font-size:12px; color:var(--text-2); padding:5px 0; }
.day-cell { min-width:0; min-height:42px; border:0; border-radius:9px; background:var(--bg); color:var(--text); font-size:12px; padding:3px 1px; }
.day-cell.has-events { outline:1px solid var(--accent); font-weight:600; }
.day-cell.selected { background:var(--accent-bg); color:var(--accent-text); }
.day-cell.blank { background:transparent; }
.calendar-actions { display:flex; align-items:center; justify-content:space-between; gap:8px; margin-top:12px; color:var(--text-2); font-size:13px; }

:root[data-theme="light"] {
  color-scheme:light;
  --bg:#faf9f6; --surface:#fff; --text:#1f1f1d; --text-2:#6b6a65;
  --border:rgba(0,0,0,.1); --accent:#b7791f; --accent-bg:#f7c948; --accent-text:#3b2a05;
  --danger:#c0392b; --c-default:#fff; --c-yellow:#fff3c4; --c-green:#dff3d9;
  --c-blue:#d9ebfb; --c-pink:#fbdfe9; --c-purple:#e8e1fa;
}
:root[data-theme="dark"] {
  color-scheme:dark;
  --bg:#161614; --surface:#222220; --text:#efede8; --text-2:#a3a199;
  --border:rgba(255,255,255,.12); --accent:#f0b429; --accent-bg:#f0b429; --accent-text:#2b2108;
  --danger:#ff7b6b; --c-default:#222220; --c-yellow:#4a3f16; --c-green:#25402a;
  --c-blue:#1f3a52; --c-pink:#4f2a3a; --c-purple:#3a3260;
}
