:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --panel: #ffffff;
  --text: #202124;
  --muted: #6b6f76;
  --line: #deded8;
  --accent: #1f6f5b;
  --accent-dark: #185746;
  --danger-bg: #fff3ef;
  --danger-text: #9b321d;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
textarea {
  font: inherit;
}

button,
.primary {
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  padding: 0.48rem 0.78rem;
  cursor: pointer;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem max(1rem, calc((100vw - 980px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(247, 247, 244, 0.94);
  backdrop-filter: blur(10px);
}

.brand {
  color: var(--text);
  font-weight: 700;
}

.nav {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.nav a,
.logout button,
.entry-action button,
.actions button {
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 0.38rem 0.62rem;
}

.nav a.active {
  border-color: var(--line);
  background: var(--panel);
  color: var(--text);
}

.logout {
  margin: 0;
}

.page {
  width: min(1180px, calc(100vw - 2rem));
  margin: 2rem auto 4rem;
}

.reader {
  width: min(980px, calc(100vw - 2rem));
  margin: 2rem auto 4rem;
}

.narrow {
  width: min(680px, calc(100vw - 2rem));
}

.page-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

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

.page-title h1,
.article-header h1 {
  margin-bottom: 0.25rem;
  letter-spacing: 0;
}

.page-title p,
.meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.meta {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.notice {
  border: 1px solid #f2c8ba;
  border-radius: 8px;
  background: var(--danger-bg);
  color: var(--danger-text);
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
}

.category-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: -0.25rem 0 1rem;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 0.35rem 0.68rem;
  font-size: 0.9rem;
}

.category-chip.active {
  border-color: var(--accent);
  background: #e6f2ee;
  color: var(--accent-dark);
  text-decoration: none;
}

.category-count {
  color: inherit;
  font-size: 0.82rem;
}

.entry-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.note-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.entry-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(32, 33, 36, 0.08);
}

.entry-media {
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #ecece6;
}

.entry-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.entry-body {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 0.9rem 0.75rem;
}

.note-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
}

.note-card {
  display: block;
}

.entry-title {
  display: inline-block;
  color: var(--text);
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 0.35rem;
}

.entry-card .entry-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  font-size: 1.02rem;
}

.entry-card .meta {
  gap: 0.3rem 0.55rem;
  font-size: 0.82rem;
}

.excerpt,
.note-body {
  margin: 0.6rem 0 0;
  color: #3f4247;
}

.entry-card .excerpt {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 0.92rem;
}

.entry-action {
  align-self: stretch;
  margin: 0;
  padding: 0 0.9rem 0.9rem;
}

.entry-card .entry-action button {
  width: 100%;
  border-color: var(--line);
  background: #fafaf8;
  color: var(--text);
  text-align: center;
}

.entry-card .entry-action button:hover {
  border-color: var(--accent);
  background: #e6f2ee;
  color: var(--accent-dark);
}

.pill {
  display: inline-block;
  border-radius: 999px;
  background: #e6f2ee;
  color: var(--accent-dark);
  padding: 0 0.5rem;
}

.empty {
  border-top: 1px solid var(--line);
  color: var(--muted);
  padding: 2rem 0;
}

.reader {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 2rem;
  align-items: start;
}

article,
.note-editor,
.login-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

article {
  padding: clamp(1rem, 4vw, 2rem);
}

.article-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
  margin-bottom: 1.3rem;
}

.article-header h1 {
  font-size: clamp(1.6rem, 4vw, 2.25rem);
  line-height: 1.2;
  margin-top: 0.55rem;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  margin-top: 0.8rem;
}

.actions form {
  margin: 0;
}

.content {
  overflow-wrap: anywhere;
}

.content img,
.content video,
.content iframe {
  max-width: 100%;
}

.content pre {
  overflow-x: auto;
  padding: 0.85rem;
  background: #f0f0ec;
  border-radius: 8px;
}

.content blockquote {
  border-left: 3px solid var(--line);
  margin-left: 0;
  padding-left: 1rem;
  color: #4d5157;
}

.note-editor {
  position: sticky;
  top: 4.5rem;
  padding: 1rem;
}

.stack {
  display: grid;
  gap: 0.8rem;
}

label span {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  padding: 0.62rem 0.7rem;
}

textarea {
  resize: vertical;
  min-height: 12rem;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-box {
  width: min(420px, 100%);
  padding: 1.4rem;
}

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

  .nav {
    grid-column: 1 / -1;
    order: 2;
  }

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

  .note-editor {
    position: static;
  }

  .entry-card {
    border-radius: 7px;
  }

  .entry-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .entry-body {
    padding: 0.65rem;
  }

  .entry-card .entry-title {
    font-size: 0.92rem;
    line-height: 1.32;
  }

  .entry-card .meta {
    gap: 0.15rem 0.38rem;
    font-size: 0.74rem;
  }

  .entry-card .excerpt {
    margin-top: 0.45rem;
    font-size: 0.8rem;
  }

  .entry-action {
    padding: 0 0.65rem 0.65rem;
  }

  .entry-card .entry-action button {
    padding: 0.32rem 0.4rem;
  }
}

@media (max-width: 420px) {
  .page {
    width: calc(100vw - 0.75rem);
  }

  .entry-list {
    gap: 0.55rem;
  }

  .category-chip {
    padding: 0.3rem 0.56rem;
    font-size: 0.82rem;
  }
}
