:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: #14171c;
  --surface-2: #1a1e24;
  --border: #262b33;
  --border-strong: #353c47;
  --text: #e6e8eb;
  --muted: #8b929e;
  --faint: #5d646f;
  --accent: #5b9dff;
  --accent-hover: #74acff;
  --danger: #f0616d;
  --success: #46c479;
  --radius: 12px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.app {
  width: min(720px, calc(100% - 40px));
  margin: 0 auto;
  padding: 56px 0 96px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.masthead {
  margin-bottom: 2px;
}

.brand {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.card-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.badge {
  margin-left: auto;
  min-width: 24px;
  padding: 1px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.field-row {
  display: flex;
  gap: 10px;
}

input[type="url"],
input[type="search"],
.select {
  width: 100%;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input::placeholder {
  color: var(--faint);
}

input:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 157, 255, 0.18);
}

.select {
  appearance: none;
  cursor: pointer;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b929e' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
}

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 140ms ease, opacity 140ms ease;
}

.btn-primary {
  background: var(--accent);
  color: #06101f;
}

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

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

.progress-wrap {
  margin-top: 16px;
}

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 220ms ease;
}

.progress.indeterminate .progress-fill {
  width: 35%;
  animation: indeterminate 1.15s ease-in-out infinite;
}

@keyframes indeterminate {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(320%);
  }
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.85rem;
}

.progress-count {
  font-variant-numeric: tabular-nums;
}

.status {
  margin: 12px 0 0;
  min-height: 18px;
  color: var(--muted);
  font-size: 0.88rem;
}

.status:empty {
  margin: 0;
  min-height: 0;
}

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--success);
}

.library {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.library-empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 2px 0;
}

.library-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 140ms ease;
}

.library-item:hover,
.library-item:focus-visible {
  border-color: var(--border-strong);
  outline: none;
}

.lib-title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lib-meta {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.select-label {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: -4px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  width: fit-content;
}

.toggle input {
  accent-color: var(--accent);
}

.results {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.results:empty {
  margin: 0;
}

.result {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.result .rank {
  color: var(--faint);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  min-width: 16px;
}

.result-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.result .ts {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-decoration: none;
  width: fit-content;
}

.result .ts:hover {
  text-decoration: underline;
}

.result .sub {
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 560px) {
  .app {
    width: calc(100% - 28px);
    padding: 28px 0 64px;
    gap: 14px;
  }

  .brand {
    font-size: 1.3rem;
  }

  .tagline {
    font-size: 0.9rem;
  }

  .card {
    padding: 16px;
    border-radius: var(--radius-sm);
  }

  /* 16px inputs prevent iOS Safari from auto-zooming on focus */
  input[type="url"],
  input[type="search"],
  .select {
    font-size: 16px;
  }

  .field-row {
    flex-direction: column;
  }

  .btn {
    width: 100%;
    padding: 13px 18px;
  }

  .library-item,
  .result {
    flex-wrap: wrap;
  }

  .lib-meta {
    margin-left: 0;
  }

  .lib-title {
    flex: 1 1 auto;
  }

  .result-body {
    flex: 1 1 100%;
  }
}
