/* ==========================================================================
   Base — reset, typography, app shell layout, utilities
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  color: var(--ink-700);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100dvh;
}

img,
svg,
video {
  display: block;
  max-width: 100%;
}

svg {
  height: auto;
}

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

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

a {
  color: var(--primary-700);
  text-decoration: none;
  text-underline-offset: 0.16em;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-serif);
  line-height: var(--leading-tight);
  color: var(--ink-900);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
  font-feature-settings: "palt" 1;
}

:lang(ja) h1,
:lang(ja) h2,
:lang(ja) h3,
:lang(ja) h4 {
  font-family: var(--font-serif-jp);
  font-weight: 600;
  letter-spacing: 0.01em;
}

p {
  text-wrap: pretty;
}

:lang(si) {
  font-family: "Inter", "Noto Sans Sinhala", "Iskoola Pota", var(--font-sans);
  line-height: 1.75;
}

:lang(ne),
:lang(hi) {
  font-family: "Inter", "Noto Sans Devanagari", var(--font-sans);
  line-height: 1.7;
}

:lang(th) {
  font-family: "Inter", "Noto Sans Thai", var(--font-sans);
  line-height: 1.8;
}

:lang(ja) {
  font-family: var(--font-jp);
}

:lang(ko) {
  font-family: "Inter", "Noto Sans KR", var(--font-jp);
}

/* CJK / Thai / Indic headings: use the localised sans, not the Latin serif */
:lang(ko) h1, :lang(ko) h2, :lang(ko) h3, :lang(ko) h4,
:lang(th) h1, :lang(th) h2, :lang(th) h3, :lang(th) h4,
:lang(hi) h1, :lang(hi) h2, :lang(hi) h3, :lang(hi) h4 {
  font-weight: 700;
  letter-spacing: 0;
}

:lang(ko) h1, :lang(ko) h2, :lang(ko) h3, :lang(ko) h4 {
  font-family: "Noto Sans KR", var(--font-jp);
}
:lang(th) h1, :lang(th) h2, :lang(th) h3, :lang(th) h4 {
  font-family: "Noto Sans Thai", var(--font-sans);
}
:lang(hi) h1, :lang(hi) h2, :lang(hi) h3, :lang(hi) h4 {
  font-family: "Noto Sans Devanagari", var(--font-sans);
}

/* Latin-script new languages read fine in the serif; keep Cyrillic there too */
:lang(ru) { font-family: var(--font-sans); }
:lang(ru) h1, :lang(ru) h2, :lang(ru) h3, :lang(ru) h4 { font-family: "Noto Serif", Georgia, serif; }

/* ---- Focus visibility -------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Programmatic focus moves to the page heading on route change (for screen
   readers). Keep the focus move, drop the visible box on this non-interactive
   target. */
h1[tabindex="-1"]:focus,
h1[tabindex="-1"]:focus-visible,
[data-quiz-mount] h2[tabindex="-1"]:focus {
  outline: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus-color);
  outline-offset: 2px;
}

/* ---- Skip link & boot ------------------------------------------------- */
.skip-link {
  position: fixed;
  top: 0;
  left: 0;
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  color: var(--primary-700);
  font-weight: 600;
  border-radius: 0 0 var(--radius-sm) 0;
  box-shadow: var(--shadow-md);
  transform: translateY(-120%);
  transition: transform var(--transition);
  z-index: var(--z-toast);
}

.skip-link:focus {
  transform: translateY(0);
}

.boot {
  min-height: 60dvh;
  display: grid;
  place-items: center;
  color: var(--ink-400);
  font-size: var(--text-sm);
}

/* ---- App shell ------------------------------------------------------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-main {
  flex: 1 0 auto;
  padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + var(--space-6));
}

@media (min-width: 900px) {
  .app-main {
    padding-bottom: var(--space-10);
  }
}

.page {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding-inline: var(--page-pad-x);
  padding-top: var(--space-7);
}

.page--narrow {
  max-width: calc(var(--reading-max) + 2 * var(--page-pad-x));
}

/* ---- Prose --------------------------------------------------------- */
.prose {
  max-width: var(--reading-max);
}

.prose p,
.prose ul,
.prose ol {
  margin-block: var(--space-4);
  color: var(--ink-600);
}

.prose h2 {
  font-size: var(--text-2xl);
  margin-top: var(--space-9);
  margin-bottom: var(--space-4);
}

.prose h3 {
  font-size: var(--text-xl);
  margin-top: var(--space-7);
  margin-bottom: var(--space-3);
}

.prose ul,
.prose ol {
  padding-left: 1.35em;
}

.prose li {
  margin-block: var(--space-2);
}

.prose strong {
  color: var(--ink-800);
  font-weight: 600;
}

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

.stack > * + * {
  margin-top: var(--flow, var(--space-4));
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.text-muted {
  color: var(--ink-500);
}

.text-center {
  text-align: center;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--primary-700);
}

.eyebrow svg {
  width: 15px;
  height: 15px;
}

.section {
  margin-top: var(--space-10);
}

.section:first-child {
  margin-top: var(--space-6);
}

.section__head {
  max-width: var(--reading-max);
  margin-bottom: var(--space-6);
}

.section__title {
  font-size: var(--text-2xl);
  margin-top: var(--space-2);
}

.section__intro {
  margin-top: var(--space-3);
  color: var(--ink-500);
  font-size: var(--text-lg);
}

.divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin-block: var(--space-8);
}

.grid {
  display: grid;
  gap: var(--space-4);
}

@media (min-width: 620px) {
  .grid--2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 860px) {
  .grid--3 {
    grid-template-columns: repeat(3, 1fr);
  }
  .grid--auto {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }
}

.hidden {
  display: none !important;
}
