/* ==========================================================================
   Pirate Search — shadcn/ui-style design system (vanilla CSS)
   System theme: light/dark follows prefers-color-scheme
   Font: Plus Jakarta Sans
   ========================================================================== */

:root {
  --font-sans: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 0.625rem;

  /* shadcn/ui neutral tokens — light */
  --background: oklch(1 0 0);
  --foreground: oklch(0.145 0 0);
  --card: oklch(1 0 0);
  --card-foreground: oklch(0.145 0 0);
  --popover: oklch(1 0 0);
  --popover-foreground: oklch(0.145 0 0);
  --primary: oklch(0.205 0 0);
  --primary-foreground: oklch(0.985 0 0);
  --secondary: oklch(0.97 0 0);
  --secondary-foreground: oklch(0.205 0 0);
  --muted: oklch(0.97 0 0);
  --muted-foreground: oklch(0.556 0 0);
  --accent: oklch(0.97 0 0);
  --accent-foreground: oklch(0.205 0 0);
  --destructive: oklch(0.577 0.245 27.325);
  --border: oklch(0.922 0 0);
  --input: oklch(0.922 0 0);
  --ring: oklch(0.708 0 0);

  /* semantic */
  --seed: oklch(0.627 0.194 149.214);
  --seed-contrast: #fff;
  --leech: oklch(0.577 0.245 27.325);
  --gold: oklch(0.681 0.162 75.834);

  --shadow-pop: 0 10px 30px rgb(0 0 0 / 0.14), 0 2px 8px rgb(0 0 0 / 0.08);

  color-scheme: light;
}

:root[data-theme="dark"] {
  --background: oklch(0.145 0 0);
  --foreground: oklch(0.985 0 0);
  --card: oklch(0.205 0 0);
  --card-foreground: oklch(0.985 0 0);
  --popover: oklch(0.205 0 0);
  --popover-foreground: oklch(0.985 0 0);
  --primary: oklch(0.922 0 0);
  --primary-foreground: oklch(0.205 0 0);
  --secondary: oklch(0.269 0 0);
  --secondary-foreground: oklch(0.985 0 0);
  --muted: oklch(0.269 0 0);
  --muted-foreground: oklch(0.708 0 0);
  --accent: oklch(0.269 0 0);
  --accent-foreground: oklch(0.985 0 0);
  --destructive: oklch(0.704 0.191 22.216);
  --border: oklch(1 0 0 / 12%);
  --input: oklch(1 0 0 / 15%);
  --ring: oklch(0.556 0 0);

  --seed: oklch(0.723 0.219 149.579);
  --seed-contrast: oklch(0.204 0.05 155);
  --leech: oklch(0.704 0.191 22.216);
  --gold: oklch(0.795 0.184 86.047);

  --shadow-pop: 0 10px 30px rgb(0 0 0 / 0.5), 0 2px 8px rgb(0 0 0 / 0.35);

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: oklch(0.145 0 0);
    --foreground: oklch(0.985 0 0);
    --card: oklch(0.205 0 0);
    --card-foreground: oklch(0.985 0 0);
    --popover: oklch(0.205 0 0);
    --popover-foreground: oklch(0.985 0 0);
    --primary: oklch(0.922 0 0);
    --primary-foreground: oklch(0.205 0 0);
    --secondary: oklch(0.269 0 0);
    --secondary-foreground: oklch(0.985 0 0);
    --muted: oklch(0.269 0 0);
    --muted-foreground: oklch(0.708 0 0);
    --accent: oklch(0.269 0 0);
    --accent-foreground: oklch(0.985 0 0);
    --destructive: oklch(0.704 0.191 22.216);
    --border: oklch(1 0 0 / 12%);
    --input: oklch(1 0 0 / 15%);
    --ring: oklch(0.556 0 0);

    --seed: oklch(0.723 0.219 149.579);
    --seed-contrast: oklch(0.204 0.05 155);
    --leech: oklch(0.704 0.191 22.216);
    --gold: oklch(0.795 0.184 86.047);

    --shadow-pop: 0 10px 30px rgb(0 0 0 / 0.5), 0 2px 8px rgb(0 0 0 / 0.35);

    color-scheme: dark;
  }
}

/* ---------- base ---------- */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.shell {
  position: relative;
  max-width: 880px;
  margin: 0 auto;
  padding: 48px 20px 60px;
}

::selection { background: color-mix(in oklab, var(--primary) 20%, transparent); }

/* ==========================================================================
   shadcn/ui components
   ========================================================================== */

/* ---------- Button ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2.25rem;
  padding: 0 1rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 45%, transparent);
}

.btn:disabled { opacity: 0.5; pointer-events: none; }

.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: color-mix(in oklab, var(--primary) 88%, var(--primary-foreground)); }

.btn-outline {
  background: var(--background);
  border-color: var(--border);
  color: var(--foreground);
}
.btn-outline:hover { background: var(--accent); color: var(--accent-foreground); }

.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn-secondary:hover { background: color-mix(in oklab, var(--secondary) 80%, var(--foreground)); }

.btn-success { background: var(--seed); color: #fff; }
.btn-success:hover { background: color-mix(in oklab, var(--seed) 85%, #000); }

:root { --seed-contrast: #fff; }
@media (prefers-color-scheme: dark) {
  :root { --seed-contrast: oklch(0.204 0.05 155); }
  .btn-success { color: var(--seed-contrast); }
}

.btn-sm { height: 2rem; padding: 0 0.75rem; font-size: 0.8125rem; }
.btn-lg { height: 2.75rem; padding: 0 1.5rem; font-size: 0.9375rem; border-radius: calc(var(--radius) - 2px); }

.btn .icon { width: 0.9375rem; height: 0.9375rem; flex-shrink: 0; }
.btn .chevron { width: 0.875rem; height: 0.875rem; transition: transform 0.15s; }
.btn[aria-expanded="true"] .chevron { transform: rotate(180deg); }

/* button-busy spinner */
.btn .btn-spinner {
  width: 0.875rem;
  height: 0.875rem;
  border-width: 2px;
  border-color: color-mix(in oklab, currentColor 30%, transparent);
  border-top-color: currentColor;
  margin-right: 0;
  vertical-align: middle;
}

.copy-btn.copied {
  background: var(--secondary);
  color: var(--secondary-foreground);
}

/* ---------- Input ---------- */

.input {
  height: 2.5rem;
  padding: 0 0.875rem;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--foreground);
  background: transparent;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input::placeholder { color: var(--muted-foreground); }

.input:focus-visible {
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 30%, transparent);
}

.input-sm { height: 2rem; font-size: 0.8125rem; padding: 0 0.75rem; }
.input-hero { height: 2.75rem; font-size: 1rem; }

/* ---------- Select (dropdown) ---------- */

.select { position: relative; }

.select-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-width: 9.5rem;
  height: 2rem;
  padding: 0 0.625rem 0 0.75rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.select-trigger:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 30%, transparent);
}

.select-trigger .chevron {
  width: 0.875rem;
  height: 0.875rem;
  color: var(--muted-foreground);
  transition: transform 0.15s;
}

.select-trigger[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.select-content {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  z-index: 50;
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  padding: 0.25rem;
  box-shadow: var(--shadow-pop);
}

.select-item {
  display: flex;
  width: 100%;
  align-items: center;
  padding: 0.3125rem 0.5rem;
  font-family: inherit;
  font-size: 0.8125rem;
  color: inherit;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 6px);
  cursor: pointer;
  text-align: left;
  transition: background 0.1s;
}

.select-item:hover,
.select-item:focus-visible {
  background: var(--accent);
  color: var(--accent-foreground);
  outline: none;
}

.select-item[aria-selected="true"] { font-weight: 600; }

/* ---------- Card ---------- */

.card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%) translateY(8px);
  padding: 0.625rem 1.125rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--popover-foreground);
  background: var(--popover);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 100;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==========================================================================
   App layout
   ========================================================================== */

/* ---------- header ---------- */

.hero { text-align: center; margin-bottom: 30px; }

.hero h1 {
  margin: 0 0 6px;
  font-size: 2.125rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

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

.searchbar {
  display: flex;
  gap: 0.625rem;
  max-width: 620px;
  margin: 28px auto 0;
}

.searchbar .input { flex: 1; }

/* ---------- status ---------- */

.status {
  text-align: center;
  padding: 28px 20px;
  color: var(--muted-foreground);
  font-size: 0.95rem;
}

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

.spinner {
  display: inline-block;
  width: 1.125rem;
  height: 1.125rem;
  border: 2px solid var(--border);
  border-top-color: var(--muted-foreground);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -4px;
  margin-right: 10px;
}

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

/* ---------- toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  align-items: center;
  justify-content: space-between;
  margin: 28px 0 16px;
}

.toolbar-field { display: flex; align-items: center; gap: 0.5rem; }
.toolbar-label { color: var(--muted-foreground); font-size: 0.8125rem; }

#name-filter { width: 11rem; }

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

.results { display: flex; flex-direction: column; gap: 0.625rem; }

.result {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0.875rem 1rem;
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.result:hover {
  border-color: color-mix(in oklab, var(--foreground) 25%, var(--border));
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.06);
}

.result-main { flex: 1; min-width: 0; }

.result-name {
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1.4;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.result-name .trusted { color: var(--gold); }

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 7px;
  font-size: 0.75rem;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}

.result-meta .seed { color: var(--seed); font-weight: 700; }
.result-meta .leech { color: var(--leech); font-weight: 700; }
.result-meta .trusted { color: var(--gold); }

/* ---------- result actions + download menu ---------- */

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

.dl-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.copy-btn.copied,
.copy-dl-btn.copied {
  background: var(--secondary);
  color: var(--secondary-foreground);
}

.dl-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 60;
  min-width: min(22rem, 80vw);
  max-height: 18rem;
  overflow-y: auto;
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  padding: 0.25rem;
  box-shadow: var(--shadow-pop);
}

.dl-menu-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  background: var(--popover);
  border-bottom: 1px solid var(--border);
}

.dl-menu-count { font-size: 0.75rem; color: var(--muted-foreground); padding-left: 2px; }

.btn-xs { height: 1.625rem; padding: 0 0.625rem; font-size: 0.75rem; gap: 0.375rem; }
.btn-xs .icon { width: 0.75rem; height: 0.75rem; }

.dl-item-row {
  display: flex;
  align-items: center;
  gap: 0.125rem;
}

.dl-item {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4375rem 0.5rem;
  font-size: 0.8125rem;
  color: inherit;
  text-decoration: none;
  border-radius: calc(var(--radius) - 6px);
  transition: background 0.1s;
}

.dl-item-copy {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  background: transparent;
  color: var(--muted-foreground);
  border-radius: calc(var(--radius) - 6px);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}

.dl-item-copy svg { width: 0.875rem; height: 0.875rem; }
.dl-item-copy:hover { background: var(--accent); color: var(--accent-foreground); }
.dl-item-copy.copied { color: var(--seed); }

.dl-item .icon { width: 0.875rem; height: 0.875rem; color: var(--seed); flex-shrink: 0; }

.dl-item:hover { background: var(--accent); color: var(--accent-foreground); }

.dl-item-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.dl-more {
  padding: 0.3125rem 0.5rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.cat-badge {
  padding: 1px 9px;
  background: var(--muted);
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 500;
  white-space: nowrap;
}

/* ---------- pagination ---------- */

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 18px;
  margin-top: 26px;
}

.pagination .select-trigger { min-width: 0; }

#page-indicator {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  min-width: 70px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- footer ---------- */

.footer {
  margin-top: 48px;
  text-align: center;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  opacity: 0.75;
}

/* ---------- homepage ---------- */

.home {
  text-align: center;
  margin-top: 26px;
  animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) 0.05s backwards;
}

.feature-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.feature-pill {
  padding: 5px 14px;
  font-size: 0.8rem;
  color: var(--muted-foreground);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}

.home-hint {
  margin: 26px 0 10px;
  color: var(--muted-foreground);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.suggestion-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip-btn {
  padding: 8px 18px;
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--foreground);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.chip-btn:hover {
  border-color: var(--ring);
  background: var(--accent);
  color: var(--accent-foreground);
  transform: translateY(-1px);
}

.chip-btn:active { transform: scale(0.96); }

/* ---------- theme toggle ---------- */

.theme-select {
  position: absolute;
  top: 28px;
  right: 20px;
  z-index: 70;
}

.theme-trigger {
  width: 2.25rem;
  min-width: 0;
  padding: 0;
  justify-content: center;
}

#theme-icon, .theme-item-icon { display: inline-flex; }
#theme-icon svg, .theme-item-icon svg { width: 1rem; height: 1rem; }
.theme-item-icon { margin-right: 0.5rem; color: var(--muted-foreground); }

/* ---------- animations ---------- */

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes menu-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.hero { animation: rise 0.45s cubic-bezier(0.2, 0.7, 0.3, 1) backwards; }

.toolbar, .pagination { animation: rise 0.4s cubic-bezier(0.2, 0.7, 0.3, 1) 0.08s backwards; }

/* staggered result entrance */
.result {
  animation: rise 0.35s cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s, background 0.25s;
}

.result:hover { transform: translateY(-1px); }

/* While a row's download menu is open, lift the whole row above its siblings
   (hover transform creates a stacking context that would otherwise trap the
   menu's z-index and let later rows paint over the overlay). */
.result:has(.dl-menu:not([hidden])) {
  position: relative;
  z-index: 100;
}

.result:nth-child(1) { animation-delay: 0.02s; }
.result:nth-child(2) { animation-delay: 0.05s; }
.result:nth-child(3) { animation-delay: 0.08s; }
.result:nth-child(4) { animation-delay: 0.11s; }
.result:nth-child(5) { animation-delay: 0.14s; }
.result:nth-child(6) { animation-delay: 0.17s; }
.result:nth-child(7) { animation-delay: 0.20s; }
.result:nth-child(8) { animation-delay: 0.23s; }
.result:nth-child(9) { animation-delay: 0.26s; }
.result:nth-child(10) { animation-delay: 0.29s; }

/* dropdown + download menus pop in when opened */
.select-content, .dl-menu { animation: menu-in 0.16s ease; }

/* press feedback */
.btn:active, .chip-btn:active { transform: scale(0.96); }

/* smooth theme switch */
body { transition: background-color 0.25s ease, color 0.25s ease; }

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

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

@media (max-width: 560px) {
  .shell {
    padding: max(28px, env(safe-area-inset-top)) 14px 40px;
  }

  .hero h1 { font-size: 1.7rem; }

  /* toolbar: one full-width row per control */
  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .toolbar-field { width: 100%; }
  .toolbar-field .select, .toolbar-field .select-trigger { flex: 1; width: 100%; min-width: 0; }
  .toolbar-field .input { flex: 1; width: auto; }
  #name-filter { width: auto; }

  /* result cards: stack, buttons wrap evenly and never overflow */
  .result { flex-direction: column; align-items: stretch; gap: 12px; padding: 14px; }
  .result-actions { flex-wrap: wrap; gap: 8px; }
  .result-actions .btn { flex: 1 1 auto; justify-content: center; min-width: 0; }
  .dl-wrap { position: relative; display: flex; flex: 1 1 auto; }
  .dl-wrap .btn { flex: 1; justify-content: center; }

  .pagination { flex-wrap: wrap; gap: 10px; }
  .theme-select { top: 18px; right: 14px; }
}
