/* =====================================================================
   English Academy — app shell (loaded last). Installed-app behaviour and
   mobile-first fixes for every page: bottom navigation, safe areas (notch,
   home indicator), touch targets, no horizontal scrolling, smooth page
   transitions, install banner, update bar, offline state, Install App guide.
   ===================================================================== */

/* ---- Never scroll sideways; media always fits */
html, body { max-width: 100%; overflow-x: clip; }
body { -webkit-tap-highlight-color: transparent; text-size-adjust: 100%; -webkit-text-size-adjust: 100%; }
img, video, canvas, svg:not(.bi), iframe { max-width: 100%; }
img, video { height: auto; }
audio { width: 100%; max-width: 100%; }
iframe { border: 0; }
.content { min-width: 0; overflow-wrap: anywhere; }
.content table:not(.table-borderless) { max-width: 100%; }
.content .table-responsive, .content pre, .code-box { -webkit-overflow-scrolling: touch; }
.row > * { min-width: 0; }
.card, .list-group-item, .dropdown-menu { min-width: 0; }
input, select, textarea { font-size: 16px; }            /* stops iOS zooming into form fields */
@media (min-width: 768px) { input, select, textarea { font-size: inherit; } .form-control-lg, .form-select-lg { font-size: 1.25rem; } }

/* ---- Smooth page transitions (browsers that support cross-document view transitions) */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .18s; }
@media (prefers-reduced-motion: no-preference) {
  .content > * { animation: shell-in .28s cubic-bezier(.22, .8, .22, 1) both; }
  @keyframes shell-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
@media (prefers-reduced-motion: reduce) { @view-transition { navigation: none; } }

/* ---- Touch screens: comfortable targets (44px, Apple / Google guidance) */
@media (pointer: coarse) {
  .btn:not(.btn-close):not(.btn-link), .form-select, .form-control:not(textarea), .nav-link, .dropdown-item, .page-link, .type-chip, .skill-pill, .ladder-step, .seg a, .view-switch a { min-height: 44px; }
  .btn-sm:not(.btn-link) { min-height: 38px; }
  .btn-icon, .btn-icon-soft { min-width: 44px; min-height: 44px; }
  .form-check-input { width: 1.3em; height: 1.3em; }
  .exercise-option, .list-group-item-action { min-height: 48px; }
  .seg a, .type-chip, .ladder-step { display: inline-flex; align-items: center; }
}

/* ---- Installed app: safe areas (notch, rounded corners, home indicator) */
.topbar { padding-top: max(.65rem, env(safe-area-inset-top)); padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); position: sticky; top: 0; z-index: 1020; }
.sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
.is-standalone .topbar { -webkit-user-select: none; user-select: none; }
.is-standalone body { overscroll-behavior-y: contain; }

/* ---- Bottom navigation (phones & tablets) */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; display: grid; grid-template-columns: repeat(5, 1fr);
  padding: .3rem max(.4rem, env(safe-area-inset-left)) calc(.3rem + env(safe-area-inset-bottom)) max(.4rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--ea-surface, #fff) 88%, transparent); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
  border-top: 1px solid var(--ea-line, #e6e8ef); }
.bn-item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .1rem; min-height: 52px; border: 0; background: none; border-radius: 12px;
  color: var(--bs-secondary-color); font-size: .68rem; font-weight: 600; text-decoration: none; transition: color .15s ease, background-color .15s ease; }
.bn-item i { font-size: 1.3rem; line-height: 1; }
.bn-item.active { color: var(--ea-accent, #2f7cf6); }
.bn-item:active { background: rgba(var(--ea-accent-rgb, 47, 124, 246), .08); }
.bn-dot { position: absolute; top: 8px; right: calc(50% - 16px); width: 8px; height: 8px; border-radius: 50%; background: #e5484d; box-shadow: 0 0 0 2px var(--ea-surface, #fff); }
@media (max-width: 991.98px) {
  .has-bottom-nav .main-wrap { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .has-bottom-nav .install-banner, .has-bottom-nav .update-bar { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .has-bottom-nav .toast-container, .has-bottom-nav [data-toasts] { bottom: calc(76px + env(safe-area-inset-bottom)) !important; }
}
@media (min-width: 992px) { .bottom-nav { display: none !important; } }

/* ---- Top bar on small screens */
@media (max-width: 575.98px) {
  .topbar { gap: .25rem; }
  .topbar-title { font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
  .topbar .btn-user .avatar, .topbar .btn-user img { width: 30px; height: 30px; }
  .page-head { gap: .5rem; } .page-actions { margin-left: 0; width: 100%; }
  .card-body { padding: 1rem; }
  .soft-hero, .lib-hero { padding: 1.15rem !important; }
  .report { padding: 1rem; }
  .rep-head { gap: .75rem; }
}
.btn-save-offline { position: relative; }
.btn-save-offline.on { color: var(--c-mint, #2fa77e); }
.btn-save-offline .visually-hidden-mobile { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Install banner & update bar */
.install-banner { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 1040; display: flex; align-items: center; gap: .75rem;
  width: min(560px, calc(100% - 1.5rem)); padding: .75rem .85rem; border-radius: 18px; background: var(--ea-surface, #fff); border: 1px solid var(--ea-line, #e6e8ef);
  box-shadow: 0 18px 50px -18px rgba(20, 40, 100, .45); transform: translate(-50%, 140%); transition: transform .35s cubic-bezier(.22, .8, .22, 1); }
.install-banner.show { transform: translate(-50%, 0); }
.install-banner img { border-radius: 12px; flex-shrink: 0; }
.install-banner > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.install-banner strong { font-size: .92rem; color: var(--bs-emphasis-color); } .install-banner span { font-size: .78rem; color: var(--bs-secondary-color); }
.update-bar { position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 1045; display: flex; align-items: center; gap: .6rem;
  padding: .55rem .6rem .55rem 1rem; border-radius: 99px; background: #14161c; color: #fff; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .5); font-size: .88rem; max-width: calc(100% - 1.5rem); }
.update-bar .btn { border-radius: 99px; }

/* ---- Offline state */
.is-offline .topbar::after { content: "Offline"; position: absolute; left: 50%; bottom: -11px; transform: translateX(-50%); font-size: .66rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; padding: .1rem .55rem; border-radius: 99px; background: #e5a43a; color: #fff; }
.is-offline [data-requires-online] { opacity: .5; pointer-events: none; }

/* =====================================================================
   Install App page
   ===================================================================== */
.install-page { max-width: 1100px; margin: 0 auto; }
.install-hero { align-items: flex-start; }
.ih-icon { width: 88px; height: 88px; border-radius: 22px; box-shadow: 0 14px 30px -12px rgba(47, 124, 246, .55); flex-shrink: 0; }
.ih-status { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; margin-top: 1rem; }
.ih-detected { display: inline-flex; align-items: center; gap: .45rem; font-size: .88rem; padding: .45rem .8rem; border-radius: 12px; background: var(--ea-surface, #fff); border: 1px solid var(--ea-line, #e6e8ef); }
.ih-detected i { color: var(--ea-accent, #2f7cf6); }
.ih-done { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; color: var(--c-mint, #2fa77e); }
.install-tabs { display: flex; flex-wrap: wrap; width: fit-content; max-width: 100%; }
.install-tabs a { display: inline-flex; align-items: center; gap: .4rem; }
.guide { padding: 1.25rem; border-radius: 22px; background: var(--ea-surface, #fff); border: 1px solid var(--ea-line, #e6e8ef); box-shadow: var(--ea-shadow-sm); }
.guide-head { display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; }
.guide-steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .9rem; counter-reset: s; }
@media (max-width: 991.98px) { .guide-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 575.98px) { .guide-steps { grid-template-columns: 1fr; } .gs { display: grid; grid-template-columns: 96px 1fr; gap: .8rem; align-items: center; } .gs-mock { margin: 0 !important; } }
.gs-text { display: flex; gap: .55rem; align-items: flex-start; }
.gs-num { width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center; background: var(--ea-accent, #2f7cf6); color: #fff; font-size: .78rem; font-weight: 700; }
.gs-p p { margin: 0; font-size: .9rem; }
.guide-note { display: flex; gap: .5rem; margin-top: 1rem; font-size: .85rem; color: var(--bs-secondary-color); padding: .7rem .85rem; border-radius: 12px; background: var(--ea-muted-surface, #f1f3f8); }
.guide-note p { margin: 0; }
/* step illustrations: a tiny phone (or browser window) with the control to tap */
.gs-mock { margin: 0 auto .8rem; width: 100%; max-width: 150px; aspect-ratio: 9 / 15; border-radius: 22px; padding: 6px; background: #1d2230; box-shadow: 0 10px 24px -14px rgba(0, 0, 0, .55); }
.gs-mock.os-windows, .gs-mock.os-mac { aspect-ratio: 16 / 11; max-width: 200px; border-radius: 12px; padding: 4px; background: #c9cdd8; }
.gm-screen { position: relative; height: 100%; border-radius: 17px; overflow: hidden; background: linear-gradient(160deg, #eef4ff, #f2efff); display: flex; flex-direction: column; }
.os-windows .gm-screen, .os-mac .gm-screen { border-radius: 9px; }
.gm-bar { height: 22px; background: #fff; display: flex; align-items: center; padding: 0 6px; border-bottom: 1px solid #e3e6ee; }
.gm-bar span { flex: 1; height: 10px; border-radius: 6px; background: #eef0f5; }
.gm-body { flex: 1; position: relative; display: grid; place-items: center; }
.gm-app img { width: 38px; height: 38px; border-radius: 10px; opacity: .25; }
.gm-pointer { position: absolute; font-size: 1.35rem; color: #2f7cf6; background: #fff; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  box-shadow: 0 6px 16px -6px rgba(47, 124, 246, .7); animation: gm-tap 1.8s ease-in-out infinite; }
@keyframes gm-tap { 0%, 100% { transform: scale(1); box-shadow: 0 6px 16px -6px rgba(47, 124, 246, .7), 0 0 0 0 rgba(47, 124, 246, .35); } 50% { transform: scale(1.08); box-shadow: 0 6px 16px -6px rgba(47, 124, 246, .7), 0 0 0 10px rgba(47, 124, 246, 0); } }
.gs-menu-android .gm-pointer { top: -8px; right: 6px; }
.gs-menu-android .gm-bar { padding-right: 34px; }
.gs-share .gm-pointer { bottom: 10px; left: calc(50% - 20px); }
.os-iphone.gs-share .gm-body::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 30px; background: #fff; border-top: 1px solid #e3e6ee; z-index: 0; }
.gs-add .gm-body::before { content: "Add to Home Screen"; position: absolute; left: 8px; right: 8px; top: 30%; padding: 6px 8px; font-size: .62rem; font-weight: 600; background: #fff; border-radius: 8px; color: #14161c; }
.gs-add .gm-pointer { top: calc(30% - 8px); right: 4px; width: 34px; height: 34px; font-size: 1.1rem; }
.gs-desktop-install .gm-pointer { top: -6px; right: 8px; width: 34px; height: 34px; font-size: 1.05rem; }
.gs-confirm .gm-body::before { content: "Install app?"; position: absolute; left: 12%; right: 12%; top: 30%; padding: 10px 8px 30px; font-size: .62rem; font-weight: 700; text-align: center; background: #fff; border-radius: 10px; box-shadow: 0 8px 20px -10px rgba(0, 0, 0, .4); color: #14161c; }
.gs-confirm .gm-pointer { top: calc(30% + 22px); width: 30px; height: 30px; font-size: 1rem; }
.gs-home .gm-app img, .gs-window .gm-app img { opacity: 1; width: 46px; height: 46px; box-shadow: 0 8px 18px -8px rgba(47, 124, 246, .7); }
.gs-home .gm-bar, .gs-window .gm-bar { visibility: hidden; }
.gs-home .gm-pointer, .gs-window .gm-pointer { right: 10px; bottom: 10px; width: 30px; height: 30px; font-size: 1rem; }
.gs-browser .gm-pointer { top: 50%; }
.offline-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }
.offline-list li { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .45rem .7rem; border-radius: 10px; background: var(--ea-muted-surface, #f1f3f8); }
.offline-list a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Minimal / auth layouts on phones */
@media (max-width: 575.98px) { .auth-shell main.container { padding-left: 1rem; padding-right: 1rem; } }
