/* ============================================================
   Notes — quick markdown jottings, styled as an open notebook.
   Lives inside .journal, so it inherits the --j-* ink/paper tokens
   and paper-grain backdrop that books.css sets up.
   ============================================================ */

/* ---------- Index: toolbar + card grid ---------- */

.notes-toolbar {
  display: flex;
  justify-content: flex-end;
  max-width: 620px;
  margin: 28px auto 36px;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 30px;
}

.note-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 168px;
  padding: 22px 20px 16px;
  background:
    repeating-linear-gradient(to bottom, transparent, transparent 27px, var(--j-tape) 27px, var(--j-tape) 28px),
    var(--j-photo);
  background-position: 0 44px;
  border-radius: 3px;
  box-shadow: var(--shadow-sm);
  color: var(--j-ink);
  text-decoration: none;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.note-card:hover {
  transform: translateY(-4px) rotate(-0.4deg);
  box-shadow: var(--shadow-md);
  color: var(--j-ink);
}
.note-card__tape {
  position: absolute;
  top: -9px; left: 24px;
  width: 52px; height: 18px;
  background: linear-gradient(160deg, rgba(228, 213, 166, 0.92), rgba(205, 187, 139, 0.86));
  border-left: 1px solid rgba(184, 166, 120, 0.5);
  border-right: 1px solid rgba(184, 166, 120, 0.5);
  box-shadow: 0 2px 4px rgba(60, 45, 25, 0.16);
  transform: rotate(-2deg);
}
.note-card__title {
  font-family: "Caveat", ui-rounded, "Segoe UI", sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
  line-height: 1.15;
  color: var(--j-ink);
}
.note-card__snippet {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--j-ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-card__snippet p { margin: 0 0 0.4em; }
.note-card__snippet strong { color: var(--j-ink); }
.note-card__date {
  font-family: var(--font-body);
  font-size: 0.74rem;
  letter-spacing: 0.02em;
  color: var(--j-ink-faint);
}

/* ---------- Show: a single typeset page ---------- */

.note-page {
  position: relative;
  max-width: 620px;
  margin: 36px auto 0;
  background: var(--j-photo);
  border-radius: 4px;
  padding: 44px 40px 32px;
  box-shadow: var(--shadow-lg);
}
.note-page__tape {
  position: absolute;
  top: -12px; left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  width: 110px; height: 26px;
  background: linear-gradient(160deg, rgba(228, 213, 166, 0.95), rgba(205, 187, 139, 0.88));
  border-left: 1px solid rgba(184, 166, 120, 0.5);
  border-right: 1px solid rgba(184, 166, 120, 0.5);
  box-shadow: 0 3px 6px rgba(60, 45, 25, 0.2);
}
.note-page__head { margin-bottom: 22px; }
.note-page__title {
  font-family: var(--font-display);
  font-size: 2rem;
  margin: 0 0 6px;
  color: var(--j-ink);
}
.note-page__date {
  font-family: var(--font-body);
  font-size: 0.86rem;
  color: var(--j-ink-faint);
  margin: 0;
}
.note-page__body { font-family: var(--font-body); color: var(--j-ink); }
.note-page__body h1, .note-page__body h2, .note-page__body h3 {
  font-family: var(--font-display);
  font-weight: 560;
  color: var(--j-ink);
  line-height: 1.2;
  margin: 0.8em 0 0.4em;
}
.note-page__body p, .note-page__body ul, .note-page__body ol { font-size: 1rem; line-height: 1.65; margin: 0.7em 0; }
.note-page__body ul, .note-page__body ol { padding-left: 1.3em; }
.note-page__body blockquote {
  margin: 0.9em 0;
  padding: 2px 18px;
  border-left: 3px solid var(--j-accent);
  color: var(--j-ink-soft);
  font-style: italic;
}
.note-page__body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  background: rgba(138, 125, 99, 0.14);
  padding: 0.1em 0.4em;
  border-radius: 4px;
}
.note-page__body pre { background: rgba(138, 125, 99, 0.12); padding: 12px 16px; border-radius: 8px; overflow-x: auto; }
.note-page__body pre code { background: none; padding: 0; }
.note-page__body a { color: var(--j-accent); text-decoration: underline; text-decoration-color: rgba(156, 59, 46, 0.4); }
.note-page__body hr { border: none; border-top: 1px solid var(--j-ink-faint); margin: 1.2em 0; opacity: 0.3; }
.note-page__actions { margin-top: 30px; display: flex; gap: 12px; }

@media (max-width: 560px) {
  .note-page { padding: 36px 24px 26px; }
  .note-page__actions { flex-direction: column-reverse; }
  .note-page__actions .btn { justify-content: center; }
}

/* ============================================================
   Note form — the live-preview notebook spread
   ============================================================ */

.nf-spread {
  position: relative;
  max-width: 900px;
  margin: 40px auto 0;
  background: var(--j-photo);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: formIn 0.55s var(--ease) both;
}
.nf-spread.is-shaking { animation: formShake 0.45s var(--ease); }
.nf-spread.is-done { transition: opacity 0.4s var(--ease), transform 0.4s var(--ease); }

.nf-tape {
  position: absolute;
  top: -14px; left: 50%;
  transform: translateX(-50%) rotate(-1.2deg);
  width: 130px; height: 30px;
  background: linear-gradient(160deg, rgba(228, 213, 166, 0.95), rgba(205, 187, 139, 0.88));
  border-left: 1px solid rgba(184, 166, 120, 0.5);
  border-right: 1px solid rgba(184, 166, 120, 0.5);
  box-shadow: 0 3px 6px rgba(60, 45, 25, 0.2);
  z-index: 3;
}

.nf-form-error {
  margin: 18px 28px 0;
  background: #f7e3dd;
  border: 1px solid #e6c3b8;
  color: #8c3a26;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.nf-titlebar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 32px 30px 16px;
  border-bottom: 1px solid var(--j-ink-faint);
  border-bottom-color: rgba(138, 125, 99, 0.18);
}
.nf-title {
  flex: 1;
  min-width: 0;
  font-family: "Caveat", ui-rounded, "Segoe UI", sans-serif;
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--j-ink);
  background: transparent;
  border: none;
  outline: none;
}
.nf-title::placeholder { color: var(--j-ink-faint); }
.nf-tag {
  flex: none;
  font-family: var(--font-body);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--sage);
  background: rgba(138, 154, 123, 0.14);
  padding: 5px 11px;
  border-radius: 999px;
}

.nf-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 10px 24px;
  border-bottom: 1px solid rgba(138, 125, 99, 0.18);
  background: rgba(138, 125, 99, 0.05);
}
.nf-tool-sep { width: 1px; height: 18px; background: rgba(138, 125, 99, 0.22); margin: 0 6px; }
.nf-tool {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--j-ink-soft);
  background: var(--j-photo);
  border: 1px solid rgba(138, 125, 99, 0.22);
  border-radius: 7px;
  padding: 5px 10px;
  cursor: pointer;
  line-height: 1.2;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), color 0.15s var(--ease), background 0.15s var(--ease);
}
.nf-tool:hover { color: var(--j-ink); background: #fff; box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.nf-tool:active { transform: translateY(0); }
.nf-tool--bold { font-weight: 800; }
.nf-tool--italic { font-style: italic; }

.nf-leaves {
  display: grid;
  grid-template-columns: 1fr 1px 1fr;
  align-items: stretch;
  min-height: 380px;
}
.nf-spine {
  background: linear-gradient(to bottom, transparent, rgba(138, 125, 99, 0.25) 10%, rgba(138, 125, 99, 0.25) 90%, transparent);
  position: relative;
}
.nf-spine::before, .nf-spine::after {
  content: "";
  position: absolute; top: 0; bottom: 0; width: 16px;
  background: linear-gradient(to right, rgba(60, 45, 25, 0.07), transparent);
}
.nf-spine::before { left: -16px; }
.nf-spine::after { right: -16px; transform: scaleX(-1); }

.nf-leaf { display: flex; flex-direction: column; min-width: 0; }
.nf-leaf__label {
  display: flex; align-items: center; gap: 7px;
  font-family: var(--font-body);
  font-size: 0.7rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--j-ink-faint);
  padding: 13px 24px 0;
}

.nf-draft {
  flex: 1; width: 100%; resize: none; border: none; outline: none;
  background:
    repeating-linear-gradient(to bottom, transparent, transparent 31px, rgba(138, 125, 99, 0.16) 31px, rgba(138, 125, 99, 0.16) 32px),
    #f7efdd;
  background-position: 0 8px;
  font-family: "Kalam", ui-rounded, "Segoe UI", sans-serif;
  font-size: 1.1rem; line-height: 32px;
  color: var(--j-ink);
  caret-color: var(--j-accent);
  padding: 10px 24px 24px;
}
.nf-draft::placeholder { color: var(--j-ink-faint); }
.nf-draft.is-error { background-color: #fbf0ec; }

.nf-error {
  max-height: 0; overflow: hidden;
  color: #a4543a; font-size: 0.82rem;
  padding: 0 24px;
  transition: max-height 0.25s var(--ease), opacity 0.25s var(--ease);
  opacity: 0;
}
.nf-draft.is-error + .nf-error { max-height: 40px; opacity: 1; padding-top: 6px; padding-bottom: 10px; }

.nf-preview {
  flex: 1; padding: 10px 28px 24px; overflow-y: auto;
  font-family: var(--font-body); color: var(--j-ink);
}
.nf-preview h1, .nf-preview h2, .nf-preview h3 {
  font-family: var(--font-display); font-weight: 560; color: var(--j-ink);
  line-height: 1.2; margin: 0.7em 0 0.35em;
}
.nf-preview h1 { font-size: 1.5rem; }
.nf-preview h2 { font-size: 1.24rem; }
.nf-preview h3 { font-size: 1.06rem; }
.nf-preview p { margin: 0.6em 0; font-size: 0.96rem; }
.nf-preview ul, .nf-preview ol { margin: 0.5em 0; padding-left: 1.3em; font-size: 0.96rem; }
.nf-preview li { margin: 0.25em 0; }
.nf-preview blockquote {
  margin: 0.8em 0; padding: 2px 16px; border-left: 3px solid var(--sage);
  color: var(--j-ink-soft); font-style: italic;
}
.nf-preview code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em;
  background: rgba(138, 125, 99, 0.14); padding: 0.1em 0.4em; border-radius: 4px;
}
.nf-preview pre { background: rgba(138, 125, 99, 0.12); padding: 10px 14px; border-radius: 8px; overflow-x: auto; }
.nf-preview pre code { background: none; padding: 0; }
.nf-preview a { color: var(--j-accent); text-decoration: underline; text-decoration-color: rgba(156, 59, 46, 0.4); }
.nf-preview hr { border: none; border-top: 1px solid rgba(138, 125, 99, 0.25); margin: 1em 0; }
.nf-preview__empty { color: var(--j-ink-faint); font-family: "Kalam", ui-rounded, "Segoe UI", sans-serif; font-size: 1.02rem; padding-top: 4px; }

.nf-footbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 26px; border-top: 1px solid rgba(138, 125, 99, 0.18);
  background: rgba(138, 125, 99, 0.05); flex-wrap: wrap;
}
.nf-wordcount { font-family: var(--font-body); font-size: 0.8rem; color: var(--j-ink-faint); font-variant-numeric: tabular-nums; }
.nf-actions { display: flex; gap: 10px; }

/* Submit button states — reuses the cozy-form keyframes (spin / checkPop) */
.nf-submit { position: relative; min-width: 172px; justify-content: center; overflow: hidden; }
.nf-submit__spinner, .nf-submit__check { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0; }
.nf-submit__spinner { width: 18px; height: 18px; inset: auto; border: 2px solid rgba(255, 247, 239, 0.4); border-top-color: #fff7ef; border-radius: 50%; }
.nf-submit__label { transition: opacity 0.2s var(--ease); }
.nf-submit--submitting { pointer-events: none; }
.nf-submit--submitting .nf-submit__label { opacity: 0; }
.nf-submit--submitting .nf-submit__spinner { opacity: 1; animation: spin 0.7s linear infinite; }
.nf-submit--success { background: var(--sage); box-shadow: 0 6px 16px rgba(138, 154, 123, 0.4); pointer-events: none; }
.nf-submit--success .nf-submit__label { opacity: 0; }
.nf-submit--success .nf-submit__check { opacity: 1; font-size: 1.2rem; animation: checkPop 0.4s var(--ease) both; }

/* Mobile leaf tabs — hidden on desktop, where both leaves sit side by side */
.nf-leaftabs { display: none; gap: 6px; padding: 10px 24px 0; }
.nf-leaftab {
  font-family: var(--font-body); font-size: 0.78rem; font-weight: 600;
  color: var(--j-ink-faint); background: transparent; border: none;
  padding: 6px 4px; cursor: pointer; position: relative;
}
.nf-leaftab.is-active { color: var(--j-ink); }
.nf-leaftab.is-active::after {
  content: ""; position: absolute; left: 4px; right: 4px; bottom: 0; height: 2px;
  background: var(--j-accent); border-radius: 2px;
}

@media (max-width: 760px) {
  .nf-leaves { grid-template-columns: 1fr; min-height: 0; }
  .nf-spine { display: none; }
  .nf-leaftabs { display: flex; }
  .nf-leaf__label { display: none; }
  .nf-leaf--hidden { display: none; }
  .nf-draft, .nf-preview { min-height: 300px; }
  .nf-titlebar { padding: 26px 20px 14px; }
  .nf-toolbar { padding: 10px 18px; }
  .nf-footbar { padding: 14px 20px; flex-direction: column-reverse; align-items: stretch; gap: 12px; }
  .nf-actions { justify-content: stretch; }
  .nf-actions .btn { flex: 1; justify-content: center; }
  .nf-wordcount { text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  .nf-spread, .nf-tool, .note-card { animation: none !important; transition: none !important; }
  .nf-spread.is-shaking { animation: none; }
}
