:root {
  --paper: #f5f3ee;
  --surface: #ffffff;
  --surface-muted: #ebe8e0;
  --ink: #17212b;
  --ink-soft: #58626d;
  --line: #d8d4ca;
  --accent: #b53b2d;
  --accent-dark: #8f2d22;
  --blue: #245b7a;
  --green: #356b55;
  --danger-bg: #fff2ef;
  --shadow: 0 14px 34px rgba(23, 33, 43, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 16px;
  line-height: 1.65;
}

a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 10px max(22px, calc((100vw - 1160px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(245, 243, 238, 0.96);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
}

.brand-mark-large {
  width: 46px;
  height: 46px;
  font-size: 21px;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.main-nav a,
.nav-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: var(--ink-soft);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}

.main-nav a:hover,
.nav-button:hover,
.main-nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--surface-muted);
}

.page {
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto;
  padding: 46px 0 80px;
}

.page-heading,
.editor-heading,
.reading-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 30px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.16;
  letter-spacing: 0;
}

h2 {
  line-height: 1.35;
  letter-spacing: 0;
}

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

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 1px rgba(23, 33, 43, 0.04);
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

.button:hover {
  border-color: #bcb7ac;
  background: #faf9f6;
}

.button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible,
button:focus-visible {
  outline: 3px solid rgba(36, 91, 122, 0.24);
  outline-offset: 2px;
}

.button-primary {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.button-primary:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.button-danger {
  border-color: #e4b7af;
  color: #8f2d22;
  background: var(--danger-bg);
}

.button-danger:hover {
  border-color: #d99c91;
  background: #ffe9e5;
}

.button-small {
  min-height: 34px;
  padding: 0 11px;
  font-size: 14px;
}

.button-wide {
  width: 100%;
}

.text-link {
  color: var(--blue);
  font-weight: 650;
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.notes-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 30px;
  align-items: start;
}

.notes-main {
  min-width: 0;
}

.tag-sidebar {
  position: sticky;
  top: 92px;
}

.tag-sidebar-inner {
  padding-right: 18px;
  border-right: 1px solid var(--line);
}

.sidebar-title {
  margin-bottom: 10px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tag-nav {
  display: grid;
  gap: 3px;
}

.tag-nav a {
  display: flex;
  min-width: 0;
  min-height: 40px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--ink-soft);
  text-decoration: none;
}

.tag-nav a:hover {
  color: var(--ink);
  background: var(--surface-muted);
}

.tag-nav a.active {
  color: #fff;
  background: var(--blue);
}

.tag-nav a span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-count {
  flex: 0 0 auto;
  color: inherit;
  font-size: 12px;
  opacity: 0.75;
}

.search-form {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 10px;
  max-width: 700px;
}

.search-field {
  flex: 1;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
}

input {
  min-height: 44px;
  padding: 9px 12px;
}

textarea {
  min-height: 340px;
  padding: 14px;
  resize: vertical;
  line-height: 1.75;
}

.result-count,
.metadata {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.note-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.note-card {
  display: flex;
  min-width: 0;
  min-height: 220px;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(23, 33, 43, 0.04);
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.note-card:hover {
  border-color: #bdb6a8;
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.note-card-main {
  display: block;
  padding: 24px 24px 18px;
  text-decoration: none;
}

.note-card h2 {
  overflow-wrap: anywhere;
  margin-bottom: 10px;
  font-size: 21px;
}

.note-card p {
  display: -webkit-box;
  overflow: hidden;
  margin-bottom: 0;
  color: var(--ink-soft);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.note-card-footer {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 24px;
  border-top: 1px solid #ece9e2;
  color: var(--ink-soft);
  font-size: 13px;
}

.note-card-actions {
  align-items: flex-start;
  flex-direction: column;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  min-height: 25px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--green);
  background: #e9f1ed;
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
}

a.tag:hover {
  color: #244d3c;
  background: #dcebe3;
}

.tag-list-large {
  margin: -10px 0 28px;
}

.empty-state {
  display: grid;
  min-height: 330px;
  place-content: center;
  justify-items: start;
  padding: 46px;
  border: 1px dashed #bbb5aa;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.46);
}

.empty-state h1,
.empty-state h2 {
  margin-bottom: 8px;
  font-size: 26px;
}

.empty-state p {
  color: var(--ink-soft);
}

.reading-shell,
.editor-shell {
  width: min(820px, 100%);
  margin: 0 auto;
}

.reading-header {
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}

.reading-title {
  min-width: 0;
}

.reading-title h1 {
  overflow-wrap: anywhere;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.note-body {
  padding-top: 14px;
  overflow-wrap: anywhere;
  color: #26313b;
  font-size: 18px;
  line-height: 1.9;
  white-space: pre-wrap;
}

.editor-form,
.stack-form {
  display: grid;
  gap: 20px;
}

.editor-form label,
.stack-form label {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 650;
}

.body-field textarea {
  min-height: 430px;
}

.form-actions {
  display: flex;
  gap: 10px;
}

.login-shell {
  display: grid;
  min-height: calc(100vh - 180px);
  place-items: center;
}

.login-panel {
  width: min(430px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-heading {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.login-heading h1 {
  margin-bottom: 2px;
  font-size: 28px;
}

.login-heading p {
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.flash {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.flash-success {
  border-color: #b9d4c6;
  color: #234f3d;
  background: #eef7f2;
}

.flash-error {
  border-color: #e1b6ae;
  color: #7c2c23;
  background: #fff2ef;
}

.info-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1px;
  margin-bottom: 22px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.info-strip > div {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 18px;
  background: var(--surface);
}

.info-strip span {
  color: var(--ink-soft);
  font-size: 13px;
}

.info-strip strong {
  overflow-wrap: anywhere;
}

.backup-list {
  display: grid;
  gap: 10px;
}

.backup-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.backup-row h2 {
  overflow-wrap: anywhere;
  margin-bottom: 2px;
  font-size: 16px;
}

.backup-row p {
  margin-bottom: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    padding: 10px 18px;
  }

  .main-nav {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .main-nav a,
  .nav-button {
    min-height: 34px;
    padding: 0 8px;
    font-size: 14px;
  }

  .page {
    width: min(100% - 28px, 1160px);
    padding-top: 30px;
  }

  .page-heading,
  .editor-heading,
  .reading-header,
  .toolbar,
  .backup-row {
    align-items: stretch;
    flex-direction: column;
  }

  .page-heading .button {
    align-self: flex-start;
  }

  .note-grid {
    grid-template-columns: 1fr;
  }

  .note-card {
    min-height: 190px;
  }

  .search-form {
    flex-wrap: wrap;
  }

  .search-field {
    flex-basis: 100%;
  }

  .info-strip {
    grid-template-columns: 1fr;
  }

  .backup-row .action-row {
    align-self: flex-start;
  }

  .login-panel {
    padding: 26px 22px;
  }

  .note-body {
    font-size: 17px;
  }
}

@media (max-width: 900px) {
  .notes-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .tag-sidebar {
    position: static;
  }

  .tag-sidebar-inner {
    padding-right: 0;
    padding-bottom: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .tag-nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .tag-nav a {
    flex: 0 0 auto;
    min-width: 112px;
  }
}

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