:root {
  --app-visual-height: 100dvh;
}

html,
body {
  min-height: var(--app-visual-height, 100dvh);
}

.celebration-img {
  transition: opacity 0.16s ease;
}

.celebration-img.is-loading,
.celebration-img:not([src]),
.celebration-img[src=""] {
  opacity: 0 !important;
  box-shadow: none !important;
  margin-top: 0 !important;
  max-height: 0 !important;
  min-height: 0 !important;
}

@media (max-width: 600px) {
  body {
    min-height: var(--app-visual-height, 100dvh) !important;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)) !important;
  }

  html.browser-chrome .app {
    width: min(100%, 430px) !important;
    border-radius: 28px !important;
    padding: 16px 16px 18px 16px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  html.browser-chrome .screen {
    padding: 4px 2px 0 2px !important;
  }

  html.browser-chrome .topbar {
    min-height: 36px !important;
    margin-bottom: 2px !important;
  }

  html.browser-chrome .brand-logo {
    width: min(26vw, 96px) !important;
    max-width: 96px !important;
    max-height: 96px !important;
    margin-bottom: 6px !important;
  }

  html.browser-chrome .title,
  html.browser-chrome .app-title {
    font-size: clamp(30px, 8vw, 46px) !important;
    line-height: 1.04 !important;
    letter-spacing: 0 !important;
    margin-bottom: 6px !important;
  }

  html.browser-chrome .subtitle,
  html.browser-chrome .age-subtitle {
    margin-bottom: 6px !important;
  }

  html.browser-chrome .small-note,
  html.browser-chrome .selector-note {
    line-height: 1.3 !important;
    margin-bottom: 10px !important;
  }

  html.browser-chrome .segmented-actions,
  html.browser-chrome .rainbow-button-row {
    margin-top: 10px !important;
    margin-bottom: 8px !important;
  }

  html.browser-chrome .single-home-wrap,
  html.browser-chrome .single-btn-wrap,
  html.browser-chrome .menu-buttons {
    margin-top: 8px !important;
  }

  html.browser-chrome .sentence-wrap {
    min-height: 230px !important;
  }

  html.browser-chrome .sentence {
    font-size: clamp(30px, 7.6vw, 48px) !important;
  }

  html.browser-chrome .sentence-emoji {
    font-size: clamp(72px, 19vw, 96px) !important;
    margin-bottom: 12px !important;
  }

  html.browser-chrome .speaker-zone {
    min-height: 132px !important;
  }

  html.browser-chrome .speaker-btn {
    width: 100px !important;
    height: 100px !important;
  }
}

@media (max-width: 600px) and (max-height: 760px) {
  html.browser-chrome .app {
    min-height: auto !important;
    height: auto !important;
    max-height: none !important;
  }

  html.browser-chrome .brand-logo {
    width: min(22vw, 82px) !important;
    max-width: 82px !important;
    max-height: 82px !important;
  }

  html.browser-chrome .title,
  html.browser-chrome .app-title {
    font-size: clamp(28px, 7.4vw, 40px) !important;
  }

  html.browser-chrome .small-note,
  html.browser-chrome .selector-note {
    font-size: 14px !important;
  }

  html.browser-chrome .sentence-wrap {
    min-height: 210px !important;
  }

  html.browser-chrome .speaker-zone {
    min-height: 118px !important;
  }

  html.browser-chrome .speaker-btn {
    width: 92px !important;
    height: 92px !important;
  }

  html.browser-chrome .game-icon,
  html.browser-chrome .bee-icon {
    font-size: 40px !important;
    margin-bottom: 4px !important;
  }
}

html.browser-chrome body {
  align-items: flex-start !important;
  justify-content: center !important;
  padding-bottom: max(96px, env(safe-area-inset-bottom)) !important;
}

html.browser-chrome .app {
  min-height: auto !important;
  height: auto !important;
  max-height: none !important;
}

html.browser-chrome .topbar {
  min-height: 30px !important;
}

html.browser-chrome .brand-logo {
  width: min(23vw, 84px) !important;
  max-width: 84px !important;
  max-height: 84px !important;
}

html.browser-chrome .title,
html.browser-chrome .app-title {
  font-size: clamp(28px, 7.4vw, 40px) !important;
}

html.standalone-app body {
  padding-bottom: max(16px, env(safe-area-inset-bottom)) !important;
}

/* ── Global design polish (all pages) ───────────────────────── */

/* Crisp font rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Button feel: smoother feedback on all interactive elements */
button {
  -webkit-tap-highlight-color: transparent;
}

/* Standalone: give bottom action strips breathing room above home indicator */
html.standalone-app .segmented-actions {
  margin-bottom: max(4px, calc(env(safe-area-inset-bottom) - 18px)) !important;
}

html.standalone-app .compact-buttons {
  padding-bottom: max(0px, calc(env(safe-area-inset-bottom) - 20px)) !important;
}

/* Standalone: prevent the app card from ending flush with home indicator */
html.standalone-app .app {
  margin-bottom: max(0px, calc(env(safe-area-inset-bottom) - 16px));
}

/* ═══════════════════════════════════════════════════════════════════════
   iPad / tablet optimizations  (768 px wide and up)
   ═══════════════════════════════════════════════════════════════════════ */

@media (min-width: 768px) {

  /* Body: more room around the card */
  body {
    padding-top:    max(24px, env(safe-area-inset-top))    !important;
    padding-right:  max(24px, env(safe-area-inset-right))  !important;
    padding-bottom: max(32px, env(safe-area-inset-bottom)) !important;
    padding-left:   max(24px, env(safe-area-inset-left))   !important;
    align-items: center !important;
  }

  /* App card: wider, more padding, softer radius */
  .app {
    width: min(100%, 640px) !important;
    border-radius: 44px !important;
    padding: 28px 32px 26px !important;
  }

  /* Brand logo */
  .brand-logo {
    width: min(13vw, 102px) !important;
    max-width: 102px !important;
    max-height: 102px !important;
    margin-bottom: 10px !important;
  }

  /* Home screen title */
  .app-title {
    font-size: clamp(38px, 5vw, 52px) !important;
    margin-bottom: 8px !important;
  }

  /* Home grid: 3 columns */
  .game-grid {
    max-width: 556px !important;
    grid-template-columns: 1fr 1fr 1fr !important;
    gap: 14px !important;
  }
  .game-tile {
    padding: 22px 12px 18px !important;
    border-radius: 26px !important;
  }
  .tile-icon { font-size: 38px !important; }
  .tile-name { font-size: 14px !important; }
  .tile-desc { font-size: 11px !important; }
  .tile-break { grid-column: 1 / -1 !important; }

  /* Game screen heading */
  .title {
    font-size: clamp(40px, 5.5vw, 60px) !important;
    margin-bottom: 10px !important;
  }

  /* Fast & Fluent: sentence */
  .sentence {
    font-size: clamp(38px, 5vw, 66px) !important;
  }
  .sentence-emoji {
    font-size: clamp(74px, 10vw, 114px) !important;
  }
  .timer-text {
    font-size: 58px !important;
  }
  .celebration-img {
    width: min(22vw, 158px) !important;
    max-height: 158px !important;
  }
  .run-history {
    max-width: 440px !important;
  }
  .report-canvas-wrap {
    max-width: 460px !important;
  }

  /* Rainbow Reader: sight word */
  .rainbow-word {
    font-size: clamp(68px, 9.5vw, 118px) !important;
  }

  /* Spelling Bee: speaker and revealed word */
  .speaker-zone {
    min-height: 162px !important;
  }
  .speaker-btn {
    width: 132px !important;
    height: 132px !important;
  }
  .speaker-btn svg {
    width: 58px !important;
    height: 58px !important;
  }
  .bee-icon {
    font-size: 64px !important;
    margin-bottom: 6px !important;
  }
  .reveal-word {
    font-size: clamp(42px, 6vw, 66px) !important;
  }

  /* Shared game controls */
  .segmented-actions {
    width: min(100%, 480px) !important;
    max-width: 480px !important;
    margin-top: 14px !important;
  }
  .segment-btn {
    padding: 17px 14px !important;
    font-size: 17px !important;
  }
  .result-title {
    font-size: clamp(36px, 5.5vw, 58px) !important;
  }
  .result-time {
    font-size: clamp(30px, 4.5vw, 52px) !important;
  }

  /* Brain Break: wider card stack and larger cards */
  .card-stack {
    max-width: 580px !important;
  }
  .vid-card {
    border-radius: 22px !important;
    padding: 18px 22px !important;
  }
  .card-icon {
    font-size: clamp(34px, 4vw, 46px) !important;
  }
  .card-name {
    font-size: clamp(16px, 2.2vw, 20px) !important;
  }
  .menu-title {
    font-size: clamp(28px, 4.5vw, 40px) !important;
  }

  /* Portrait-lock overlay: iPads are big enough in any orientation */
  .rotate-overlay {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   iPad Pro 12.9" and larger  (1024 px wide and up)
   ═══════════════════════════════════════════════════════════════════════ */

@media (min-width: 1024px) {

  .app {
    width: min(100%, 720px) !important;
    padding: 32px 38px 30px !important;
  }

  .brand-logo {
    width: min(10vw, 116px) !important;
    max-width: 116px !important;
    max-height: 116px !important;
  }

  .app-title {
    font-size: clamp(42px, 4.5vw, 56px) !important;
  }

  .game-grid {
    max-width: 628px !important;
    gap: 16px !important;
  }
  .game-tile {
    padding: 26px 14px 20px !important;
    border-radius: 28px !important;
  }
  .tile-icon { font-size: 44px !important; }
  .tile-name { font-size: 15.5px !important; }
  .tile-desc { font-size: 11.5px !important; }

  .title {
    font-size: clamp(46px, 5vw, 68px) !important;
  }

  .sentence {
    font-size: clamp(44px, 4.5vw, 74px) !important;
  }
  .timer-text {
    font-size: 68px !important;
  }
  .celebration-img {
    width: min(18vw, 180px) !important;
    max-height: 180px !important;
  }

  .rainbow-word {
    font-size: clamp(76px, 8.5vw, 126px) !important;
  }

  .speaker-btn {
    width: 150px !important;
    height: 150px !important;
  }
  .speaker-btn svg {
    width: 66px !important;
    height: 66px !important;
  }

  .segmented-actions {
    width: min(100%, 540px) !important;
    max-width: 540px !important;
  }

  .card-stack {
    max-width: 640px !important;
  }
  .card-name {
    font-size: clamp(17px, 2vw, 22px) !important;
  }
}
