/* ============================================================
   mobile.css — TheStoryPilot Responsive Stylesheet
   Both page4.html and page5.html already link to this file.
   Breakpoints: 1024px (tablet landscape), 768px (tablet), 480px (phone)
   ============================================================ */

/* ────────────────────────────────────────────
   1. GLOBAL MOBILE FOUNDATIONS
   ──────────────────────────────────────────── */

/* Prevent 300ms tap delay and double-tap-to-zoom on all touch targets */
html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

/* Remove iOS tap highlight flash */
*,
*::before,
*::after {
  -webkit-tap-highlight-color: transparent;
}

/* Prevent Safari auto-zoom on input focus (requires ≥16px) */
input,
textarea,
select {
  font-size: max(16px, 1em);
}

/* Smooth scrolling everywhere */
html, body {
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* All interactive elements: minimum 44×44 touch target (WCAG), 
   but we aim for 48px+ since the audience is young children */
button,
.action-button,
.mainBtn,
.mcq-option,
.emotionPickBtn,
.calm-tool,
.btn {
  min-height: 48px;
  cursor: pointer;
}

/* Safe area insets for notched phones (iPhone X+) */
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}


/* ────────────────────────────────────────────
   2. TABLET LANDSCAPE & SMALL LAPTOPS (≤1024px)
   ──────────────────────────────────────────── */

@media (max-width: 1024px) {

  /* --- PAGE 5: Story Display --- */
  #panel {
    width: min(80vw, 680px) !important;
    margin: 6vh 0 0 3vw !important;
  }

  #storyContainer {
    width: min(78vw, 700px) !important;
    font-size: 1.1rem !important;
  }

  /* Questions panel: give it more room */
  #questionsPanel {
    width: min(400px, 38vw) !important;
  }

  /* Loading caption — slightly smaller */
  #pebbleCaption {
    font-size: 3.5rem !important;
  }

  /* --- PAGE 4: Voice Q&A --- */
  .big-mic-btn {
    width: 140px !important;
    height: 140px !important;
  }
  .big-mic-btn .mic-emoji {
    font-size: 48px !important;
  }
  .pulse-ring.ring-1 { width: 140px !important; height: 140px !important; }
  .pulse-ring.ring-2 { width: 175px !important; height: 175px !important; }
  .pulse-ring.ring-3 { width: 210px !important; height: 210px !important; }
}


/* ────────────────────────────────────────────
   3. TABLET PORTRAIT / iPads (≤768px)
   ──────────────────────────────────────────── */

@media (max-width: 768px) {

  /* --- PAGE 5: Story Display --- */
  #panel {
    width: 96vw !important;
    margin: 3vh auto 16px !important;
    align-items: center !important;
    padding: 0 2vw !important;
  }

  #storyContainer {
    width: calc(100vw - 24px) !important;
    max-width: none !important;
    margin: 16px 12px 16px !important;
    padding: 18px 16px !important;
    font-size: 1.15rem !important;
    line-height: 1.8 !important;
    max-height: 60vh !important;
  }

  /* Buttons row: wrap and center */
  #buttons {
    justify-content: center !important;
    gap: 10px !important;
    margin-left: 0 !important;
    padding: 0 8px !important;
    flex-wrap: wrap !important;
  }

  .action-button {
    padding: 14px 20px !important;
    font-size: 1.05rem !important;
    min-height: 52px !important;
    border-radius: 12px !important;
  }

  /* Loading overlay */
  #pebbleCaption {
    font-size: 2.5rem !important;
    padding: 8px 12px !important;
  }

  /* Questions panel: center overlay on tablet */
  #questionsPanel {
    position: fixed !important;
    right: auto !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    width: 88vw !important;
    max-height: 80vh !important;
  }

  /* Badge shelf: center on bottom */
  #badgeShelf {
    right: auto !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    justify-content: center !important;
    max-width: 90vw !important;
    flex-wrap: wrap !important;
  }

  #badgeToast {
    right: auto !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
  }

  /* Emotion overlay — make emoji buttons bigger for kids on tablets */
  .emotionPickBtn {
    font-size: 2.8rem !important;
    padding: 14px 18px !important;
    min-width: 64px !important;
    min-height: 64px !important;
  }

  /* Heart frame overlay */
  #heartFrameOverlay > div {
    width: min(600px, 94vw) !important;
    padding: 18px 16px !important;
  }

  /* Social emotion overlay */
  #socialEmotionOverlay > div {
    width: min(480px, 94vw) !important;
  }

  /* --- PAGE 4: Voice Q&A --- */
  /* Stack controls vertically instead of split left/right */
  #bottomControls {
    left: 12px !important;
    right: 12px !important;
    bottom: 12px !important;
    align-items: center !important;
  }

  #sideControls {
    position: fixed !important;
    right: auto !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    bottom: auto !important;
    top: 50% !important;
  }

  #currentQuestionDisplay {
    font-size: 1.3em !important;
    padding: 10px 16px !important;
    max-width: calc(100vw - 32px) !important;
  }

  #answerInputContainer {
    width: 92% !important;
    max-width: none !important;
  }

  #answerInput {
    font-size: 1.15em !important;
    min-height: 70px !important;
  }

  /* Mic button: smaller on tablet portrait */
  .big-mic-btn {
    width: 130px !important;
    height: 130px !important;
  }
  .big-mic-btn .mic-emoji {
    font-size: 44px !important;
  }
  .big-mic-btn .mic-label {
    font-size: 14px !important;
  }

  .pulse-ring.ring-1 { width: 130px !important; height: 130px !important; }
  .pulse-ring.ring-2 { width: 165px !important; height: 165px !important; }
  .pulse-ring.ring-3 { width: 195px !important; height: 195px !important; }

  /* Plane flyby: smaller on tablets */
  #flyingPlane {
    width: 80px !important;
  }

  /* --- INDEX / INTRO --- */
  .mainBtn {
    padding: 16px 36px !important;
    font-size: 1.3rem !important;
    min-width: 160px !important;
    min-height: 56px !important;
  }

  .btnRow {
    gap: 12px !important;
  }

  /* Instructions panel */
  #instructionsPanel {
    padding: 22px 20px !important;
    max-height: 85vh !important;
  }

  #instructionsPanel h1 {
    font-size: 1.5rem !important;
  }

  /* --- TEACHER DASHBOARD --- */
  .topbar {
    padding: 12px 16px !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  .topbar-nav {
    gap: 6px !important;
    flex-wrap: wrap !important;
  }

  .topbar-nav button {
    padding: 8px 12px !important;
    font-size: 0.8rem !important;
  }

  .container {
    padding: 20px 14px 50px !important;
  }

  .form-row {
    flex-direction: column !important;
  }

  .card-row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
  }

  .card-meta {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  /* --- TEACHER CONTROLS --- */
  .option-group {
    gap: 8px !important;
  }

  .option-button {
    padding: 12px 18px !important;
    min-height: 48px !important;
  }
}


/* ────────────────────────────────────────────
   4. PHONES (≤480px)
   ──────────────────────────────────────────── */

@media (max-width: 480px) {

  /* --- PAGE 5: Story Display --- */
  #panel {
    width: 100vw !important;
    margin: 2vh 0 12px !important;
    padding: 0 !important;
  }

  #storyContainer {
    width: calc(100vw - 16px) !important;
    margin: 10px 8px 12px !important;
    padding: 14px 12px !important;
    font-size: 1.05rem !important;
    line-height: 1.75 !important;
    max-height: 50vh !important;
    border-radius: 14px !important;
  }

  /* Buttons: full width stack on phones */
  #buttons {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 0 12px !important;
    margin-left: 0 !important;
  }

  .action-button {
    width: 100% !important;
    padding: 16px 18px !important;
    font-size: 1.1rem !important;
    font-weight: 700 !important;
    min-height: 56px !important;
    text-align: center !important;
    border-radius: 14px !important;
  }

  /* Loading overlay on phones */
  #pebbleCaption {
    font-size: 1.75rem !important;
    padding: 6px 10px !important;
    border-radius: 10px !important;
    line-height: 1.2 !important;
  }

  #pebbleRow {
    gap: 8px !important;
  }

  .pebble {
    width: 10px !important;
    height: 10px !important;
  }

  /* Questions panel: full width on phones */
  #questionsPanel {
    width: 96vw !important;
    max-height: 85vh !important;
    padding: 16px !important;
    border-radius: 14px !important;
  }

  /* MCQ options: bigger touch targets */
  .mcq-option {
    padding: 16px !important;
    font-size: 1.05rem !important;
    min-height: 52px !important;
    border-radius: 14px !important;
  }

  /* Answer input row in questions */
  .answer-input-row {
    flex-direction: column !important;
    gap: 8px !important;
  }

  .mic-btn {
    width: 52px !important;
    height: 52px !important;
    font-size: 1.5rem !important;
    align-self: flex-end !important;
  }

  /* Badge shelf: horizontal scroll on phones */
  #badgeShelf {
    bottom: 6px !important;
    gap: 6px !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    padding: 0 8px !important;
  }

  .badge-pill {
    font-size: 0.7rem !important;
    padding: 3px 8px !important;
  }

  #badgeToast {
    bottom: 50px !important;
    font-size: 0.85rem !important;
  }

  /* Emotion buttons: bigger on phones for tiny fingers */
  .emotionPickBtn {
    font-size: 2.5rem !important;
    padding: 12px 14px !important;
    min-width: 58px !important;
    min-height: 58px !important;
    border-radius: 16px !important;
  }

  /* Calm tools: full-width buttons */
  .calm-tool {
    font-size: 1.1rem !important;
    padding: 16px !important;
    min-height: 56px !important;
  }

  /* Heart frame: fit phone screens */
  #heartFrameOverlay > div {
    width: 96vw !important;
    padding: 16px 14px !important;
    border-radius: 16px !important;
  }

  #heartFrameOverlay > div > div:nth-child(2) {
    font-size: 22px !important;
  }

  /* Video overlay: full-width on phone */
  #videoOverlay > div {
    width: 98% !important;
    border-radius: 14px !important;
  }

  /* Preview overlay */
  #previewOverlay > div {
    width: 96vw !important;
    padding: 18px 16px !important;
  }

  /* Practice overlay */
  #practiceOverlay > div {
    width: 96vw !important;
    padding: 18px 16px !important;
  }

  /* --- PAGE 4: Voice Q&A on Phones --- */

  /* Reorganize layout: question at top, mic in center */
  #bottomControls {
    position: fixed !important;
    bottom: auto !important;
    top: 12px !important;
    left: 8px !important;
    right: 8px !important;
    z-index: 10 !important;
  }

  #currentQuestionDisplay {
    font-size: 1.15em !important;
    padding: 10px 14px !important;
    border-radius: 10px !important;
    max-width: 100% !important;
  }

  /* Center the mic button */
  #sideControls {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) !important;
    z-index: 10 !important;
  }

  .big-mic-btn {
    width: 120px !important;
    height: 120px !important;
  }
  .big-mic-btn .mic-emoji {
    font-size: 40px !important;
  }
  .big-mic-btn .mic-label {
    font-size: 13px !important;
  }

  .pulse-ring.ring-1 { width: 120px !important; height: 120px !important; }
  .pulse-ring.ring-2 { width: 150px !important; height: 150px !important; }
  .pulse-ring.ring-3 { width: 180px !important; height: 180px !important; }

  /* Answer input: full-width on phones */
  #answerInputContainer {
    width: 100% !important;
  }

  #answerInput {
    font-size: 1.1em !important;
    padding: 12px !important;
    min-height: 60px !important;
  }

  /* Waiting overlay */
  .waiting-title {
    font-size: 1.3rem !important;
  }
  .waiting-sub {
    font-size: 0.95rem !important;
  }

  /* Pete the Pilot: smaller on phones */
  #peteThePilot {
    width: 80px !important;
    bottom: 30px !important;
    right: 10px !important;
  }

  #peteThePilotSpeechBubble {
    max-width: 180px !important;
    right: 10px !important;
    bottom: 120px !important;
    font-size: 0.95em !important;
  }

  /* Plane flyby: smaller on phones */
  #flyingPlane {
    width: 60px !important;
    top: 10% !important;
  }

  /* --- INDEX / INTRO on Phones --- */
  .mainBtn {
    padding: 16px 28px !important;
    font-size: 1.2rem !important;
    min-width: 140px !important;
    min-height: 54px !important;
  }

  .btnRow {
    flex-direction: column !important;
    align-items: center !important;
    gap: 10px !important;
    width: 80% !important;
  }

  .btnRow .mainBtn {
    width: 100% !important;
  }

  /* Start overlay padding for notched phones */
  #startOverlay {
    padding-bottom: calc(40px + env(safe-area-inset-bottom)) !important;
  }

  /* Instructions panel: full-height on phones */
  #instructionsPanel {
    padding: 18px 16px !important;
    border-radius: 16px !important;
    max-height: 92vh !important;
  }

  #instructionsPanel h1 {
    font-size: 1.35rem !important;
  }

  .section-title {
    font-size: 1.1rem !important;
  }

  #instructionsPanel p {
    font-size: 0.95rem !important;
  }

  #closeInstructionsBtn {
    padding: 14px 32px !important;
    min-height: 52px !important;
  }

  /* Teacher login link */
  #teacherLoginLink {
    padding: 6px 12px !important;
    font-size: 0.8rem !important;
    top: 10px !important;
    right: 10px !important;
  }

  /* --- TEACHER DASHBOARD on Phones --- */
  .topbar {
    padding: 10px 12px !important;
  }

  .topbar-brand .logo {
    font-size: 1.2rem !important;
  }

  .topbar-nav {
    width: 100% !important;
    justify-content: flex-start !important;
    overflow-x: auto !important;
  }

  .topbar-nav button {
    white-space: nowrap !important;
    padding: 8px 10px !important;
    font-size: 0.75rem !important;
    min-height: 40px !important;
  }

  .section-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .section-header h2 {
    font-size: 1.35rem !important;
  }

  .card {
    padding: 16px !important;
  }

  .btn {
    padding: 12px 18px !important;
    font-size: 0.9rem !important;
    min-height: 48px !important;
  }

  /* --- TEACHER CONTROLS on Phones --- */
  .container {
    padding: 20px 12px 40px !important;
    margin: 16px auto !important;
  }
}


/* ────────────────────────────────────────────
   5. VERY SMALL PHONES (≤360px, e.g. iPhone SE)
   ──────────────────────────────────────────── */

@media (max-width: 360px) {

  #storyContainer {
    font-size: 1rem !important;
    padding: 12px 10px !important;
  }

  #pebbleCaption {
    font-size: 1.4rem !important;
  }

  .action-button {
    font-size: 1rem !important;
    padding: 14px 14px !important;
  }

  .big-mic-btn {
    width: 100px !important;
    height: 100px !important;
  }
  .big-mic-btn .mic-emoji {
    font-size: 34px !important;
  }

  .mainBtn {
    padding: 14px 22px !important;
    font-size: 1.1rem !important;
  }

  .emotionPickBtn {
    font-size: 2rem !important;
    padding: 10px !important;
    min-width: 48px !important;
    min-height: 48px !important;
  }

  #currentQuestionDisplay {
    font-size: 1em !important;
  }
}


/* ────────────────────────────────────────────
   6. LANDSCAPE PHONES (short + wide)
   ──────────────────────────────────────────── */

@media (max-height: 500px) and (orientation: landscape) {

  /* Story container: use most of the width, less height */
  #storyContainer {
    max-height: 65vh !important;
    margin-top: 8px !important;
  }

  /* Buttons: horizontal row, smaller */
  #buttons {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .action-button {
    padding: 10px 16px !important;
    font-size: 0.9rem !important;
    min-height: 42px !important;
    width: auto !important;
  }

  /* Loading */
  #pebbleCaption {
    font-size: 1.5rem !important;
  }

  /* Page 4: side-by-side layout */
  #bottomControls {
    position: fixed !important;
    bottom: 8px !important;
    top: auto !important;
    left: 8px !important;
    right: 50% !important;
  }

  #sideControls {
    position: fixed !important;
    right: 20px !important;
    left: auto !important;
    top: 50% !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
  }

  .big-mic-btn {
    width: 90px !important;
    height: 90px !important;
  }
  .big-mic-btn .mic-emoji {
    font-size: 30px !important;
  }
  .big-mic-btn .mic-label {
    font-size: 11px !important;
  }

  .pulse-ring.ring-1 { width: 90px !important; height: 90px !important; }
  .pulse-ring.ring-2 { width: 110px !important; height: 110px !important; }
  .pulse-ring.ring-3 { width: 130px !important; height: 130px !important; }

  /* Overlays: shorter */
  #questionsPanel {
    max-height: 90vh !important;
  }

  #instructionsPanel {
    max-height: 95vh !important;
  }
}


/* ────────────────────────────────────────────
   7. iPAD-SPECIFIC REFINEMENTS
   ──────────────────────────────────────────── */

/* iPad Mini / iPad (portrait): 768×1024 */
@media (min-width: 700px) and (max-width: 820px) and (orientation: portrait) {

  #storyContainer {
    font-size: 1.2rem !important;
    line-height: 1.85 !important;
    max-height: 55vh !important;
  }

  .action-button {
    padding: 16px 24px !important;
    font-size: 1.15rem !important;
  }

  .emotionPickBtn {
    font-size: 3rem !important;
    padding: 16px 20px !important;
  }

  .big-mic-btn {
    width: 150px !important;
    height: 150px !important;
  }
  .big-mic-btn .mic-emoji {
    font-size: 52px !important;
  }
}

/* iPad Pro (portrait): ~1024×1366 */
@media (min-width: 980px) and (max-width: 1100px) and (orientation: portrait) {

  #panel {
    width: min(70vw, 680px) !important;
  }

  #storyContainer {
    width: min(68vw, 700px) !important;
    font-size: 1.2rem !important;
  }
}


/* ────────────────────────────────────────────
   8. ACCESSIBILITY: REDUCED MOTION
   ──────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  #flyingPlane {
    display: none !important;
  }
}


/* ────────────────────────────────────────────
   9. PRINT (for teacher print use case)
   ──────────────────────────────────────────── */

@media print {
  body {
    background: white !important;
    color: black !important;
  }

  #buttons,
  #badgeShelf,
  #badgeToast,
  #loadingOverlay,
  #flyingPlane,
  #teacherLoginLink,
  .topbar-nav,
  #beachAmbienceLayer {
    display: none !important;
  }

  #panel,
  #storyContainer {
    visibility: visible !important;
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    border: none !important;
    backdrop-filter: none !important;
    margin: 0 !important;
    padding: 20px !important;
  }

  /* Keep yellow highlighting visible in print */
  .answer-hl,
  .answer-yellow,
  .story-word.highlighted-word {
    background: #ffd54f !important;
    color: black !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
