:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --text: #14181f;
  --text-2: #5c646f;
  --text-3: #9aa2ad;
  --line: #eceef1;
  --accent: #0ea5e9;
  --accent-soft: #e8f6fe;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(var(--safe-top) + 10px) 16px 0;
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
}

.brand {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.search-wrap {
  flex: 1;
  position: relative;
}

#search {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 9px 12px 9px 34px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

#search:focus {
  border-color: var(--accent);
  background: #fff;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  opacity: 0.4;
  pointer-events: none;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 10px;
  scrollbar-width: none;
  margin: 0 -16px;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text-2);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.chip.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #0369a1;
}

#view { padding-bottom: calc(var(--safe-bottom) + 40px); }

.list-head {
  padding: 14px 16px 6px;
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  justify-content: space-between;
}

.card {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  align-items: flex-start;
}

.card:active { background: var(--bg-soft); }

.card-text { flex: 1; min-width: 0; }

.card h3 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: -0.1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card .meta {
  font-size: 12px;
  color: var(--text-3);
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.thumb {
  width: 76px;
  height: 76px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  flex: 0 0 auto;
}

.tag-list { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 7px; }

.tag {
  font-size: 11px;
  color: #0369a1;
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 2px 6px;
}

.tag.plain {
  color: var(--text-3);
  background: var(--bg-soft);
}

.empty {
  padding: 64px 28px;
  text-align: center;
  color: var(--text-3);
  font-size: 14px;
  line-height: 1.9;
}

.empty b { color: var(--text-2); font-weight: 500; }

.more {
  display: block;
  width: calc(100% - 32px);
  margin: 18px 16px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 14px;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--text-2);
  padding: 12px 16px 0;
}

.article { padding: 8px 16px 0; }

.article h1 {
  font-size: 23px;
  line-height: 1.4;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin: 10px 0 12px;
}

.article .byline {
  font-size: 13px;
  color: var(--text-3);
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.content {
  font-size: 17px;
  line-height: 1.85;
  padding: 18px 0 8px;
  color: #1c2027;
  overflow-wrap: break-word;
  word-break: break-word;
}

.content p { margin: 0 0 1.05em; }
.content section { margin: 0; }
.content img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  display: block;
  margin: 1.1em auto;
  background: var(--bg-soft);
}
.content strong { font-weight: 600; }
.content a { color: var(--accent); word-break: break-all; }
.content ul, .content ol { padding-left: 1.3em; margin: 0 0 1.05em; }
.content li { margin-bottom: 0.35em; }
.content blockquote {
  margin: 1.1em 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--line);
  color: var(--text-2);
}
.content table { width: 100%; border-collapse: collapse; font-size: 15px; margin: 1em 0; }
.content td, .content th { border: 1px solid var(--line); padding: 6px 8px; }
.content iframe, .content video { max-width: 100%; }
.content h1, .content h2, .content h3 { font-size: 18px; margin: 1.4em 0 0.6em; font-weight: 600; }

.actions {
  display: flex;
  gap: 10px;
  padding: 20px 16px 8px;
  border-top: 1px solid var(--line);
  margin-top: 12px;
  flex-wrap: wrap;
}

.btn {
  flex: 1;
  min-width: 92px;
  text-align: center;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 11px 8px;
  font-size: 14px;
  color: var(--text-2);
}

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

.btn.danger { color: #b91c1c; }

.tag-editor { padding: 12px 16px 20px; }
.tag-editor input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  outline: none;
}
.tag-editor input:focus { border-color: var(--accent); }
.tag-editor .hint { font-size: 12px; color: var(--text-3); margin: 8px 2px 0; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 31, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.dialog {
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 340px;
}

.dialog h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.dialog p { margin: 0 0 14px; font-size: 13px; color: var(--text-3); line-height: 1.6; }
.dialog input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
}
.dialog input:focus { border-color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 28px);
  transform: translateX(-50%);
  background: rgba(20, 24, 31, 0.9);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.toast.on { opacity: 1; }

.skeleton {
  height: 92px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, #f6f7f9 25%, #fbfbfc 37%, #f6f7f9 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.add-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text-2);
  font-size: 19px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 2px;
  font-family: inherit;
}
.add-btn:active { background: var(--accent-soft); color: var(--accent); }

.dialog textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  resize: none;
  margin-bottom: 12px;
}
.dialog textarea:focus { border-color: var(--accent); }
.dialog .actions { display: flex; gap: 10px; }
