/* Responsive hardening layer for public pages, admin, and WebView/PWA shells. */
:root {
  --mobile-page-pad: clamp(12px, 4vw, 18px);
  --tap-target: 42px;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

img,
video,
svg {
  max-width: 100%;
}

canvas {
  max-width: 100%;
}

iframe {
  max-width: 100%;
  border: 0;
}

button,
a,
input,
select,
textarea {
  min-width: 0;
}

.museum-shell,
.home-shell,
.public-list-page,
.public-detail-page,
.audio-guide-page,
.qr-page-shell,
.flipbook-page,
.gallery-viewer-page {
  max-width: 100vw;
}

.container {
  max-width: min(100% - 2rem, 1280px);
}

.museum-button,
.home-login-button,
.home-cta,
.home-cta-secondary,
.home-nav-link,
.gallery-viewer-button,
.viewer-control,
.qr-actions button,
.qr-actions a {
  touch-action: manipulation;
}

.museum-card,
.home-card,
.quick-card,
.feature-panel,
.museum-search-panel,
.audio-guide-card,
.qr-scanner-card,
.admin-card {
  max-width: 100%;
}

.museum-card img,
.feature-panel-image img,
.home-artifact-image,
.audio-qr-visual img,
.public-detail-page article img {
  height: auto;
}

.public-detail-page article,
.public-list-page main,
.audio-guide-page main,
.qr-page-shell main {
  overflow-wrap: anywhere;
}

@media (max-width: 1024px) {
  .container {
    max-width: min(100% - 1.5rem, 100%);
  }

  .home-hero {
    min-height: auto;
  }

  .home-hero-visual {
    min-width: 0;
  }

  .feature-panel-grid,
  .quick-access-grid {
    align-items: stretch;
  }
}

@media (max-width: 768px) {
  body {
    overflow-x: hidden;
  }

  .container {
    max-width: 100%;
    padding-left: var(--mobile-page-pad) !important;
    padding-right: var(--mobile-page-pad) !important;
  }

  .museum-header,
  .home-header {
    max-width: 100vw;
  }

  .museum-nav,
  .home-nav,
  .admin-nav {
    min-height: 62px;
    gap: 10px;
  }

  .museum-section,
  .home-section {
    padding-top: clamp(28px, 8vw, 48px);
    padding-bottom: clamp(28px, 8vw, 48px);
  }

  .museum-section-heading,
  .home-section-head h2 {
    font-size: clamp(1.55rem, 8vw, 2.3rem) !important;
    line-height: 1.12;
  }

  .museum-page-intro {
    margin-bottom: 18px;
  }

  .museum-search-panel {
    padding: 10px;
  }

  .museum-search-panel input,
  input,
  select,
  textarea {
    max-width: 100%;
  }

  .museum-card,
  .quick-card,
  .feature-panel {
    border-radius: 12px;
  }

  .home-hero-section {
    padding-top: 14px;
  }

  .home-hero {
    grid-template-columns: 1fr !important;
    gap: 22px;
    padding: clamp(20px, 6vw, 30px);
  }

  .home-hero-actions,
  .feature-panel-actions,
  .qr-actions {
    width: 100%;
    align-items: stretch;
  }

  .home-hero-actions > *,
  .feature-panel-actions > *,
  .qr-actions > * {
    min-height: var(--tap-target);
  }

  .home-hero-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .home-hero-visual {
    width: 100%;
    min-height: 260px;
  }

  .home-artifact-card {
    max-width: 100%;
  }

  .home-artifact-image {
    width: 100%;
    max-height: 310px;
    object-fit: contain;
  }

  .feature-panel-image {
    min-height: 190px;
  }

  .feature-panel-image img,
  .audio-qr-visual img {
    width: 100%;
    max-height: 260px;
    object-fit: contain;
  }

  .visit-stats .grid {
    grid-template-columns: 1fr !important;
  }

  .audio-guide-page .museum-nav,
  .qr-page-shell .museum-nav,
  .public-list-page .museum-nav,
  .public-detail-page .museum-nav {
    flex-wrap: wrap;
    justify-content: center;
  }

  .audio-guide-card {
    padding: clamp(18px, 5vw, 26px) !important;
  }

  .audio-guide-card audio {
    width: 100%;
    min-height: 44px;
  }

  .qr-scanner-card {
    padding: clamp(16px, 5vw, 24px) !important;
  }

  .qr-camera-frame {
    width: min(100%, 420px) !important;
    aspect-ratio: 3 / 4;
    max-height: min(62dvh, 520px);
  }

  .qr-camera-frame video {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .qr-actions {
    flex-direction: column;
  }

  .public-detail-page .museum-prose,
  .public-detail-page article {
    font-size: 1rem;
    line-height: 1.75;
  }

  .public-detail-page article figure,
  .public-detail-page article img {
    max-width: 100%;
  }

  .admin-shell .admin-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
  }

  .admin-shell .admin-nav {
    flex-wrap: wrap;
    justify-content: center;
  }

  .admin-shell .admin-title-wrap {
    text-align: center;
  }

  .admin-shell aside.admin-card {
    position: static;
  }

  .admin-shell #admin-menu {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-shell .admin-tab {
    min-height: 42px;
    padding: 0.72rem 0.78rem;
    text-align: center;
  }

  .admin-shell form,
  .admin-shell .admin-card,
  .admin-shell [id$="-list"],
  .admin-shell [id$="-grid"] {
    min-width: 0;
  }

  .admin-shell table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
  }

  .admin-shell .museum-button,
  .admin-shell button {
    min-height: 40px;
  }

  .flipbook-page .viewer-toolbar {
    min-height: 64px !important;
    max-width: 100vw;
  }

  .flipbook-page .book-stage {
    min-height: 0;
    overflow: hidden;
  }

  .flipbook-page .flip-layout {
    max-width: 100vw;
    min-height: 0;
  }

  .flipbook-page .flipbook-nav-wrap {
    padding-bottom: max(10px, env(safe-area-inset-bottom)) !important;
  }

  .flipbook-page #ai-toggle,
  .qr-page-shell #ai-toggle,
  .audio-guide-page #ai-toggle {
    right: 10px !important;
    bottom: 86px !important;
    width: 44px !important;
    height: 44px !important;
  }

  .flipbook-page #ai-box,
  .qr-page-shell #ai-box,
  .audio-guide-page #ai-box {
    right: 10px !important;
    bottom: 138px !important;
    max-width: calc(100vw - 20px) !important;
    height: min(520px, calc(100dvh - 158px)) !important;
  }

  .gallery-viewer-page {
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
  }

  .gallery-viewer-page .gallery-viewer-stage {
    min-height: 0;
  }

  .gallery-viewer-page .gallery-viewer-shell {
    min-height: 0;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .gallery-viewer-page .gallery-image-frame {
    max-width: 100%;
    max-height: 100%;
  }

  .gallery-viewer-page .gallery-image-frame img {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .viewer-page,
  .viewer-3d-page,
  .vr-page,
  .panoee-page {
    max-width: 100vw;
    overflow-x: hidden;
  }

  #viewer,
  #panoee-viewer,
  .panoee-frame,
  .vr-frame,
  .viewer-frame {
    max-width: 100vw;
  }
}

@media (max-width: 480px) {
  :root {
    --mobile-page-pad: 12px;
  }

  .home-brand,
  .museum-nav > a:first-child {
    min-width: 0;
  }

  .home-brand .home-brand-title,
  .museum-nav .font-serif {
    font-size: clamp(1.05rem, 5vw, 1.35rem) !important;
  }

  .home-hero {
    border-radius: 14px;
  }

  .home-hero h1 {
    font-size: clamp(2.15rem, 11vw, 3rem) !important;
  }

  .home-hero-stats {
    grid-template-columns: 1fr;
  }

  .home-floating-badge {
    display: none;
  }

  .quick-access-grid,
  .feature-panel-grid,
  .museum-grid {
    grid-template-columns: 1fr !important;
  }

  .museum-button,
  .home-cta,
  .home-cta-secondary {
    width: 100%;
    justify-content: center;
  }

  .admin-shell #admin-menu {
    grid-template-columns: 1fr;
  }

  .admin-shell .admin-card {
    padding: 1rem !important;
  }

  .gallery-viewer-page .gallery-viewer-header {
    grid-template-columns: auto minmax(0, 1fr) 38px;
  }

  .gallery-viewer-page .gallery-thumbnails {
    max-height: 52px;
  }
}

@media (orientation: landscape) and (max-height: 540px) {
  .gallery-viewer-page .gallery-viewer-header,
  .flipbook-page .viewer-toolbar {
    min-height: 54px !important;
  }

  .gallery-viewer-page .gallery-thumbnails,
  .gallery-viewer-page .gallery-caption,
  .gallery-viewer-page .gallery-hint {
    display: none !important;
  }

  .qr-camera-frame {
    aspect-ratio: 16 / 9;
    max-height: 62dvh;
  }
}
