:root {
  --topbar-h: 57px;
  --bg: #f5f3ee;
  --paper: #fffdf9;
  --ink: #2e2c28;
  --muted: #9a958c;
  --line: #ece7dd;
  --rule: #e7ddc9;
  --accent: #d98b3a;
  --done: #b6b1a7;
  --shadow: 0 1px 2px rgba(60, 50, 30, .06), 0 8px 30px rgba(60, 50, 30, .07);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1200px 600px at 50% -200px, #fbf9f3, transparent),
    var(--bg);
  color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(245, 243, 238, .82);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 700;
  letter-spacing: -.01em;
  cursor: pointer;
  user-select: none;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.save-status {
  font-size: 13px;
  color: var(--muted);
  min-width: 64px;
  text-align: right;
}

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn.ghost:hover { background: #efece4; }
.btn.primary {
  background: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: #c97c2c; }

/* ---- menu button (mobile) ---- */
.menu-btn {
  display: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  border-radius: 8px;
  padding: 7px 11px;
  margin-right: 10px;
  cursor: pointer;
}
.menu-btn:hover { background: #efece4; }

/* ---- layout: sidebar + sheet ---- */
.layout {
  display: flex;
  align-items: flex-start;
}

.sidebar {
  flex: 0 0 264px;
  width: 264px;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: rgba(250, 247, 240, .6);
}
.sidebar-head {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  padding: 4px 10px 10px;
}
.sidebar-new {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px dashed var(--rule);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.sidebar-new:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #fbf4e9;
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.recent-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  transition: background .12s;
}
.recent-item:hover { background: #f1ede3; }
.recent-item.active { background: #f6e7cf; }
.recent-name {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recent-name.untitled { color: var(--muted); }
.recent-del {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: #c4beb1;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity .12s, color .12s, background .12s;
}
.recent-item:hover .recent-del { opacity: 1; }
.recent-del:hover { color: #c0392b; background: #f7ece8; }

.recent-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 6px 10px;
  line-height: 1.5;
}

.scrim {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(40, 36, 30, .28);
  z-index: 15;
}

/* ---- sheet (the "paper") ---- */
.sheet {
  flex: 1 1 auto;
  max-width: 720px;
  margin: 40px auto 120px;
  padding: 56px 64px 64px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  position: relative;
}
.sheet::before {
  /* margin rule, like a notebook */
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: 38px;
  width: 1px;
  background: rgba(217, 139, 58, .18);
}

.doc-title {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--ink);
  padding: 0;
  margin-bottom: 4px;
}
.doc-title::placeholder { color: #cfc9bd; }

.doc-meta {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 28px;
  min-height: 16px;
}

/* ---- sections ---- */
.section {
  margin-bottom: 26px;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 6px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 8px;
}
.section-title {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--ink);
  padding: 4px 0;
}
.section-title::placeholder { color: #cfc9bd; }

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

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 0 3px 4px;
  border-radius: 7px;
}
.item:hover { background: #faf6ec; }

.check {
  appearance: none;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border: 1.6px solid #cdc6b8;
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
  position: relative;
  transition: background .12s, border-color .12s;
}
.check:hover { border-color: var(--accent); }
.check:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.check:checked::after {
  content: "";
  position: absolute;
  left: 5px; top: 1px;
  width: 4px; height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.item-text {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  padding: 2px 0;
}
.item-text::placeholder { color: #d3cdbf; }
.item.done .item-text {
  color: var(--done);
  text-decoration: line-through;
  text-decoration-color: rgba(182, 177, 167, .8);
}

.icon-btn {
  border: none;
  background: transparent;
  color: #c4beb1;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity .12s, color .12s, background .12s;
}
.item:hover .icon-btn,
.section-head:hover .icon-btn { opacity: 1; }
.icon-btn:hover { color: #c0392b; background: #f7ece8; }

.add-item {
  margin-top: 4px;
  margin-left: 2px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 4px;
  border-radius: 6px;
}
.add-item:hover { color: var(--accent); background: #faf3e7; }

.add-section {
  display: block;
  width: 100%;
  margin: 8px 0 30px;
  padding: 10px;
  border: 1px dashed var(--rule);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.add-section:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #fbf4e9;
}

/* ---- notes ---- */
.notes-block { margin-top: 18px; }
.notes-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}
.notes {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: none;
  outline: none;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent 27px,
      var(--rule) 27px,
      var(--rule) 28px
    );
  line-height: 28px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 0;
}
.notes::placeholder { color: #d3cdbf; }

/* ---- toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2e2c28;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  z-index: 50;
  opacity: 0;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-2px); }

@media (max-width: 980px) {
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    height: auto;
    z-index: 20;
    background: var(--paper);
    box-shadow: 0 12px 40px rgba(60, 50, 30, .18);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body:not(.sidebar-open) .scrim { display: none; }
}

@media (min-width: 981px) {
  .scrim { display: none; }
}

@media (max-width: 640px) {
  .sheet { margin: 16px; padding: 32px 22px 44px; border-radius: 12px; }
  .sheet::before { left: 14px; }
  .doc-title { font-size: 27px; }
}
