/* SmartBox Labs: language selector and layout safeguards for translated text.
   Loaded by the three pages. Everything for the selector lives under #language-slot so the
   pages' own generic rules (details, summary, form, button) cannot leak into it. */

/* ---------- Colours (light by default, dark inside the dark header areas) ---------- */
#language-slot {
  --lang-ink: #173454;
  --lang-muted: #5d7590;
  --lang-border: rgba(17, 50, 91, .2);
  --lang-surface: #fff;
  --lang-hover: rgba(20, 113, 253, .08);
  --lang-panel: #fff;
  --lang-accent: #1469de;
  --lang-selected: rgba(20, 113, 253, .1);
  --lang-shadow: 0 24px 60px -18px rgba(16, 39, 71, .35), 0 2px 8px rgba(16, 39, 71, .08);
  position: relative; flex: none; min-width: 0;
  color: var(--lang-ink);
  font: 500 .95rem/1.3 var(--display, "Outfit", "Helvetica Neue", Arial, sans-serif);
  letter-spacing: 0; text-align: left;
}
.page #language-slot, .top-dark #language-slot {
  --lang-ink: #edf4ff;
  --lang-muted: #a9bad3;
  --lang-border: rgba(169, 186, 211, .3);
  --lang-surface: rgba(255, 255, 255, .06);
  --lang-hover: rgba(111, 168, 255, .13);
  --lang-panel: #10243d;
  --lang-accent: #8cbaff;
  --lang-selected: rgba(20, 113, 253, .22);
  --lang-shadow: 0 24px 64px -16px rgba(3, 10, 25, .7), 0 2px 8px rgba(3, 10, 25, .25);
}
#language-slot, #language-slot *, #language-slot *::before, #language-slot *::after { box-sizing: border-box; }

/* ---------- Header: keep the panel above the page and lay the tools out in one row ---------- */
header { position: relative; z-index: 30; }
.top-dark { position: relative; z-index: 20; }
.header-tools { display: flex; align-items: center; gap: .65rem; min-width: 0; }
header .brand { flex: none; }

/* ---------- Trigger ---------- */
#language-slot details.language-menu { display: block; position: relative; margin: 0; padding: 0; border: 0; border-bottom: 0; background: none; }
#language-slot summary.language-trigger {
  display: inline-flex; align-items: center; justify-content: flex-start; gap: .5rem;
  position: relative; z-index: 52; height: 40px; margin: 0; padding: 0 .85rem 0 .75rem;
  border: 1px solid var(--lang-border); border-radius: 999px;
  background: var(--lang-surface); color: var(--lang-ink);
  font: inherit; font-weight: 500; line-height: 1; list-style: none; cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background .18s ease, border-color .18s ease;
}
#language-slot summary.language-trigger::-webkit-details-marker { display: none; }
#language-slot summary.language-trigger::marker { content: ""; }
/* The founders page draws a "+" after every summary (FAQ). Not here. */
#language-slot summary.language-trigger::after { content: none; display: none; }
#language-slot summary.language-trigger:hover,
#language-slot details[open] > summary.language-trigger { background: var(--lang-hover); border-color: var(--lang-accent); }
#language-slot summary.language-trigger:focus-visible { outline: 3px solid var(--lang-accent); outline-offset: 3px; }
.language-label { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.language-code { display: none; font-weight: 600; letter-spacing: .05em; }
.language-icon, .language-chevron, .language-check {
  display: block; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.language-icon { width: 17px; height: 17px; color: var(--lang-accent); }
.language-chevron { width: 13px; height: 13px; color: var(--lang-muted); transition: transform .18s ease; }
details[open] > summary .language-chevron { transform: rotate(180deg); }

/* ---------- Panel (desktop: popover under the trigger) ---------- */
#language-slot .language-panel {
  position: absolute; z-index: 51; top: calc(100% + 10px); right: 0;
  width: min(400px, calc(100vw - 2rem));
  max-height: min(640px, calc(100vh - 6.5rem)); max-height: min(640px, calc(100dvh - 6.5rem));
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--lang-border) transparent;
  padding: .9rem; border: 1px solid var(--lang-border); border-radius: 18px;
  background: var(--lang-panel); color: var(--lang-ink); box-shadow: var(--lang-shadow);
}
details[open] > .language-panel { animation: language-reveal .16s ease-out; }
@keyframes language-reveal { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.language-panel-heading { padding: .1rem .5rem .7rem; color: var(--lang-muted); font-size: .75rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; }
/* Neutralise the generic form styles of the pages. */
#language-slot form.language-picker { display: block; margin: 0; padding: 0; gap: 0; border: 0; border-radius: 0; background: transparent; color: inherit; font: inherit; }
.language-picker button {
  display: flex; align-items: center; gap: .55rem; position: relative;
  width: 100%; min-width: 0; min-height: 38px; margin: 0; padding: .45rem .7rem;
  border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--lang-ink);
  font: inherit; line-height: 1.25; text-align: left; letter-spacing: 0; text-transform: none; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.language-picker button:hover { background: var(--lang-hover); }
.language-picker button[aria-current="true"] { background: var(--lang-selected); border-color: var(--lang-border); color: var(--lang-accent); }
.language-picker button:focus-visible { outline: 2px solid var(--lang-accent); outline-offset: -2px; }
.language-picker .language-auto { gap: .7rem; min-height: 56px; margin: 0 0 .6rem; padding: .6rem .7rem; border-color: var(--lang-border); }
.language-auto-copy { display: flex; flex: 1; flex-direction: column; gap: .2rem; min-width: 0; }
.language-auto-copy small { color: var(--lang-muted); font-size: .78rem; font-weight: 400; }
.language-picker .language-auto[aria-current="true"] .language-auto-copy small { color: inherit; opacity: .8; }
.language-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(12, auto);
  grid-auto-flow: column; gap: 2px 6px; padding-top: .6rem; border-top: 1px solid var(--lang-border);
}
.language-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.language-check { width: 15px; height: 15px; margin-left: auto; stroke-width: 2; }

/* ---------- Small screens: bottom sheet with a dimmed backdrop ---------- */
@media (max-width: 640px) {
  details.language-menu[open]::before { content: ""; position: fixed; inset: 0; z-index: 50; background: rgba(3, 10, 25, .62); }
  #language-slot .language-panel {
    position: fixed; z-index: 51; left: 0; right: 0; bottom: 0; top: auto; width: auto;
    max-height: min(86vh, 640px); max-height: min(86dvh, 640px);
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    border-width: 1px 0 0; border-radius: 22px 22px 0 0;
    animation: language-sheet .2s ease-out;
  }
  .language-panel::before { content: ""; display: block; width: 40px; height: 4px; margin: -.3rem auto .8rem; border-radius: 4px; background: var(--lang-border); }
  .language-picker button { min-height: 46px; }
  html.language-open { overflow: hidden; }
}
@keyframes language-sheet { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
/* Phones: show a short code (ES, DE...) instead of the language name, and slim the trigger. */
@media (max-width: 480px) {
  .language-label { display: none; }
  .language-code { display: inline; }
  #language-slot summary.language-trigger { gap: .4rem; padding: 0 .7rem 0 .65rem; }
}
@media (max-width: 360px) {
  header .brand { font-size: 1.15rem; }
  header .brand svg { width: 26px; height: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  #language-slot summary.language-trigger, .language-chevron, .language-picker button { transition: none; }
  details[open] > .language-panel { animation: none; }
}

/* ---------- Page layout: header tools ---------- */
/* Teaser: the "In the lab" pill is decoration; drop it when the language selector needs the room. */
@media (max-width: 480px) { header .lab { display: none; } }
/* Founders: the hero already has the same call to action right below. */
@media (max-width: 640px) { .site-header .header-link { display: none; } }
/* Privacy page: "Back" link on the left, selector on the right. */
.page-bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.75rem; }
.page-bar > a { min-width: 0; }

/* ---------- Translated text must never break the layout ---------- */
/* `1fr` tracks refuse to shrink below their widest content; minmax(0, 1fr) lets long words wrap instead. */
@media (max-width: 860px) {
  main .wrap, .hero .wrap, .waitlist .wrap, .problems, .routine { grid-template-columns: minmax(0, 1fr); }
  .routine > li { grid-template-columns: 60px minmax(0, 1fr); }
}
.copy, .notify, .row { min-width: 0; }
.row input[type="email"] { width: 100%; min-width: 0; }
.day li { grid-template-columns: 3.4rem minmax(0, 1fr) auto; }
.day li > span { min-width: 0; overflow-wrap: anywhere; }
.day { max-width: 100%; }
h1, h2, h3 { overflow-wrap: break-word; hyphens: auto; }
p { overflow-wrap: anywhere; } /* `anywhere` also lets grid/flex items shrink below their longest word */
li, label, summary, figcaption, .lede, .intro { overflow-wrap: break-word; }
.btn { white-space: normal; text-align: center; line-height: 1.2; overflow-wrap: break-word; }
.row .btn { max-width: 100%; }
footer nav { flex-wrap: wrap; gap: .5rem 1.5rem; }
/* The Worker sets --fit (1 or less) on a headline whose longest word would not fit. */
.copy h1 { font-size: calc(clamp(2.9rem, 7vw, 5.8rem) * var(--fit, 1)); max-width: 100%; }
.hero h1 { font-size: calc(clamp(2.75rem, 6.5vw, 5.25rem) * var(--fit, 1)); max-width: none; }
html:lang(en) .hero h1 { max-width: 11ch; }
main > h1 { font-size: calc(2.5rem * var(--fit, 1)); }
@media (max-width: 480px) {
  .copy h1 { font-size: calc(clamp(2.1rem, 11.2vw, 2.9rem) * var(--fit, 1)); }
  .hero h1 { font-size: calc(clamp(2.1rem, 11vw, 2.75rem) * var(--fit, 1)); }
}

/* Founding-member card: keep the card shape without forcing a minimum width (aspect-ratio would). */
.pass { aspect-ratio: auto; min-height: calc(min(440px, 100vw - 3rem) / 1.586); }
.pass-title { line-height: 1.05; }
.pass-bottom { flex-wrap: wrap; gap: .75rem 1.5rem; }
.pass-value, .pass-label { overflow-wrap: break-word; }
.pass-bottom > div { min-width: 0; }
