/* SONIC GAME STORE — mobile-first refinements layered after desktop & theme CSS.
   Desktop (801px and wider) stays unchanged. */
@media (max-width: 800px) {
  :root { -webkit-text-size-adjust: 100%; }
  html, body { max-width: 100%; }
  .container { width: calc(100% - 32px); max-width: 100%; }
  main, main > section { min-width: 0; }
  main img, main video, main iframe { max-width: 100%; }
  main :is(p, h1, h2, h3, h4, strong, a) { overflow-wrap: anywhere; }
  input, select, textarea { max-width: 100%; min-width: 0; }
  button, a, summary { -webkit-tap-highlight-color: transparent; }
  button:focus-visible, a:focus-visible, summary:focus-visible,
  input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid #b77cff; outline-offset: 2px; }

  /* Compact two-row header: logo / actions, followed by full-width search. */
  .topbar-inner { height: 29px; padding-inline: 4px; }
  .topbar-promo { font-size: 10px; text-align: center; }
  .topbar-links { display: none; }
  .sonic-header .header-main {
    display: grid; grid-template-columns: minmax(0,1fr) auto;
    grid-template-rows: 50px 44px; gap: 7px 8px;
    height: auto; padding-block: 7px 10px;
    width: calc(100% - 28px); position: static;
  }
  .sonic-header .sonic-brand { grid-column: 1; grid-row: 1; order: initial;
    flex: initial; min-width: 0; gap: 8px; }
  .sonic-header .brand-mark { width: 42px; height: 42px; border-radius: 12px; flex-shrink: 0; }
  .sonic-header .brand-copy { display: flex; }
  .sonic-header .brand-copy strong { font-size: 17px; }
  .sonic-header .brand-copy small { display: block; font-size: 8px; letter-spacing: 1.2px; margin-top: 5px; }
  .sonic-header .header-tools { grid-column: 2; grid-row: 1; order: initial;
    display: flex; align-items: center; gap: 6px; margin: 0; min-width: 0; }
  .sonic-header .tool-text { display: none; }
  .sonic-header .header-tools .tool-link, .sonic-header .theme-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; min-width: 40px; min-height: 40px;
    padding: 0; margin: 0; border-radius: 12px;
    border: 1px solid #343047; background: #171729;
  }
  .sonic-header .header-tools .tool-link .tool-icon { display: inline-block; font-size: 23px; line-height: 1.1; }
  .sonic-header .header-tools .favorites { display: none; }
  .sonic-header .theme-toggle .theme-label { display: none; }
  .sonic-header .header-tools .logout-inline { display: none; }
  .sonic-header .header-search {
    grid-column: 1 / -1; grid-row: 2; order: initial;
    position: static; top: auto; right: auto; left: auto;
    width: 100%; max-width: none; min-width: 0;
    margin: 0; height: 44px; border-radius: 12px;
  }
  .sonic-header .header-search input { font-size: 16px; padding-inline: 12px; width: 100%; min-width: 0; }
  .sonic-header .header-search button { width: 46px; flex: 0 0 46px; }
  .sonic-header .sonic-nav { display: block; margin: 0 !important; }
  .sonic-nav .nav-inner {
    width: calc(100% - 28px); height: 50px; min-height: 50px;
    padding: 4px 0; display: flex; flex-wrap: nowrap;
    justify-content: flex-start; gap: 5px; overflow: visible;
  }
  .category-menu-trigger { min-width: 0; min-height: 42px; flex: 0 1 auto;
    padding-inline: 11px; gap: 7px; font-size: 12px; white-space: nowrap; }
  .category-trigger-bars { flex-shrink: 0; }
  .category-trigger-chevron { display: none; }
  .category-nav-shortcuts { display: flex; min-width: 0; gap: 3px; }
  .sonic-nav .category-nav-shortcut { min-height: 40px; padding: 0 8px;
    font-size: 11px; white-space: nowrap; }
  .category-drawer { width: min(390px, 94vw); height: 100dvh; max-height: 100dvh; }
  .category-drawer-header { padding: 16px; }
  .category-drawer-body { padding: 12px 12px 26px; }
  .category-drawer-service-heading { margin-top: 12px !important; }
  .category-drawer-logout button { width: 100%; min-height: 40px; text-align: right;
    padding: 9px 12px; background: transparent; border: 0; color: #ff94a7;
    font-size: 12px; }
  html[data-theme='light'] .category-drawer-logout button { color: #bb314f; }
  .message-stack { top: 10px; left: 10px; right: 10px; }
  .site-message { min-width: 0; }

  /* Homepage: remove oversize blank hero, make CTAs and promo cards fit. */
  .sonic-hero { min-height: 0; }
  .sonic-hero-inner { display: flex; flex-direction: column; gap: 24px;
    width: calc(100% - 32px); min-height: 0; padding: 31px 0 30px;
    direction: rtl; align-items: stretch; }
  .sonic-hero-copy { width: 100%; padding: 0; text-align: center; max-width: none; }
  .sonic-hero-copy .hero-badge { margin-bottom: 14px; font-size: 11px; }
  .sonic-hero-copy h1 { font-size: clamp(25px, 7.3vw, 34px); line-height: 1.5; letter-spacing: 0; }
  .sonic-hero-copy p { max-width: 520px; margin: 12px auto 20px;
    font-size: 13px; line-height: 2; }
  .sonic-hero-copy .hero-actions { display: grid; grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 9px; width: 100%; max-width: 440px; margin: 0 auto; }
  .sonic-hero-copy .hero-actions .btn { width: 100%; min-width: 0;
    min-height: 46px; height: auto; padding: 7px 8px; font-size: 12px; line-height: 1.5; }
  .sonic-hero-offers { width: 100%; flex-basis: auto; min-width: 0; }
  .sonic-offers-heading { gap: 10px; margin-bottom: 11px; font-size: 16px; }
  .sonic-offers-heading small { font-size: 10px; white-space: nowrap; }
  .sonic-offers-track { gap: 10px; padding: 3px 1px 12px; }
  .sonic-offer-item { flex: 0 0 clamp(145px, 48%, 195px); min-width: 0; padding: 10px; }
  .sonic-offer-picture { height: 124px; }
  .sonic-offer-name { font-size: 13px; }
  .sonic-offer-price { font-size: 14px; }
  .sonic-offers-empty { padding: 24px 12px; font-size: 13px; }
  .sonic-trust .trust-grid { padding: 9px; gap: 0;
    grid-template-columns: repeat(2, minmax(0,1fr)); }
  .sonic-trust .trust-item { display: flex; justify-content: flex-start;
    padding: 9px 7px; min-width: 0; gap: 8px; }
  .sonic-trust .trust-item > span { font-size: 21px; flex-shrink: 0; }
  .sonic-trust .trust-item strong { font-size: 11px; }
  .sonic-trust .trust-item small { font-size: 9px; line-height: 1.5; }
  .store-section.sonic-section, .sonic-section { width: auto; padding: 30px 0; }
  .sonic-section.categories-section { padding-bottom: 16px; }
  .section-heading { min-width: 0; gap: 8px; align-items: center; }
  .section-heading h2 { font-size: 19px; line-height: 1.5; }
  .section-heading .section-link { font-size: 11px; flex-shrink: 0; }
  .sonic-category-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .sonic-category-card .category-tile-image { height: auto; aspect-ratio: 1.35; }
  .sonic-category-card .category-tile-body { padding: 9px 10px 11px; }
  .sonic-category-card .category-tile-body strong { font-size: 12px; line-height: 1.6; }
  .sonic-product-grid, .latest-section .sonic-product-grid,
  .products-grid, .related-products-grid { display: grid;
    grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .sonic-product-card, .products-grid .product-card { min-width: 0; display: flex; flex-direction: column; }
  .sonic-product-card .store-product-image, .products-grid .product-image,
  .related-product-image { width: 100%; height: auto; aspect-ratio: 1 / 1;
    max-height: 230px; overflow: hidden; }
  .sonic-product-card .store-product-image img, .products-grid .product-image img { object-fit: contain; }
  .sonic-product-card .store-product-title { padding: 8px 9px 3px; }
  .sonic-product-card .store-product-title a { display: -webkit-box;
    -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    font-size: 12px; line-height: 1.6; min-height: 3.2em; }
  .sonic-product-card .store-product-info { padding: 0 9px 10px;
    display: flex; flex-direction: column; flex: 1; }
  .sonic-product-card .rating-row { flex-wrap: wrap; gap: 3px; }
  .sonic-product-card .price-row { flex-wrap: wrap; gap: 4px; }
  .sonic-product-card .price-row strong { font-size: 13px; }
  .sonic-product-card .quick-add { display: block; margin-top: auto; padding-top: 10px; }
  .sonic-product-card .quick-add button { width: 100%; min-height: 38px;
    font-size: 11px; padding: 6px 5px; white-space: normal; }
  .products-grid .product-info { display: flex; flex-direction: column; flex: 1;
    padding: 9px 9px 11px; }
  .products-grid .product-name { display: -webkit-box !important;
    -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
    min-height: 3.1em; font-size: 12px; line-height: 1.55; margin-bottom: 5px; }
  .products-grid .product-brand { font-size: 10px; }
  .products-grid .product-price { font-size: 13px; line-height: 1.65; }
  .products-grid .product-stock, .products-grid .product-out-stock { font-size: 10px; }
  .products-grid .quick-add { margin-top: auto; padding-top: 9px; }
  .products-grid .quick-add button { width: 100%; min-height: 38px; padding: 5px;
    font-size: 11px; white-space: normal; }
  .card-favorite-form { top: 8px; left: 8px; }
  .card-favorite-form .wish-btn { min-width: 35px; min-height: 35px; }
  .sonic-promo .dark-promo-inner { padding: 22px 16px;
    min-height: 0; display: flex; flex-direction: column; gap: 8px; }
  .dark-promo h2 { font-size: 22px; }
  .dark-promo p { font-size: 12px; }
  .sonic-promo .promo-controller { font-size: 54px; }

  /* Shop: expandable filters above the two-column products. */
  .products-page { padding: 24px 0 52px; }
  .products-header { display: flex; flex-wrap: wrap; align-items: center;
    gap: 10px 12px; margin-bottom: 14px; }
  .products-header h1 { font-size: 22px; }
  .products-header p { font-size: 12px; line-height: 1.8; }
  .products-header .sort-form { margin-right: auto; }
  .products-header .sort-form select { min-height: 42px; font-size: 12px; }
  .products-layout { grid-template-columns: minmax(0,1fr); gap: 13px; direction: rtl; }
  .mobile-filter-toggle { display: flex; width: 100%; min-height: 46px;
    align-items: center; justify-content: space-between; padding: 0 15px;
    background: #1d1730; color: #ece3ff; border: 1px solid #594077;
    border-radius: 12px; font-size: 13px; font-weight: 800; text-align: right; }
  .mobile-filter-toggle .mobile-filter-arrow { font-size: 20px; transition: transform .2s; }
  .mobile-filter-toggle[aria-expanded='true'] .mobile-filter-arrow { transform: rotate(180deg); }
  .products-sidebar { display: none; position: static; top: auto;
    width: 100%; max-width: 100%; padding: 14px; }
  .products-sidebar.mobile-filters-expanded { display: block; }
  .products-content { min-width: 0; }
  .filter-section > a { font-size: 12px; padding-block: 8px; }
  .price-filter-form input, .price-filter-form select, .price-filter-form button { font-size: 14px; min-height: 42px; }
  .products-result-meta { font-size: 11px; flex-wrap: wrap; gap: 5px; }
  .products-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
  .products-pagination a, .products-pagination span { min-width: 40px; min-height: 40px; }

  /* Detail, checkout and account pages: remove wide columns and tiny tap areas. */
  .product-detail-page, .cart-page, .checkout-page, .payment-page,
  .account-page, .invoice-page { padding: 22px 0 52px; }
  .product-breadcrumb { overflow: hidden; white-space: nowrap;
    text-overflow: ellipsis; font-size: 11px; margin-bottom: 12px; }
  .product-breadcrumb > :last-child { overflow: hidden; text-overflow: ellipsis; }
  .product-detail { grid-template-columns: minmax(0,1fr); gap: 14px; }
  .product-detail-gallery, .product-detail-info { min-width: 0; }
  .product-detail-image { height: auto; min-height: 260px; aspect-ratio: 1/1;
    max-height: 440px; border-radius: 16px; }
  .product-detail-image img { object-fit: contain; }
  .product-gallery { overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 6px; }
  .gallery-thumbnail { flex: 0 0 65px; height: 65px; }
  .product-detail-info { padding: 0; }
  .product-detail-info h1 { font-size: 23px; line-height: 1.65; }
  .product-meta-line { flex-wrap: wrap; gap: 6px; }
  .product-detail-pricing { margin: 15px 0 12px; padding: 14px 0; }
  .product-detail-price { font-size: 24px; overflow-wrap: anywhere; }
  .product-detail-discount { position: static; display: inline-block; margin-top: 7px; }
  .add-to-cart-form { gap: 8px; min-width: 0; flex-wrap: wrap; }
  .add-to-cart-form.has-colors { display: flex; flex-wrap: wrap; }
  .product-color-picker { width: 100%; min-width: 0; }
  .add-to-cart-form .quantity-box { flex: 0 0 auto; }
  .add-to-cart-form .add-to-cart { flex: 1 1 120px; min-width: 0;
    min-height: 50px; padding-inline: 7px; font-size: 12px; }
  .product-trust-box { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .product-trust-box > div { padding: 9px 5px; }
  .product-trust-box strong { font-size: 10px; }
  .product-trust-box small { font-size: 9px; }
  .product-detail-tabs, .order-detail-grid { grid-template-columns: minmax(0,1fr); gap: 13px; }
  .product-detail-section { padding: 16px; min-width: 0; }
  .product-description, .product-detail-short-description { font-size: 13px; }
  .specification-row { grid-template-columns: minmax(0,1fr); }
  .specification-key, .specification-value { font-size: 12px; }
  .related-products-section { margin-top: 28px; }
  .related-product-info { padding: 9px; }
  .related-product-info h3 { font-size: 12px; }

  .cart-header, .account-header { align-items: center; gap: 10px; flex-wrap: wrap; }
  .cart-header h1, .checkout-page > h1, .account-header h1 { font-size: 23px; }
  .cart-layout, .checkout-layout { grid-template-columns: minmax(0,1fr); gap: 14px; }
  .cart-items, .cart-summary, .checkout-form, .checkout-summary { min-width: 0; }
  .cart-item { grid-template-columns: 75px minmax(0,1fr) 34px; gap: 8px;
    padding: 10px; }
  .cart-item-image { width: 75px; height: 75px; grid-column: 1; grid-row: 1; }
  .cart-item-info { grid-column: 2; grid-row: 1; }
  .cart-product-name { font-size: 12px; }
  .cart-item-quantity { grid-column: 2; grid-row: 2; }
  .cart-item-total { grid-column: 1; grid-row: 2; font-size: 11px; }
  .cart-item-remove { grid-column: 3; grid-row: 1; }
  .cart-item-quantity button { min-width: 36px; min-height: 36px; }
  .cart-summary, .checkout-form, .checkout-summary { padding: 16px; }
  .checkout-form input, .checkout-form select, .checkout-form textarea,
  .coupon-form input { width: 100%; min-width: 0; font-size: 16px; }
  .checkout-item, .checkout-price-row, .summary-row, .summary-total { gap: 8px; }
  .coupon-form { display: flex; min-width: 0; }
  .coupon-form input { flex: 1; }
  .coupon-form button { flex: 0 0 auto; }
  .auth-page { padding: 26px 0 54px; }
  .auth-card { width: 100%; max-width: 470px; padding: 20px; }
  .auth-card input { font-size: 16px; width: 100%; }
  .account-stats { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .account-stat { min-width: 0; padding: 13px 10px; }
  .account-stat strong { overflow-wrap: anywhere; }
  .account-security-card { flex-direction: column; align-items: stretch; }
  .account-security-card .btn { width: 100%; }
  .orders-card { min-width: 0; padding: 15px; }
  .orders-table-wrap { max-width: 100%; overflow-x: auto;
    -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
  .orders-table { min-width: 630px; }
  .order-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .order-actions > .btn, .order-actions > form { flex: 1 1 auto; }
  .order-actions > form button { min-height: 44px; }
  .sonic-footer .footer-grid { grid-template-columns: repeat(2,minmax(0,1fr));
    gap: 22px 12px; padding-block: 30px; }
  .sonic-footer .footer-brand, .sonic-footer .footer-contact { grid-column: 1/-1; }
  .sonic-footer .footer-grid h3 { font-size: 15px; }
  .sonic-footer .footer-grid a { font-size: 12px !important; }
  .footer-brand p { font-size: 12px; }
  /* Favorites uses an inline grid declaration; override it only on phones. */
  section .products-grid[style] { grid-template-columns: repeat(2,minmax(0,1fr)) !important; gap: 10px !important; }
  .product-body { min-width: 0; }
  .product-title { overflow-wrap: anywhere; }
  /* Embedded controller tester shouldn't force an oversized mobile viewport. */
  .repair-card iframe { max-width: 100%; }
}

@media (max-width: 360px) {
  .container { width: calc(100% - 24px); }
  .sonic-header .header-main, .sonic-nav .nav-inner { width: calc(100% - 20px); }
  .sonic-header .brand-copy strong { font-size: 15px; }
  .sonic-header .brand-copy small { font-size: 7px; }
  .sonic-header .header-tools { gap: 4px; }
  .sonic-header .header-tools .tool-link, .sonic-header .theme-toggle { width: 36px; min-width: 36px; height: 38px; min-height: 38px; }
  .sonic-nav .nav-inner { gap: 1px; }
  .category-menu-trigger { gap: 5px; font-size: 10px; padding-inline: 7px; }
  .category-trigger-bars, .category-trigger-bars i { width: 16px; }
  .sonic-nav .category-nav-shortcut { padding-inline: 5px; font-size: 10px; }
  .sonic-hero-inner { width: calc(100% - 24px); }
  .sonic-hero-copy .hero-actions { gap: 6px; }
  .sonic-hero-copy .hero-actions .btn { font-size: 11px; padding-inline: 4px; }
  .sonic-offers-heading { font-size: 14px; }
  .sonic-trust .trust-item { gap: 5px; padding: 8px 4px; }
  .sonic-trust .trust-item strong { font-size: 10px; }
  .sonic-product-grid, .latest-section .sonic-product-grid,
  .products-grid, .related-products-grid { gap: 8px; }
  .product-detail-info h1 { font-size: 21px; }
  .add-to-cart-form .quantity-box { width: 100%; justify-content: space-between; }
  .add-to-cart-form .quantity-box input { flex: 1; }
  .add-to-cart-form .add-to-cart { width: 100%; flex: 1 0 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-filter-toggle .mobile-filter-arrow { transition: none; }
}

/* The toggle is only a mobile control; leave filters permanently exposed on desktop. */
@media (min-width: 801px) {
  .mobile-filter-toggle { display: none; }
}

/* Light-mode corrections for controls introduced in this sheet. */
@media (max-width: 800px) {
  html[data-theme='light'] .sonic-header .header-tools .tool-link,
  html[data-theme='light'] .sonic-header .theme-toggle { background: #f6f3fc; border-color: #ddd6ed; }
  html[data-theme='light'] .mobile-filter-toggle { background: #f1e8ff;
    color: #54248a; border-color: #d6bce9; }
  html[data-theme='light'] .products-sidebar { background: #fff; }
}

/* Preserve contrast in light-mode on the mobile hero and shortcuts. */
@media (max-width: 800px) {
  html[data-theme='light'] .sonic-header .sonic-nav .category-nav-shortcut {
    color: #35405b;
  }
  html[data-theme='light'] .sonic-header .sonic-nav .category-nav-shortcut:hover,
  html[data-theme='light'] .sonic-header .sonic-nav .category-nav-shortcut.active {
    color: #652dac;
  }
  html[data-theme='light'] .sonic-hero-copy p { color: #46516b; }
  html[data-theme='light'] .sonic-offers-heading { color: #24314a; }
  html[data-theme='light'] .sonic-offers-heading small { color: #536079; }
  html[data-theme='light'] .sonic-offers-empty { color: #3e4a64;
    background: rgba(255,255,255,.78); border: 1px solid #e0e5f1; }
  html[data-theme='light'] .sonic-offers-controls button { color: #55319a;
    background: #fff; border-color: #d6c7ed; }
  .products-grid .product-card:only-child { grid-column: 1 / -1;
    width: min(100%, 285px); justify-self: center; }
}

@media (max-width: 800px) {
  .cart-item .cart-price { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
  .cart-item .cart-price .old-price { margin: 0; font-size: 10px; }
  .cart-item .cart-price .discount-price { font-size: 12px; }
}
