:root {
  --pink: #f7c6d9;
  --pink-2: #f3b2cb;
  --pink-deep: #e9a0bd;
  --paper: #fffdfb;
  --ink: #2b1a24;
  --ink-2: #6e5463;
  --ink-3: #a78d9b;
  --accent: #d6336c;
  --accent-2: #b8215a;
  --line: rgba(43, 26, 36, 0.1);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(120, 30, 70, 0.08), 0 12px 32px -8px rgba(120, 30, 70, 0.22);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 90% -10%, #fbd9e6 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 110%, #f4b6ce 0%, transparent 55%),
    var(--pink);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: rgba(247, 198, 217, 0.78);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid rgba(184, 33, 90, 0.08);
}
.brand { display: flex; align-items: center; gap: 7px; min-width: 0; }
.logo { font-size: 20px; }
.wordmark {
  font-family: var(--serif); font-size: 21px; font-weight: 700; letter-spacing: -0.02em;
}
.bar-actions { display: flex; align-items: center; gap: 4px; }

.btn {
  border: 0; border-radius: 999px; padding: 8px 12px;
  font-size: 14px; font-weight: 600; letter-spacing: -0.01em;
  transition: transform .12s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(.96); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.5); }
.btn.primary {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 8px -2px rgba(214, 51, 108, 0.6);
}
.btn.primary:hover { background: var(--accent-2); }
.btn.primary[disabled] { opacity: .6; cursor: default; }
.btn.wide { width: 100%; padding: 13px 16px; font-size: 16px; }
.btn.is-dirty { animation: nudge 2.4s ease-in-out infinite; }
@keyframes nudge {
  0%, 100% { box-shadow: 0 2px 8px -2px rgba(214, 51, 108, 0.6); }
  50% { box-shadow: 0 0 0 5px rgba(214, 51, 108, 0.18), 0 2px 8px -2px rgba(214, 51, 108, 0.6); }
}

.chip {
  border: 1px solid rgba(184, 33, 90, 0.18); background: rgba(255, 255, 255, 0.65);
  border-radius: 999px; padding: 7px 11px; margin-left: 2px;
  font-size: 13px; font-weight: 600; max-width: 110px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.in { color: var(--accent-2); }

/* ---------- desk ---------- */
.desk {
  flex: 1; width: 100%; max-width: 820px; margin: 0 auto;
  padding: 12px 12px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px;
}

.toolbar {
  position: sticky; top: calc(58px + env(safe-area-inset-top)); z-index: 4;
  display: flex; align-items: center; gap: 2px;
  padding: 6px; border-radius: 12px;
  background: rgba(255, 253, 251, 0.9);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 1px 2px rgba(120, 30, 70, 0.08), 0 6px 16px -8px rgba(120, 30, 70, 0.25);
  overflow-x: auto; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar select {
  appearance: none; -webkit-appearance: none;
  border: 0; border-radius: 8px; padding: 7px 24px 7px 9px;
  font: 600 13px var(--sans); color: var(--ink);
  background: #fbeef3 url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M1 1l4 4 4-4' stroke='%236e5463' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>") no-repeat right 8px center;
  flex: none;
}
.tool {
  flex: none; width: 34px; height: 34px; border: 0; border-radius: 8px;
  background: transparent; display: grid; place-items: center;
  font-size: 15px; transition: background .12s ease, color .12s ease;
}
.tool svg { width: 18px; height: 18px; fill: currentColor; }
.tool:hover { background: #fbeef3; }
.tool.on { background: #fde0ea; color: var(--accent-2); }
.sep { flex: none; width: 1px; height: 20px; background: var(--line); margin: 0 3px; }

/* ---------- paper ---------- */
.paper {
  flex: 1; background: var(--paper); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px 48px; min-height: 60vh;
  animation: rise .35s cubic-bezier(.2, .8, .2, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (min-width: 700px) { .paper { padding: 56px 72px 80px; } }

.doc-title {
  width: 100%; border: 0; outline: none; background: transparent; padding: 0;
  font: 700 28px/1.2 var(--serif); letter-spacing: -0.02em; color: var(--ink);
  margin-bottom: 14px;
}
.doc-title::placeholder { color: #d9c3ce; }

.editor {
  outline: none; min-height: 50vh;
  font: 18px/1.65 var(--serif); color: var(--ink);
  word-wrap: break-word; caret-color: var(--accent);
}
.editor:empty::before { content: attr(data-placeholder); color: #cdb4c1; pointer-events: none; }
.editor > :first-child { margin-top: 0; }
.editor p { margin: 0 0 .8em; }
.editor h1 { font-size: 1.7em; line-height: 1.2; letter-spacing: -0.02em; margin: 1em 0 .4em; }
.editor h2 { font-size: 1.35em; line-height: 1.25; letter-spacing: -0.01em; margin: 1em 0 .4em; }
.editor h3 { font-size: 1.1em; margin: 1em 0 .3em; color: var(--ink-2); }
.editor blockquote {
  margin: 1em 0; padding: .2em 0 .2em 1em;
  border-left: 3px solid var(--pink-deep); color: var(--ink-2); font-style: italic;
}
.editor ul, .editor ol { padding-left: 1.4em; margin: 0 0 .8em; }
.editor li { margin: .2em 0; }
.editor a { color: var(--accent-2); }
.editor ::selection, .doc-title::selection { background: #fbcfe0; }

/* ---------- status ---------- */
.status {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 2px 6px; font-size: 12.5px; color: var(--ink-2); font-weight: 500;
}
.status-save::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 6px; vertical-align: 1px; background: var(--ink-3);
}
.status-save.saved::before { background: #3aa76d; }
.status-save.dirty::before { background: var(--accent); }
.status-count { font-variant-numeric: tabular-nums; }

/* ---------- sheets ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(60, 15, 38, 0.32);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .18s ease;
}
.scrim[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
@media (min-width: 600px) { .scrim { align-items: center; } }

.sheet {
  position: relative; width: 100%; max-width: 420px;
  background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 26px 22px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px -10px rgba(80, 20, 50, 0.35);
  animation: up .28s cubic-bezier(.2, .9, .25, 1);
  text-align: center;
}
@media (min-width: 600px) { .sheet { border-radius: 22px; } }
.sheet.tall { max-height: 80dvh; display: flex; flex-direction: column; text-align: left; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h2 { margin: 6px 0 6px; font: 700 22px/1.2 var(--serif); letter-spacing: -0.01em; }
.sheet-sub { margin: 0 0 18px; color: var(--ink-2); font-size: 14px; line-height: 1.45; }
.sheet-emoji { font-size: 34px; }
.sheet-x {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px;
  border: 0; border-radius: 50%; background: #fbeef3; font-size: 20px; line-height: 1;
  color: var(--ink-2);
}

.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: #fbeef3; border-radius: 12px; margin-bottom: 16px;
}
.tab {
  border: 0; background: transparent; border-radius: 9px; padding: 9px;
  font-size: 14px; font-weight: 600; color: var(--ink-2);
  transition: background .15s ease, color .15s ease;
}
.tab.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(120, 30, 70, 0.14); }

.field { display: block; text-align: left; margin-bottom: 12px; }
.field span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin: 0 0 5px 2px; }
.field input {
  width: 100%; border: 1.5px solid #f0d9e3; border-radius: 12px;
  padding: 12px 13px; font: 16px var(--sans); color: var(--ink); background: #fff;
  transition: border-color .15s ease;
}
.field input:focus { outline: none; border-color: var(--accent); }
.form-error { min-height: 1.2em; margin: 2px 0 12px; color: var(--accent-2); font-size: 13.5px; font-weight: 500; }

.doc-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.doc-item {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid var(--line);
}
.doc-item:first-child { border-top: 0; }
.doc-open {
  flex: 1; min-width: 0; text-align: left; border: 0; background: transparent;
  padding: 13px 4px; border-radius: 10px;
}
.doc-open:hover { background: #fdf3f7; }
.doc-open strong {
  display: block; font: 600 16px var(--serif);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.doc-open small { color: var(--ink-3); font-size: 12.5px; }
.doc-item.current .doc-open strong { color: var(--accent-2); }
.doc-del {
  flex: none; border: 0; background: transparent; color: var(--ink-3);
  font-size: 12.5px; font-weight: 600; padding: 8px 10px; border-radius: 999px;
  transition: background .15s ease, color .15s ease;
}
.doc-del:hover { color: var(--accent-2); background: #fdf3f7; }
.doc-del.arm { background: var(--accent); color: #fff; }
.doc-empty { padding: 26px 8px; text-align: center; color: var(--ink-2); font-size: 14.5px; line-height: 1.5; }
.doc-empty span { font-size: 30px; display: block; margin-bottom: 6px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 40;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 500; white-space: nowrap;
  box-shadow: 0 8px 24px -6px rgba(43, 26, 36, 0.5);
  transition: opacity .2s ease, transform .25s cubic-bezier(.2, .9, .25, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .wordmark { display: none; }
}

@media print {
  body { background: #fff; }
  .bar, .toolbar, .status { display: none; }
  .paper { box-shadow: none; padding: 0; }
}
