:root {
  --bg: #EEF0F2;
  --surface: #FFFFFF;
  --surface-2: #E1E5E9;
  --ink: #10171F;
  --ink-soft: #57626C;
  --ink-faint: #8A939B;
  --accent: #2F6F5E;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEAE5;
  --gold: #9C7527;
  --gold-soft: #F1E6CC;
  --border: #D2D7DC;
  --danger: #A8402E;
  --danger-soft: #F5E1DC;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 23, 31, 0.06), 0 1px 1px rgba(16, 23, 31, 0.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D1114;
    --surface: #161B1F;
    --surface-2: #1F262B;
    --ink: #E7EBEE;
    --ink-soft: #97A2AA;
    --ink-faint: #626C73;
    --accent: #4FAF95;
    --accent-ink: #06120E;
    --accent-soft: #17302A;
    --gold: #D9AE55;
    --gold-soft: #362A12;
    --border: #2A3238;
    --danger: #D97A63;
    --danger-soft: #2E1D18;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 1px rgba(0, 0, 0, 0.2);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding-inline: 16px;
  padding-block: 24px 60px;
}

.mono { font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace; }

.app {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

header.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding-block: 4px 2px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

h1 {
  font-weight: 700;
  font-size: 1.4rem;
  letter-spacing: -0.01em;
  margin: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.signin-panel {
  text-align: center;
  padding: 48px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.signin-panel p { color: var(--ink-soft); margin: 0; max-width: 40ch; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-direction: column; gap: 12px; }

.stats-strip {
  display: flex;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.stat-cell {
  flex: 1;
  padding: 10px 14px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-cell:last-child { border-right: none; }
.stat-cell .stat-num {
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink);
}
.stat-cell .stat-label { font-size: 0.72rem; color: var(--ink-soft); }

.search-row { display: flex; gap: 8px; }
#search-input { flex: 1; min-width: 0; }

input[type="text"], input[type="url"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.92rem;
  padding: 9px 11px;
  min-width: 0;
}
input[type="text"]:focus, input[type="url"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
input::placeholder { color: var(--ink-faint); }

button {
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  padding: 9px 16px;
  font-family: inherit;
}
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary { background: var(--accent); color: var(--accent-ink); white-space: nowrap; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-secondary {
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.btn-secondary:hover { color: var(--ink); border-color: var(--ink-faint); }

.form-error { color: var(--danger); font-size: 0.82rem; margin: 6px 0 0; }

.chip-row { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }

.chip {
  flex: 0 0 auto;
  background: var(--surface-2);
  color: var(--ink-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 10px 5px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.chip .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.chip .chip-count {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  background: var(--surface);
  color: var(--ink-faint);
  border-radius: 999px;
  padding: 1px 6px;
}
.chip.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.chip.active .chip-count { color: var(--accent); }

.tag-filter-banner { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--ink-soft); }
.tag-filter-banner button { background: none; border: 1px solid var(--border); color: var(--ink-soft); padding: 3px 9px; font-size: 0.75rem; font-weight: 500; }

/* ---------- Grid of link cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--card-color, var(--ink-faint));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card.done { opacity: 0.6; }

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }

.platform-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--card-color, var(--ink-soft));
}

.timestamp {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--ink-faint);
  white-space: nowrap;
}

.card-url {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.85rem;
  color: var(--ink);
  text-decoration: none;
  word-break: break-all;
  line-height: 1.4;
}
.card-url:hover { color: var(--accent); text-decoration: underline; }
.card.done .card-url { text-decoration: line-through; }

.card-note { font-size: 0.86rem; color: var(--ink-soft); line-height: 1.4; }

.card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 2px; }

.tag {
  background: var(--surface-2);
  color: var(--ink-soft);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.7rem;
  border-radius: 5px;
  padding: 2px 7px;
  cursor: pointer;
  border: 1px solid transparent;
}
.tag:hover { border-color: var(--border); }
.tag.active-tag { background: var(--accent-soft); color: var(--accent); }

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--surface-2);
}
.card-footer-left, .card-footer-right { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--ink-faint);
  padding: 4px 8px;
  font-size: 0.78rem;
  line-height: 1;
  border-radius: 6px;
}
.icon-btn:hover { color: var(--ink); border-color: var(--border); }
.icon-btn.confirm { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); font-weight: 600; }

.star-btn {
  background: none;
  border: 1px solid transparent;
  padding: 4px 6px;
  font-size: 1rem;
  line-height: 1;
  color: var(--ink-faint);
  border-radius: 6px;
}
.star-btn:hover { border-color: var(--border); }
.star-btn.active { color: var(--gold); }

.done-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 3px 9px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-faint);
  border-radius: 999px;
}
.done-btn.active { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.empty-state .big { font-weight: 700; font-size: 1.05rem; color: var(--ink); }
.empty-state code { font-family: "IBM Plex Mono", monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 0.82rem; }

.status-banner { font-size: 0.85rem; color: var(--ink-soft); text-align: center; padding: 10px; grid-column: 1 / -1; }

.user-bar { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--ink-soft); }
.user-bar img { width: 22px; height: 22px; border-radius: 50%; }
.user-bar button { background: none; border: 1px solid var(--border); color: var(--ink-soft); padding: 4px 10px; font-size: 0.75rem; }

/* ---------- Add-link modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 18, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.modal {
  width: 100%;
  max-width: 420px;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent,
      transparent 30px,
      var(--surface-2) 31px
    ),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(16, 23, 31, 0.2);
  padding: 18px 20px 20px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h2 { font-size: 1.05rem; font-weight: 700; margin: 0; }

.modal-close {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}
.modal-close:hover { color: var(--ink); }

.modal form { display: flex; flex-direction: column; gap: 4px; }
.modal label {
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-top: 10px;
}
.modal label:first-of-type { margin-top: 0; }
.modal input { width: 100%; background: var(--surface); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

@media (max-width: 420px) {
  h1 { font-size: 1.25rem; }
  .search-row { flex-direction: column; }
}
