/* The landing page's cards (landing/_cards.html.j2, cards.js), in the variables styles.css sets on :root.
   The landing project (projects/landing/landing/) uses them too, with its own values for the variables. */

/* Logos: white silhouettes that take their brand colors on hover or selection */
.logo {
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo svg {
  width: 100%;
  height: 100%;
  filter: brightness(0) invert(1);
  opacity: 0.85;
  transition: filter 0.25s ease, opacity 0.25s ease;
}

.card:hover .logo svg,
.card:focus-visible .logo svg,
.card[aria-expanded="true"] .logo svg,
.subcard:hover .logo svg,
.subcard:focus-visible .logo svg {
  filter: none;
  opacity: 1;
}

/* Picker: the language cards, and the sub-cards of whichever family is open */
.picker {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cards-grid {
  display: grid;
  /* one column per card (index.html.j2 sets --cards on the picker), unless a section sets columns */
  grid-template-columns: repeat(var(--cards, 8), 1fr);
  gap: 0.75rem;
  width: 100%;
}

.card {
  appearance: none;
  font: inherit;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 1.4rem 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  transition: transform 0.2s var(--ease), background-color 0.2s var(--ease),
    border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.card:hover {
  transform: translateY(-3px);
  background-color: var(--bg-card-hover);
  border-color: var(--border-strong);
}

.card .logo {
  width: 36px;
  height: 36px;
  margin-bottom: 0.4rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}

/* Open state: only the chosen card stays, and its sub-cards sit beside it */
.picker.is-open {
  flex-direction: row;
  align-items: stretch;
  justify-content: center;
  gap: 1.5rem;
}

.picker.is-open .cards-grid {
  display: flex;
  width: 180px;
  flex-shrink: 0;
}

.picker.is-open .card {
  display: none;
}

.picker.is-open .card[aria-expanded="true"] {
  display: flex;
  flex: 1;
  justify-content: center;
  border-color: var(--text-main);
  background-color: var(--bg-card-selected);
  box-shadow: 0 0 30px rgba(255, 255, 255, 0.06);
  transform: none;
}

.subpanel {
  flex: 1;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.6rem;
}

.subpanel[hidden] {
  display: none;
}

.subpanel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.4rem;
}

.subpanel-label {
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-weight: 600;
}

.subpanel-label strong {
  color: var(--text-main);
  font-weight: 600;
}

/* "← All": an outline button, like the header's, so it reads as clickable */
.subpanel-back {
  appearance: none;
  background-color: transparent;
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1.35;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0.5rem 0.95rem;
  white-space: nowrap;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.subpanel-back:hover,
.subpanel-back:focus-visible {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: var(--text-main);
}

.subcard {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.7rem 0.9rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: inherit;
  text-decoration: none;
  opacity: 0;
  animation: slide-in 0.35s var(--ease) forwards;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.subcard:nth-of-type(2) { animation-delay: 0.04s; }
.subcard:nth-of-type(3) { animation-delay: 0.08s; }

.subcard:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--text-main);
}

.subcard .logo {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.subcard-body {
  flex-grow: 1;
  min-width: 0;
}

.subcard-title,
.subcard-subtitle {
  display: block;
  font-size: 0.875rem;
  line-height: 1.43;
}

.subcard-title {
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: -0.02em;
}

.subcard-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.subcard-arrow {
  flex-shrink: 0;
  color: var(--text-dim);
  transition: transform 0.15s ease, color 0.15s ease;
}

.subcard:hover .subcard-arrow {
  color: var(--text-main);
  transform: translateX(3px);
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 760px) {
  .cards-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .picker.is-open {
    flex-direction: column;
    align-items: center;
  }

  .picker.is-open .cards-grid {
    width: 100%;
    max-width: 460px;
  }

  .picker.is-open .card[aria-expanded="true"] {
    flex-direction: row;
    padding: 0.9rem 1rem;
    gap: 0.85rem;
  }

  .picker.is-open .card[aria-expanded="true"] .logo {
    margin-bottom: 0;
    width: 28px;
    height: 28px;
  }

  .subpanel {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .cards-grid {
    gap: 0.5rem;
  }

  .card {
    padding: 1rem 0.5rem;
  }

  .card .logo {
    width: 30px;
    height: 30px;
  }

  .card-title {
    font-size: 0.9rem;
  }
}

/* Shorter card rows */
.picker.cols-2 {
  max-width: 400px;
}

.picker.cols-3 {
  max-width: 580px;
}

/* an open family needs the full width for the card plus its sub-cards */
.picker.cols-2.is-open,
.picker.cols-3.is-open {
  max-width: 980px;
}

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

.picker.cols-3 .cards-grid {
  grid-template-columns: repeat(3, 1fr);
}

/* A sub-card's badge (cards.yaml `badge`), such as "Coming soon" */
.subcard-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0 0.45rem;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.5;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  vertical-align: middle;
}

/* A sub-card with a badge and no href: shown, but not a link */
.subcard-off,
.subcard-off:hover {
  cursor: default;
  background-color: var(--bg-card);
  border-color: var(--border-subtle);
}

.subcard-off:hover .logo svg {
  filter: brightness(0) invert(1);
  opacity: 0.85;
}

.picker.cols-1 {
  max-width: 500px;
}

.picker.cols-1 .cards-grid {
  /* minmax(0, ...): a code snippet wider than the screen scrolls inside the card */
  grid-template-columns: minmax(0, 1fr);
}

/* A row of code cards (Quickstart): the page's full width (index.md's content_max_width, 1200px inside
   its padding), which fits three snippets with lines of up to 46 characters side by side, without a
   scrollbar. Each card is at least as wide as such a line (46 x 0.6em of the 0.75rem mono font, plus
   the paddings and borders: about 379px), so on narrower screens the cards wrap onto more rows rather
   than scroll. A longer line needs a wider minimum. */
.picker.has-code {
  max-width: none;
}

.picker.has-code .cards-grid {
  /* min(100%, ...): below a card's width (phones), a snippet scrolls inside it */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
  gap: 0.75rem;
}

.picker.has-code .card-link {
  padding: 1rem 0.75rem;
}

.picker.has-code .card-snippet {
  --snippet-pad: 0.625rem;
}

/* A card that links straight to a page (Quickstart), with an optional code snippet under its title */
.card-link {
  align-items: stretch;
  text-align: left;
  padding: 1.1rem 1rem;
  gap: 0.9rem;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.card-link .logo {
  width: 28px;
  height: 28px;
  margin-bottom: 0;
}

.card-link .card-title {
  flex: 1;
}

.card-link:hover .subcard-arrow {
  color: var(--text-main);
  transform: translateX(3px);
}

.card-snippet {
  --snippet-pad: 0.875rem;
  margin: 0;
  padding: 0.9rem var(--snippet-pad);
  overflow-x: auto;
  background-color: var(--bg-muted);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--text-body);
}

/* An agent session (cards.yaml lang: session): the prompt on a band, as a terminal agent shows it */
.card-snippet .line {
  display: block;
  white-space: pre;
}

.card-snippet .prompt {
  color: var(--text-main);
  background-color: var(--bg-card-hover);
  /* the snippet's side padding, so the band spans it */
  margin: 0 calc(-1 * var(--snippet-pad));
  padding: 0 var(--snippet-pad);
}

.card-snippet .prompt + :not(.prompt) {
  margin-top: 0.5rem;
}

.card-snippet .tool { color: #c3e88d; }
.card-snippet .reply { color: var(--text-body); }
.card-snippet .result { color: var(--text-dim); }

/* Pygments token classes, in the page's greys with a few accents */
.card-snippet .k,
.card-snippet .kn,
.card-snippet .kc { color: #c792ea; }
.card-snippet .nc,
.card-snippet .nn { color: #82aaff; }
.card-snippet .s,
.card-snippet .s1,
.card-snippet .s2 { color: #c3e88d; }
.card-snippet .mi,
.card-snippet .mf { color: #f78c6c; }
.card-snippet .c1 { color: var(--text-dim); }
.card-snippet .o,
.card-snippet .p { color: var(--text-muted); }

/* Third level (index.html Core): a sub-card that opens a column of mini cards beside its siblings */
.tiers {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.tier2 {
  flex: 1 1 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  transition: flex-basis 0.35s var(--ease);
}

/* keep the panel's label where it was; the shorter content would otherwise re-center */
.subpanel.has-l3 {
  justify-content: flex-start;
}

.subpanel.has-l3 .tier2 {
  flex-basis: 160px;
  flex-grow: 0;
}

.subpanel.has-l3 .tier2 .subcard-subtitle {
  display: none;
}

.subcard-toggle {
  appearance: none;
  font: inherit;
  text-align: left;
  width: 100%;
  cursor: pointer;
}

.subcard-toggle[aria-expanded="true"] {
  border-color: var(--text-main);
  background-color: var(--bg-card-selected);
}

.subcard-toggle[aria-expanded="true"] .logo svg {
  filter: none;
  opacity: 1;
}

.subcard-toggle[aria-expanded="true"] .subcard-chevron {
  color: var(--text-main);
}

.tier3 {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.tier3[hidden] {
  display: none;
}

.subcard-mini {
  gap: 0.6rem;
  padding: 0.45rem 0.75rem;
}

.subcard-mini .logo {
  width: 20px;
  height: 20px;
}

.subcard-mini .subcard-title {
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .tiers {
    flex-direction: column;
    align-items: stretch;
  }

  .subpanel.has-l3 .tier2 {
    flex-basis: auto;
  }
}

/* Section headings (index.html: By Language / By Product) */
/* set like the section links under the title (.hero-nav) */
.section-heading {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 1rem;
  text-align: center;
}

/* each heading links back to the top of the page; an arrow shows on hover */
.section-heading a {
  position: relative;
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.35em;
  transition: color 0.15s ease;
}

.section-heading a:hover,
.section-heading a:focus-visible {
  color: var(--text-main);
}

/* outside the text, so the heading stays centred */
.section-heading a::after {
  content: "\2191";
  position: absolute;
  left: 100%;
  margin-left: 0.4em;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.section-heading a:hover::after,
.section-heading a:focus-visible::after {
  opacity: 1;
}

.picker + .section-heading,
.picker + .picker {
  margin-top: 4.5rem;
}

/* Opening/closing a family animates via the View Transitions API (index.html) */
::view-transition-group(*) {
  animation-duration: 0.4s;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 0.25s;
}

/* Card boxes (plain border and fill) show only their new look, stretched from the old size, instead of
   cross-fading two differently shaped images. Cards that only disappear or only appear fade quickly,
   so they don't ghost behind the incoming sub-cards. Browsers without view-transition-class keep the
   default cross-fade. */
::view-transition-old(*.card-box) {
  animation: none;
  opacity: 0;
}

::view-transition-new(*.card-box) {
  animation: none;
  height: 100%;
}

::view-transition-old(*.card-box):only-child {
  opacity: 1;
  animation: vt-fade-out 0.08s ease-out both;
}

::view-transition-new(*.card-box):only-child {
  animation: vt-fade-in 0.25s ease-out both;
}

/* the logo and title of a card that only disappears or appears fade on the same timing as its box */
::view-transition-old(*.card-part):only-child {
  animation: vt-fade-out 0.08s ease-out both;
}

::view-transition-new(*.card-part):only-child {
  animation: vt-fade-in 0.25s ease-out both;
}

@keyframes vt-fade-out {
  to { opacity: 0; }
}

@keyframes vt-fade-in {
  from { opacity: 0; }
}

/* breathing room when an opened section, or a section from the links under the title, is scrolled into view */
.picker,
.section-heading {
  scroll-margin: 1.5rem;
}

/* A section's picture that links to a page (cards.yaml `image`), such as the stack diagram */
.section-picture {
  display: block;
  /* the landing page centers its rows in a flex column, which would shrink the picture to the
     SVG's own width, so it takes the full width up to its max-width, as .picker does */
  box-sizing: border-box;
  width: 100%;
  max-width: 515px;
  margin: 0 auto;
  padding: 1.25rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-body);
  transition: border-color 0.2s ease;
}

.section-picture:hover,
.section-picture:focus-visible {
  border-color: var(--border-strong);
}

.section-picture > svg {
  display: block;
  width: 100%;
  height: auto;
}
