:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #8b8b85;
  --faint: #b9b9b3;
  --line: #e7e7e2;
  --accent: #2f6b4f;
  --accent-soft: #e3eee8;
  --danger: #b4362f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.05);
  --radius: 14px;
  --bar-h: 56px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1c1c1b;
    --text: #ededea;
    --muted: #8f8f89;
    --faint: #5c5c58;
    --line: #2a2a28;
    --accent: #7cc39c;
    --accent-soft: #1f2e26;
    --danger: #ef7d74;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.icon { display: inline-flex; width: 24px; height: 24px; flex: none; }
.icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon svg.fill { fill: currentColor; stroke: none; }

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}
.bar-title { flex: 1; margin: 0 0 0 12px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%; background: none; color: var(--text);
}
.icon-btn:active { background: var(--line); }
.title-input {
  flex: 1; min-width: 0;
  border: 0; background: none; outline: none;
  font-size: 22px; font-weight: 650; letter-spacing: -0.015em;
  padding: 6px 4px;
}
.title-input::placeholder { color: var(--faint); }

.page {
  max-width: 640px; margin: 0 auto;
  padding: 8px 16px calc(120px + env(safe-area-inset-bottom));
}

/* ---------- home ---------- */
.notes { display: grid; gap: 10px; }
.card {
  display: block; padding: 14px 16px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform 0.12s ease;
}
.card:active { transform: scale(0.985); }
.card-title { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 18px; }
.card-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 4px; padding-left: 18px; color: var(--muted); font-size: 14px; }
.meta-main { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.meta-when { flex: none; }
.kind { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--faint); }
.kind.list { background: var(--accent); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; list-style: none; }
.preview-note { margin: 0 0 12px; font-size: 13px; color: var(--muted); text-align: center; }

.fab {
  position: fixed; right: 20px; bottom: calc(24px + env(safe-area-inset-bottom));
  display: grid; place-items: center;
  width: 58px; height: 58px; border: 0; border-radius: 18px;
  background: var(--accent); color: var(--bg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.fab:active { transform: scale(0.95); }
@media (min-width: 700px) { .fab { right: calc(50% - 320px + 4px); } }

/* ---------- checklist ---------- */
.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  padding: 4px; margin: 4px 0 12px;
  background: var(--line); border-radius: 12px;
}
.seg-btn {
  border: 0; border-radius: 9px; padding: 8px 0;
  background: none; color: var(--muted); font-size: 15px; font-weight: 600;
}
.seg-btn[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg-btn .count { font-weight: 500; opacity: 0.7; margin-left: 2px; }

.items { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 6px;
  min-height: 50px; padding: 0 0 0 2px;
  border-bottom: 1px solid var(--line);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.item.leaving { opacity: 0; transform: translateX(24px); }
.item.ghost { opacity: 0.35; }
.check {
  display: grid; place-items: center;
  width: 44px; height: 44px; margin-left: -8px; flex: none;
  border: 0; background: none; padding: 0;
}
.check .icon {
  width: 24px; height: 24px; padding: 3px;
  border: 2px solid var(--faint); border-radius: 7px;
  color: transparent; transition: all 0.15s ease;
}
.check .icon svg { stroke-width: 3; }
.item.done .check .icon { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.item-text {
  flex: 1; min-width: 0; padding: 12px 0;
  border: 0; background: none; outline: none;
}
.item.done .item-text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--faint); }
.handle {
  display: grid; place-items: center; width: 40px; height: 44px; flex: none;
  color: var(--faint); touch-action: none; cursor: grab;
}
.todo-mode .handle { display: none; }
.todo-mode .item.done .item-text { text-decoration: none; }

.add-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding-left: 3px; color: var(--muted);
}
.add-row .icon { width: 22px; height: 22px; }
.add-input { flex: 1; border: 0; background: none; outline: none; padding: 12px 0; }
.add-input::placeholder { color: var(--muted); }

/* ---------- text note ---------- */
.body-input {
  display: block; width: 100%; min-height: 60vh;
  border: 0; background: none; outline: none; resize: none;
  line-height: 1.55; padding: 4px 4px;
}
.body-input::placeholder { color: var(--faint); }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center; }
.login h1 { margin: 0 0 12px; font-size: 28px; letter-spacing: -0.02em; }
.logo {
  justify-self: center; display: grid; place-items: center;
  width: 56px; height: 56px; border-radius: 16px;
  background: var(--accent); color: var(--bg);
}
.logo .icon { width: 30px; height: 30px; }
.logo svg { stroke-width: 2.6; }
.login input {
  width: 100%; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); outline: none;
}
.login input:focus { border-color: var(--accent); }
.primary {
  padding: 14px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--bg); font-weight: 600;
}
.primary:disabled { opacity: 0.6; }
.error { margin: 0; min-height: 1.2em; color: var(--danger); font-size: 14px; }
.hint { margin: -8px 0 4px; color: var(--muted); font-size: 14px; }

/* ---------- sheet + toast ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  animation: fade 0.15s ease;
}
.sheet {
  width: 100%; max-width: 480px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  display: grid; gap: 6px;
  animation: rise 0.2s ease;
}
.sheet-title { padding: 12px; text-align: center; color: var(--muted); font-size: 14px; background: var(--surface); border-radius: 14px; }
.sheet-btn {
  padding: 16px; border: 0; border-radius: 14px;
  background: var(--surface); font-size: 17px; font-weight: 500;
}
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.cancel { margin-top: 4px; font-weight: 600; }
.sheet-btn:active { filter: brightness(0.95); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 16px;
  max-width: calc(100% - 32px); padding: 12px 16px;
  border-radius: 12px; background: #2b2b29; color: #f4f4f1; font-size: 15px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.2s ease;
}
.toast span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.toast button { border: 0; background: none; color: #9fd9b8; font-weight: 700; padding: 0; }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 12px); } }
