/* V0.20 mobile-first responsive hardening.
   Loaded last so it can safely correct the accumulated legacy UI layers. */

html,
body {
  max-width: 100%;
}

body {
  overflow-x: hidden;
  overflow-x: clip;
}

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

:where(main, section, article, aside, nav, form, fieldset, div) {
  min-width: 0;
}

:where(input, select, textarea, button) {
  max-width: 100%;
}

:where(p, h1, h2, h3, h4, a, b, strong, span, small, label) {
  overflow-wrap: anywhere;
}

.table-wrap,
.chips,
.top-chips,
.top-grades,
.breadcrumb,
body:not(.grade-choice-page) > header .nav-links {
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 920px) {
  .btn,
  .page-btn {
    white-space: normal;
    text-align: center;
    line-height: 1.35;
  }

  .profile-dl-title {
    white-space: normal;
  }
}

@media (max-width: 640px) {
  html {
    scroll-padding-top: 126px;
  }

  body {
    font-size: 15px;
  }

  .wrap,
  .catalog .wrap {
    width: 100%;
    max-width: 100%;
    padding-inline: 12px !important;
  }

  body:not(.grade-choice-page) > header .nav {
    width: 100% !important;
    padding: 8px 10px 0 !important;
    gap: 7px 8px !important;
  }

  body:not(.grade-choice-page) > header .logo {
    gap: 7px !important;
    font-size: 16px !important;
  }

  body:not(.grade-choice-page) > header .logo-mark {
    width: 34px !important;
    height: 34px !important;
    border-width: 2px !important;
    border-radius: 11px !important;
    box-shadow: 2px 2px 0 var(--ink) !important;
  }

  body:not(.grade-choice-page) > header .logo-mark svg {
    width: 19px;
    height: 19px;
  }

  body:not(.grade-choice-page) > header .nav-actions {
    width: auto !important;
    display: flex !important;
    flex-flow: row nowrap !important;
    gap: 5px !important;
  }

  body:not(.grade-choice-page) > header .nav-actions .btn {
    min-width: 0 !important;
    min-height: 36px !important;
    padding: 6px 8px !important;
    border-width: 2px !important;
    border-radius: 11px !important;
    font-size: 11px !important;
    white-space: nowrap !important;
  }

  body:not(.grade-choice-page) > header .nav-links {
    padding: 7px 10px 9px !important;
    gap: 7px !important;
  }

  body:not(.grade-choice-page) > header .nav-links a {
    min-height: 34px !important;
    padding: 6px 9px !important;
    font-size: 11px !important;
  }

  .hero-grid,
  .store-panel,
  .download-rules-card,
  .bundle,
  .worksheet-preview-panel,
  .worksheet-info-panel,
  .auth-card,
  .profile-card,
  .topup-form-card,
  .payment-info-card,
  .topup-history,
  .topup-success {
    max-width: 100%;
  }

  .hero h1,
  .auth-copy h1,
  .profile-head h1,
  .worksheet-info-panel h1 {
    overflow-wrap: anywhere;
  }

  .hero-actions,
  .worksheet-actions,
  .profile-actions,
  .download-actions {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 9px !important;
  }

  .hero-actions .btn,
  .worksheet-actions .btn,
  .profile-actions .btn,
  .download-actions .btn {
    width: 100%;
  }

  .advanced-search-form {
    padding: 11px !important;
  }

  .advanced-search-row,
  .advanced-filter-grid {
    grid-template-columns: 1fr !important;
  }

  .advanced-search-row .btn,
  .advanced-filter-grid input,
  .advanced-filter-grid select {
    width: 100% !important;
  }

  .advanced-filter-details summary {
    min-width: 0;
  }

  .search-suggestion-strip {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    padding: 2px 2px 8px !important;
    scrollbar-width: none;
  }

  .search-suggestion-strip::-webkit-scrollbar {
    display: none;
  }

  .search-suggestion-strip > * {
    flex: 0 0 auto;
  }

  .resultbar {
    align-items: flex-start !important;
    flex-direction: column !important;
  }

  /* The former 112px horizontal card was the main mobile breakage. */
  .product-grid.product-grid-wide,
  .product-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px !important;
  }

  .product-grid.product-grid-wide .card,
  .product-grid .card,
  .card {
    width: 100%;
    min-height: 0;
    display: flex !important;
    grid-template-columns: none !important;
    flex-direction: column !important;
    border-radius: 20px !important;
  }

  .product-grid.product-grid-wide .cover,
  .product-grid .cover,
  .card .cover {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    aspect-ratio: 210 / 297 !important;
    align-self: stretch !important;
    border-right: 0 !important;
    border-bottom: 2px solid var(--line) !important;
    padding: 12px !important;
    background: linear-gradient(145deg, #eaf1fb, #f6f8fc) !important;
  }

  .card .cover-link {
    display: block !important;
    width: 100%;
    height: 100%;
  }

  .card .card-preview-img,
  .card .geo-thumb {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    border-radius: 8px !important;
    background: #fff !important;
    box-shadow: 0 10px 24px rgba(23, 35, 63, .13), 0 0 0 1px rgba(23, 35, 63, .12) !important;
  }

  .product-grid.product-grid-wide .card-body,
  .product-grid .card-body,
  .card .card-body {
    width: 100%;
    padding: 14px !important;
    gap: 8px !important;
  }

  .card h3 {
    min-height: 0 !important;
    font-size: 17px !important;
    line-height: 1.4 !important;
  }

  .card .desc {
    min-height: 0 !important;
    display: -webkit-box !important;
    font-size: 13px !important;
    line-height: 1.55 !important;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .card .stats {
    font-size: 11px !important;
  }

  .card .stats span {
    display: inline-flex !important;
  }

  .card .price {
    font-size: 19px !important;
  }

  .card .icon-btn {
    width: 42px !important;
    height: 42px !important;
  }

  .pagination {
    width: 100%;
    gap: 6px !important;
    justify-content: center;
  }

  .pagination .page-btn {
    min-width: 36px !important;
    min-height: 40px;
    padding: 7px 9px !important;
    font-size: 12px !important;
  }

  .pagination .page-info {
    width: 100%;
    flex-basis: 100%;
    order: 10;
  }

  .breadcrumb {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 5px;
  }

  .breadcrumb > * {
    flex: 0 0 auto;
  }

  .worksheet-page {
    padding-top: 18px !important;
  }

  .worksheet-preview-panel,
  .worksheet-info-panel {
    padding: 14px !important;
    border-radius: 19px !important;
  }

  .worksheet-preview-frame {
    width: 100%;
    min-height: 0 !important;
    aspect-ratio: 210 / 297;
    padding: 8px !important;
  }

  .worksheet-facts {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .worksheet-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .worksheet-facts div,
  .worksheet-stats div {
    min-width: 0;
    padding: 11px !important;
  }

  .worksheet-stats b {
    font-size: clamp(17px, 5vw, 22px) !important;
  }

  .ws-dl-status {
    align-items: flex-start;
    gap: 9px;
    padding: 12px !important;
  }

  .auth-page,
  .profile-page {
    padding: 22px 0 48px !important;
  }

  .auth-card,
  .profile-card {
    padding: 18px !important;
    border-radius: 20px !important;
  }

  .auth-copy h1,
  .profile-head h1 {
    font-size: 28px !important;
  }

  .auth-form input,
  .auth-form select,
  .auth-form textarea {
    width: 100%;
    min-height: 46px;
    font-size: 16px !important;
  }

  .password-control input {
    padding-right: 68px !important;
  }

  .profile-points-banner {
    padding: 17px !important;
  }

  .profile-points-banner > div[style] {
    width: 100%;
  }

  .quota-display {
    width: 100%;
    text-align: left;
  }

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

  .profile-section-head,
  .profile-txn-item,
  .profile-dl-item,
  .profile-payment-item,
  .profile-payment-meta {
    align-items: flex-start !important;
  }

  .profile-dl-item {
    flex-wrap: wrap;
  }

  .profile-dl-title {
    width: 100%;
    flex-basis: 100%;
  }

  .profile-dl-time {
    margin-left: auto;
  }

  .topup-hero {
    padding: 22px 0 18px !important;
  }

  .topup-hero .lead {
    padding-inline: 0;
  }

  .topup-balance {
    width: min(100%, 330px);
    padding: 15px 18px !important;
  }

  .topup-package-grid,
  .selected-package-summary {
    grid-template-columns: 1fr !important;
  }

  .package-card-select,
  .topup-form-card,
  .payment-info-card,
  .topup-history,
  .topup-success {
    padding: 16px !important;
  }

  .payment-row,
  .selected-package-summary > div {
    min-width: 0;
  }

  .payment-row b,
  .selected-package-summary b {
    word-break: break-word;
  }

  .slip-preview {
    grid-template-columns: 62px minmax(0, 1fr) !important;
  }

  .slip-preview img {
    width: 62px !important;
    height: 62px !important;
  }

  .site-footer-brand {
    min-width: 0;
  }

  .site-footer a,
  .site-version {
    width: fit-content;
    max-width: 100%;
  }

  .overlay.open {
    padding: 6px !important;
  }

  .modal {
    width: calc(100vw - 12px) !important;
    height: calc(100dvh - 12px) !important;
    max-height: calc(100dvh - 12px) !important;
    border-radius: 18px !important;
  }

  .modal-info {
    min-height: 0;
    padding: 12px !important;
  }

  .modal-actions {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 420px) {
  .wrap,
  .catalog .wrap {
    padding-inline: 9px !important;
  }

  body:not(.grade-choice-page) > header .logo b {
    display: none;
  }

  .hero h1 {
    font-size: 30px !important;
  }

  .hero-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .metric {
    padding: 9px !important;
  }

  .store-panel.store-panel-wide,
  .store-panel {
    padding: 9px !important;
  }

  .worksheet-facts {
    grid-template-columns: 1fr !important;
  }

  .worksheet-stats div {
    padding: 8px 5px !important;
  }

  .profile-head {
    gap: 12px;
  }

  .profile-avatar {
    width: 66px;
    height: 66px;
    font-size: 34px;
  }

  .profile-section-head h2,
  .topup-section-head h2 {
    font-size: 21px !important;
  }

  .payment-row:has(.copy-value) {
    padding-right: 68px !important;
  }

  .copy-value {
    right: 7px;
    padding-inline: 7px;
    font-size: 11px;
  }
}

@media (max-width: 340px) {
  body:not(.grade-choice-page) > header .nav-actions {
    width: 100% !important;
    justify-content: stretch !important;
  }

  body:not(.grade-choice-page) > header .nav-actions .btn {
    flex: 1 1 0;
  }

  .hero-metrics {
    grid-template-columns: 1fr !important;
  }

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