:root {
  color-scheme: light dark;
  --paper: #f4efe5;
  --paper-deep: #ece4d5;
  --paper-warm: #f8f4eb;
  --surface: #fffdf8;
  --surface-2: #f8f3e9;
  --surface-3: #f1eadc;
  --ink: #28231c;
  --ink-soft: #4c4539;
  --muted: #887f6f;
  --faint: #ada18d;
  --line: #e3d9c7;
  --line-strong: #d2c5af;
  --accent: #ad5638;
  --accent-strong: #8d4028;
  --accent-soft: #f3e0d4;
  --accent-faint: #fbf1e9;
  --accent-ink: #8e4129;
  --green: #527b63;
  --amber: #a8752f;
  --danger: #a64034;
  --danger-soft: #f9e8e4;
  --hover: rgba(255, 253, 248, 0.62);
  --shadow-soft: 0 8px 30px rgba(74, 55, 32, 0.08);
  --shadow-large: 0 26px 70px rgba(55, 39, 21, 0.22);
  --radius: 14px;
  --font-ui: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --font-serif: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "Noto Serif CJK SC",
    "Noto Serif", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17140f;
    --paper-deep: #1c1813;
    --paper-warm: #1e1a14;
    --surface: #211d17;
    --surface-2: #28231b;
    --surface-3: #302920;
    --ink: #ece4d6;
    --ink-soft: #cec4b3;
    --muted: #a89c89;
    --faint: #7e7463;
    --line: #352e24;
    --line-strong: #493f31;
    --accent: #d97a59;
    --accent-strong: #e98d6d;
    --accent-soft: #3c2a21;
    --accent-faint: #291f1a;
    --accent-ink: #ee9b7d;
    --green: #8db59d;
    --amber: #d9ab63;
    --danger: #e08274;
    --danger-soft: #3a2521;
    --hover: rgba(255, 253, 248, 0.045);
    --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.28);
    --shadow-large: 0 26px 70px rgba(0, 0, 0, 0.55);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
}

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

button {
  border: 0;
  background: none;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input,
textarea {
  border-radius: 0;
}

[hidden] {
  display: none !important;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.inline-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  display: inline-block;
  vertical-align: -3px;
}

::selection {
  background: var(--accent-soft);
  color: var(--ink);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 99px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-color: var(--line-strong);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 15px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.primary-button {
  background: var(--accent);
  color: #fff8ed;
  box-shadow: 0 7px 18px rgba(141, 64, 40, 0.2);
}

.primary-button:hover {
  background: var(--accent-strong);
  transform: translateY(-1px);
  box-shadow: 0 9px 22px rgba(141, 64, 40, 0.26);
}

.primary-button:active {
  transform: translateY(0);
}

.secondary-button {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

.secondary-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  height: 36px;
  padding: 0 11px;
}

.ghost-button:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.danger-button {
  background: var(--danger);
  color: #fff9f5;
}

.danger-button:hover {
  filter: brightness(0.94);
}

.compact {
  height: 35px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 9px;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  color: var(--muted);
  transition:
    background-color 0.18s ease,
    color 0.18s ease;
}

.icon-button .inline-icon {
  width: 19px;
  height: 19px;
}

.icon-button:hover {
  background: var(--hover);
  color: var(--ink);
}

.icon-button.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
}

.note-title:focus-visible,
.note-content:focus-visible {
  outline: none;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.19em;
  text-transform: uppercase;
}

/* ---------- Boot ---------- */

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background:
    radial-gradient(800px 500px at 50% 30%, var(--accent-faint), transparent 70%),
    var(--paper);
}

.boot-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-serif);
  font-size: 25px;
  letter-spacing: 0.12em;
}

.boot-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Auth ---------- */

.auth-view {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(420px, 0.94fr);
  background: var(--paper);
}

.auth-story {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 42px 54px 34px;
  color: #f8f0e1;
  background:
    radial-gradient(900px 520px at 8% 0%, rgba(230, 168, 124, 0.2), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, rgba(173, 86, 56, 0.34), transparent 65%),
    linear-gradient(148deg, #221a13 0%, #382218 48%, #673121 100%);
}

.auth-story::before {
  content: "";
  position: absolute;
  z-index: -1;
  width: 620px;
  height: 620px;
  right: -250px;
  top: -210px;
  border: 1px solid rgba(255, 243, 223, 0.13);
  border-radius: 50%;
}

.auth-story::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 380px;
  height: 380px;
  left: -170px;
  bottom: -160px;
  border: 1px solid rgba(255, 243, 223, 0.09);
  border-radius: 50%;
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: var(--font-serif);
  font-size: 21px;
  letter-spacing: 0.13em;
}

.auth-brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
}

.auth-brand small {
  display: block;
  margin-top: 3px;
  color: rgba(248, 240, 225, 0.48);
  font-family: var(--font-ui);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.32em;
}

.auth-story-main {
  max-width: 540px;
  padding-bottom: 16px;
}

.auth-kicker {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 24px;
  color: rgba(244, 218, 184, 0.72);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
}

.auth-kicker .inline-icon {
  width: 15px;
  height: 15px;
}

.auth-story blockquote {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(32px, 3.2vw, 47px);
  font-weight: 500;
  line-height: 1.42;
  letter-spacing: 0.02em;
  text-wrap: balance;
}

.auth-desc {
  margin: 25px 0 0;
  color: rgba(248, 240, 225, 0.57);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.auth-paper {
  position: absolute;
  right: clamp(40px, 7vw, 100px);
  bottom: 8%;
  width: 225px;
  height: 272px;
  padding: 35px 26px 24px;
  transform: rotate(-5.5deg);
  border-radius: 3px;
  background:
    linear-gradient(162deg, rgba(255, 255, 255, 0.4), transparent 45%),
    #f5ead2;
  color: #473220;
  box-shadow:
    0 30px 70px rgba(20, 10, 4, 0.34),
    0 2px 0 rgba(255, 255, 255, 0.55) inset;
  pointer-events: none;
}

.auth-paper::after {
  content: "";
  position: absolute;
  inset: 11px;
  border: 1px solid rgba(120, 81, 45, 0.14);
  border-radius: 1px;
}

.paper-tape {
  position: absolute;
  top: -13px;
  left: 50%;
  width: 74px;
  height: 24px;
  transform: translateX(-50%) rotate(2deg);
  background: rgba(225, 204, 165, 0.65);
  box-shadow: 0 1px 2px rgba(90, 60, 30, 0.12);
}

.paper-date {
  position: relative;
  z-index: 1;
  display: block;
  color: #9b7655;
  font-size: 9px;
  letter-spacing: 0.14em;
}

.paper-title {
  position: relative;
  z-index: 1;
  display: block;
  margin: 18px 0 25px;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.paper-line {
  position: relative;
  z-index: 1;
  display: block;
  height: 1px;
  margin-bottom: 17px;
  background: rgba(112, 76, 43, 0.17);
}

.paper-line.w1 {
  width: 100%;
}

.paper-line.w2 {
  width: 87%;
}

.paper-line.w3 {
  width: 61%;
}

.paper-stamp {
  position: absolute;
  right: 24px;
  bottom: 30px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  transform: rotate(6deg);
  border: 1px solid rgba(157, 66, 42, 0.6);
  border-radius: 6px;
  color: rgba(157, 66, 42, 0.7);
  font-family: var(--font-serif);
  font-size: 14px;
  letter-spacing: 0.06em;
}

.auth-story-foot {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  color: rgba(248, 240, 225, 0.36);
  font-size: 10px;
  letter-spacing: 0.09em;
}

.auth-panel {
  display: grid;
  place-items: center;
  padding: 34px;
  background:
    radial-gradient(700px 500px at 100% 0%, var(--accent-faint), transparent 68%),
    var(--paper);
}

.auth-card {
  width: min(382px, 100%);
  animation: rise-in 0.5s ease both;
}

.auth-mobile-brand {
  display: none;
}

.auth-card h1 {
  margin: 9px 0 8px;
  font-family: var(--font-serif);
  font-size: 35px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.auth-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.75;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 28px 0 22px;
  padding: 4px;
  border-radius: 12px;
  background: var(--paper-deep);
}

.auth-tab {
  height: 37px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.auth-tab:hover {
  color: var(--ink-soft);
}

.auth-tab.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 3px 10px rgba(64, 45, 24, 0.08);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field-label {
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.field input,
.field textarea,
.search-field input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease;
}

.field input {
  height: 46px;
  padding: 0 13px;
  border-radius: 11px;
  font-size: 14px;
}

.field input::placeholder,
.field textarea::placeholder,
.search-field input::placeholder,
.note-title::placeholder,
.note-content::placeholder {
  color: var(--faint);
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
  outline: none;
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
  line-height: 1.6;
}

.auth-submit {
  justify-content: space-between;
  width: 100%;
  height: 47px;
  margin-top: 2px;
  padding: 0 17px;
}

.auth-submit .inline-icon {
  width: 17px;
  height: 17px;
}

.auth-hint {
  margin: 19px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.75;
}

.server-state {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.server-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--faint) 14%, transparent);
}

.server-state.is-ok .server-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 14%, transparent);
}

.server-state.is-error .server-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 14%, transparent);
}

/* ---------- Main / sidebar ---------- */

.main-view {
  height: 100dvh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  background: var(--paper);
}

.sidebar {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 22px 16px 13px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface) 62%, transparent), transparent 38%),
    var(--paper-deep);
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 11px;
  box-shadow: 0 7px 18px rgba(110, 55, 33, 0.2);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.brand-name {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 1.2;
}

.brand-sub {
  color: var(--muted);
  font-size: 9px;
  letter-spacing: 0.16em;
}

#sync-button.is-syncing {
  color: var(--accent);
}

#sync-button.is-syncing .inline-icon {
  animation: spin 1s linear infinite;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 23px;
}

.new-note-button {
  width: 100%;
  justify-content: flex-start;
  height: 44px;
  padding: 0 14px;
}

.new-note-button kbd {
  margin-left: auto;
  border-color: rgba(255, 248, 237, 0.2);
  background: rgba(255, 248, 237, 0.1);
  color: rgba(255, 248, 237, 0.65);
}

.template-button {
  width: 100%;
  justify-content: flex-start;
  height: 40px;
  padding: 0 12px;
  box-shadow: none;
}

.count-badge {
  margin-left: auto;
  display: inline-grid;
  place-items: center;
  min-width: 21px;
  height: 19px;
  padding: 0 6px;
  border-radius: 99px;
  background: var(--paper-deep);
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
  margin-top: 17px;
  color: var(--muted);
}

.search-field > .inline-icon {
  position: absolute;
  left: 11px;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.search-field input {
  height: 38px;
  padding: 0 33px 0 34px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 68%, transparent);
  font-size: 12.5px;
  outline: none;
}

.search-field input:focus {
  border-color: var(--line-strong);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 7%, transparent);
}

.search-field input::-webkit-search-cancel-button {
  display: none;
}

.search-clear {
  position: absolute;
  right: 6px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  color: var(--muted);
}

.search-clear:hover {
  background: var(--hover);
  color: var(--ink);
}

.search-clear .inline-icon {
  width: 13px;
  height: 13px;
}

.list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
  padding: 0 5px 8px;
}

.list-title {
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
}

.list-count {
  margin-left: 3px;
  color: var(--faint);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 6px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 10.5px;
  transition:
    background-color 0.18s ease,
    color 0.18s ease;
}

.sort-button .inline-icon {
  width: 13px;
  height: 13px;
}

.sort-button:hover {
  background: var(--hover);
  color: var(--ink-soft);
}

.note-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 1px 2px 10px 1px;
  margin-right: -4px;
  padding-right: 4px;
}

.note-card {
  position: relative;
  display: block;
  width: 100%;
  padding: 11px 12px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: inherit;
  text-align: left;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

.note-card:hover {
  background: var(--hover);
}

.note-card.is-active {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 4px 16px rgba(70, 51, 27, 0.07);
}

.note-card.is-active::before {
  content: "";
  position: absolute;
  top: 13px;
  bottom: 13px;
  left: -1px;
  width: 2px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}

.note-card-title {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card.is-untitled .note-card-title {
  color: var(--muted);
}

.note-card-snippet {
  display: -webkit-box;
  overflow: hidden;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.62;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  word-break: break-word;
}

.note-times {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 7px;
  margin-top: 8px;
  color: var(--faint);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}

.note-time {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

.note-time .time-label {
  opacity: 0.78;
}

.note-time.updated {
  color: var(--accent-ink);
}

.note-time-sep {
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--faint);
  opacity: 0.6;
}

.list-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 13px;
  padding: 24px 18px 50px;
  text-align: center;
}

.list-empty-icon {
  width: 33px;
  height: 33px;
  color: var(--faint);
  opacity: 0.7;
}

.list-empty p {
  max-width: 210px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.75;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 4px 2px;
  border-top: 1px solid var(--line);
}

.user-block {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 600;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.user-name {
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync-status {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 9.5px;
  line-height: 1.3;
}

.sync-dot {
  width: 5px;
  height: 5px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--green) 12%, transparent);
}

.sync-status.is-dirty .sync-dot {
  background: var(--amber);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--amber) 15%, transparent);
}

.sync-status.is-syncing .sync-dot {
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}

.sync-status.is-error .sync-dot {
  background: var(--danger);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 14%, transparent);
}

.sync-status.is-offline .sync-dot {
  background: var(--faint);
  box-shadow: none;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

/* ---------- Editor ---------- */

.editor-pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(900px 520px at 80% 0%, var(--accent-faint), transparent 62%),
    var(--surface);
}

.editor-pane::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.45;
  pointer-events: none;
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 5%, transparent) 0.7px, transparent 0.7px);
  background-size: 5px 5px;
}

.editor-empty {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 38px;
  overflow: hidden;
  text-align: center;
}

.empty-watermark {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -52%);
  color: var(--accent);
  font-family: var(--font-serif);
  font-size: min(42vw, 460px);
  line-height: 1;
  opacity: 0.035;
  user-select: none;
  pointer-events: none;
}

.empty-eyebrow {
  position: relative;
  margin: 0 0 16px;
  color: var(--faint);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.26em;
}

.editor-empty h2 {
  position: relative;
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(22px, 2.3vw, 29px);
  font-weight: 500;
  letter-spacing: 0.03em;
  line-height: 1.5;
}

.empty-hint {
  position: relative;
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

.empty-shortcuts {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px 22px;
  margin-top: 34px;
  color: var(--faint);
  font-size: 10.5px;
}

.empty-shortcuts span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.empty-shortcuts kbd {
  background: var(--surface-2);
}

.editor {
  position: relative;
  z-index: 1;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  animation: editor-in 0.28s ease both;
}

@keyframes editor-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px clamp(20px, 3.5vw, 40px);
  border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: blur(12px);
}

.back-button {
  display: none;
}

.save-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 27px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 500;
  white-space: nowrap;
}

.save-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
}

.save-pill.is-dirty {
  color: var(--amber);
  border-color: color-mix(in srgb, var(--amber) 26%, var(--line));
}

.save-pill.is-dirty .save-dot {
  background: var(--amber);
}

.save-pill.is-syncing {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 25%, var(--line));
}

.save-pill.is-syncing .save-dot {
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}

.save-pill.is-error {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 24%, var(--line));
}

.save-pill.is-error .save-dot {
  background: var(--danger);
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.editor-actions .ghost-button {
  font-size: 11.5px;
}

.editor-actions .ghost-button .inline-icon {
  width: 14px;
  height: 14px;
}

.editor-doc {
  display: flex;
  flex: 1;
  flex-direction: column;
  width: 100%;
  max-width: 900px;
  min-height: 0;
  margin: 0 auto;
  padding: clamp(28px, 4vw, 48px) clamp(24px, 5vw, 64px) 0;
}

.note-title {
  width: 100%;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: clamp(29px, 3.1vw, 40px);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

.note-title::placeholder {
  color: var(--faint);
}

.note-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px 11px;
  margin-top: 15px;
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}

.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.meta-item .inline-icon {
  width: 13px;
  height: 13px;
  opacity: 0.72;
}

.meta-updated {
  color: var(--accent-ink);
}

.meta-divider {
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--faint);
  opacity: 0.55;
}

.note-content {
  flex: 1;
  width: 100%;
  min-height: 0;
  margin-top: 26px;
  padding: 0 0 17vh;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 2;
  letter-spacing: 0.015em;
  tab-size: 2;
}

.note-content::placeholder {
  color: var(--faint);
}

/* ---------- Modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(32, 23, 15, 0.44);
  backdrop-filter: blur(5px);
  animation: fade-in 0.2s ease both;
}

.modal-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(770px, 100%);
  max-height: min(84vh, 780px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-large);
  animation: modal-in 0.23s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(9px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 26px 17px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 5px 0 0;
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.template-list-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.template-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 17px 26px;
}

.template-toolbar p {
  max-width: 460px;
  margin: 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
}

.template-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
  min-height: 0;
  padding: 0 26px 26px;
  overflow-y: auto;
}

.template-card {
  display: flex;
  flex-direction: column;
  min-height: 158px;
  padding: 15px 16px 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  transition:
    border-color 0.18s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.template-card:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: 0 8px 22px rgba(61, 44, 24, 0.06);
}

.template-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.template-card h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
}

.template-card time {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
}

.template-preview {
  display: -webkit-box;
  overflow: hidden;
  margin: 9px 0 12px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.template-card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: auto;
  padding-top: 9px;
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.template-card-actions .primary-button {
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 11px;
  box-shadow: none;
}

.template-card-actions .ghost-button {
  height: 29px;
  padding: 0 8px;
  font-size: 10.5px;
}

.template-card-actions .icon-button {
  width: 29px;
  height: 29px;
  border-radius: 8px;
}

.template-card-actions .icon-button .inline-icon {
  width: 15px;
  height: 15px;
}

.template-card-actions .spacer {
  flex: 1;
}

.template-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px 26px 34px;
  text-align: center;
}

.template-empty-icon {
  width: 36px;
  height: 36px;
  margin-bottom: 12px;
  color: var(--faint);
}

.template-empty h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
}

.template-empty > p {
  max-width: 370px;
  margin: 8px 0 20px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.7;
}

.starter-templates {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  width: 100%;
  max-width: 570px;
}

.starter-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  text-align: left;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    transform 0.18s ease;
}

.starter-card:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: var(--surface);
}

.starter-icon {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  flex: 0 0 auto;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-family: var(--font-serif);
  font-size: 14px;
}

.starter-card strong {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
}

.starter-card small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 9.5px;
  line-height: 1.35;
}

.template-editor-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 21px 26px 24px;
}

.template-editor-head {
  margin-bottom: 16px;
}

.template-editor-head h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.template-editor-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.6;
}

.template-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
  min-height: 100%;
}

.template-form .field textarea {
  min-height: 260px;
  padding: 12px 13px;
  resize: vertical;
  border-radius: 11px;
  font-size: 13px;
  line-height: 1.8;
}

.field-grow {
  flex: 1;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.confirm-card {
  width: min(400px, 100%);
  padding: 25px 25px 22px;
}

.confirm-card h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 23px;
  font-weight: 600;
}

.confirm-card p {
  margin: 10px 0 22px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.75;
}

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  z-index: 120;
  right: 22px;
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(360px, calc(100vw - 36px));
  padding: 10px 14px;
  border: 1px solid rgba(255, 250, 240, 0.12);
  border-radius: 10px;
  background: #2b251d;
  color: #f8f1e5;
  font-size: 12px;
  line-height: 1.6;
  box-shadow: 0 12px 34px rgba(22, 14, 7, 0.28);
  animation: toast-in 0.24s ease both;
}

.toast.is-error {
  background: #5c2b24;
}

.toast.is-leaving {
  animation: toast-out 0.2s ease both;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(4px);
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 1800px) {
  .auth-paper {
    display: none;
  }
}

@media (max-width: 1120px) {
  .main-view {
    grid-template-columns: 330px minmax(0, 1fr);
  }

  .auth-story {
    padding: 38px 42px 30px;
  }
}

@media (max-width: 920px) {
  .auth-view {
    grid-template-columns: 1fr;
  }

  .auth-story {
    display: none;
  }

  .auth-panel {
    place-items: start center;
    align-content: center;
    padding: 34px 22px;
    overflow-y: auto;
  }

  .auth-mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 30px;
    font-family: var(--font-serif);
    font-size: 19px;
    letter-spacing: 0.09em;
  }

  .auth-mobile-brand .auth-brand-logo {
    width: 36px;
    height: 36px;
  }

  .auth-tabs {
    margin-top: 23px;
  }
}

@media (max-width: 820px) {
  .main-view {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: 100dvh;
    padding-top: calc(18px + env(safe-area-inset-top));
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    border-right: 0;
  }

  .new-note-button kbd {
    display: none;
  }

  .note-meta .meta-divider {
    display: none;
  }

  .editor-pane {
    display: none;
    height: 100dvh;
  }

  .main-view.editor-open .sidebar {
    display: none;
  }

  .main-view.editor-open .editor-pane {
    display: flex;
  }

  .back-button {
    display: inline-grid;
  }

  .editor-header {
    padding-top: calc(11px + env(safe-area-inset-top));
    padding-bottom: 11px;
  }

  .editor-actions .ghost-button span {
    display: none;
  }

  .editor-actions .ghost-button {
    width: 36px;
    padding: 0;
  }

  .editor-doc {
    padding: 25px 21px 0;
  }

  .note-title {
    font-size: clamp(27px, 7.4vw, 34px);
  }

  .note-content {
    margin-top: 20px;
    padding-bottom: 25vh;
    font-size: 16.5px;
    line-height: 1.95;
  }

  .toolbar {
    padding-top: 14px;
  }

  .modal {
    padding: 12px;
  }

  .modal-card {
    width: 100%;
    max-height: calc(100dvh - 24px);
    border-radius: 18px;
  }

  .modal-header {
    padding: 18px 19px 14px;
  }

  .modal-header h2 {
    font-size: 23px;
  }

  .template-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 11px;
    padding: 14px 19px;
  }

  .template-list {
    grid-template-columns: 1fr;
    padding: 0 19px 20px;
  }

  .template-editor-view {
    padding: 17px 19px 20px;
  }

  .starter-templates {
    grid-template-columns: 1fr;
  }

  .template-empty {
    padding: 6px 19px 26px;
  }

  .toast-stack {
    right: 14px;
    left: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    align-items: stretch;
  }

  .toast {
    max-width: none;
  }
}

@media (max-width: 450px) {
  .sidebar {
    padding-left: 13px;
    padding-right: 13px;
  }

  .auth-panel {
    padding: 28px 18px;
  }

  .auth-card h1 {
    font-size: 31px;
  }

  .auth-mobile-brand {
    margin-bottom: 24px;
  }

  .editor-actions {
    gap: 0;
  }

  .save-pill {
    padding: 0 8px;
  }

  .editor-header {
    gap: 7px;
  }

  .template-card {
    min-height: 145px;
  }
}

@media (max-height: 760px) and (min-width: 921px) {
  .auth-paper {
    display: none;
  }

  .auth-story blockquote {
    font-size: 34px;
  }

  .auth-story-main {
    padding-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
