:root {
  color-scheme: light dark;

  /* Near-monochrome paper/ink — refinement carries it, not color */
  --bg: oklch(0.985 0.0015 250);
  --surface: oklch(1 0 0);
  --surface-2: oklch(0.974 0.0025 255);
  --ink: oklch(0.2 0.008 265);
  --ink-2: oklch(0.34 0.008 265);
  --muted: oklch(0.5 0.007 265);
  --faint: oklch(0.62 0.006 265);
  --line: oklch(0.905 0.003 265);
  --line-2: oklch(0.82 0.004 265);

  /* One quiet accent — interaction and selection only */
  --accent: oklch(0.52 0.12 40);
  --accent-2: oklch(0.45 0.12 38);
  --accent-tint: oklch(0.967 0.013 45);
  --accent-ring: oklch(0.52 0.12 40 / 0.28);

  /* Ink terminal surface for code */
  --code-bg: oklch(0.205 0.01 265);
  --code-ink: oklch(0.92 0.008 250);

  --ok: oklch(0.5 0.09 150);

  --r-xs: 5px;
  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 14px;

  --z-sticky: 100;
  --z-toast: 600;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 170ms;

  --serif: "Instrument Serif", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", "Liberation Mono", Menlo,
    Consolas, monospace;

  font-family: var(--sans);
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-size: 0.9375rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

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

button {
  cursor: pointer;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ---------- Headings ---------- */

h1,
h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-feature-settings: "lnum" 1;
  letter-spacing: 0;
  text-wrap: balance;
  color: var(--ink);
}

h3,
h4 {
  margin: 0;
}

/* Data, identifiers, figures all align on the mono grid */
.mono,
code,
pre,
.stat strong,
.pkg-index,
.pkg-name,
.pkg-meta,
.detail-title h3,
.meta-item strong,
.meta-item a,
.token-list li {
  font-variant-numeric: tabular-nums;
}

/* ---------- Shell ---------- */

.site-shell {
  width: min(1080px, calc(100% - 48px));
  margin: 0 auto;
}

/* ---------- Header ---------- */

.site-header {
  border-bottom: 1px solid var(--line);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.4rem 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
}

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

.brand-mark {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--surface);
  background: var(--ink);
  border-radius: var(--r-sm);
}

.brand-name {
  font-family: var(--mono);
  font-size: 0.92rem;
  letter-spacing: -0.01em;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.nav-links a {
  padding: 0.45rem 0.7rem;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--r-sm);
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}

.nav-links a:hover {
  color: var(--ink);
  background: var(--surface-2);
  text-decoration: none;
}

.nav-links .icon-button {
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--muted);
  border-color: transparent;
}

.nav-links .icon-button:hover {
  color: var(--ink);
  background: var(--surface-2);
  border-color: transparent;
}

.nav-links .icon-button svg {
  width: 19px;
  height: 19px;
}

/* ---------- Hero ---------- */

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: clamp(2rem, 5vw, 4rem);
  align-items: center;
  padding: clamp(3.25rem, 8vw, 6rem) 0;
}

.hero-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.5rem;
}

.hero-copy h1 {
  font-size: clamp(2.6rem, 5.5vw, 4rem);
  line-height: 1.04;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

/* ---------- Buttons ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  padding: 0 1.2rem;
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

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

.button.primary {
  color: var(--surface);
  background: var(--ink);
}

.button.primary:hover {
  background: oklch(0.32 0.01 265);
}

.button.ghost {
  color: var(--ink);
  background: transparent;
  border-color: var(--line-2);
}

.button.ghost:hover {
  background: var(--surface-2);
  border-color: var(--muted);
}

/* ---------- Install panel ---------- */

.install-card {
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.card-heading span {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--ink-2);
}

.install-card pre {
  margin: 0;
  padding: 1.15rem;
  overflow: auto;
  font-size: 0.82rem;
  line-height: 1.75;
  color: var(--code-ink);
  background: var(--code-bg);
  white-space: pre-wrap;
}

.card-note {
  margin: 0;
  padding: 0.85rem 1.1rem;
  font-size: 0.82rem;
  line-height: 1.55;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.card-note code {
  padding: 0.08em 0.34em;
  font-size: 0.9em;
  color: var(--ink);
  background: var(--surface-2);
  border-radius: var(--r-xs);
}

/* Icon buttons (copy / download / external) */
.icon-button {
  display: inline-grid;
  flex-shrink: 0;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

.icon-button:hover {
  color: var(--accent-2);
  border-color: var(--accent);
  background: var(--accent-tint);
  text-decoration: none;
}

.icon-button svg {
  display: block;
  width: 17px;
  height: 17px;
}

/* ---------- Stats band ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: clamp(1rem, 3vw, 2.5rem);
  padding: 1.6rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stat-label {
  display: block;
  margin-bottom: 0.55rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
}

.stat strong {
  font-family: var(--mono);
  font-size: clamp(1.15rem, 2.2vw, 1.5rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
}

/* ---------- Browser ---------- */

.browser {
  padding: clamp(2.75rem, 6vw, 4.5rem) 0 0;
}

.browser-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.6rem;
}

.browser-header h2 {
  font-size: clamp(1.8rem, 3.5vw, 2.4rem);
  line-height: 1;
}

.browser-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.refresh-button {
  height: 42px;
  gap: 0.5rem;
  padding: 0 0.9rem;
}

.refresh-button svg,
.refresh-button i {
  width: 16px;
  height: 16px;
}

.controls-search-and-icon {
  align-items: stretch;
  gap: 0.5rem;
}

.controls-search-and-icon .search-wrap {
  width: min(372px, 100%);
}

.controls-search-and-icon .refresh-button {
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--ink-2);
  border-color: var(--line-2);
}

.controls-search-and-icon .refresh-button:hover {
  color: var(--ink);
  background: var(--surface-2);
  border-color: var(--muted);
}

.controls-short-copy {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  width: min(410px, 100%);
  gap: 0.5rem;
}

.controls-short-copy .search-wrap {
  width: auto;
}

.controls-short-copy #package-search {
  font-size: 0.9rem;
}

.controls-short-copy .refresh-button {
  width: 42px;
  padding: 0;
}

.refresh-button[aria-busy="true"] svg {
  animation: refresh-spin 800ms linear infinite;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.search-wrap {
  width: min(340px, 100%);
}

#package-search {
  width: 100%;
  height: 42px;
  padding: 0 0.95rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}

#package-search::placeholder {
  color: var(--muted);
}

#package-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.status {
  padding: 1.5rem 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

.package-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.82fr) minmax(0, 1.18fr);
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: start;
}

/* ---------- Package index ---------- */

.package-list {
  border-top: 1px solid var(--line-2);
}

.package-card {
  display: grid;
  grid-template-columns: 2.25rem 1fr;
  gap: 0.5rem 1rem;
  width: 100%;
  padding: 1.05rem 0.75rem;
  margin: 0;
  color: inherit;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: background var(--dur) var(--ease);
}

.package-card:hover {
  background: var(--surface-2);
}

.package-card.is-active {
  background: var(--accent-tint);
}

.pkg-index {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--faint);
  padding-top: 0.1rem;
}

.package-card.is-active .pkg-index {
  color: var(--accent-2);
}

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

.pkg-name {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.package-card.is-active .pkg-name {
  color: var(--accent-2);
}

.pkg-desc {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink-2);
  font-size: 0.86rem;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.pkg-meta {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--muted);
}

/* ---------- Detail panel ---------- */

.package-details {
  position: sticky;
  top: 1.5rem;
  z-index: var(--z-sticky);
  padding: clamp(1.35rem, 2.5vw, 1.85rem);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.detail-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.35rem;
}

.detail-title {
  min-width: 0;
}

.detail-title h3 {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.detail-title p {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.command-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1.35rem 0;
  padding: 0.6rem 0.6rem 0.6rem 0.95rem;
  color: var(--code-ink);
  background: var(--code-bg);
  border-radius: var(--r-md);
}

.command-box code {
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.command-box .icon-button {
  color: var(--code-ink);
  border-color: oklch(1 0 0 / 0.2);
  background: oklch(1 0 0 / 0.06);
}

.command-box .icon-button:hover {
  color: var(--code-ink);
  border-color: oklch(1 0 0 / 0.45);
  background: oklch(1 0 0 / 0.14);
}

/* Meta as a ruled definition list, not boxes */
.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 1.5rem;
  margin: 1.35rem 0;
  border-top: 1px solid var(--line);
}

.meta-item {
  min-width: 0;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
}

.meta-item span {
  display: block;
  margin-bottom: 0.28rem;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 500;
}

.meta-item strong,
.meta-item a {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.meta-item a {
  color: var(--accent-2);
}

.section-block {
  margin-top: 1.6rem;
}

.section-block h4 {
  margin: 0 0 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  color: var(--ink-2);
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-block > code {
  display: block;
  margin-top: 0.55rem;
  padding: 0.55rem 0.75rem;
  font-size: 0.78rem;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow-wrap: anywhere;
}

.token-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.token-list li {
  padding: 0.22rem 0.55rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-2);
  background: var(--surface-2);
  border-radius: var(--r-xs);
}

.file-list {
  max-height: 240px;
  margin: 0.55rem 0 0;
  padding: 0.9rem 1rem;
  overflow: auto;
  font-size: 0.78rem;
  line-height: 1.7;
  color: var(--code-ink);
  background: var(--code-bg);
  border-radius: var(--r-md);
}

.empty-state {
  padding: 2.5rem 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.package-list .empty-state {
  border-bottom: 1px solid var(--line);
}

/* ---------- Footer ---------- */

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: clamp(3rem, 7vw, 5rem);
  padding: 1.5rem 0 2.5rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--muted);
}

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

.toast {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: var(--z-toast);
  padding: 0.62rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--surface);
  background: var(--ink);
  border-radius: var(--r-sm);
  box-shadow: 0 8px 24px oklch(0 0 0 / 0.2);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .site-shell {
    width: min(1080px, calc(100% - 36px));
  }

  .hero {
    grid-template-columns: 1fr;
    gap: 2.25rem;
  }

  .package-layout {
    grid-template-columns: 1fr;
  }

  .package-details {
    position: static;
  }
}

@media (max-width: 560px) {
  .site-shell {
    width: calc(100% - 28px);
  }

  .topbar {
    flex-wrap: wrap;
    gap: 0.85rem;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.4rem 1rem;
  }

  .meta-grid {
    grid-template-columns: 1fr;
  }

  .browser-controls {
    width: 100%;
    justify-content: stretch;
  }

  .refresh-button,
  .search-wrap {
    width: 100%;
  }

  .command-box,
  .detail-heading {
    flex-direction: column;
    align-items: stretch;
  }
}

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

/* ---------- Dark ---------- */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.155 0.004 265);
    --surface: oklch(0.188 0.005 265);
    --surface-2: oklch(0.235 0.006 265);
    --ink: oklch(0.94 0.004 250);
    --ink-2: oklch(0.8 0.006 255);
    --muted: oklch(0.65 0.008 258);
    --faint: oklch(0.52 0.008 258);
    --line: oklch(0.27 0.006 265);
    --line-2: oklch(0.37 0.008 265);

    --accent: oklch(0.74 0.1 52);
    --accent-2: oklch(0.81 0.09 56);
    --accent-tint: oklch(0.27 0.035 48);
    --accent-ring: oklch(0.74 0.1 52 / 0.32);

    --code-bg: oklch(0.12 0.005 265);
    --code-ink: oklch(0.9 0.008 250);

    --ok: oklch(0.78 0.11 152);
  }

  .brand-mark,
  .button.primary {
    color: var(--bg);
    background: var(--ink);
  }

  .button.primary:hover {
    background: oklch(0.85 0.005 250);
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .refresh-button[aria-busy="true"] svg {
    animation: none;
  }
}
