/* Friendly TOEIC — mobile / PWA UI optimizations */

/* Prevent iOS zoom on input focus */
@media (max-width: 767px) {
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Comfortable tap targets */
  button,
  [role="button"],
  a.rounded-xl,
  a.rounded-lg,
  .vocab-start-cta-btn {
    touch-action: manipulation;
  }

  /* Extra bottom space for thumb + home indicator */
  main .flex-1.p-3 {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
  }

  body.mobile-nav-visible main .flex-1.p-3 {
    padding-bottom: calc(6.25rem + env(safe-area-inset-bottom, 0px));
  }

  body.mobile-lesson-active main .flex-1.p-3 {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
  }

  /* Hide duplicate in-scroll lesson footer when fixed bar shows */
  body.mobile-lesson-active #toeicLessonFlow .lesson-stage-footer {
    display: none;
  }

  /* Progress pills: horizontal scroll on phone */
  #toeicLessonFlow [data-progress-step] {
    scroll-snap-align: start;
  }

  #toeicLessonFlow .flex.flex-wrap.gap-2:has([data-progress-step]) {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
  }

  /* Grammar tables scroll horizontally */
  .lesson-prose table,
  #toeicLessonFlow table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Modals: use full width on small screens */
  .fixed.inset-0.flex.items-center.justify-center > div {
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 1rem);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Lesson prose: slightly tighter on phone */
  .lesson-prose {
    font-size: 0.9375rem;
    line-height: 1.6;
  }

  .lesson-prose h2,
  .lesson-prose h3 {
    font-size: 1.05rem;
  }

  /* Mini test overlay safe areas */
  #miniTestExamOverlay.mt-open {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* Billing / QR: stack cleanly */
  .bill-qr-wrap img {
    max-width: min(280px, 88vw);
    height: auto;
  }
}

/* Standalone PWA (Add to Home Screen) */
@media (display-mode: standalone) {
  #mobileHeaderStack {
    padding-top: env(safe-area-inset-top, 0px);
  }

  body {
    user-select: none;
    -webkit-user-select: none;
  }

  .lesson-prose,
  #story-content,
  input,
  textarea {
    user-select: text;
    -webkit-user-select: text;
  }
}

/* PWA install banner */
.pwa-install-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  padding: 0.75rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}

.pwa-install-banner.hidden {
  display: none;
}

.pwa-install-banner__inner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 28rem;
  margin: 0 auto;
  padding: 0.875rem 1rem;
  background: linear-gradient(135deg, #312e81 0%, #4338ca 100%);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  color: #fff;
}

.pwa-install-banner__icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.pwa-install-banner__text {
  flex: 1;
  min-width: 0;
}

.pwa-install-banner__title {
  font-size: 0.875rem;
  font-weight: 800;
  line-height: 1.2;
}

.pwa-install-banner__desc {
  font-size: 0.6875rem;
  opacity: 0.85;
  margin-top: 0.125rem;
  line-height: 1.3;
}

.pwa-install-banner__cta {
  flex-shrink: 0;
  background: #fff;
  color: #4338ca;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.5rem 0.875rem;
  border-radius: 0.625rem;
  min-height: 44px;
}

.pwa-install-banner__close {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  margin: -0.25rem -0.5rem -0.25rem 0;
}

.pwa-install-banner__close:hover {
  opacity: 1;
}

@media (min-width: 768px) {
  .pwa-install-banner {
    display: none !important;
  }

  #mobileBottomNav,
  #mobileLessonBar {
    display: none !important;
  }
}

/* ── Bottom navigation (mobile) ── */
.mobile-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: 0.25rem;
  padding: 0.35rem 0.5rem;
  padding-bottom: calc(0.35rem + env(safe-area-inset-bottom, 0px));
  background: rgba(15, 23, 42, 0.96);
  border-top: 1px solid rgba(99, 102, 241, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.mobile-bottom-nav.hidden {
  display: none;
}

.mobile-bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  min-height: 52px;
  padding: 0.35rem 0.25rem;
  border-radius: 0.75rem;
  color: #94a3b8;
  font-size: 0.625rem;
  font-weight: 700;
  transition: color 0.15s, background 0.15s;
}

.mobile-bottom-nav__item i {
  font-size: 1.125rem;
}

.mobile-bottom-nav__item--active {
  color: #c7d2fe;
  background: rgba(79, 70, 229, 0.22);
}

.mobile-bottom-nav__item--active i {
  color: #a5b4fc;
}

/* ── Fixed lesson action bar ── */
.mobile-lesson-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 95;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.98);
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -4px 24px rgba(15, 23, 42, 0.08);
}

.mobile-lesson-bar.hidden {
  display: none;
}

.mobile-lesson-bar__center {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.mobile-lesson-bar__step {
  font-size: 0.6875rem;
  font-weight: 800;
  color: #4338ca;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-lesson-bar__day {
  font-size: 0.625rem;
  font-weight: 600;
  color: #64748b;
  margin-top: 0.125rem;
}

.mobile-lesson-bar__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-width: 4.5rem;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
}

.mobile-lesson-bar__btn--ghost {
  background: #f1f5f9;
  color: #475569;
}

.mobile-lesson-bar__btn--primary {
  background: #4f46e5;
  color: #fff;
}

.mobile-lesson-bar__btn--disabled,
.mobile-lesson-bar__btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* PWA install banner sits above bottom nav */
body.mobile-nav-visible .pwa-install-banner {
  bottom: calc(3.75rem + env(safe-area-inset-bottom, 0px));
}

/* iOS Add to Home Screen guide modal */
.pwa-ios-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.pwa-ios-modal.hidden {
  display: none;
}

.pwa-ios-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.72);
}

.pwa-ios-modal__sheet {
  position: relative;
  width: 100%;
  max-width: 26rem;
  margin: 0 0.75rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  padding: 1.25rem 1.25rem 1rem;
  background: #fff;
  color: #0f172a;
  border-radius: 1.25rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
}

.pwa-ios-modal__close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  border-radius: 999px;
}

.pwa-ios-modal__icon {
  width: 3rem;
  height: 3rem;
  margin: 0 auto 0.75rem;
  border-radius: 0.875rem;
  background: linear-gradient(135deg, #312e81, #4338ca);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.pwa-ios-modal__title {
  text-align: center;
  font-size: 1.125rem;
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 0.5rem;
}

.pwa-ios-modal__lead {
  text-align: center;
  font-size: 0.8125rem;
  color: #475569;
  line-height: 1.45;
  margin-bottom: 1rem;
}

.pwa-ios-modal__steps {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: grid;
  gap: 0.625rem;
}

.pwa-ios-modal__steps li {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: #1e293b;
}

.pwa-ios-modal__steps li span {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pwa-ios-modal__steps li i {
  color: #4338ca;
}

.pwa-ios-modal__note {
  font-size: 0.75rem;
  color: #64748b;
  text-align: center;
  line-height: 1.4;
  margin-bottom: 0.875rem;
}

.pwa-ios-modal__done {
  width: 100%;
  min-height: 48px;
  border-radius: 0.75rem;
  background: #4338ca;
  color: #fff;
  font-size: 0.9375rem;
  font-weight: 800;
}
