/* ==========================================================================
   HrefKeep
   A quiet reading-list tool. Neutral surfaces, so the few colors on screen
   carry meaning: reading status, favorites, and link problems. Addresses and
   domains are set in monospace because they are the thing being kept.

   Type scale: 1.25rem view title · 1rem link title · 0.9375rem body/inputs ·
   0.8125rem meta and buttons · 0.75rem captions. Radii: 6px surfaces and
   controls, 4px small controls, pills only for tags and filter chips.
   ========================================================================== */

:root {
  color-scheme: light;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;

  --bg: #fafafa;
  --surface: #ffffff;
  --surface-muted: #f5f5f5;
  --hover: #efefef;
  --selected: #ececec;
  --text: #171717;
  --text-body: #404040;
  --text-muted: #666666;   /* 5.7:1 on white */
  --text-subtle: #767676;  /* 4.5:1 on white, smallest allowed */
  --border: #e5e5e5;
  --border-strong: #a3a3a3;
  --focus: #1d4ed8;
  --brand-glyph: #ffffff;

  --primary-bg: #171717;
  --primary-hover: #333333;
  --primary-text: #ffffff;

  /* Reading status */
  --unread-bg: #f5f5f5;
  --unread-text: #404040;
  --unread-border: #d4d4d4;

  --reading-bg: #eff6ff;
  --reading-text: #1d4ed8;
  --reading-border: #bfdbfe;

  --finished-bg: #f0fdf4;
  --finished-text: #166534;
  --finished-border: #bbf7d0;

  --star: #b45309;
  --mark-bg: #fef08a;
  --mark-text: #171717;

  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --warning-border: #fde68a;

  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --backdrop: rgba(0, 0, 0, 0.4);
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121212;
    --surface: #1a1a1a;
    --surface-muted: #222222;
    --hover: #262626;
    --selected: #2b2b2b;
    --text: #ededed;
    --text-body: #cfcfcf;
    --text-muted: #a3a3a3;
    --text-subtle: #8f8f8f;
    --border: #2e2e2e;
    --border-strong: #525252;
    --focus: #60a5fa;
    --brand-glyph: #121212;
    --primary-bg: #ededed;
    --primary-hover: #d4d4d4;
    --primary-text: #121212;
    --unread-bg: #262626;
    --unread-text: #d4d4d4;
    --unread-border: #404040;
    --reading-bg: #172033;
    --reading-text: #93c5fd;
    --reading-border: #1e3a8a;
    --finished-bg: #132418;
    --finished-text: #86efac;
    --finished-border: #14532d;
    --star: #fbbf24;
    --mark-bg: #713f12;
    --mark-text: #fef9c3;
    --warning-bg: #2a2110;
    --warning-text: #fcd34d;
    --warning-border: #78350f;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-bg: #2a1616;
    --danger-border: #7f1d1d;
    --backdrop: rgba(0, 0, 0, 0.6);
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212;
  --surface: #1a1a1a;
  --surface-muted: #222222;
  --hover: #262626;
  --selected: #2b2b2b;
  --text: #ededed;
  --text-body: #cfcfcf;
  --text-muted: #a3a3a3;
  --text-subtle: #8f8f8f;
  --border: #2e2e2e;
  --border-strong: #525252;
  --focus: #60a5fa;
  --brand-glyph: #121212;
  --primary-bg: #ededed;
  --primary-hover: #d4d4d4;
  --primary-text: #121212;
  --unread-bg: #262626;
  --unread-text: #d4d4d4;
  --unread-border: #404040;
  --reading-bg: #172033;
  --reading-text: #93c5fd;
  --reading-border: #1e3a8a;
  --finished-bg: #132418;
  --finished-text: #86efac;
  --finished-border: #14532d;
  --star: #fbbf24;
  --mark-bg: #713f12;
  --mark-text: #fef9c3;
  --warning-bg: #2a2110;
  --warning-text: #fcd34d;
  --warning-border: #78350f;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-bg: #2a1616;
  --danger-border: #7f1d1d;
  --backdrop: rgba(0, 0, 0, 0.6);
  --shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a {
  color: inherit;
}

code, kbd {
  font-family: var(--mono);
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

::selection {
  background-color: var(--mark-bg);
  color: var(--mark-text);
}

mark {
  background-color: var(--mark-bg);
  color: var(--mark-text);
  border-radius: 2px;
  padding: 0 1px;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 10;
  background: var(--primary-bg);
  color: var(--primary-text);
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  font-size: 0.875rem;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
}

.muted {
  color: var(--text-muted);
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 2rem 1.5rem 2rem;
  padding-left: max(1.5rem, env(safe-area-inset-left));
  padding-right: max(1.5rem, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.kbd {
  display: inline-block;
  font-size: 0.6875rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--text-muted);
  background: var(--surface);
  font-weight: 500;
}

/* ==========================================================================
   Header
   ========================================================================== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--text);
  border-radius: 6px;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  color: var(--primary-bg);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.tagline {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.palette-btn {
  gap: 0.5rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Quick add: the primary action, so it gets the strongest input on screen
   ========================================================================== */
.quick-add {
  padding: 1rem 1.1rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 1.75rem;
}

.quick-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.45rem;
}

.quick-label {
  font-size: 0.875rem;
  font-weight: 600;
}

.quick-row {
  display: flex;
  gap: 0.5rem;
}

#quickUrl {
  flex: 1;
  min-width: 0;
  padding: 0.65rem 0.8rem;
  font-family: var(--mono);
  font-size: 0.9375rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

#quickUrl:focus {
  border-color: var(--text);
  background: var(--surface);
}

#quickUrl[aria-invalid="true"] {
  border-color: var(--danger);
}

.quick-row .btn {
  padding-inline: 1.1rem;
  font-size: 0.875rem;
}

.quick-msg {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.45rem;
  overflow-wrap: anywhere;
}

.quick-msg:empty {
  display: none;
}

.quick-msg.is-error {
  color: var(--warning-text);
}

.page-alert {
  margin-bottom: 1.25rem;
}

/* ==========================================================================
   Layout: library sidebar + list
   ========================================================================== */
.layout {
  display: grid;
  grid-template-columns: 13rem minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
  flex: 1;
}

.sidebar {
  position: sticky;
  top: 1rem;
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 0.1rem 0.25rem 1rem 0.1rem;
}

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  padding: 0.35rem 0.55rem;
  border: none;
  border-radius: 6px;
  background: none;
  font-size: 0.875rem;
  color: var(--text-body);
  text-align: left;
  cursor: pointer;
}

.nav-item:hover {
  background: var(--hover);
  color: var(--text);
}

.nav-item[aria-current="page"] {
  background: var(--selected);
  color: var(--text);
  font-weight: 600;
}

.nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
}

.nav-item-warning .nav-label {
  color: var(--danger);
}

/* A public collection gets a small marker after its name */
.nav-item.is-public .nav-label::after {
  content: " · public";
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
}

.nav-empty {
  font-size: 0.8125rem;
  color: var(--text-muted);
  padding: 0.1rem 0.55rem;
}

.nav-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 0 0.55rem;
  margin-bottom: 0.35rem;
}

.nav-heading h2 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tag-search {
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.35rem 0.55rem;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.tag-cloud {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding: 0 0.3rem;
}

.tag-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.8125rem;
  color: var(--text-body);
  cursor: pointer;
}

.tag-filter:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.tag-filter[aria-pressed="true"] {
  background: var(--primary-bg);
  border-color: var(--primary-bg);
  color: var(--primary-text);
}

.tag-count {
  font-size: 0.6875rem;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}

.nav-section > .text-action {
  margin: 0.4rem 0.55rem 0;
}

.list-heading .browse-btn {
  display: none;
}

.sidebar-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0 0.55rem;
}

/* ==========================================================================
   List head and toolbar
   ========================================================================== */
.list-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
}

.list-heading {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  min-width: 0;
}

.list-heading h1 {
  font-size: 1.25rem;
  font-weight: 650;
  letter-spacing: -0.015em;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.list-count {
  font-size: 0.8125rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.collection-tools {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.8125rem;
}

.public-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--finished-text);
  background: var(--finished-bg);
  border: 1px solid var(--finished-border);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
}

.list-description {
  font-size: 0.875rem;
  color: var(--text-body);
  max-width: 70ch;
  margin-top: 0.3rem;
  white-space: pre-wrap;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0 0.75rem;
}

.search-box {
  position: relative;
  flex: 1 1 18rem;
}

#searchInput {
  width: 100%;
  padding: 0.5rem 2.4rem 0.5rem 0.75rem;
  font-size: 0.9375rem;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: border-color 0.15s ease;
}

#searchInput::placeholder {
  color: var(--text-subtle);
}

#searchInput:focus {
  border-color: var(--text);
}

/* Hide the browser's own clear icon; we render one */
#searchInput::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-kbd {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

#searchInput:focus ~ .search-kbd,
#searchInput:not(:placeholder-shown) ~ .search-kbd {
  display: none;
}

.clear-btn {
  position: absolute;
  right: 0.3rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 4px;
  line-height: 1;
}

.clear-btn:hover {
  color: var(--text);
  background-color: var(--hover);
}

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.compact-select {
  width: auto;
  padding: 0.45rem 0.5rem;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background-color: var(--surface);
  cursor: pointer;
}

.view-toggle,
.notes-tabs {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}

.view-toggle button,
.notes-tabs button {
  border: none;
  background: none;
  padding: 0.4rem 0.7rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  cursor: pointer;
}

.view-toggle button + button,
.notes-tabs button + button {
  border-left: 1px solid var(--border);
}

.view-toggle button:hover,
.notes-tabs button:hover {
  color: var(--text);
  background: var(--hover);
}

.view-toggle button[aria-pressed="true"],
.notes-tabs button[aria-pressed="true"] {
  background: var(--selected);
  color: var(--text);
  font-weight: 600;
}

.view-toggle button:focus-visible,
.notes-tabs button:focus-visible {
  outline-offset: -2px;
}

.active-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
  font-size: 0.8125rem;
}

.filters-label {
  color: var(--text-muted);
}

.filter-chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.12rem 0.6rem;
  font-size: 0.8125rem;
  cursor: pointer;
}

.filter-chip:hover {
  background: var(--hover);
}

.active-filters .text-action {
  font-size: 0.8125rem;
  margin-left: 0.25rem;
}

/* ==========================================================================
   Links: shared pieces
   ========================================================================== */
.link-list {
  display: flex;
  flex-direction: column;
}

.link-list[data-layout="cards"] {
  gap: 0.75rem;
}

.favicon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  overflow: hidden;
}

.favicon img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.favicon-letter {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--text-muted);
  font-family: var(--font);
}

.domain-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.domain-btn:hover {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.meta-dot {
  color: var(--text-subtle);
}

.tag {
  display: inline-flex;
  align-items: center;
  border: none;
  background: var(--surface-muted);
  color: var(--text-body);
  border-radius: 999px;
  padding: 0.08rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

.tag::before {
  content: "#";
  color: var(--text-subtle);
  margin-right: 0.05rem;
}

.tag:hover {
  background: var(--hover);
  color: var(--text);
}

.tag-static {
  cursor: default;
}

.collection-label {
  border: 1px solid var(--border);
  background: none;
  border-radius: 4px;
  padding: 0.02rem 0.4rem;
  font-size: 0.75rem;
  color: var(--text-body);
  cursor: pointer;
  white-space: nowrap;
}

.collection-label:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.badge {
  font-size: 0.6875rem;
  font-weight: 600;
  border-radius: 4px;
  padding: 0 0.35rem;
  line-height: 1.5;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-broken {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.badge-redirected {
  color: var(--warning-text);
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.badge-copy {
  color: var(--text-muted);
  border-color: var(--border);
  font-weight: 500;
}

.star-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  border: none;
  background: none;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-subtle);
  flex-shrink: 0;
}

.star-btn svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.star-btn:hover {
  background: var(--hover);
  color: var(--star);
}

.star-btn[aria-pressed="true"] {
  color: var(--star);
}

.star-btn[aria-pressed="true"] svg {
  fill: currentColor;
}

.status-select {
  width: auto;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
}

.status-select.status-unread { background: var(--unread-bg); color: var(--unread-text); border-color: var(--unread-border); }
.status-select.status-reading { background: var(--reading-bg); color: var(--reading-text); border-color: var(--reading-border); }
.status-select.status-finished { background: var(--finished-bg); color: var(--finished-text); border-color: var(--finished-border); }

.status-select option {
  background: var(--surface);
  color: var(--text);
}

.is-archived {
  background: var(--surface-muted);
}

.is-flash {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ==========================================================================
   Card layout
   ========================================================================== */
.link-card {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.9rem 1.1rem 0.6rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  column-gap: 1.25rem;
  transition: border-color 0.15s ease;
}

.link-card.has-thumb {
  grid-template-columns: minmax(0, 1fr) 8.5rem;
}

.link-card:hover {
  border-color: var(--border-strong);
}

.link-card:focus-visible {
  outline-offset: 1px;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.card-source {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  min-width: 0;
  flex-wrap: wrap;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.card-title a {
  text-decoration: none;
}

.card-title a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.card-title a:visited {
  color: var(--text-body);
}

.card-desc {
  font-size: 0.875rem;
  color: var(--text-body);
  max-width: 72ch;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.card-note {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-align: left;
  font-size: 0.8125rem;
  color: var(--text-body);
  background: none;
  border: none;
  border-left: 2px solid var(--border-strong);
  padding: 0.05rem 0 0.05rem 0.6rem;
  margin: 0.15rem 0;
  max-width: 72ch;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.card-note:hover {
  color: var(--text);
  border-left-color: var(--text);
}

.note-label {
  font-weight: 600;
  color: var(--text-muted);
}

.card-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.2rem;
}

.card-thumb {
  grid-column: 2;
  grid-row: 1;
  width: 8.5rem;
  aspect-ratio: 1.6;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  align-self: start;
  margin-top: 0.15rem;
}

.card-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  margin-top: 0.6rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
}

.card-actions .star-btn {
  margin-left: -0.45rem;
  margin-right: -0.5rem;
}

.card-actions .more-btn {
  margin-left: auto;
}

/* Loading placeholder for a description being fetched */
.skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.2rem;
}

.skeleton span {
  display: block;
  height: 0.6rem;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--surface-muted), var(--hover), var(--surface-muted));
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton span + span {
  width: 60%;
}

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

/* ==========================================================================
   List layout: one row per link inside a single bordered block
   ========================================================================== */
.link-list[data-layout="list"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}

.link-row {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto auto auto auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.75rem 0.35rem 0.4rem;
  font-size: 0.875rem;
  min-height: 2.6rem;
}

.link-row + .link-row {
  border-top: 1px solid var(--border);
}

.link-row:hover {
  background: var(--surface-muted);
}

.link-row:focus-visible {
  outline-offset: -2px;
}

.link-row.is-fetching .row-title {
  color: var(--text-muted);
}

.row-main {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  min-width: 0;
}

.row-title {
  font-weight: 500;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.row-title:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.row-main .domain-btn {
  flex-shrink: 1;
  min-width: 3rem;
}

.row-tags {
  display: flex;
  gap: 0.25rem;
  overflow: hidden;
  max-width: 14rem;
}

.row-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.link-row .more-btn {
  font-size: 0.8125rem;
}

.show-more {
  align-self: center;
  margin: 1rem auto 0;
  display: flex;
}

/* ==========================================================================
   Text buttons and buttons
   ========================================================================== */
.link-btn,
.link-btn-danger,
.text-action {
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  background: none;
  border: none;
  font-size: inherit;
  padding: 0.15rem 0;
  border-radius: 2px;
}

.link-btn {
  color: var(--text);
}

.link-btn:hover {
  text-decoration-thickness: 2px;
}

.link-btn-danger {
  color: var(--text-muted);
}

.link-btn-danger:hover {
  color: var(--danger);
}

.text-action {
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0.2rem 0;
}

.text-action:hover {
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  line-height: 1.2;
}

.btn-primary {
  background-color: var(--primary-bg);
  color: var(--primary-text);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background-color: var(--hover);
  border-color: var(--border-strong);
}

.btn-danger {
  background-color: var(--danger);
  color: #ffffff;
}

.btn-danger:hover {
  background-color: var(--danger-hover);
}

.btn-ghost-danger {
  background: none;
  color: var(--danger);
  border-color: transparent;
}

.btn-ghost-danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ==========================================================================
   Cloud sync
   ========================================================================== */
.sync-btn {
  gap: 0.4rem;
}

/* Static status dot; the label carries the meaning, the dot helps scanning */
.sync-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background-color: var(--border-strong);
  flex-shrink: 0;
}

.sync-btn[data-status="off"] .sync-dot { display: none; }
.sync-btn[data-status="idle"] .sync-dot { background-color: var(--finished-text); }
.sync-btn[data-status="pending"] .sync-dot,
.sync-btn[data-status="syncing"] .sync-dot { background-color: var(--reading-text); }
.sync-btn[data-status="auth"] .sync-dot,
.sync-btn[data-status="error"] .sync-dot { background-color: var(--warning-text); }

.sync-btn[data-status="auth"],
.sync-btn[data-status="error"] {
  border-color: var(--warning-border);
  background-color: var(--warning-bg);
  color: var(--warning-text);
}

.sync-body,
.share-body,
.import-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.sync-intro {
  font-size: 0.875rem;
  color: var(--text-body);
}

.sync-intro code,
.settings-text code,
.field-hint code,
.settings-status code {
  font-size: 0.8125rem;
  background-color: var(--surface-muted);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  overflow-wrap: anywhere;
}

.sync-intro .link-btn {
  display: inline-block;
  margin-top: 0.25rem;
}

/* One bordered list with dividers rather than a stack of separate cards */
.provider-list,
.option-list {
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.provider-list li + li,
.option-list li + li {
  border-top: 1px solid var(--border);
}

.provider-option,
.option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: 100%;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border: none;
  text-align: left;
  cursor: pointer;
}

.provider-option:hover:not(:disabled),
.option:hover {
  background-color: var(--hover);
}

.provider-option:focus-visible,
.option:focus-visible {
  outline-offset: -2px;
}

.provider-option:disabled {
  cursor: not-allowed;
}

.provider-name,
.option-name {
  font-size: 0.9375rem;
  font-weight: 600;
}

.provider-option:disabled .provider-name {
  color: var(--text-muted);
}

.provider-detail,
.option-detail {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.sync-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.sync-form .field {
  margin-bottom: 0;
}

.sync-form input[type="password"] {
  width: 100%;
  padding: 0.5rem 0.65rem;
  font-size: 0.9375rem;
  font-family: var(--mono);
  border: 1px solid var(--border);
  border-radius: 5px;
  background-color: var(--surface);
}

.sync-form input[type="password"]:focus {
  border-color: var(--text);
}

.sync-details {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.sync-details div {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.75rem;
}

.sync-details dt {
  color: var(--text-muted);
}

.sync-details dd {
  font-weight: 500;
  overflow-wrap: anywhere;
}

.sync-account {
  font-weight: 400;
  color: var(--text-muted);
}

.sync-footer {
  justify-content: space-between;
}

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty-state {
  padding: 2.5rem 1.5rem;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
}

.empty-text {
  font-size: 1rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.empty-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  max-width: 58ch;
  margin-top: 0.35rem;
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.empty-actions:not(:empty) {
  margin-top: 1.25rem;
}

/* ==========================================================================
   Alerts and toasts
   ========================================================================== */
.warning-alert {
  background-color: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
  padding: 0.5rem 0.75rem;
  border-radius: 5px;
  font-size: 0.8125rem;
  overflow-wrap: anywhere;
}

.warning-alert .link-btn {
  color: inherit;
}

.field .warning-alert {
  margin-top: 0.2rem;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: min(30rem, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.55rem 0.55rem 0.55rem 0.9rem;
  background: var(--primary-bg);
  color: var(--primary-text);
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 0.875rem;
}

.toast-error {
  background: var(--danger);
  color: #ffffff;
}

.toast-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.toast-action {
  background: none;
  border: none;
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  white-space: nowrap;
  padding: 0.2rem 0.3rem;
  border-radius: 3px;
}

.toast-close {
  background: none;
  border: none;
  color: inherit;
  opacity: 0.75;
  font-size: 1.15rem;
  line-height: 1;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 4px;
  cursor: pointer;
}

.toast-close:hover {
  opacity: 1;
}

.toast :focus-visible {
  outline-color: currentColor;
}

/* ==========================================================================
   Popup menu
   ========================================================================== */
.popup-menu {
  position: fixed;
  z-index: 60;
  list-style: none;
  min-width: 13rem;
  max-width: calc(100vw - 1rem);
  padding: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 0.45rem 0.65rem;
  font-size: 0.875rem;
  border-radius: 4px;
  cursor: pointer;
}

.menu-item:hover,
.menu-item:focus {
  background: var(--hover);
  outline: none;
}

.menu-item:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.menu-item-danger {
  color: var(--danger);
}

.menu-sep {
  height: 1px;
  background: var(--border);
  margin: 0.3rem 0.2rem;
}

/* ==========================================================================
   Dialogs
   ========================================================================== */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--text);
  max-width: 480px;
  width: calc(100vw - 2rem);
  max-height: calc(100dvh - 2rem);
  margin: auto;
  overflow: visible;
}

.modal-sm {
  max-width: 400px;
}

.modal-lg {
  max-width: 620px;
}

.modal::backdrop {
  background-color: var(--backdrop);
}

.modal-dialog {
  background-color: var(--surface);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow);
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.close-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  width: 2rem;
  height: 2rem;
  border-radius: 4px;
  flex-shrink: 0;
  margin: -0.25rem -0.5rem 0 0;
}

.close-btn:hover {
  color: var(--text);
  background-color: var(--hover);
}

.dialog-toasts {
  position: fixed;
}

.dialog-subject {
  font-size: 0.9375rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.confirm-content {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.confirm-message {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Form */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.85rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

label {
  font-size: 0.8125rem;
  font-weight: 600;
}

.req {
  color: var(--danger);
}

input[type="text"],
input[type="url"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  font-size: 0.9375rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background-color: var(--surface);
  transition: border-color 0.15s ease;
}

input[type="url"] {
  font-family: var(--mono);
  font-size: 0.875rem;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-subtle);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--text);
}

input[aria-invalid="true"] {
  border-color: var(--danger);
}

textarea {
  resize: vertical;
  min-height: 70px;
  line-height: 1.5;
}

#linkNotes {
  min-height: 7.5rem;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.field-error {
  font-size: 0.75rem;
  color: var(--danger);
}

.field-error:empty {
  display: none;
}

.input-with-action {
  display: flex;
  gap: 0.5rem;
}

.input-with-action input {
  flex: 1;
  min-width: 0;
}

.new-collection-input {
  margin-top: 0.35rem;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  margin-bottom: 0.85rem;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
}

.check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary-bg);
}

.check:has(input:disabled) {
  color: var(--text-muted);
  cursor: not-allowed;
}

.notes-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.notes-tabs button {
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
}

.notes-preview {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.5rem 0.75rem;
  background: var(--surface-muted);
  overflow-wrap: anywhere;
}

.more-fields {
  margin-bottom: 0.5rem;
}

.more-fields summary {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0;
  border-radius: 2px;
  width: fit-content;
}

.more-fields[open] summary {
  margin-bottom: 0.5rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.footer-start {
  margin-right: auto;
}

/* Tag input */
.tag-input {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  cursor: text;
}

.tag-input:focus-within {
  border-color: var(--text);
}

.chip-list {
  display: contents;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 0.1rem 0 0.55rem;
  font-size: 0.8125rem;
}

.chip-remove {
  border: none;
  background: none;
  width: 1.4rem;
  height: 1.4rem;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.chip-remove:hover {
  background: var(--hover);
  color: var(--text);
}

.tag-input input[type="text"] {
  flex: 1;
  min-width: 8rem;
  border: none;
  padding: 0.2rem 0.25rem;
  background: transparent;
}

.tag-input input[type="text"]:focus {
  outline: none;
}

.tag-suggestions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.15rem;
}

.suggest-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: 0.2rem;
}

.tag-suggestion {
  border: 1px dashed var(--border-strong);
  background: none;
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-body);
}

.tag-suggestion:hover {
  border-style: solid;
  color: var(--text);
}

/* Details dialog */
.details-title {
  font-size: 1.1rem;
}

.details-body {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.details-facts {
  font-size: 0.8125rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.details-url {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-body);
}

.details-description {
  font-size: 0.9375rem;
  color: var(--text-body);
}

.details-section {
  border-top: 1px solid var(--border);
  padding-top: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.details-section h3 {
  font-size: 0.875rem;
  font-weight: 600;
}

.details-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.saved-copy {
  max-height: 22rem;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.75rem 1rem;
  background: var(--surface-muted);
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--text-body);
}

.saved-copy p + p {
  margin-top: 0.75rem;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* Rendered Markdown notes */
.markdown {
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--text-body);
  overflow-wrap: anywhere;
}

.markdown > * + * {
  margin-top: 0.6rem;
}

.markdown h3, .markdown h4, .markdown h5, .markdown h6 {
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 650;
}

.markdown h3 {
  font-size: 1rem;
}

.markdown ul, .markdown ol {
  padding-left: 1.4rem;
}

.markdown blockquote {
  border-left: 2px solid var(--border-strong);
  padding-left: 0.75rem;
  color: var(--text-muted);
}

.markdown code {
  font-size: 0.8125rem;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 0.25rem;
}

.markdown pre {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.6rem 0.75rem;
  overflow-x: auto;
}

.markdown pre code {
  border: none;
  padding: 0;
  background: none;
}

.markdown a {
  color: var(--text);
  text-underline-offset: 2px;
}

.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
}

/* Settings */
.settings {
  display: flex;
  flex-direction: column;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
}

.settings-section:first-child {
  border-top: none;
  padding-top: 0;
}

.settings-section h3 {
  font-size: 0.9375rem;
  font-weight: 600;
}

.settings-text,
.settings-status {
  font-size: 0.875rem;
  color: var(--text-body);
  overflow-wrap: anywhere;
}

.settings-text a,
.settings-status a {
  text-underline-offset: 2px;
}

.segmented {
  display: inline-flex;
  width: fit-content;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.segmented label {
  font-weight: 500;
  font-size: 0.8125rem;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  color: var(--text-muted);
}

.segmented label + label {
  border-left: 1px solid var(--border);
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label:has(input:checked) {
  background: var(--selected);
  color: var(--text);
  font-weight: 600;
}

.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.inline-form {
  display: flex;
  gap: 0.5rem;
}

.inline-form input {
  flex: 1;
  min-width: 0;
}

.bookmarklet {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
  cursor: grab;
}

.shortcut-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.875rem;
}

.shortcut-list div {
  display: grid;
  grid-template-columns: 9rem 1fr;
  align-items: center;
  gap: 0.75rem;
}

.shortcut-list dt {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.shortcut-list .kbd {
  font-size: 0.75rem;
  color: var(--text);
}

/* Command palette: sits near the top, like a search field */
.palette {
  max-width: 560px;
  margin-top: 12vh;
}

.palette-dialog {
  padding: 0;
  gap: 0;
}

.palette-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.1rem;
  font-size: 1rem;
  background: transparent;
  border-radius: 8px 8px 0 0;
}

.palette-input:focus {
  outline: none;
}

.palette-list {
  list-style: none;
  max-height: min(24rem, 55dvh);
  overflow-y: auto;
  padding: 0.35rem;
}

.palette-group {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.55rem 0.65rem 0.25rem;
}

.palette-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0.65rem;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
}

.palette-item[aria-selected="true"] {
  background: var(--selected);
}

.palette-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.palette-hint-text {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
}

.palette-empty {
  padding: 0.9rem 0.65rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.palette-hint {
  border-top: 1px solid var(--border);
  padding: 0.5rem 1.1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ==========================================================================
   Footer
   ========================================================================== */
.footer {
  margin-top: 3rem;
  padding-top: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

.footer p {
  max-width: 60ch;
}

.footer-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.sep {
  color: var(--text-subtle);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1000px) {
  .row-tags {
    display: none;
  }

  .link-row {
    grid-template-columns: auto auto minmax(0, 1fr) auto auto auto;
  }
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  /* The library becomes a panel above the list, opened with Browse */
  .sidebar {
    display: none;
    position: static;
    max-height: none;
    margin-bottom: 1.25rem;
    padding: 0.9rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
  }

  .layout.nav-open .sidebar {
    display: flex;
  }

  .list-heading .browse-btn {
    display: inline-flex;
    align-self: center;
  }

  .palette-btn {
    display: none;
  }

  .link-row .row-date {
    display: none;
  }

  .link-row {
    grid-template-columns: auto auto minmax(0, 1fr) auto auto;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 1.25rem 1rem 1.5rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .header {
    margin-bottom: 1.1rem;
  }

  .tagline {
    display: none;
  }

  .quick-add {
    padding: 0.8rem;
  }

  .quick-row .btn {
    padding-inline: 0.8rem;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .modal-dialog {
    padding: 1rem 1.1rem;
  }

  .sync-details div,
  .shortcut-list div {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .toolbar-controls {
    width: 100%;
  }

  .compact-select {
    flex: 1 1 30%;
    min-width: 0;
  }

  .link-card.has-thumb {
    grid-template-columns: minmax(0, 1fr) 4.5rem;
    column-gap: 0.85rem;
  }

  .card-thumb {
    width: 4.5rem;
    aspect-ratio: 1;
  }

  .card-desc {
    -webkit-line-clamp: 3;
  }

  /* Larger tap targets for the in-card actions */
  .card-actions {
    font-size: 0.875rem;
    gap: 0.25rem 0.9rem;
  }

  .link-btn,
  .link-btn-danger {
    padding: 0.4rem 0;
  }

  .status-select {
    padding: 0.35rem 0.4rem;
  }

  .star-btn {
    width: 2.4rem;
    height: 2.4rem;
  }

  .link-row {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    padding-left: 0.2rem;
  }

  .link-row .favicon {
    display: none;
  }

  .row-main {
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
  }

  .row-title,
  .row-main .domain-btn {
    max-width: 100%;
  }

  /* Edit and Archive stay one tap away in the More menu */
  .card-actions [data-action="edit"],
  .card-actions [data-action="archive"] {
    display: none;
  }

  .palette {
    margin-top: 1rem;
  }

  .input-with-action {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}

/* ==========================================================================
   Selecting several links
   ========================================================================== */
.bulk-bar {
  position: sticky;
  top: 0.5rem;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 0.8125rem;
}

.bulk-summary {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex: 1 1 12rem;
}

.bulk-count {
  font-weight: 600;
}

.bulk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.select-box {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--primary-bg);
  cursor: pointer;
  flex-shrink: 0;
}

.row-lead {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}

.row-lead .select-box {
  margin-left: 0.35rem;
}

.link-card.is-selected,
.link-card.is-selected:hover {
  border-color: var(--text);
  box-shadow: inset 0 0 0 1px var(--text);
}

.link-row.is-selected {
  background: var(--selected);
}

#selectModeBtn[aria-pressed="true"] {
  background: var(--selected);
  border-color: var(--border-strong);
  font-weight: 600;
}

@media (max-width: 560px) {
  .bulk-bar {
    top: 0.25rem;
  }

  .bulk-actions .btn {
    padding-inline: 0.6rem;
  }

  .bulk-done {
    flex: 1 1 100%;
  }
}
