:root {
  color-scheme: light;
  --paper: #fff8ea;
  --ink: #243042;
  --muted: #52606f;
  --accent: #b7372f;
  --leaf: #3f7f5f;
  --sky: #5f95c8;
  --gold: #d9a53f;
  --line: #e6d8bd;
  --panel: #fffdf7;
  font-family: "Atkinson Hyperlegible", "Trebuchet MS", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  /* Keep anchor jumps clear of the sticky header. */
  scroll-padding-top: 5rem;
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1.55;
  text-align: center;
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

a:focus-visible,
button:focus-visible,
[tabindex]:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: 4px;
  box-shadow: 0 0 0 7px rgba(217, 165, 63, 0.24);
  /* Remote/keyboard focus must stay clear of the sticky header. */
  scroll-margin-top: 5rem;
}

/* Fallback for older TV/console browsers without :focus-visible. */
@supports not selector(:focus-visible) {
  a:focus,
  button:focus,
  [tabindex]:focus {
    outline: 4px solid var(--gold);
    outline-offset: 4px;
    box-shadow: 0 0 0 7px rgba(217, 165, 63, 0.24);
    scroll-margin-top: 5rem;
  }
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: 0.5rem;
  transform: translateY(-150%);
  background: var(--ink);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  z-index: 2;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(255, 248, 234, 0.96);
  border-bottom: 1px solid var(--line);
}

.site-nav {
  width: min(100%, 72rem);
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) auto minmax(16rem, 1fr);
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

.site-nav a,
.site-nav span[aria-disabled="true"],
.primary-action {
  min-height: 3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  background: var(--panel);
  text-decoration: none;
}

.site-nav a:hover,
.alphabet-nav a:hover,
.primary-action:hover,
.site-nav a:focus-visible,
.alphabet-nav a:focus-visible,
.primary-action:focus-visible {
  background: #ffffff;
  border-color: var(--accent);
}

.site-nav .brand-link {
  justify-self: start;
  color: var(--ink);
  font-weight: 700;
}

.activity-link {
  justify-self: center;
}

.nav-turns {
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1.5rem;
}

.turn-link {
  white-space: nowrap;
}

.site-nav span[aria-disabled="true"],
.alphabet-nav span {
  color: var(--muted);
  background: #f5ead5;
}

/* Disabled previous/next controls should read as non-interactive. */
.site-nav span[aria-disabled="true"] {
  opacity: 0.6;
  cursor: default;
}

/* "You are here" indicator across all input types. */
.alphabet-nav a[aria-current="page"],
.site-nav a[aria-current="page"] {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

main {
  width: min(100%, 72rem);
  margin: 0 auto;
  padding: 1rem;
}

.cover,
.front-matter,
.letter-section,
.review-section {
  padding: clamp(1rem, 3vw, 2.5rem) 0;
  border-bottom: 1px solid var(--line);
}

.cover {
  min-height: 85vh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1rem;
}

.primary-action {
  width: fit-content;
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 700;
}

h1,
h2,
h3 {
  line-height: 1.12;
  margin: 0 0 0.75rem;
}

h1 {
  font-size: clamp(2.6rem, 9vw, 6rem);
  color: var(--accent);
}

h2 {
  font-size: clamp(2rem, 6vw, 4.5rem);
}

h3 {
  font-size: 1.35rem;
}

.subtitle,
.section-note,
.pronunciation,
.parent-note {
  color: var(--muted);
}

.letter-mark {
  /* Read by letter-animation.js before it replaces the text fallback. */
  --letter-animation-ready: 1;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.letter-mark .upper {
  font-size: clamp(5rem, 22vw, 12rem);
  line-height: 0.9;
  color: var(--accent);
  font-weight: 800;
}

.letter-mark .lower {
  font-size: clamp(3rem, 12vw, 7rem);
  line-height: 1;
  color: var(--leaf);
  font-weight: 700;
}

/* The original text above is the no-JavaScript fallback. The SVG version keeps
   the full glyph outline visible while its centre-line strokes reveal the fill. */
.letter-mark--animated {
  align-items: flex-end;
  gap: clamp(0.35rem, 2vw, 1rem);
  min-height: clamp(7rem, 24vw, 13rem);
}

.letter-mark--interactive {
  width: fit-content;
  margin-inline: auto;
  padding-inline: 0.5rem;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
}

.written-letter {
  display: block;
  flex: 0 0 auto;
  overflow: visible;
}

.written-letter--upper {
  width: clamp(7rem, 22vw, 13rem);
  color: var(--accent);
}

.written-letter--lower {
  width: clamp(4.75rem, 13vw, 8rem);
  color: var(--leaf);
}

.written-letter text {
  font-family: "Atkinson Hyperlegible", "Trebuchet MS", Arial, sans-serif;
  font-size: 142px;
  font-weight: 700;
}

.written-letter--lower text {
  font-size: 126px;
}

.letter-outline {
  fill: transparent;
  stroke: currentColor;
  stroke-width: 2.4px;
  stroke-linejoin: round;
  opacity: 0.48;
}

.letter-fill {
  fill: currentColor;
}

.letter-finish {
  fill: currentColor;
  opacity: 0;
  animation: finish-letter-fill 0.18s ease-out var(--finish-delay) forwards;
}

.letter-static-svg {
  display: none;
  fill: currentColor;
}

.letter-mark--complete .letter-fill,
.letter-mark--complete .letter-finish,
.letter-mark--complete .letter-outline {
  display: none;
}

.letter-mark--complete .letter-static-svg {
  display: block;
}

.letter-fill-stroke {
  fill: none;
  stroke: white;
  stroke-width: var(--stroke-width, 54px);
  stroke-linecap: var(--stroke-cap, square);
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: reveal-letter-stroke var(--write-duration) ease-in-out var(--write-delay) forwards;
}

.written-letter--lower .letter-fill-stroke {
  stroke-width: var(--stroke-width, 50px);
}

@keyframes reveal-letter-stroke {
  to { stroke-dashoffset: 0; }
}

@keyframes finish-letter-fill {
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .letter-fill-stroke {
    animation: none;
    stroke-dashoffset: 0;
  }

  .letter-finish {
    animation: none;
    opacity: 1;
  }
}

.object-grid {
  --object-card-width: 19rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: 1rem;
}

.alphabet-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(3.75rem, 4.5rem));
  justify-content: center;
  gap: 0.65rem;
  margin-top: 1rem;
}

.alphabet-nav a,
.alphabet-nav span {
  min-height: 3.75rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 1.4rem;
  font-weight: 800;
  text-decoration: none;
}

.alphabet-nav a {
  color: var(--accent);
}

.bottom-alphabet-nav {
  margin-block: clamp(2rem, 5vw, 4rem) clamp(1.5rem, 4vw, 3rem);
}

.object-card {
  flex: 0 0 min(100%, var(--object-card-width));
  width: min(100%, var(--object-card-width));
  max-width: var(--object-card-width);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

figure {
  margin: 0 0 0.75rem;
}

img {
  display: block;
  width: 100%;
  height: auto;
}

.object-image {
  width: auto;
  max-width: 100%;
  height: clamp(14rem, 28vw, 20rem);
  margin-inline: auto;
  object-fit: contain;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.mascot-figure {
  width: min(100%, 24rem);
  margin: 1rem auto;
}

.mascot-image {
  width: auto;
  max-width: 100%;
  height: clamp(16rem, 36vw, 24rem);
  margin-inline: auto;
  object-fit: contain;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.image-placeholder {
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fffaf0;
  text-align: center;
  padding: 1rem;
}

.language-table {
  width: 100%;
  margin: 0.85rem 0 1rem;
  border-collapse: collapse;
  table-layout: auto;
  text-align: center;
}

.language-row {
  border-bottom: 1px solid rgba(230, 216, 189, 0.7);
}

.language-row--playable {
  cursor: pointer;
}

.language-row--playable:hover {
  background: #fff8ea;
  outline: 1px solid var(--line);
  outline-offset: -1px;
}

.language-row--playable:focus-visible,
.language-row--playable:has(.pronunciation-button:focus-visible) {
  background: #fff8ea;
  outline: 4px solid var(--gold);
  outline-offset: -2px;
  box-shadow: inset 0 0 0 3px rgba(217, 165, 63, 0.24);
}

.language-row:last-child {
  border-bottom: 0;
}

.language-name,
.language-word,
.language-pronunciation {
  padding: 0.35rem 0.3rem;
  vertical-align: middle;
}

.language-name {
  width: 5.5rem;
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.language-word {
  min-width: 7rem;
  overflow-wrap: anywhere;
}

.language-word [lang="ur"] {
  display: inline-block;
  direction: rtl;
  unicode-bidi: isolate;
}

.language-pronunciation {
  width: 8rem;
  min-width: 0;
}

.pronunciation-button {
  min-height: 2rem;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.2rem 0.35rem;
  background: transparent;
  color: var(--muted);
  font: inherit;
  line-height: 1.25;
  overflow-wrap: anywhere;
  text-align: center;
  cursor: pointer;
}

.pronunciation-button:hover,
.pronunciation-button:focus-visible {
  background: transparent;
  border-color: transparent;
  outline: 0;
  box-shadow: none;
}

.pronunciation-button .pronunciation {
  color: inherit;
}

.pronunciation-note {
  max-width: 46rem;
  margin: -0.25rem auto 1.25rem;
  color: var(--muted);
  text-align: center;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

[lang="ur"] {
  font-family: "Noto Nastaliq Urdu", "Noto Naskh Arabic", serif;
  font-size: 1.2em;
}

.activity-list,
.review-list {
  display: inline-grid;
  gap: 0.35rem;
  justify-items: center;
  margin-inline: auto;
  padding-left: 0;
  list-style: none;
  text-align: center;
}

.activity-section {
  margin-top: clamp(2rem, 5vw, 4rem);
}

.memory-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 1rem;
  margin-top: 1rem;
  text-align: center;
}

.site-footer {
  width: min(100%, 72rem);
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}

@media (max-width: 40rem) {
  body {
    font-size: 1rem;
  }

  main {
    padding: 0.75rem;
  }

  .site-nav {
    grid-template-columns: 1fr;
    padding-inline: 0.75rem;
  }

  .site-nav .brand-link,
  .activity-link,
  .nav-turns {
    justify-self: center;
  }

  .nav-turns {
    width: 100%;
    justify-content: space-between;
    gap: 0.75rem;
  }

  .turn-link {
    flex: 1 1 0;
  }

  .language-name,
  .language-word,
  .language-pronunciation {
    padding: 0.3rem 0.2rem;
  }

  .language-name {
    width: 4.75rem;
  }

  .language-word {
    min-width: 0;
  }

  .language-pronunciation {
    width: 6.75rem;
  }

}

@media (min-width: 64rem) {
  .alphabet-nav {
    grid-template-columns: repeat(13, minmax(3.75rem, 4.5rem));
  }
}

/* Touch, D-pad remotes (which expose no pointer), and TV-scale viewports
   all need larger targets. */
@media (pointer: coarse), (pointer: none), (min-width: 80rem) {
  .site-nav a,
  .site-nav span[aria-disabled="true"],
  .primary-action {
    min-height: 3.25rem;
    padding: 0.65rem 0.9rem;
  }

  .alphabet-nav a,
  .alphabet-nav span {
    min-height: 4.25rem;
  }
}

@media (min-width: 80rem) {
  main,
  .site-nav,
  .site-footer {
    width: min(100%, 86rem);
    /* Guard against TV overscan clipping the edges. */
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .alphabet-nav {
    grid-template-columns: repeat(13, minmax(4.25rem, 1fr));
  }

  .alphabet-nav a,
  .alphabet-nav span {
    min-height: 4.5rem;
    font-size: 1.7rem;
  }
}
