/* Mobile layout — only applies below 1024px. Desktop styles live in layout-desktop.css */

@media (max-width: 1023px) {
  html {
    overflow-x: clip;
  }

  body.mobile-nav-open .site-main {
    overflow: hidden;
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  body.search-modal-open {
    overflow: hidden;
  }

  .site-main {
    padding-top: calc(4.75rem + var(--safe-top));
    padding-bottom: var(--safe-bottom);
  }

  .site-content-wrap {
    padding-left: max(1rem, var(--safe-left));
    padding-right: max(1rem, var(--safe-right));
    padding-top: 1.25rem;
    padding-bottom: 2rem;
  }

  .wiki-shell.site-content-wrap {
    padding-left: max(0.875rem, var(--safe-left));
    padding-right: max(0.875rem, var(--safe-right));
  }

  /* ——— Mobile header ——— */
  .mobile-header-root {
    position: relative;
  }

  .site-header-mobile {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    padding: calc(0.5rem + var(--safe-top)) max(0.75rem, var(--safe-right)) 0.5rem max(0.75rem, var(--safe-left));
    pointer-events: none;
  }

  .mobile-header-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    pointer-events: auto;
    background: var(--shell-bg);
    border: 1px solid var(--shell-border);
    border-radius: 0.75rem;
    padding: 0.125rem 0.25rem 0.125rem 0.125rem;
    backdrop-filter: blur(18px) saturate(1.2);
    box-shadow: 0 8px 28px var(--shadow-elevated);
  }

  .mobile-header-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: var(--text-primary);
  }

  .mobile-header-logo {
    width: 2rem;
    height: 2rem;
    object-fit: contain;
    flex-shrink: 0;
  }

  .mobile-header-title {
    font-family: Syne, 'DM Sans', system-ui, sans-serif;
    font-weight: 700;
    font-size: 0.875rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  @media (max-width: 380px) {
    .mobile-header-title {
      display: none;
    }

    .mobile-header-brand {
      flex: 0;
    }
  }

  .mobile-header-actions {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    flex-shrink: 0;
  }

  /* Full-screen menu portal — sibling of header, not inside backdrop-filter bar */
  .mobile-nav-portal {
    position: fixed;
    inset: 0;
    z-index: 10001;
    pointer-events: none;
  }

  .mobile-nav-portal.is-open {
    pointer-events: auto;
  }

  .mobile-nav-backdrop {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: var(--overlay-scrim);
    opacity: 0;
    transition: opacity 0.2s ease;
  }

  .mobile-nav-portal.is-open .mobile-nav-backdrop {
    opacity: 1;
  }

  .mobile-nav-drawer {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 2;
    width: min(20rem, 88vw);
    max-width: 100%;
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--shell-bg-solid);
    border-right: 1px solid var(--shell-border);
    box-shadow: 12px 0 48px var(--shadow-elevated);
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    padding-bottom: var(--safe-bottom);
    overflow: hidden;
  }

  .mobile-nav-portal.is-open .mobile-nav-drawer {
    transform: translateX(0);
  }

  .mobile-nav-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-shrink: 0;
    padding: calc(0.75rem + var(--safe-top)) 0.75rem 0.75rem 1rem;
    border-bottom: 1px solid var(--shell-border);
  }

  .mobile-nav-drawer-title {
    font-family: Syne, 'DM Sans', system-ui, sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
  }

  .mobile-nav-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem 0.75rem 1.5rem;
  }

  .mobile-nav-link {
    display: flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--mobile-text);
    text-decoration: none;
    touch-action: manipulation;
  }

  .mobile-nav-link.is-active,
  .mobile-nav-link:hover {
    color: var(--text-primary);
    background: rgba(139, 122, 168, 0.14);
  }

  .mobile-nav-accordion-trigger,
  .mobile-nav-subtrigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 2.75rem;
    padding: 0 0.75rem;
    border: none;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--mobile-text);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    touch-action: manipulation;
  }

  .mobile-nav-chevron {
    width: 1rem;
    height: 1rem;
    color: var(--ink-faint);
    flex-shrink: 0;
    transition: transform 0.2s ease;
  }

  .mobile-nav-chevron.is-open {
    transform: rotate(180deg);
  }

  .mobile-nav-accordion-body,
  .mobile-nav-subbody {
    padding: 0.25rem 0 0.5rem 0.75rem;
  }

  .mobile-nav-accordion-body[hidden],
  .mobile-nav-subbody[hidden] {
    display: none !important;
  }

  .mobile-nav-sublink {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--ink-muted);
    text-decoration: none;
    border-radius: 0.375rem;
    line-height: 1.35;
  }

  .mobile-nav-sublink:hover,
  .mobile-nav-sublink--accent {
    color: var(--accent-soft);
  }

  .mobile-nav-subscribe {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 2.75rem;
    padding: 0 0.75rem;
    margin: 0.125rem 0 0.25rem;
    border-radius: 0.5rem;
    background: rgba(139, 122, 168, 0.12);
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-weight: 600;
    text-decoration: none;
    touch-action: manipulation;
  }

  .mobile-nav-subscribe:hover,
  .mobile-nav-subscribe.is-active {
    color: var(--text-primary);
    background: rgba(139, 122, 168, 0.2);
  }

  .mobile-nav-subscribe-tag {
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent-soft);
  }

  .mobile-nav-count {
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--ink-faint);
    background: var(--surface-hover);
    padding: 0.1rem 0.35rem;
    border-radius: 9999px;
  }

  .mobile-nav-footer {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--shell-border-subtle);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  .mobile-nav-footer-link {
    min-height: 2.75rem;
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    color: var(--accent-soft);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
  }

  /* ——— Mobile context (replaces side rails) ——— */
  .mobile-context-panel {
    margin-bottom: 1.25rem;
  }

  .mobile-context-strip,
  .mobile-context-details,
  .mobile-home-updates {
    margin-bottom: 0.75rem;
  }

  .mobile-context-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--mobile-text-faint);
    margin: 0 0 0.5rem;
  }

  .mobile-context-chips {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-context-chips::-webkit-scrollbar {
    display: none;
  }

  .mobile-context-chip {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    min-height: 2.25rem;
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: none;
    background: var(--surface-hover);
    border: 1px solid var(--shell-border);
    touch-action: manipulation;
  }

  .mobile-context-chip.is-active,
  .mobile-context-chip--accent {
    color: var(--text-primary);
    border-color: rgba(167, 139, 250, 0.35);
    background: rgba(139, 122, 168, 0.16);
  }

  .mobile-context-details {
    border-radius: 0.75rem;
    border: 1px solid var(--shell-border);
    background: var(--surface-muted);
    overflow: hidden;
  }

  .mobile-context-summary {
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    list-style: none;
    touch-action: manipulation;
  }

  .mobile-context-summary::-webkit-details-marker {
    display: none;
  }

  .mobile-context-body {
    padding: 0 1rem 1rem;
  }

  .mobile-wiki-section + .mobile-wiki-section {
    margin-top: 0.75rem;
  }

  .mobile-wiki-section-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
    margin: 0 0 0.35rem;
  }

  .mobile-home-updates {
    padding: 1rem;
  }

  .mobile-home-updates-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.35rem;
  }

  .mobile-home-updates-more {
    font-size: 0.75rem;
    color: var(--accent-soft);
    text-decoration: none;
  }

  .mobile-home-updates-block + .mobile-home-updates-block {
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--shell-border-subtle);
  }

  .mobile-home-updates-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .mobile-home-updates-link {
    display: block;
    padding: 0.45rem 0;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    text-decoration: none;
    line-height: 1.35;
  }

  .mobile-home-updates-tag {
    display: inline-block;
    margin-right: 0.35rem;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--accent-soft);
  }

  /* ——— Homepage ——— */
  .hero-headline {
    font-size: clamp(1.75rem, 8vw, 2.5rem) !important;
  }

  /* ——— Product detail ——— */
  .product-header-main {
    flex-direction: column !important;
    align-items: flex-start !important;
  }

  .product-header-icon {
    align-self: center;
  }

  /* ——— Cart sticky checkout ——— */
  .mobile-cart-footer {
    position: sticky;
    bottom: 0;
    z-index: 10;
    margin: 1.5rem calc(-1 * max(1rem, var(--safe-left))) 0;
    padding: 1rem max(1rem, var(--safe-right)) calc(1rem + var(--safe-bottom)) max(1rem, var(--safe-left));
    background: var(--shell-bg);
    border-top: 1px solid var(--shell-border-subtle);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .mobile-cart-footer .btn-primary {
    width: 100%;
    min-height: 2.75rem;
  }

  /* ——— Search modal (mobile) ——— */
  .search-modal {
    z-index: 110;
  }

  .search-modal-panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding:
      calc(0.75rem + var(--safe-top))
      max(1rem, var(--safe-right))
      max(1rem, var(--safe-bottom))
      max(1rem, var(--safe-left));
  }

  .search-modal-card {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 1rem;
    border-radius: 1rem;
  }

  .search-modal-input-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .search-modal-field {
    position: relative;
    flex: 1;
    min-width: 0;
  }

  .search-modal-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.125rem;
    height: 1.125rem;
    color: var(--ink-faint);
    pointer-events: none;
  }

  .search-modal-input {
    width: 100%;
    min-height: 2.75rem;
    padding-left: 2.5rem !important;
    font-size: 1rem;
  }

  .search-modal-close {
    flex-shrink: 0;
  }

  .search-modal-results {
    list-style: none;
    margin: 0.75rem 0 0;
    padding: 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .search-modal-result {
    display: block;
    padding: 0.7rem 0.75rem;
    font-size: 0.9375rem;
    color: var(--mobile-text);
    text-decoration: none;
    border-radius: 0.5rem;
    line-height: 1.35;
    touch-action: manipulation;
  }

  .search-modal-result:hover,
  .search-modal-result:focus-visible {
    color: var(--text-primary);
    background: var(--surface-hover);
  }

  .search-modal-result-type {
    display: inline-block;
    margin-left: 0.35rem;
    font-size: 0.6875rem;
    color: var(--ink-faint);
    text-transform: capitalize;
  }

  .search-modal-empty {
    padding: 0.75rem;
    font-size: 0.875rem;
    color: var(--ink-muted);
  }

  .search-modal-hint {
    flex-shrink: 0;
    margin: 0.75rem 0 0;
    font-size: 0.75rem;
    text-align: center;
    color: var(--ink-faint);
  }

  .search-modal-hint--desktop {
    display: none;
  }

  .search-modal-hint--mobile {
    display: block;
  }

  /* ——— Cookie banner ——— */
  #cookie-banner {
    left: max(1rem, var(--safe-left)) !important;
    right: max(1rem, var(--safe-right)) !important;
    bottom: calc(1rem + var(--safe-bottom)) !important;
    max-width: none !important;
  }

  #cookie-banner .btn-primary {
    width: 100%;
    min-height: 2.75rem;
  }

  /* ——— Discord FAB ——— */
  .discord-fab {
    bottom: calc(1rem + var(--safe-bottom)) !important;
    right: max(1rem, var(--safe-right)) !important;
  }

  /* ——— Support layout ——— */
  .support-shell--chat {
    grid-template-columns: 1fr !important;
  }

  .support-sidebar {
    display: none !important;
  }

  .support-page {
    max-width: 100% !important;
  }

  .support-page .glass-panel {
    padding: 1rem !important;
  }

  .support-page input,
  .support-page select,
  .support-page textarea {
    font-size: 1rem !important;
  }

  .support-page .btn-primary,
  .support-page .btn-outline {
    width: 100%;
    min-height: 2.75rem;
    justify-content: center;
  }

  .support-thread-header h2 {
    overflow-wrap: anywhere;
  }

  .support-aside {
    margin-top: 0.25rem;
  }

  .support-aside-links {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
  }

  .support-aside-link {
    min-height: 2.75rem;
  }

  .suggestion-history-head {
    flex-direction: column;
    align-items: flex-start !important;
  }

  .suggestion-history-badges {
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: wrap;
  }

  /* ——— Product category filters ——— */
  .product-category-filters {
    display: flex;
    gap: 0.5rem;
    margin: 0 0 1rem;
    padding-bottom: 0.15rem;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .product-category-filters::-webkit-scrollbar {
    display: none;
  }

  .product-category-chip {
    flex-shrink: 0;
    scroll-snap-align: start;
    display: inline-flex;
    align-items: center;
    min-height: 2.5rem;
    padding: 0 0.9rem;
    border-radius: 9999px;
    border: 1px solid var(--shell-border);
    background: var(--inset-panel-bg);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
  }

  .product-category-chip.is-active {
    color: var(--text-primary);
    border-color: rgba(167, 139, 250, 0.35);
    background: rgba(107, 91, 138, 0.2);
  }

  .products-page {
    max-width: 100%;
  }

  .products-page.max-w-content {
    padding-left: 0;
    padding-right: 0;
  }

  /* ——— Auth + account ——— */
  .auth-page,
  .account-page {
    width: 100%;
  }

  .auth-form input,
  .auth-form select,
  .auth-form textarea,
  .account-page input,
  .account-page select,
  .account-page textarea {
    font-size: 1rem !important;
  }

  .auth-submit,
  .account-page .btn-primary,
  .account-page .btn-outline {
    min-height: 2.75rem;
  }

  .account-page-header {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
  }

  .account-logout-btn {
    width: 100%;
    min-height: 2.75rem;
    justify-content: center;
  }

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

  .theme-settings-options {
    grid-template-columns: 1fr !important;
  }

  .theme-settings-card {
    min-height: 3.25rem;
  }

  /* ——— Checkout success ——— */
  .checkout-success-page {
    min-height: calc(100svh - 8rem);
    display: flex;
    align-items: flex-start;
    padding-top: 0.5rem;
  }

  .checkout-success-card {
    width: 100%;
    padding: 1.25rem !important;
  }

  .checkout-success-cta {
    width: 100%;
    min-height: 2.75rem;
    justify-content: center;
  }

  /* ——— Wiki mobile TOC + prose ——— */
  .wiki-article {
    padding: 1rem !important;
  }

  .wiki-mobile-toc {
    margin-bottom: 1rem;
    border: 1px solid var(--shell-border);
    border-radius: 0.75rem;
    background: var(--inset-panel-bg);
    overflow: hidden;
  }

  .wiki-mobile-toc-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 2.75rem;
    padding: 0.75rem 0.9rem;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
  }

  .wiki-mobile-toc-toggle svg {
    transition: transform 0.18s ease;
  }

  .wiki-mobile-toc-toggle[aria-expanded='true'] svg {
    transform: rotate(180deg);
  }

  .wiki-mobile-toc-list {
    list-style: none;
    margin: 0;
    padding: 0 0.75rem 0.75rem;
    display: none;
    flex-direction: column;
    gap: 0.35rem;
  }

  .wiki-mobile-toc-list.is-open {
    display: flex;
  }

  .wiki-mobile-toc-link {
    display: block;
    padding: 0.45rem 0.55rem;
    border-radius: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    text-decoration: none;
  }

  .wiki-mobile-toc-link.is-sub {
    padding-left: 1.1rem;
    font-size: 0.75rem;
  }

  .wiki-prose-body pre,
  .prose-wiki pre {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .wiki-prose-body table,
  .prose-wiki table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ——— News / changelogs / FAQ ——— */
  .content-list-page {
    width: 100%;
  }

  .content-list-page .glass-panel {
    padding: 1rem !important;
  }

  .faq-cat-header,
  .faq-item-summary {
    min-height: 2.75rem;
  }

  .faq-answer {
    font-size: 0.9375rem;
    line-height: 1.6;
  }

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

  .changelog-card-media {
    width: 100%;
  }

  /* ——— Modals ——— */
  .confirm-email-shell {
    align-items: flex-start !important;
    padding-top: calc(1rem + var(--safe-top));
    padding-bottom: calc(1rem + var(--safe-bottom));
    overflow-y: auto;
  }

  .confirm-email-card {
    max-height: calc(100svh - 2rem - var(--safe-top) - var(--safe-bottom));
    overflow-y: auto;
    padding: 1.25rem !important;
  }

  .confirm-email-card .btn-primary,
  .confirm-email-card .btn-outline {
    width: 100%;
    min-height: 2.75rem;
    justify-content: center;
  }

  .search-modal-panel {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    width: 100%;
  }

  /* ——— Homepage LCP ——— */
  .hero-logo {
    width: 7rem !important;
    height: 7rem !important;
  }

  /* ——— Overflow fixes ——— */
  .marquee-wrapper,
  .product-description-panel,
  .product-header-main,
  .wiki-article,
  .content-list-page {
    max-width: 100%;
  }

  .product-description-panel {
    padding: 1rem !important;
  }

  /* ——— Product grids ——— */
  .product-grid {
    grid-template-columns: 1fr !important;
  }

  .product-marquee-track {
    animation-duration: 40s;
  }

  @media (prefers-reduced-motion: reduce) {
    .product-marquee-track {
      animation: none !important;
    }
  }

  html[data-theme='light'] .site-header-mobile {
    background: transparent;
  }

  html[data-theme='light'] .mobile-header-bar {
    background: rgba(255, 255, 255, 0.94);
    border-color: rgba(18, 16, 26, 0.1);
  }

  html[data-theme='light'] .mobile-header-title {
    color: var(--text-primary);
  }

  html[data-theme='light'] .mobile-nav-drawer {
    background: rgba(255, 255, 255, 0.98);
    border-right-color: rgba(18, 16, 26, 0.1);
  }

  html[data-theme='light'] .mobile-nav-link,
  html[data-theme='light'] .mobile-nav-accordion-trigger,
  html[data-theme='light'] .mobile-nav-subtrigger {
    color: rgba(18, 16, 26, 0.82);
  }

  html[data-theme='light'] .mobile-context-chip {
    color: rgba(18, 16, 26, 0.72);
    background: rgba(18, 16, 26, 0.04);
    border-color: rgba(18, 16, 26, 0.1);
  }
}
