/*
 * まなび動画ナビ Future UI v240 — responsive layer
 * Existing navigation, modal, table, player, and canvas owners remain unchanged.
 */

body.mnv-future-ui {
  --mnv-content-inline: clamp(16px, 3.4vw, 48px);
  --mnv-content-max: 1540px;
}

body.mnv-future-ui :where(.container, .admin-container, .shell-container) {
  max-width: var(--mnv-content-max);
}

body.mnv-future-ui :where(img, svg, video) {
  max-width: 100%;
}

body.mnv-future-ui :where(.table-scroll, .org-table-wrap, .comparison-table-wrap) {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

body.mnv-future-ui :where(.video-frame, .video-shell, .player-wrap, .youtube-wrap) {
  max-width: 100%;
  aspect-ratio: 16 / 9;
}

body.mnv-future-ui :where(.video-frame, .video-shell, .player-wrap, .youtube-wrap) :where(iframe, video) {
  width: 100%;
  height: 100%;
}

body.mnv-future-ui :where(dialog, .guide-panel, .qr-login-modal, .mf-command-palette, .mf-detail-drawer, .luxury-command-panel) {
  overflow: auto;
  overscroll-behavior: contain;
}

body.mnv-future-ui :where(.mobile-tabbar, .future-study-dock, .pwa-nudge) {
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}

body.mnv-future-ui.has-mobile-tabbar {
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

@media (min-width: 1801px) {
  body.mnv-future-ui :where(.container, .admin-container, .shell-container) {
    width: min(calc(100% - 64px), var(--mnv-content-max));
  }

  body.mnv-future-ui :where(.dash-layout, .admin-shell, .org-shell) {
    column-gap: clamp(24px, 2.2vw, 40px);
  }

  body.mnv-future-ui :where(.admin-sidebar, .org-sidebar, .dash-nav) {
    border-radius: var(--mnv-radius-lg);
  }
}

/* Laptops and 125–150% browser zoom: retain useful side rails without overlap. */
@media (min-width: 981px) and (max-width: 1800px) {
  body.mnv-future-ui :where(.container, .admin-container, .shell-container) {
    width: min(calc(100% - 36px), var(--mnv-content-max));
  }

  body.mnv-future-ui :where(.admin-shell, .org-shell, .dash-layout) {
    min-width: 0;
  }

  body.mnv-future-ui :where(.admin-main, .org-main, .dash-main) {
    min-width: 0;
  }

  body.mnv-future-ui :where(.grid-3, .admin-cols-3, .org-grid-3, .kpi-row, .org-kpis) {
    grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  }
}

/* Portrait tablets and narrow laptop windows. Existing accessible drawers remain owners. */
@media (max-width: 1180px) {
  body.mnv-future-ui :where(.container, .admin-container, .shell-container) {
    width: min(calc(100% - 28px), var(--mnv-content-max));
  }

  body.mnv-future-ui :where(.grid-3, .admin-cols-3, .org-grid-3, .kpi-row, .org-kpis) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.mnv-future-ui :where(.admin-page-head, .org-page-head, .section-heading, .result-head) {
    gap: var(--mnv-space-md);
  }

  body.mnv-future-ui :where(.inline-actions, .hero-actions) {
    flex-wrap: wrap;
  }

  body.mnv-future-ui :where(.inline-actions, .hero-actions) > * {
    max-width: 100%;
  }
}

@media (max-width: 980px) {
  body.mnv-future-ui {
    --mnv-content-inline: clamp(14px, 3vw, 28px);
  }

  body.mnv-future-ui :where(.container, .admin-container, .shell-container) {
    width: min(calc(100% - (var(--mnv-content-inline) * 2)), var(--mnv-content-max));
  }

  body.mnv-future-ui :where(.dash-layout, .admin-shell, .org-shell) {
    min-width: 0;
  }

  body.mnv-future-ui :where(.dash-main, .admin-main, .org-main) {
    min-width: 0;
    max-width: 100%;
  }

  body.mnv-future-ui :where(.admin-sidebar, .org-sidebar, .dash-nav) {
    max-height: min(88vh, 88dvh);
    overscroll-behavior: contain;
  }

  body.mnv-future-ui :where(.grid-2, .admin-cols-2, .org-grid-2, .compact-grid) {
    grid-template-columns: minmax(0, 1fr);
  }

  body.mnv-future-ui .mf-journey-rail ol {
    gap: 8px;
  }

  body.mnv-future-ui .mf-journey-rail li {
    min-width: 0;
  }

  body.mnv-future-ui .mf-journey-step-copy small {
    line-height: 1.25;
  }

  body.mnv-future-ui :where(.watch-layout, .study-session-layout, .assessment-layout) {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Phones and compact tablet split-screen. */
@media (max-width: 760px) {
  body.mnv-future-ui {
    --mnv-radius-lg: 21px;
    --mnv-radius-md: 16px;
    --mnv-content-inline: 12px;
    background-attachment: scroll;
  }

  body.mnv-future-ui:is(.shell-auth, .shell-learner, .shell-immersive, .shell-admin),
  body.mnv-future-ui.organization-app {
    background:
      radial-gradient(circle at 88% -2%, rgba(98, 230, 255, .11), transparent 22rem),
      linear-gradient(155deg, #040b19, #081a35 68%, #0b2342);
  }

  body.mnv-future-ui :where(.container, .admin-container, .shell-container) {
    width: calc(100% - 24px);
  }

  body.mnv-future-ui :where(.panel, .card, .admin-card, .org-card, .org-panel, .auth-card) {
    box-shadow: var(--mnv-shadow-sm);
  }

  body.mnv-future-ui :where(.grid-3, .admin-cols-3, .org-grid-3, .kpi-row, .org-kpis) {
    grid-template-columns: minmax(0, 1fr);
  }

  body.mnv-future-ui :where(.section-heading, .admin-page-head, .org-page-head, .result-head, .dash-greet) {
    align-items: flex-start;
    flex-direction: column;
  }

  body.mnv-future-ui :where(.section-heading, .admin-page-head, .org-page-head, .result-head, .dash-greet) > * {
    max-width: 100%;
  }

  body.mnv-future-ui :where(.inline-actions, .hero-actions) {
    width: 100%;
  }

  body.mnv-future-ui :where(.inline-actions, .hero-actions) :where(.button, button, input[type="submit"]) {
    flex: 1 1 min(100%, 180px);
  }

  body.mnv-future-ui :where(.auth-wrap, .auth-shell) {
    width: 100%;
    max-width: 100%;
  }

  body.mnv-future-ui .mf-journey-rail {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  body.mnv-future-ui .mf-journey-rail ol {
    min-width: max-content;
  }

  body.mnv-future-ui .mf-journey-rail li {
    min-width: 144px;
  }

  body.mnv-future-ui :where(.mobile-tabbar, .future-study-dock) {
    inset-inline: 7px;
    bottom: max(7px, env(safe-area-inset-bottom));
    border-radius: 18px;
  }

  body.mnv-future-ui .mobile-tabbar a {
    min-width: 0;
    min-height: 48px;
    border-radius: 12px;
  }

  body.mnv-future-ui .mobile-tabbar a > span:last-child {
    overflow: hidden;
    max-width: 100%;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.mnv-future-ui :where(dialog, .guide-panel, .qr-login-modal, .mf-command-palette, .mf-detail-drawer, .luxury-command-panel) {
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
    margin: 10px;
    border-radius: 20px;
  }

  body.mnv-future-ui :where(.table-scroll, .org-table-wrap, .comparison-table-wrap) {
    margin-inline: 0;
  }

  body.mnv-future-ui :where(.data-table, .org-table, .comparison-table) {
    min-width: max(620px, 100%);
  }

  body.mnv-future-ui :where(.future-utility-dock, .pwa-nudge) {
    max-width: calc(100vw - 16px);
  }

  body.mnv-future-ui.page-index .koto-device {
    transform: none;
  }

  body.mnv-future-ui :where(.page-transition-overlay, .ai-wait-overlay) {
    min-height: 100vh;
    min-height: 100dvh;
  }

  body.mnv-future-ui :where(.page-loader-card, .ai-wait-card, .practice-processing-card) {
    width: min(calc(100vw - 24px), 680px);
    max-height: calc(100dvh - 24px);
    overflow: auto;
  }

  body.mnv-future-ui :where(.qr-code, .qr-image, [data-qr-code], [data-qr-value], [data-sheet-qr], [data-coupon-qr], .family-qr, .learner-sheet-qr) {
    max-width: min(78vw, 360px);
    margin-inline: auto;
  }
}

@media (max-width: 480px) {
  body.mnv-future-ui {
    --mnv-content-inline: 10px;
  }

  body.mnv-future-ui :where(.container, .admin-container, .shell-container) {
    width: calc(100% - 20px);
  }

  body.mnv-future-ui :where(h1) {
    font-size: clamp(1.65rem, 8vw, 2.25rem);
    line-height: 1.14;
  }

  body.mnv-future-ui :where(h2) {
    font-size: clamp(1.3rem, 6vw, 1.75rem);
    line-height: 1.2;
  }

  body.mnv-future-ui :where(.button, button, input[type="submit"], input[type="button"]) {
    min-height: 46px;
  }

  body.mnv-future-ui :where(.inline-actions, .hero-actions) :where(.button, button, input[type="submit"]) {
    width: 100%;
  }

  body.mnv-future-ui .mf-journey-rail li {
    min-width: 132px;
  }

  body.mnv-future-ui .mf-journey-step-copy small {
    max-width: 112px;
    font-size: .7rem;
    line-height: 1.2;
  }

  body.mnv-future-ui .mobile-tabbar a {
    padding-inline: 4px;
    font-size: .69rem;
  }

  body.mnv-future-ui :where(.future-utility-dock > .guide-fab, .future-utility-dock > .qr-login-fab, .future-utility-dock > .child-read-aloud) {
    min-width: 48px;
    min-height: 48px;
  }
}

/* Short landscape phones and software keyboards: content remains scrollable. */
@media (max-height: 560px) and (orientation: landscape) {
  body.mnv-future-ui :where(dialog, .guide-panel, .qr-login-modal, .mf-command-palette, .mf-detail-drawer, .luxury-command-panel) {
    max-height: calc(100dvh - 12px);
    margin-block: 6px;
  }

  body.mnv-future-ui :where(.page-loader-card, .ai-wait-card, .practice-processing-card) {
    max-height: calc(100dvh - 16px);
    overflow: auto;
  }

  body.mnv-future-ui.has-mobile-tabbar {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  body.mnv-future-ui {
    scroll-behavior: auto;
  }
}
