:root {
  color-scheme: light dark;

  --bg: #f4efe7;
  --bg-top: #f8f2e8;
  --panel: rgba(255, 252, 247, 0.84);
  --ink: #142218;
  --muted: #536053;
  --line: rgba(20, 34, 24, 0.12);
  --accent: #ff6b2c;
  --accent-dark: #db4d12;
  --moss: #94b49f;
  --shadow: 0 24px 60px rgba(20, 34, 24, 0.12);

  /* Bare triplets so call sites can keep their own alpha, e.g.
     rgb(var(--surface-rgb) / 0.52). Swapping the triplet per theme
     re-tints every translucent surface at once. */
  --surface-rgb: 255 255 255;
  --accent-rgb: 255 107 44;
  --tint-rgb: 148 180 159;
  --grid-rgb: 20 34 24;

  --icon-tile: rgb(255 255 255 / 0.72);

  --glow-warm: rgb(var(--accent-rgb) / 0.2);
  --glow-cool: rgb(var(--tint-rgb) / 0.4);

  --terminal-bg: #171c17;
  --terminal-fg: #d6f2de;
  --terminal-fg-rgb: 214 242 222;
  --terminal-bar: #4f5d4f;
}

/* The dark values live here once and are emitted twice below: CSS cannot share a
   declaration block between a media query and a plain selector. Both copies are
   generated from the same source, so they cannot drift apart. */

/* System preference, unless the visitor has pinned light. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1410;
    --bg-top: #151c15;
    --panel: rgba(28, 36, 29, 0.74);
    --ink: #e9e4da;
    --muted: #a8b5a8;
    --line: rgba(233, 228, 218, 0.14);
    /* Nudged brighter: #ff6b2c is fine on cream but sits heavy on near-black. */
    --accent: #ff7a42;
    --accent-dark: #ff6b2c;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);

    /* Sage rather than white, so translucent surfaces lift off the background
       instead of blowing out to grey. */
    --surface-rgb: 76 90 76;
    --accent-rgb: 255 122 66;
    --grid-rgb: 233 228 218;

    --icon-tile: rgb(226 222 212 / 0.9);

    /* Same glows at light-mode strength washed the whole page brown: a 20%
       orange veil is a warm tint over cream but dominates over near-black. */
    --glow-warm: rgb(var(--accent-rgb) / 0.07);
    --glow-cool: rgb(var(--tint-rgb) / 0.05);

    /* Below the page background, so the script card still reads as inset. */
    --terminal-bg: #080b08;
  }
}

/* Explicit choice from the theme switch. */
:root[data-theme="dark"] {
    --bg: #0f1410;
    --bg-top: #151c15;
    --panel: rgba(28, 36, 29, 0.74);
    --ink: #e9e4da;
    --muted: #a8b5a8;
    --line: rgba(233, 228, 218, 0.14);
    /* Nudged brighter: #ff6b2c is fine on cream but sits heavy on near-black. */
    --accent: #ff7a42;
    --accent-dark: #ff6b2c;
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);

    /* Sage rather than white, so translucent surfaces lift off the background
       instead of blowing out to grey. */
    --surface-rgb: 76 90 76;
    --accent-rgb: 255 122 66;
    --grid-rgb: 233 228 218;

    --icon-tile: rgb(226 222 212 / 0.9);

    /* Same glows at light-mode strength washed the whole page brown: a 20%
       orange veil is a warm tint over cream but dominates over near-black. */
    --glow-warm: rgb(var(--accent-rgb) / 0.07);
    --glow-cool: rgb(var(--tint-rgb) / 0.05);

    /* Below the page background, so the script card still reads as inset. */
    --terminal-bg: #080b08;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, var(--glow-warm), transparent 30%),
    radial-gradient(circle at right, var(--glow-cool), transparent 35%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg) 100%);
  min-height: 100vh;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background-image:
    linear-gradient(rgb(var(--grid-rgb) / 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgb(var(--grid-rgb) / 0.05) 1px, transparent 1px);
  background-size: 24px 24px;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

/* Sits above the hero rather than fixed to the viewport: the page has no nav
   bar to pin it to, and fixed positioning would float it over the catalog. */
/* One segmented control, not three loose buttons: the choices are mutually
   exclusive, so they should read as a single control with one active segment,
   the way the macOS appearance picker does. */
.theme-switch {
  /* Block-level flex, not inline-flex: margin-left:auto only right-aligns a
     block box. On an inline box the auto margin is dropped and it drifts left. */
  display: flex;
  margin: 0 0 8px auto;
  width: fit-content;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgb(var(--surface-rgb) / 0.45);
  backdrop-filter: blur(12px);
}

.theme-switch button {
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 14px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    background 160ms ease,
    color 160ms ease;
}

.theme-switch button:hover {
  color: var(--ink);
}

.theme-switch button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--bg);
}

.theme-switch button:focus-visible {
  outline: 2px solid rgb(var(--accent-rgb) / 0.4);
  outline-offset: 2px;
}

.hero {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 28px;
  align-items: center;
  min-height: 90vh;
}

.eyebrow {
  margin: 0 0 16px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.8rem;
  color: var(--muted);
}

h1,
h2,
h3,
pre {
  margin: 0;
}

h1 {
  font-family: "Instrument Serif", serif;
  font-size: clamp(3.6rem, 11vw, 7.4rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

h1 span {
  color: var(--accent);
  font-style: italic;
}

.subcopy,
.feature-strip p,
.selection-list,
.command-card,
.catalog-card p {
  color: var(--muted);
}

.subcopy {
  font-size: 1.1rem;
  line-height: 1.7;
  max-width: 56ch;
  margin: 22px 0 0;
}

.hero-actions {
  display: flex;
  gap: 14px;
  margin-top: 28px;
  flex-wrap: wrap;
}

.button,
.ghost-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 13px 20px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 700;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.button:hover,
.ghost-button:hover,
.catalog-card:hover {
  transform: translateY(-2px);
}

.button-primary {
  background: var(--accent);
  border-color: transparent;
  color: white;
}

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

.button-secondary,
.ghost-button {
  background: rgb(var(--surface-rgb) / 0.55);
  backdrop-filter: blur(12px);
}

.hero-card,
.feature-strip article,
.selection-panel,
.catalog-card {
  background: var(--panel);
  border: 1px solid rgb(var(--surface-rgb) / 0.62);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-card {
  border-radius: 28px;
  padding: 22px;
  transform: rotate(2deg);
}

.terminal {
  background: var(--terminal-bg);
  border-radius: 20px;
  padding: 14px;
  color: var(--terminal-fg);
  overflow: auto;
}

.terminal-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.terminal-bar span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--terminal-bar);
}

.terminal-bar span:nth-child(1) {
  background: #ff5f57;
}

.terminal-bar span:nth-child(2) {
  background: #febc2e;
}

.terminal-bar span:nth-child(3) {
  background: #28c840;
}

pre {
  white-space: pre-wrap;
  /* pre-wrap breaks on whitespace but never inside a token, and the generated
     script carries a 66-character Homebrew URL with nothing to break on. Left
     alone it pushed the script block far wider than its card. `anywhere` also
     keeps the long token out of the container's min-content width, so the
     panel cannot be stretched by it either. */
  overflow-wrap: anywhere;
  font-size: 0.97rem;
  line-height: 1.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 14px;
}

.stat-grid article,
.feature-strip article {
  border-radius: 18px;
  padding: 16px;
}

.stat-grid strong {
  display: block;
  font-size: 1.7rem;
}

.stat-grid span {
  color: var(--muted);
  font-size: 0.92rem;
}

.feature-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 24px 0 56px;
}

.feature-strip h2,
.builder-head h2 {
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.05;
}

.feature-strip p {
  line-height: 1.65;
  margin: 10px 0 0;
}

.builder-head {
  margin-bottom: 18px;
}

.preset-strip {
  display: grid;
  gap: 16px;
  margin-bottom: 22px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.preset-card {
  border-radius: 24px;
  padding: 18px;
  background: rgb(var(--surface-rgb) / 0.62);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: grid;
  /* Cards are stretched to equal height by the grid, and two auto rows would
     split that height between them, so a longer description stole pixels from
     the button, leaving Designer's 10px shorter than the rest. Let the content
     row absorb the slack and size the button to its own padding. */
  grid-template-rows: 1fr auto;
  gap: 18px;
}

.preset-card.active {
  border-color: rgb(var(--accent-rgb) / 0.5);
  box-shadow: 0 24px 60px rgb(var(--accent-rgb) / 0.16);
}

.preset-kicker {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 700;
}

.preset-card h4 {
  margin: 0;
  font-size: 1.2rem;
}

.preset-card p:last-child {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.preset-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

/* Direct children only. A descendant selector here also matched the nested
   .app-icon-fallback span, which outranked its own `display: none` and painted
   the initials on top of an icon that had loaded perfectly well. */
.preset-preview > span {
  border-radius: 999px;
  padding: 7px 10px;
  background: rgb(var(--tint-rgb) / 0.18);
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

.preset-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 12px 16px;
  background: rgb(var(--surface-rgb) / 0.75);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.preset-button:hover {
  transform: translateY(-2px);
}

.preset-button.active {
  background: var(--accent);
  color: white;
  border-color: transparent;
}

.builder-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.search-field {
  display: grid;
  gap: 8px;
  min-width: min(100%, 320px);
}

.search-field span {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
}

.search-field input {
  width: min(100%, 340px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  font: inherit;
  color: var(--ink);
  background: rgb(var(--surface-rgb) / 0.72);
  backdrop-filter: blur(10px);
}

.search-field input:focus-visible,
.filter-chip:focus-visible,
.catalog-card a:focus-visible {
  outline: 2px solid rgb(var(--accent-rgb) / 0.4);
  outline-offset: 2px;
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.filter-chip {
  border: 1px solid var(--line);
  background: rgb(var(--surface-rgb) / 0.58);
  color: var(--ink);
  border-radius: 999px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.filter-chip:hover {
  transform: translateY(-2px);
}

.filter-chip.active {
  background: var(--ink);
  /* Paired with --ink, not a literal white: in dark mode --ink is a light
     cream, so white text on it was nearly invisible. */
  color: var(--bg);
  border-color: transparent;
}

.builder-grid {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr;
  gap: 18px;
}

.catalog {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.catalog-card {
  border-radius: 22px;
  padding: 18px;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.catalog-card.selected {
  border-color: rgb(var(--accent-rgb) / 0.5);
  box-shadow: 0 24px 60px rgb(var(--accent-rgb) / 0.16);
}

.catalog-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.catalog-card h3 {
  display: flex;
  align-items: center;
}

.catalog-card .tag {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgb(var(--tint-rgb) / 0.22);
  color: var(--ink);
  font-size: 0.82rem;
}

.catalog-card p {
  margin: 14px 0 0;
  line-height: 1.6;
}

.app-label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-label-text {
  min-width: 0;
}

.app-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  /* Stays light in both themes on purpose: simple-icons ships solid black
     marks, so a dark tile would swallow them. */
  background: var(--icon-tile);
  border: 1px solid rgb(var(--grid-rgb) / 0.08);
  overflow: hidden;
}

.app-icon img {
  width: 14px;
  height: 14px;
  object-fit: contain;
}

.app-icon-fallback {
  display: none;
  font-size: 0.56rem;
  font-weight: 700;
  color: var(--muted);
}

.app-icon-fallback-only {
  font-size: 0.56rem;
  font-weight: 700;
  color: var(--muted);
}

.app-icon-fallback-only .app-icon-fallback,
.app-icon-fallback-only:not(img) {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.catalog-card footer {
  margin-top: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.84rem;
}

.catalog-card footer span {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.catalog-card a {
  color: var(--ink);
  font-weight: 700;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.empty-state {
  border-radius: 24px;
  padding: 28px;
  background: rgb(var(--surface-rgb) / 0.58);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.empty-state p {
  margin: 10px 0 0;
  color: var(--muted);
}

.selection-panel {
  border-radius: 28px;
  padding: 18px;
  position: sticky;
  top: 24px;
  height: fit-content;
  /* Sticky pins the top, so anything past the viewport is unreachable. With a
     full pack the Copy and Download buttons fell below the fold on short
     laptop viewports. Cap the height and let the panel scroll internally. */
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  /* Required, not redundant: setting only overflow-y makes overflow-x compute
     to auto rather than staying visible, which let the panel scroll sideways
     and carry the script card out over the catalog. */
  overflow-x: hidden;
}

.selection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.selection-list {
  list-style: none;
  padding: 0;
  margin: 18px 0;
  display: grid;
  gap: 10px;
}

.selection-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.selection-remove {
  border: 1px solid var(--line);
  background: none;
  color: var(--muted);
  border-radius: 999px;
  width: 22px;
  height: 22px;
  line-height: 1;
  font-size: 1rem;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease;
}

.selection-remove:hover {
  background: var(--accent);
  border-color: transparent;
  color: white;
}

.selection-remove:focus-visible {
  outline: 2px solid rgb(var(--accent-rgb) / 0.4);
  outline-offset: 2px;
}

.selection-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgb(var(--surface-rgb) / 0.52);
  border: 1px solid var(--line);
}

.saved-packs {
  margin: 18px 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.saved-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.saved-header h4 {
  margin: 0;
  font-size: 1rem;
}

.saved-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  display: grid;
  gap: 10px;
}

.saved-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgb(var(--surface-rgb) / 0.52);
  border: 1px solid var(--line);
}

.saved-list li.active {
  border-color: var(--accent);
  background: rgb(var(--surface-rgb) / 0.78);
}

.saved-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.saved-meta strong {
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-meta span {
  font-size: 0.78rem;
  color: var(--muted);
}

.saved-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.saved-actions .ghost-button {
  padding: 8px 12px;
  font-size: 0.82rem;
}

.saved-list li.saved-empty {
  display: block;
  font-size: 0.86rem;
  color: var(--muted);
  background: none;
  border-style: dashed;
}

.label {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.78rem;
  color: var(--muted);
}

.command-card {
  padding: 16px;
  border-radius: 18px;
  background: var(--terminal-bg);
  color: var(--terminal-fg);
}

.command-head {
  display: flex;
  /* Wrap here rather than inside .command-actions: when the panel is too narrow
     for label plus both buttons, the actions should drop below the label as a
     group. Without this the buttons broke apart and stacked on top of each
     other while the label squeezed into two lines. */
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: start;
  gap: 12px 16px;
  margin-bottom: 12px;
}

.command-actions {
  display: flex;
  gap: 10px;
  /* Keep the pair side by side; .command-head handles the narrow case. */
  flex-wrap: nowrap;
}

.command-actions .ghost-button.is-flashing {
  background: var(--accent);
  border-color: transparent;
  color: white;
}

.command-actions .ghost-button,
.command-actions .button {
  padding: 10px 14px;
  font-size: 0.88rem;
}

.status-message {
  /* Sits between the actions and the script now, so the spacing flipped. */
  margin: 0 0 12px;
  color: rgb(var(--terminal-fg-rgb) / 0.78);
  min-height: 1.4em;
  font-size: 0.92rem;
}

@media (max-width: 980px) {
  .hero,
  .builder-grid,
  .feature-strip {
    grid-template-columns: 1fr;
  }

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

  .hero {
    min-height: auto;
    padding-top: 32px;
  }

  .builder-toolbar,
  .command-head {
    align-items: stretch;
  }

  .hero-card {
    transform: none;
  }

  /* Single column here, so the panel is no longer a sidebar. Let it flow with
     the page instead of sticking and scrolling inside itself. */
  .selection-panel {
    position: static;
    max-height: none;
    overflow-y: visible;
  }
}

@media (max-width: 700px) {
  .shell {
    width: min(100% - 20px, 1180px);
  }

  .catalog,
  .stat-grid,
  .preset-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: clamp(3.2rem, 18vw, 5rem);
  }

  .search-field,
  .search-field input,
  .command-actions .ghost-button,
  .command-actions .button {
    width: 100%;
  }
}
