/* ═══════════════════════════════════════════════════════════
   MOBILE POLISH – phones & small tablets
   ═══════════════════════════════════════════════════════════ */

/* Paint status bar / home indicator zones (iOS white bars fix) */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background-color: var(--body-bg, #faf9f6);
  min-height: 100%;
  min-height: 100dvh;
}

body {
  background-color: var(--body-bg, #faf9f6);
  min-height: 100%;
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  /* top/bottom safe areas painted by bg, not padding (padding caused white gaps) */
}

/* Home screen uses dark purple gradient — match letterbox / overscroll */
html.boot-home,
html.boot-home body {
  background-color: #0a0718;
}
html.boot-archives,
html.boot-archives body {
  background-color: var(--body-bg);
}

html.boot-main,
html.boot-main body,
html.boot-teacher,
html.boot-teacher body {
  background-color: var(--body-bg, #faf9f6);
}

/* Full-bleed dark backdrop on unit select + archives */
#screen-unit-select,
#screen-teacher {
  background-color: #0a0718;
}

.unit-select-bg {
  /* Cover notch + home indicator */
  top: calc(-1 * env(safe-area-inset-top, 0px));
  bottom: calc(-1 * env(safe-area-inset-bottom, 0px));
  left: calc(-1 * env(safe-area-inset-left, 0px));
  right: calc(-1 * env(safe-area-inset-right, 0px));
  width: auto;
  height: auto;
}

/* Main study screen fills safe areas with theme body color */
#screen-main {
  background-color: var(--body-bg, #faf9f6);
  padding-top: var(--sat, env(safe-area-inset-top, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Prefer larger tap targets */
button,
.choice-btn,
.tab-btn,
.diff-btn,
.unit-card,
.home-lb-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 640px) {
  .unit-select-container {
    padding: 36px 16px calc(100px + env(safe-area-inset-bottom, 0px)); /* the screen itself leaves room for the status bar (nav.css) */
    max-width: 100%;
  }
  .unit-select-header {
    margin-bottom: 28px;
  }
  .logo {
    font-size: 42px !important;
  }
  .logo-book {
    font-size: 36px;
  }
  .tagline {
    font-size: 9px;
    letter-spacing: 2px;
  }
  .home-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }
  .home-lb-btn {
    font-size: 11px !important;
    padding: 10px 12px !important;
    min-height: 40px;
  }
  .unit-card {
    padding: 18px !important;
    border-radius: 16px !important;
  }
  .unit-card h2 {
    font-size: 22px !important;
  }
  .unit-emoji {
    font-size: 32px !important;
  }
  .unit-card:hover {
    transform: none !important;
  }
  .unit-card:active {
    transform: scale(0.98) !important;
  }

  #wotd-card > div {
    padding: 14px 16px !important;
  }
  #wotd-card .wotd-word {
    font-size: 22px !important;
  }

  /* In the page flow on phones so it never covers the header */
  .home-announcement {
    position: relative !important;
    inset: auto !important;
    margin: max(12px, env(safe-area-inset-top, 0px) + 4px) 12px -4px;
    max-width: none !important;
    font-size: 12px;
  }
  .home-announcement.collapsed {
    width: fit-content;
  }

  .main-header {
    padding: 10px 12px;
    /* padding-top already handled by #screen-main safe-area */
    gap: 8px;
  }
  .main-unit-title {
    font-size: 18px;
  }
  .main-word-count {
    font-size: 10px;
  }
  .back-btn,
  .settings-btn,
  .theme-toggle {
    width: 42px;
    height: 42px;
    border-radius: 12px;
  }

  .difficulty-bar {
    padding: 8px 12px;
    gap: 6px;
  }
  .diff-btn {
    padding: 8px 12px;
    min-height: 36px;
    font-size: 11px;
  }
  .tab-bar-wrapper {
    padding: 0 10px 10px;
  }
  .tab-bar {
    gap: 2px;
    padding: 3px;
  }
  .tab-btn {
    padding: 9px 10px;
    font-size: 10px;
    min-height: 36px;
  }

  .tab-content {
    padding: 14px 14px 88px;
  }
  .big-word {
    font-size: 28px !important;
  }
  .word-display-card,
  .card {
    padding: 16px !important;
  }
  .choice-btn {
    padding: 14px 14px;
    font-size: 15px;
    min-height: 48px;
  }
  .next-btn {
    padding: 14px;
    min-height: 48px;
    font-size: 14px;
  }

  .modal {
    width: calc(100vw - 24px) !important;
    max-width: 100% !important;
    max-height: calc(100dvh - 48px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    margin: 12px;
    border-radius: 16px !important;
  }
  /* No box-in-a-box: the window scrolls as a whole (a full page scrolls with the page) */
  .modal-body { max-height: none; overflow: visible; }

  .name-submit-row {
    flex-wrap: wrap;
  }
  .name-input {
    min-height: 44px;
    font-size: 16px !important;
  }
  .name-submit-btn {
    min-height: 44px;
  }

  .dino-container {
    padding: 0 4px;
  }
  .dino-canvas {
    width: 100% !important;
    max-width: 100%;
    height: auto !important;
  }
  .dino-controls {
    gap: 10px;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .dino-ctrl-btn {
    min-height: 48px;
    flex: 1;
    font-size: 14px;
  }
  .dino-how-title {
    font-size: 22px;
  }
  .dino-how-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .jeopardy-board {
    gap: 4px;
  }
  .jeopardy-cell {
    font-size: 12px;
    padding: 8px 4px;
    min-height: 40px;
  }

  .match-grid {
    gap: 8px;
  }

  .lb-row {
    font-size: 12px;
    padding: 10px 8px;
  }
  .lb-switcher {
    flex-wrap: wrap;
    gap: 4px;
  }
  .lb-switch-btn {
    font-size: 10px;
    padding: 6px 8px;
  }
}

@media (max-width: 380px) {
  .logo {
    font-size: 36px !important;
  }
  .big-word {
    font-size: 24px !important;
  }
  .tab-btn {
    padding: 8px 7px;
    font-size: 11px;
  }
  .home-lb-btn {
    font-size: 11.5px !important;
    padding: 8px 10px !important;
  }
}

@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  .unit-select-container {
    padding-top: 20px;
    padding-bottom: 40px;
  }
  .main-header {
    padding-top: 6px;
    padding-bottom: 6px;
  }
  .tab-content {
    padding-top: 10px;
    padding-bottom: 48px;
  }
}
