:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #e3e3dd;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --danger: #d23c3c;
  --pin: #f2b300;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1e1e1c;
    --surface-2: #272725;
    --text: #ececea;
    --muted: #9a9a94;
    --border: #33332f;
    --accent: #5b8cff;
    --danger: #ff6b6b;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
h1, h2, h3 { margin: 0; line-height: 1.3; }
h2 { font-size: 17px; }
.muted { color: var(--muted); font-size: 13px; }

input, textarea {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }

.btn {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.small { padding: 4px 12px; font-size: 13px; }
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .6; cursor: default; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn.on { color: var(--pin); }

.form-error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 340px;
  display: grid; gap: 12px;
  background: var(--surface);
  padding: 32px 28px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.login-card p { margin: 0; }

/* Layout */
.topbar {
  max-width: 960px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 24px 16px 8px;
}
.greeting { font-size: 22px; font-weight: 600; }
.container { max-width: 960px; margin: 0 auto; padding: 8px 16px 48px; display: grid; gap: 20px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; }
.search { max-width: 220px; padding: 5px 10px; font-size: 14px; }
.empty { color: var(--muted); font-size: 14px; text-align: center; margin: 12px 0 4px; }

/* Links */
.links {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.link {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  color: inherit; text-decoration: none;
  min-width: 0;
}
a.link:hover { outline: 1px solid var(--accent); }
.link-avatar {
  flex: none; width: 32px; height: 32px; border-radius: 8px;
  display: grid; place-items: center;
  color: #fff; font-weight: 600;
}
.link-text { min-width: 0; }
.link-title, .link-host { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-title { font-weight: 500; }
.link-host { color: var(--muted); font-size: 12px; }
.link.editing { flex-wrap: wrap; }
.link.editing .link-text { flex: 1; }
.link-tools { display: flex; justify-content: space-between; width: 100%; border-top: 1px solid var(--border); padding-top: 4px; }

/* Memos */
.memo-new { display: grid; gap: 8px; margin-bottom: 16px; }
.memo-new-foot { display: flex; justify-content: space-between; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); cursor: pointer; }
.check input { width: auto; }
.memos { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.memo {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.memo.pinned { border-color: var(--pin); }
.memo-content { white-space: pre-wrap; word-break: break-word; margin: 0 0 8px; }
.memo-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.memo-tools { display: flex; gap: 2px; }
.memo textarea { margin-bottom: 8px; }

/* Dialog */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0,0,0,.35); }
.dialog-body { display: grid; gap: 12px; padding: 22px; }
.dialog-body label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 8px; font-size: 14px;
  max-width: calc(100vw - 32px);
}

@media (max-width: 560px) {
  .panel-head { flex-wrap: wrap; }
  .search { max-width: none; }
  .links { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
