:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #3f3f46;
  --muted: #71717a;
  --subtle: #a1a1aa;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --accent-ink: #3730a3;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --good: #15803d;
  --brand-ink: #ffffff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --surface: #111113;
    --surface-2: #18181b;
    --border: #27272a;
    --border-strong: #3f3f46;
    --text: #fafafa;
    --text-2: #d4d4d8;
    --muted: #a1a1aa;
    --subtle: #71717a;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --accent-soft: #1e1b4b;
    --accent-ink: #c7d2fe;
    --warn: #fbbf24;
    --warn-soft: #422006;
    --danger: #fca5a5;
    --danger-soft: #450a0a;
    --good: #4ade80;
    --brand-ink: #09090b;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

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

a:hover {
  text-decoration: underline;
}

code {
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.icon {
  flex: none;
  display: inline-block;
  vertical-align: middle;
}

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

.small {
  font-size: 13px;
}

main,
.footer {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  color: var(--text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.source-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 4px;
}

/* ------------------------------------------------------------ buttons */

.btn {
  font: inherit;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}

.btn:hover {
  text-decoration: none;
}

.btn:focus-visible,
.link:focus-visible,
.segmented button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

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

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

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

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

.btn-ghost {
  background: transparent;
  color: var(--text-2);
}

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

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

.btn-attention:hover {
  background: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.link {
  font: inherit;
  font-weight: 500;
  color: var(--accent);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

.link:hover {
  text-decoration: underline;
}

/* ------------------------------------------------------------ welcome */

.welcome {
  padding: 56px 0 24px;
}

.welcome-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 48px;
  align-items: start;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0 0 14px;
  font-size: clamp(30px, 4.6vw, 44px);
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.lede {
  margin: 0 0 28px;
  font-size: 16px;
  line-height: 1.6;
  color: var(--muted);
  max-width: 34em;
}

.feature-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 16px;
}

.feature-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.feature-list li > span:first-child {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  flex: none;
}

.feature-list strong {
  display: block;
  font-weight: 600;
}

.feature-list li div span {
  color: var(--muted);
}

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

.import-panel {
  padding: 20px;
}

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 36px 20px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}

.drop-zone:hover,
.drop-zone.dragging,
.drop-zone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  margin-bottom: 6px;
}

.import-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.import-actions .btn:only-child {
  grid-column: 1 / -1;
}

.import-hint {
  margin: 12px 0 0;
}

.import-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.howto-section {
  margin-top: 56px;
}

.section-heading {
  margin: 0 0 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.howto-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.howto summary,
.identity summary,
.caught-up summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-weight: 550;
}

.howto summary::-webkit-details-marker,
.identity summary::-webkit-details-marker,
.caught-up summary::-webkit-details-marker,
.shared summary::-webkit-details-marker {
  display: none;
}

.howto summary {
  padding: 12px 16px;
}

.howto summary:hover {
  background: var(--surface-2);
}

details[open] > summary .icon {
  transform: rotate(180deg);
}

summary .icon {
  color: var(--subtle);
  transition: transform 0.15s;
}

.howto ol {
  margin: 0;
  padding: 0 16px 14px 36px;
  color: var(--text-2);
}

.howto li + li {
  margin-top: 4px;
}

/* ------------------------------------------------------------ busy */

.busy {
  padding: 120px 0;
  text-align: center;
}

.spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 2.5px solid var(--border);
  border-top-color: var(--text);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------------------------------------ results */

#results-view {
  padding: 32px 0 16px;
}

.banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 13px;
}

.banner .link {
  margin-left: auto;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-title {
  margin: 0;
  font-size: clamp(22px, 3vw, 28px);
  letter-spacing: -0.02em;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.segmented button {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.notice {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
}

.notice.warn {
  border-color: transparent;
  background: var(--warn-soft);
  color: var(--warn);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric-label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
}

.metric-value {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.metric-sub {
  font-size: 12px;
  color: var(--subtle);
}

.identity {
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.identity summary {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-2);
}

.me-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  padding: 4px 14px 14px;
}

.me-picker label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

select {
  font: inherit;
  font-size: 13px;
  height: 30px;
  padding: 0 28px 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.list-section {
  margin-top: 28px;
}

.section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
}

.list {
  display: grid;
  gap: 10px;
}

.empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  transition: opacity 0.25s, transform 0.25s;
}

.card.leaving {
  opacity: 0;
  transform: translateY(-4px);
}

.item-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.avatar {
  --hue: 230;
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  color: hsl(var(--hue) 45% 32%);
  background: hsl(var(--hue) 60% 93%);
}

@media (prefers-color-scheme: dark) {
  .avatar {
    color: hsl(var(--hue) 70% 82%);
    background: hsl(var(--hue) 30% 20%);
  }
}

.item-title {
  flex: 1;
  min-width: 0;
}

.item-name {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item-name strong {
  font-size: 15px;
  font-weight: 600;
}

.app-badge {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 6px;
  line-height: 18px;
}

.item-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 550;
  padding: 1px 8px;
  border-radius: 999px;
}

.pill-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.item-summary {
  margin: 12px 0 0;
  color: var(--text-2);
}

.suggestion {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.suggestion-label {
  padding: 8px 12px 0;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--subtle);
}

.suggestion-text {
  margin: 4px 0 0;
  padding: 0 12px 10px;
  color: var(--text);
}

.suggestion-actions {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
}

.suggestion-actions.solo {
  border: none;
  padding: 10px 0 0;
}

.item-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--muted);
}

.rate {
  display: flex;
  align-items: center;
  gap: 8px;
}

.meter {
  width: 72px;
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}

.meter i {
  display: block;
  height: 100%;
  background: var(--good);
}

.shared {
  margin-left: auto;
}

.shared summary {
  list-style: none;
  cursor: pointer;
  color: var(--text-2);
  font-weight: 500;
}

.shared ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.caught-up {
  margin-top: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.caught-up summary {
  padding: 12px 16px;
  font-size: 13px;
}

.caught-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

/* ------------------------------------------------------------ footer + toast */

.footer {
  margin-top: 48px;
  padding-top: 20px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
}

.footer p {
  margin: 0 0 6px;
}

.footer-links {
  display: flex;
  gap: 8px;
  align-items: center;
}

.footer .link {
  font-size: 12.5px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 860px) {
  .welcome-grid {
    grid-template-columns: 1fr;
    gap: 28px;
  }

  .welcome {
    padding-top: 32px;
  }

  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 560px) {
  main,
  .footer,
  .topbar-inner {
    padding-left: 16px;
    padding-right: 16px;
  }

  .source-status,
  #connect-folder-2 {
    display: none !important;
  }

  .item-head .done {
    padding: 0 8px;
  }

  .item-head .done .label {
    display: none;
  }

  .shared {
    margin-left: 0;
  }

  .page-head {
    align-items: flex-start;
  }
}
