/* Device-aware layout. Loaded last so it can adapt every page without
   changing the compact iPhone presentation that remains the default. */

html,
body {
  width: 100%;
  overflow-x: hidden;
}

.phone-shell {
  container-type: inline-size;
}

.app-view,
.app-view > *,
.page-head > div,
.kural-page-head > div,
.pf2-top > div {
  min-width: 0;
}

input,
select,
textarea,
table,
canvas {
  max-width: 100%;
}

/* Activity content uses its actual available space, including split-screen. */
.quest-models article > *,
.learning-workspace > *,
.learning-match > div,
.learning-tile,
.learning-match-tile {
  min-width: 0;
}

.quest-models-visual article > strong,
.quest-models-visual article > span,
.learning-tile,
.learning-match-label,
.quest-memory button > [lang="ta"],
.writing-picker strong,
.quest-review [lang="ta"] {
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
}

.quest-models.quest-models-visual article {
  grid-template-columns: clamp(44px, 9cqi, 72px) minmax(0, 1fr) 44px;
  gap: 6px clamp(8px, 2cqi, 16px);
  padding: clamp(12px, 3cqi, 22px);
}

.quest-models-visual .quest-model-picture {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}

.quest-models.quest-models-visual article > strong {
  font-size: clamp(19px, 3.8cqi, 30px);
  line-height: 1.75;
}

.quest-models-visual article > span {
  font-size: clamp(14px, 2.3cqi, 18px);
  line-height: 1.5;
}

.quest-models-visual .preschool-number-model {
  font-size: clamp(24px, 4.5cqi, 36px);
}

.bubbles-field {
  gap: 16px 12px;
}

.kid-bubble {
  min-width: 0;
  max-width: 144px;
  padding: clamp(10px, 2cqi, 22px);
  font-size: clamp(24px, 5cqi, 38px);
}

.kid-bubble > [lang="ta"],
.feed-food > [lang="ta"],
.kid-car > [lang="ta"] {
  display: block;
  min-width: 0;
  max-width: 100%;
  font-family: var(--font-tamil);
  line-height: 1.65;
  overflow-wrap: anywhere;
}

/* Whole words get wider bubbles so they remain readable at a useful size. */
.bubbles-field.has-words {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
}

.has-words .kid-bubble {
  max-width: none;
  min-height: 86px;
  aspect-ratio: auto;
  margin-top: 0;
  padding: 18px 16px;
  border-radius: 50px;
  font-size: clamp(20px, 3.5cqi, 28px);
}

.has-words .kid-bubble > [lang="ta"] {
  white-space: nowrap;
}

.feed-food {
  display: grid;
  place-items: center;
  padding: 12px;
}

.kid-train-options {
  flex-wrap: wrap;
}

.kid-train-options .learning-tile,
.learning-bank .learning-tile,
.learning-answer-zone .learning-tile {
  min-width: min(64px, 100%);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.writing-board-card {
  width: 100%;
  max-width: 680px;
  margin-inline: auto;
}

.writing-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}

.writing-instruction {
  flex-wrap: wrap;
}

.page-writing .writing-letter-nav span {
  overflow-wrap: anywhere;
  white-space: normal;
  text-overflow: clip;
}

.modal-card,
.bottom-sheet,
.lesson-feedback-sheet {
  max-height: min(88dvh, 820px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Tablets, foldables and medium browser windows. */
@media (min-width: 600px) {
  :root {
    --shell-width: 900px;
    --side: clamp(28px, 5vw, 48px);
    --nav-height: 84px;
  }

  body {
    display: block;
    min-height: 100dvh;
    padding: 0;
  }

  .phone-shell {
    width: min(100%, var(--shell-width));
    height: auto;
    min-height: 100dvh;
    margin-inline: auto;
    overflow-x: clip;
    overflow-y: visible;
    border: 0;
    border-radius: 0;
    box-shadow: 0 0 58px rgba(42, 32, 25, 0.12);
  }

  .bottom-nav,
  .feedback-panel {
    bottom: 0;
    width: min(calc(100% - 32px), 720px);
    border-radius: 24px 24px 0 0;
  }

  .bottom-sheet {
    width: min(720px, calc(100% - 32px));
    margin-inline: auto;
    border-radius: 30px 30px 0 0;
  }

  .village-grid,
  .preschool-theme-grid,
  .preschool-activity-grid,
  .review-module-grid,
  .page-review-v3 .review-module-grid,
  .page-foundations .review-module-grid,
  .page-foundations-v2 .review-module-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .page-alphabet .alphabet-grid-clean,
  .page-alphabet .syllable-grid,
  .writing-picker,
  .pronunciation-letter-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .quest-memory,
  .quest-memory.quest-memory-big {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .pf-badge-grid,
  .page-profile .badge-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .kural-parts-clean {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .page-poem .poem-games {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .page-head h1,
  .kural-page-head h1,
  .pf2-top h1 {
    font-size: clamp(32px, 4.5vw, 42px);
  }

  .learning-workspace,
  .quest-models,
  .quest-instruction,
  .quest-help,
  .writing-actions {
    max-width: 760px;
    margin-inline: auto;
  }

  .quest-memory button {
    min-height: 112px;
  }

  .quest-memory button > [lang="ta"] {
    font-size: clamp(22px, 3.4cqi, 30px);
  }

  .learning-tile {
    font-size: 22px;
    line-height: 1.7;
  }
}

/* Large tablets and desktop browsers. */
@media (min-width: 1024px) {
  :root {
    --shell-width: 1180px;
    --side: clamp(48px, 6vw, 72px);
  }

  .phone-shell {
    box-shadow: 0 0 80px rgba(42, 32, 25, 0.14);
  }

  .village-grid,
  .preschool-theme-grid,
  .preschool-activity-grid,
  .review-module-grid,
  .page-review-v3 .review-module-grid,
  .page-foundations .review-module-grid,
  .page-foundations-v2 .review-module-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .page-alphabet .alphabet-grid-clean,
  .page-alphabet .syllable-grid,
  .writing-picker,
  .pronunciation-letter-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }

  .quest-memory,
  .quest-memory.quest-memory-big {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .pf-badge-grid,
  .page-profile .badge-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .page-poem .poem-games {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .bottom-nav,
  .feedback-panel {
    width: min(calc(100% - 48px), 780px);
  }
}

/* Short landscape screens keep controls reachable without squeezing content. */
@media (orientation: landscape) and (max-height: 600px) {
  :root {
    --nav-height: 68px;
    --side: clamp(18px, 4vw, 36px);
  }

  .phone-shell {
    padding-top: calc(var(--safe-top) + 8px);
  }

  .brandbar {
    margin-block: 7px 10px;
  }

  .bottom-nav {
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-top: 4px;
  }

  .nav-btn {
    min-height: 50px;
  }

  .modal-backdrop {
    align-items: flex-start;
    overflow-y: auto;
    padding-top: max(12px, var(--safe-top));
  }

  .modal-card,
  .bottom-sheet,
  .lesson-feedback-sheet {
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 20px);
  }
}

/* Installed mobile apps should always fill their device, including iPad. */
@media (display-mode: standalone) and (min-width: 600px) {
  .phone-shell {
    max-width: none;
    box-shadow: none;
  }
}
