/* Inkbrary site. Tokens come from the app's "cute" theme (design/redesign/glass/TOKENS.md, reference column;
   dark values from design/redesign/paper/TOKENS.md "Cute dark"). Names mirror AppTheme. */

@font-face {
  font-family: 'Baloo 2';
  src: url('/fonts/baloo2-latin.woff2') format('woff2');
  font-weight: 600 800;
  font-display: swap;
}
@font-face {
  font-family: 'Quicksand';
  src: url('/fonts/quicksand-latin.woff2') format('woff2');
  font-weight: 500 700;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --bg: #faf2e4;
  --card: #fffdf8;
  --ink: #3a3670;
  /* App value is #8B87AE (3.06:1 on bg). Darkened for the web so secondary text clears 4.5:1. */
  --sub: #5f5b89;
  --line: #f0e5cf;
  --orange: #f6a13f;
  --orange-soft: #fbdcac;
  --pink: #ee907f;
  --pink-soft: #f9d3c8;
  --teal: #5fb4a4;
  --teal-soft: #cde8e0;
  --sky: #6ea5e0;
  --sky-soft: #d3e3f7;
  --moss: #8fb35e;
  --chip: #f3ead6;
  --shape-c: #f3b9ac;
  --primary-fill: #3a3670;
  --primary-text: #fffdf8;
  /* Input outline: the app's `sub` is too faint for a 3:1 control boundary on the card, so use a mid plum. */
  --field-line: #7a76a0;
  --error: #9e3b2c;
  --shadow: 0 10px 24px rgba(58, 54, 112, 0.1);
  --phone: #3a3670;
  --icon-sun: inline-block;
  --icon-moon: none;
  --shot-light: block;
  --shot-dark: none;
  --r-card: 24px;
  --r-ctrl: 18px;
  --r-chip: 14px;
  --font-display: 'Baloo 2', 'Trebuchet MS', 'Avenir Next', system-ui, sans-serif;
  --font-body: 'Quicksand', 'Trebuchet MS', 'Avenir Next', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #221f42;
    --card: #2e2a55;
    --ink: #f6efdf;
    --sub: #a9a5cf;
    --line: #3c3768;
    --orange-soft: #6b5230;
    --pink-soft: #6a4650;
    --teal-soft: #2f5a52;
    --sky-soft: #2f4a6b;
    --chip: #38336a;
    --shape-c: #b4776c;
    /* App dark primary is orange with the dark ground as its label (7.5:1). */
    --primary-fill: #f6a13f;
    --primary-text: #221f42;
    --field-line: #8b87ae;
    --error: #f4a090;
    --shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
    --phone: #120f2b;
    --icon-sun: none;
    --icon-moon: inline-block;
    --shot-light: none;
    --shot-dark: block;
  }
}

/* Explicit choice from the header button (see js/theme.js); wins over the system preference. */
:root[data-theme='light'] {
  color-scheme: light;
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #221f42;
  --card: #2e2a55;
  --ink: #f6efdf;
  --sub: #a9a5cf;
  --line: #3c3768;
  --orange-soft: #6b5230;
  --pink-soft: #6a4650;
  --teal-soft: #2f5a52;
  --sky-soft: #2f4a6b;
  --chip: #38336a;
  --shape-c: #b4776c;
  /* App dark primary is orange with the dark ground as its label (7.5:1). */
  --primary-fill: #f6a13f;
  --primary-text: #221f42;
  --field-line: #8b87ae;
  --error: #f4a090;
  --shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  --phone: #120f2b;
  --icon-sun: none;
  --icon-moon: inline-block;
  --shot-light: none;
  --shot-dark: block;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 1.0625rem;
  line-height: 1.6;
}
main {
  overflow-x: clip; /* decorative blobs bleed past the viewport edge */
}
img {
  max-width: 100%;
  height: auto;
}
a {
  color: var(--ink);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  text-decoration-color: var(--orange);
}
a:hover {
  text-decoration-color: var(--pink);
}
:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
  border-radius: 6px;
}
.wrap {
  width: min(100% - 40px, 1120px);
  margin-inline: auto;
}
.skip {
  position: absolute;
  inset-inline-start: 12px;
  top: -80px;
  background: var(--primary-fill);
  color: var(--primary-text);
  padding: 10px 16px;
  border-radius: var(--r-chip);
  z-index: 10;
}
.skip:focus {
  top: 12px;
}

/* Type */
.h-display,
.h-section,
h3 {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0;
}
.h-display {
  font-size: clamp(2.6rem, 8.2vw, 4.6rem);
  line-height: 1.02;
  text-wrap: balance;
}
.h-display-s {
  font-size: clamp(2.1rem, 6.4vw, 3.3rem);
}
.h-section {
  font-size: clamp(1.9rem, 5vw, 2.8rem);
  line-height: 1.1;
  text-wrap: balance;
}
h3 {
  font-size: 1.45rem;
  line-height: 1.15;
}
.lede {
  font-size: 1.25rem;
  font-weight: 600;
  max-width: 34ch;
  margin: 18px 0 0;
}
.section-intro {
  max-width: 52ch;
  color: var(--sub);
  margin: 12px 0 0;
}
.fine {
  color: var(--sub);
  font-size: 0.9rem;
  margin-top: 28px;
}
.quiet {
  color: var(--sub);
  font-size: 0.95rem;
  margin: 16px 0 0;
}
.quiet a {
  color: var(--sub);
}
.todo {
  background: var(--orange-soft);
  color: var(--ink);
  padding: 1px 8px;
  border-radius: 8px;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(100% - 40px, 1120px);
  margin-inline: auto;
  padding: 18px 0 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-height: 44px;
}
.theme-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 2px solid var(--field-line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.theme-toggle[hidden] {
  display: none;
}
.theme-toggle:hover {
  background: var(--chip);
}
.theme-toggle:active {
  transform: translateY(1px);
}
.theme-toggle svg {
  display: none;
}
.theme-toggle .icon-sun {
  display: var(--icon-sun);
}
.theme-toggle .icon-moon {
  display: var(--icon-moon);
}
@media (prefers-reduced-motion: no-preference) {
  .theme-toggle svg {
    animation: theme-icon-in 0.28s ease-out;
  }
}
@keyframes theme-icon-in {
  from {
    transform: rotate(-50deg) scale(0.6);
    opacity: 0;
  }
}
.brand-icon {
  border-radius: 11px;
  box-shadow: var(--shadow);
  display: block;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}

/* Buttons and form */
.btn {
  font: inherit;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  line-height: 1;
  min-height: 52px;
  padding: 0 26px;
  border: 0;
  border-radius: var(--r-ctrl);
  background: var(--primary-fill);
  color: var(--primary-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}
.btn:hover {
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(1px);
}
.btn[disabled] {
  opacity: 0.7;
  cursor: progress;
  transform: none;
}
.form-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  margin: 34px 0 6px;
}
.form-hint {
  margin: 0 0 10px;
  color: var(--sub);
  max-width: 46ch;
}
.signup-wrap {
  max-width: 520px;
  margin-top: 8px;
}
.field-label {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 6px;
}
.field-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.field {
  flex: 1 1 220px;
  min-width: 0;
  min-height: 52px;
  padding: 0 18px;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--field-line);
  border-radius: var(--r-ctrl);
}
.field::placeholder {
  color: var(--sub);
  opacity: 1;
}
.field[aria-invalid='true'] {
  border-color: var(--error);
}
.field:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
}
.msg {
  min-height: 1.5em;
  margin: 8px 0 0;
  font-weight: 700;
  color: var(--error);
}
.consent {
  margin: 4px 0 0;
  font-size: 0.9rem;
  color: var(--sub);
  max-width: 46ch;
}
.consent a {
  color: var(--sub);
}
.hp {
  /* Visually hidden without an off-screen offset: a -9999px left offset makes RTL pages scroll 10,000px wide. */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.readers {
  border: 0;
  padding: 0;
  margin: 26px 0 18px;
}
.readers legend {
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0;
  margin-bottom: 8px;
}
.reader-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.pill {
  position: relative;
  cursor: pointer;
}
.pill input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.pill span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 20px;
  border-radius: var(--r-chip);
  background: var(--chip);
  font-weight: 700;
  border: 2px solid transparent;
}
.pill input:checked + span {
  background: var(--primary-fill);
  color: var(--primary-text);
}
.pill input:focus-visible + span {
  outline: 3px solid var(--ink);
  outline-offset: 3px;
}

/* Joined state. Without JS the Worker redirects to #joined and :target reveals it. */
.joined {
  display: none;
  align-items: center;
  gap: 18px;
  background: var(--card);
  border: 2px dashed var(--field-line);
  border-radius: var(--r-card);
  padding: 22px;
  box-shadow: var(--shadow);
}
.joined.is-on,
.joined:target {
  display: flex;
}
.signup-wrap:has(.joined:target) .signup,
.signup-wrap:has(.joined.is-on) .signup {
  display: none;
}
.joined-text {
  margin: 0;
  font-weight: 700;
  font-size: 1.1rem;
}
.stamp {
  flex: none;
  display: inline-grid;
  place-items: center;
  text-align: center;
  width: 92px;
  height: 92px;
  padding: 8px;
  border: 3px solid var(--teal);
  border-radius: 50%;
  color: var(--ink);
  background: var(--teal-soft);
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1;
  font-size: 1.05rem;
  transform: rotate(-8deg);
  box-shadow: inset 0 0 0 4px var(--bg);
}
@media (prefers-reduced-motion: no-preference) {
  .joined.is-on .stamp,
  .joined:target .stamp {
    animation: stamp 0.34s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  }
}
@keyframes stamp {
  from {
    transform: scale(1.9) rotate(-22deg);
    opacity: 0;
  }
  to {
    transform: scale(1) rotate(-8deg);
    opacity: 1;
  }
}

/* Hero */
.hero {
  display: grid;
  gap: 40px;
  padding-top: 36px;
  padding-bottom: 72px;
  position: relative;
}
.hero::before {
  /* Soft paper blobs behind the hero, the app's onboarding corner shapes. */
  content: '';
  position: absolute;
  z-index: -1;
  inset-inline-end: -12%;
  top: -40px;
  width: min(70vw, 620px);
  aspect-ratio: 1.1;
  background: var(--orange-soft);
  border-radius: 58% 42% 55% 45% / 48% 56% 44% 52%;
  opacity: 0.8;
}
.hero-art {
  position: relative;
  display: flex;
  justify-content: center;
  padding-bottom: 20px;
}
.phone {
  width: min(300px, 78vw);
  padding: 9px;
  background: var(--phone);
  border-radius: 44px;
  box-shadow: 0 24px 48px rgba(58, 54, 112, 0.22);
  position: relative;
}
.phone::before {
  content: '';
  position: absolute;
  top: 17px;
  left: 50%;
  width: 78px;
  height: 22px;
  margin-left: -39px;
  background: var(--phone);
  border-radius: 12px;
  z-index: 1;
}
.phone img {
  display: block;
  width: 100%;
  border-radius: 36px;
}
/* Both screenshots are in the HTML; the theme tokens pick one (hidden lazy images are not fetched). */
.phone .shot-light {
  display: var(--shot-light);
}
.phone .shot-dark {
  display: var(--shot-dark);
}
.hero-cat {
  position: absolute;
  inset-inline-start: max(0px, calc(50% - 250px));
  bottom: -26px;
  width: clamp(130px, 38vw, 210px);
  height: auto;
  filter: drop-shadow(0 10px 14px rgba(58, 54, 112, 0.18));
}
@media (min-width: 900px) {
  .hero {
    grid-template-columns: 1.1fr 0.9fr;
    align-items: center;
    padding-top: 56px;
  }
  .phone-hero {
    width: 320px;
  }
  .hero-cat {
    inset-inline-start: calc(50% - 300px);
  }
}

/* Bands and sections */
.band {
  background: var(--card);
  padding: 72px 0;
}
.band-soft {
  background: var(--chip);
  overflow: hidden;
}
.section {
  padding: 72px 0;
}

/* Steps */
.steps {
  list-style: none;
  padding: 0;
  margin: 36px 0 0;
  display: grid;
  gap: 20px;
}
.step {
  position: relative;
  background: var(--bg);
  border-radius: var(--r-card);
  padding: 64px 22px 26px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.step > p {
  margin: 0;
}
.step-art {
  width: 160px;
  height: 160px;
  align-self: center;
}
.step-no {
  position: absolute;
  top: 16px;
  inset-inline-start: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--ink);
}
@media (min-width: 860px) {
  .steps {
    grid-template-columns: repeat(3, 1fr);
    gap: 0 20px;
  }
  /* Subgrid keeps art, title and text on shared rows, so a taller art block
     in one language pushes all three cards down together instead of overlapping. */
  .step {
    display: grid;
    grid-row: span 3;
    grid-template-rows: subgrid;
    row-gap: 10px;
  }
  .step > :first-child {
    align-self: center;
    justify-self: center;
  }
  .step > .chips {
    justify-self: stretch;
  }
}
.accent-orange {
  background: var(--orange-soft);
}
.accent-pink {
  background: var(--pink-soft);
}
.accent-teal {
  background: var(--teal-soft);
}
.accent-sky {
  background: var(--sky-soft);
}
.chips {
  list-style: none;
  padding: 0;
  margin: 0;
  min-height: 160px; /* rows wrap in longer languages, so the box must be able to grow */
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}
.chip-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--r-chip);
  padding: 8px 12px;
  box-shadow: var(--shadow);
}
.chip-name {
  font-weight: 700;
  flex: 1;
  min-width: 0;
}
.chip-kind {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--sub);
}
.bubble {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  display: inline-block;
}
.chip-row .bubble.accent-orange {
  background: var(--orange);
}
.chip-row .bubble.accent-pink {
  background: var(--pink);
}
.chip-row .bubble.accent-teal {
  background: var(--teal);
}

/* The one moment of motion: a book hops from the phone to the reader. Three hops, then it rests. */
.hop {
  position: relative;
  width: 100%;
  max-width: 360px;
  aspect-ratio: 360 / 200;
  align-self: center;
  height: auto;
}
.hop svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.s-phone {
  fill: var(--ink);
}
.s-reader {
  fill: var(--teal);
}
.s-screen {
  fill: var(--card);
}
.s-bar-pink {
  fill: var(--pink);
}
.s-bar-teal {
  fill: var(--teal);
}
.s-bar-orange {
  fill: var(--orange);
}
.s-line {
  fill: var(--line);
}
.s-arc {
  fill: none;
  stroke: var(--orange);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 0.1 11;
}
.hop-book {
  position: absolute;
  width: 8%;
  aspect-ratio: 1 / 0.8;
  background: var(--pink);
  border-radius: 4px 6px 6px 4px;
  border-right: 4px solid var(--card);
  box-shadow: 0 0 0 2px var(--ink);
  left: 70%;
  top: 36%;
  opacity: 0;
}
.hop-check {
  position: absolute;
  left: 84%;
  top: 56%;
  width: 7%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--teal-soft);
  box-shadow: 0 0 0 2px var(--ink);
  transform: translate(-50%, -50%);
}
.hop-check::after {
  content: '';
  position: absolute;
  left: 32%;
  top: 18%;
  width: 24%;
  height: 46%;
  border: solid var(--ink);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
}
@media (prefers-reduced-motion: no-preference) {
  .hop-book {
    animation: hop 2.6s ease-in-out 0.4s 3 both;
  }
  .hop-check {
    animation: arrive 2.6s ease-in-out 0.4s 3 both;
  }
}
@keyframes hop {
  0% {
    left: 22%;
    top: 40%;
    opacity: 0;
    transform: scale(0.6);
  }
  8% {
    opacity: 1;
    transform: scale(1);
  }
  30% {
    left: 36%;
    top: 12%;
  }
  50% {
    left: 48%;
    top: 4%;
  }
  72% {
    left: 60%;
    top: 14%;
    opacity: 1;
    transform: scale(1);
  }
  86% {
    left: 70%;
    top: 40%;
    opacity: 1;
    transform: scale(0.8);
  }
  100% {
    left: 72%;
    top: 46%;
    opacity: 0;
    transform: scale(0.4);
  }
}
@keyframes arrive {
  0%,
  80% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
  }
  92% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.15);
  }
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

/* Readers */
.reader-cards {
  list-style: none;
  padding: 0;
  margin: 32px 0 0;
  display: grid;
  gap: 18px;
}
.reader-card {
  background: var(--card);
  border-radius: var(--r-card);
  padding: 24px;
  box-shadow: var(--shadow);
}
.reader-card .bubble {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  margin-bottom: 14px;
}
.reader-card p {
  margin: 8px 0 0;
  color: var(--sub);
}
@media (min-width: 860px) {
  .reader-cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Screens */
.screens {
  margin-top: 40px;
  display: flex;
  gap: 28px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  padding: 10px max(20px, calc((100vw - 1120px) / 2)) 28px;
  scroll-padding-inline: max(20px, calc((100vw - 1120px) / 2));
}
.screen {
  margin: 0;
  flex: none;
  scroll-snap-align: start;
  text-align: center;
}
.screen .phone {
  width: min(260px, 70vw);
  margin-inline: auto;
}
.screen figcaption {
  margin-top: 14px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
}
@media (min-width: 900px) {
  .screens {
    justify-content: center;
    overflow: visible;
  }
}

/* Privacy points */
.points {
  list-style: none;
  padding: 0;
  margin: 32px 0 0;
  display: grid;
  gap: 18px;
}
.points li {
  border-top: 3px solid var(--orange);
  padding-top: 16px;
}
.points p {
  margin: 8px 0 0;
  color: var(--sub);
}
@media (min-width: 860px) {
  .points {
    grid-template-columns: repeat(3, 1fr);
    gap: 32px;
  }
}

/* CTA */
.cta {
  background: var(--pink-soft);
  padding: 72px 0;
}
.cta-inner {
  display: grid;
  gap: 24px;
  align-items: center;
}
.cta-cat {
  width: 140px;
  height: 140px;
}
@media (min-width: 760px) {
  .cta-inner {
    grid-template-columns: 200px 1fr;
    gap: 40px;
  }
  .cta-cat {
    width: 200px;
    height: 200px;
  }
}

/* Inner pages */
.page-narrow {
  max-width: 720px;
  padding: 40px 0 72px;
}
.page-narrow .lede {
  max-width: 44ch;
}
.page-cat {
  display: block;
  width: 150px;
  height: auto;
  margin-bottom: 14px;
}
.page-center {
  min-height: 60vh;
}
.prose section {
  margin-top: 34px;
}
.prose h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.6rem;
  margin: 0 0 6px;
}
.prose p,
.prose li {
  max-width: 62ch;
}
.prose p {
  margin: 8px 0;
}
.prose ul {
  padding-inline-start: 1.2em;
  margin: 8px 0;
}

/* Footer */
.site-footer {
  border-top: 2px solid var(--line);
  padding: 36px 0 48px;
  color: var(--sub);
  font-size: 0.95rem;
}
.footer-grid {
  display: grid;
  gap: 16px;
}
.footer-grid p {
  margin: 0;
}
.footer-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0 22px;
}
.footer-nav > a,
.footer-nav > span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}
.footer-nav > a {
  color: var(--ink);
}
.footer-nav > span a {
  color: var(--ink);
  margin-inline-start: 0.35em;
}
.footer-aff {
  max-width: 60ch;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  /* Reduced motion: the book rests, the check is already shown. */
  .hop-book {
    opacity: 0;
  }
}

/* The CTA band sits on a tinted fill, where the quieter `sub` text would drop below 4.5:1. */
.cta .section-intro,
.cta .consent,
.cta .consent a,
.cta .quiet,
.cta .quiet a {
  color: var(--ink);
}

/* Language picker in the header: a <details> dropdown of plain links, so it works without JavaScript.
   Each name is set in its own language. js/lang-menu.js only adds Escape and outside-click closing. */
.header-tools {
  position: relative; /* anchors the dropdown to the whole tool group, so it never runs off the screen edge */
  display: flex;
  align-items: center;
  gap: 10px;
}
.lang-menu {
  position: static;
}
.lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 14px;
  border: 2px solid var(--field-line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.lang-btn::-webkit-details-marker {
  display: none;
}
.lang-btn:hover,
.lang-menu[open] > .lang-btn {
  background: var(--chip);
}
.lang-icon,
.lang-chevron {
  flex: none;
}
.lang-menu[open] .lang-chevron {
  transform: rotate(180deg);
}
.lang-list {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 8px);
  z-index: 30;
  list-style: none;
  margin: 0;
  padding: 8px;
  min-width: 220px;
  max-height: min(70vh, 520px);
  overflow-y: auto;
  background: var(--card);
  border: 2px solid var(--field-line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}
.lang-list a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--r-chip);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}
.lang-list a:hover {
  background: var(--chip);
}
.lang-list a[aria-current] {
  font-weight: 800;
}
.lang-list a[aria-current]::after {
  content: '';
  flex: none;
  width: 0.65em;
  height: 1.15em;
  border: solid var(--teal);
  border-width: 0 3px 3px 0;
  transform: translateY(-15%) rotate(45deg) scale(0.8);
}
/* On a phone the label would crowd the logo and the theme button; keep it for screen readers only. */
@media (max-width: 479px) {
  .lang-btn {
    padding: 0 12px;
    gap: 6px;
  }
  .lang-btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .brand-name {
    font-size: 1.4rem;
  }
}

/* Right-to-left (Arabic). Layout uses logical properties; these cover what cannot be logical. */
[dir='rtl'] .hop {
  /* The book hops from the phone (now on the right) to the reader (on the left): mirror the whole scene... */
  transform: scaleX(-1);
}
[dir='rtl'] .hop-check::after {
  /* ...and flip the tick back so it still reads as a tick. */
  transform: scaleX(-1) rotate(45deg);
}

/* Type for scripts the Latin-only web fonts do not cover. System stacks on purpose: shipping CJK or Arabic
   web fonts would add megabytes and the CSP allows no third-party hosts. The Latin fonts stay first so brand
   words and numerals still use Baloo 2 and Quicksand; each glyph falls through to the stack for its script. */
html[lang='ja'] {
  --font-display: 'Baloo 2', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'Yu Gothic UI', 'Yu Gothic', Meiryo, 'Noto Sans JP', system-ui, sans-serif;
  --font-body: 'Quicksand', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic UI', 'Yu Gothic', Meiryo, 'Noto Sans JP', system-ui, sans-serif;
}
html[lang='ko'] {
  --font-display: 'Baloo 2', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
  --font-body: 'Quicksand', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', system-ui, sans-serif;
}
html[lang='zh-Hans'] {
  --font-display: 'Baloo 2', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif;
  --font-body: 'Quicksand', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei UI', 'Microsoft YaHei', 'Noto Sans SC', system-ui, sans-serif;
}
html[lang='zh-Hant'] {
  --font-display: 'Baloo 2', 'PingFang TC', 'Microsoft JhengHei UI', 'Microsoft JhengHei', 'Noto Sans TC', system-ui, sans-serif;
  --font-body: 'Quicksand', 'PingFang TC', 'Microsoft JhengHei UI', 'Microsoft JhengHei', 'Noto Sans TC', system-ui, sans-serif;
}
html[lang='ar'] {
  --font-display: 'Baloo 2', 'Geeza Pro', 'Segoe UI', 'Noto Sans Arabic', Tahoma, system-ui, sans-serif;
  --font-body: 'Quicksand', 'Geeza Pro', 'Segoe UI', 'Noto Sans Arabic', Tahoma, system-ui, sans-serif;
}
/* Tight tracking breaks Arabic letter joins and crowds CJK; headline line-height needs room for taller glyphs. */
html[lang='ar'] .h-display,
html[lang='ar'] .h-section,
html[lang='ar'] h3,
html[lang='ar'] .brand-name,
html[lang='ar'] .prose h2 {
  letter-spacing: 0;
}
html[lang='ar'] .h-display,
html[lang='ja'] .h-display,
html[lang='ko'] .h-display,
html[lang^='zh'] .h-display {
  line-height: 1.2;
}
html[lang='ja'] .h-display,
html[lang='ko'] .h-display,
html[lang^='zh'] .h-display,
html[lang='ja'] .h-section,
html[lang='ko'] .h-section,
html[lang^='zh'] .h-section,
html[lang='ja'] h3,
html[lang='ko'] h3,
html[lang^='zh'] h3 {
  letter-spacing: 0;
}
html[lang='ja'] .h-section,
html[lang='ko'] .h-section,
html[lang^='zh'] .h-section,
html[lang='ar'] .h-section {
  line-height: 1.25;
}
html[lang='ja'] body,
html[lang='ko'] body,
html[lang^='zh'] body {
  line-height: 1.75;
}
html[lang='ja'] .lede,
html[lang='ko'] .lede,
html[lang^='zh'] .lede {
  max-width: 22em;
}
html[lang='ja'] .btn,
html[lang='ko'] .btn,
html[lang^='zh'] .btn,
html[lang='ar'] .btn {
  line-height: 1.2;
}
/* Long words (German, Russian) must wrap rather than push the page wider than the phone. */
h1,
h2,
h3,
p,
li,
.btn,
.pill span {
  overflow-wrap: break-word;
}
.btn {
  padding-block: 12px;
}
