/* Phone layouts share the same content, navigation and commerce flows. */
.mobile-chat-back { display: none; }
.chat-empty { padding: 20px 16px; color: var(--m9-muted); font-size: 0.875rem; }

@media (max-width: 820px) {
  :root { --phone-nav: 68px; --phone-bottom: env(safe-area-inset-bottom, 0px); }
  body { padding-bottom: calc(var(--phone-nav) + var(--phone-bottom)); }
  main, body:has(#view-shop.is-active) main { width: 100%; padding: 12px 12px 28px; }
  main > .view, .product-main, .shop-main, .wallet-dashboard, .wallet-primary { min-width: 0; max-width: 100%; }
  button, a, input, select { touch-action: manipulation; }
  input:not([type="checkbox"]):not([type="radio"]), textarea, select { font-size: 1.0rem; }
  .topbar { padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right)); }
  .top-actions { gap: 8px; }
  .header-search-btn, .cart-btn, .avatar { width: 44px; height: 44px; flex-shrink: 0; }
  .search-shell { width: 44px; flex-basis: 44px; }
  .header-search-panel .searchbox input { font-size: 1.0rem; }
  .header-search-panel { max-height: calc(100dvh - 160px); }
  .mobile-nav { height: calc(var(--phone-nav) + var(--phone-bottom)); padding: 6px max(4px, env(safe-area-inset-right)) calc(6px + var(--phone-bottom)) max(4px, env(safe-area-inset-left)); }
  .mobile-nav button { min-width: 0; min-height: 48px; font-size: 0.8125rem; line-height: 1.4; gap: 4px; white-space: nowrap; }
  .mobile-nav .m9-icon-slot { width: 22px; height: 22px; }
  .section-heading, .home-section-head, .panel-head { gap: 8px; flex-wrap: wrap; }
  .section-heading h2, .home-section-head h2 { font-size: 1.0rem; line-height: 1.5; }
  .tiny-link, .home-section-head > button { min-height: 44px; font-size: 0.875rem; flex-shrink: 0; }
  .filter-chips, .result-tabs, .order-tabs { max-width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .filter-chips button, .result-tabs button, .order-tabs button { flex-shrink: 0; min-height: 44px; }
  .site-footer { min-height: 0; padding: 24px 16px; grid-template-columns: minmax(0, 1fr) 130px; gap: 16px; }
  .site-footer > .footer-brand { grid-column: 1 / -1; grid-row: 1; }
  .site-footer > .footer-links { grid-column: 1; grid-row: 2; }
  .site-footer .footer-mascot { grid-column: 2; grid-row: 2; width: 130px; height: 156px; }
  .site-footer p { font-size: 0.8125rem; line-height: 1.65; }
  .site-footer button { min-height: 44px; font-size: 0.875rem; text-align: left; }
  .toast { bottom: calc(var(--phone-nav) + var(--phone-bottom) + 12px); width: max-content; max-width: calc(100% - 24px); white-space: normal; text-align: center; border-radius: var(--m9-radius-xl); font-size: 0.875rem; }

  /* Home and TV: carousel cards keep their own readable width. */
  .market-hero { min-height: 510px; padding: 150px 18px 18px; display: flex; flex-direction: column; justify-content: flex-end; gap: 20px; }
  .market-hero-copy { position: relative; inset: auto; width: 100%; transform: none; }
  .market-hero h1 { font: var(--m9-type-page-title); line-height: 1.18; letter-spacing: -.025em; }
  .market-hero-copy > p { font-size: 1.0rem; line-height: 1.6; }
  .hero-kicker { font-size: 0.75rem; letter-spacing: .06em; }
  .hero-actions { flex-direction: column; align-items: stretch; gap: 10px; }
  .hero-actions .btn { width: 100%; min-height: 48px; font-size: 0.875rem; padding: 10px 14px; }
  .hero-shop-card { position: relative; inset: auto; width: 100%; grid-template-columns: 64px minmax(0, 1fr); padding: 12px; gap: 10px; }
  .hero-shop-card img { width: 64px; height: 64px; }
  .hero-shop-card b { font-size: 0.875rem; line-height: 1.5; }
  .hero-shop-card button { grid-column: 1 / -1; min-height: 44px; }
  .journey-strip { grid-template-columns: 1fr; gap: 8px; }
  .journey-strip > button { min-height: 76px; }
  .journey-strip b { font-size: 0.875rem; }
  .journey-strip small { font-size: 0.8125rem; }
  .home-section { margin-top: 24px; }
  .split-head { grid-template-columns: minmax(0, 1fr) auto; }
  .split-head .filter-chips { grid-column: 1 / -1; grid-row: 2; }
  .channel-strip, .home-channel-row, .home-show-row, .merchant-row, .home-live-row, .poster-grid {
    display: grid; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 176px; gap: 12px;
    overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; padding-bottom: 8px;
  }
  .channel-strip { grid-auto-columns: 144px; }
  .home-channel-row { grid-auto-columns: 168px; }
  .merchant-row, .home-live-row { grid-auto-columns: 240px; }
  .channel-strip > *, .home-channel-row > *, .home-show-row > *, .merchant-row > *, .home-live-row > *, .poster-grid > * { min-width: 0; scroll-snap-align: start; }
  .mini-channel { min-height: 196px; padding: 26px 12px 14px; gap: 12px; }
  .mini-channel div { width: 100%; min-width: 0; gap: 4px; }
  .mini-channel b { font-size: 0.875rem; line-height: 1.5; }
  .mini-channel small { font-size: 0.8125rem; line-height: 1.6; overflow-wrap: anywhere; }
  .mini-channel em { font-size: 0.75rem; }
  .home-channel-card { min-height: 225px; text-align: center; gap: 4px; }
  .home-channel-card > b { font-size: 1.0rem; }
  .home-channel-card > small { font-size: 0.8125rem; }
  .home-channel-card > button { min-height: 44px; margin-top: 8px; }
  .home-show-card { min-height: 270px; }
  .home-show-card b { font-size: 1.0rem; line-height: 1.5; }
  .tv-feature { min-height: 470px; padding: 130px 18px 18px; display: flex; flex-direction: column; justify-content: flex-end; gap: 20px; }
  .tv-feature > * { opacity: 1; }
  .tv-feature-copy { position: relative; inset: auto; max-width: none; transform: none; }
  .tv-feature-copy h1 { font: var(--m9-type-page-title); line-height: 1.4; letter-spacing: -.02em; }
  .tv-feature-copy p { font-size: 1.0rem; line-height: 1.6; }
  .video-commerce-pin { position: relative; inset: auto; width: 100%; min-height: 90px; }
  .video-commerce-pin b { font-size: 0.875rem; line-height: 1.5; }
  .video-commerce-pin small { font-size: 0.8125rem; }
  .watch-row, .continuity-grid { scroll-snap-type: x proximity; overscroll-behavior-x: contain; padding-bottom: 8px; }
  .watch-card, .continue-card { flex: 0 0 min(80%, 340px); scroll-snap-align: start; }
  .watch-card > div { height: auto; aspect-ratio: 16 / 9; }
  .watch-card b { font-size: 1.0rem; line-height: 1.5; }
  .watch-card small { font-size: 0.875rem; }
  .tv-main .poster-card { min-height: 260px; }
  .tv-main .poster-card .poster-image { aspect-ratio: 2 / 3; }
  .tv-main .poster-info { left: 12px; right: 12px; bottom: 12px; }
  .tv-main .poster-info b { font-size: 1.0rem; line-height: 1.5; }
  .tv-main .poster-info small { font-size: 0.8125rem; }
  .tv-main .poster-badge, .tv-main .poster-quality { font-size: 0.75rem; }

  /* Shorts fills the available viewport; controls occupy separate zones. */
  body:has(#view-shorts.is-active) main { padding: 0; }
  body:has(#view-shorts.is-active) .site-footer { display: none; }
  .shorts-view.is-active { gap: 0; }
  .short-phone { width: 100%; height: calc(100dvh - 64px - var(--phone-nav) - var(--phone-bottom)); min-height: 480px; max-height: none; aspect-ratio: auto; border-radius: 0; box-shadow: var(--m9-shadow-surface); }
  .short-copy { left: 16px; right: 76px; bottom: 126px; }
  .short-copy p { font-size: 0.875rem; line-height: 1.5; }
  .creator-line { flex-wrap: wrap; }
  .creator-line strong { font-size: 0.875rem; }
  .creator-line button { min-height: 36px; }
  .short-actions { right: 10px; bottom: 126px; gap: 10px; }
  .short-actions button { min-width: 48px; min-height: 58px; }
  .shop-scene-card { left: 16px; right: 76px; bottom: 18px; min-height: 92px; gap: 3px; }
  .shop-scene-card b { font-size: 0.875rem; line-height: 1.5; }
  .shop-scene-card span, .shop-scene-card small { font-size: 0.75rem; letter-spacing: 0; }
  .short-switcher { left: 16px; right: auto; top: 68px; display: flex; gap: 8px; }
  .short-switcher button { width: 44px; height: 44px; }

  /* Shop keeps two product columns and independent horizontal carousels. */
  .shop-utility { gap: 8px; }
  .shop-utility > div { flex-wrap: wrap; gap: 8px 14px; }
  .shop-utility button { min-height: 44px; font-size: 0.875rem !important; }
  .market-campaign-grid { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
  .primary-campaign { grid-column: 1 / -1; grid-row: auto; min-height: 250px; padding: 24px 18px; }
  .primary-campaign > div:first-child { width: 75%; }
  .primary-campaign h2 { font: var(--m9-type-page-title); line-height: 1.4; }
  .primary-campaign p { font-size: 0.875rem; line-height: 1.6; }
  .primary-campaign button { min-height: 44px; }
  .mini-campaign { min-height: 124px; padding: 14px 12px; }
  .mini-campaign > b { font-size: 1.0rem; }
  .mini-campaign > span, .mini-campaign small { font-size: 0.75rem; }
  .shop-shortcuts { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px 6px; padding: 18px 8px; }
  .shop-shortcut { font-size: 0.8125rem !important; overflow-wrap: anywhere; }
  .shop-shortcut > span:first-child { width: 44px; height: 44px; }
  .market-section-head { flex-wrap: wrap; gap: 8px; padding: 12px; }
  .market-section-head > button { min-height: 44px; font-size: 0.875rem !important; }
  .category-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: minmax(160px, auto); }
  .category-tile { padding: 12px 4px; font-size: 0.875rem !important; }
  .category-tile .category-photo { width: 62px; height: 62px; }
  .category-tile > b { line-height: 1.5; min-height: 48px; }
  .flash-grid, .popular-grid { grid-auto-columns: 156px; scroll-snap-type: x proximity; }
  .flash-grid > *, .popular-grid > *, .shop-live-grid > * { scroll-snap-align: start; }
  .flash-heading { flex-wrap: wrap; }
  .official-body { grid-template-columns: 1fr; }
  .official-editorial { min-height: 150px; }
  .official-editorial img { width: 120px; height: 120px; left: auto; right: 12px; bottom: 12px; }
  .official-products { display: grid; grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 156px; overflow-x: auto; }
  .official-product:nth-child(n) { display: grid; }
  .shop-live-grid { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: 190px; overflow-x: auto; }
  .catalog-toolbar { margin: 12px; }
  .sort-buttons { display: flex; gap: 6px; width: 100%; overflow-x: auto; }
  .sort-buttons button { min-height: 44px; flex-shrink: 0; font-size: 0.875rem !important; }
  .catalog-toolbar select, .catalog-filter-button { min-height: 44px; }
  .catalog-toolbar select { width: auto; max-width: 100%; font-size: 1.0rem; }
  .catalog-subcategories { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .catalog-subcategories button { flex-shrink: 0; min-height: 44px; }
  .catalog-filters { padding: 14px; }
  .catalog-filters button, .catalog-filters label { min-height: 44px; }
  #view-shop .catalog-layout .product-grid, #view-shop .recommended-products { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  #view-shop .product-card { min-width: 0; min-height: 0; padding: 8px; }
  #view-shop .product-store { flex-wrap: wrap; }
  #view-shop .product-card h3 { font-size: 0.875rem; line-height: 1.5; min-height: 42px; }
  #view-shop .product-price { justify-content: flex-start; }
  #view-shop .add-cart { min-width: 44px; min-height: 44px; flex-shrink: 0; }
  #view-shop .save-product { width: 36px; height: 36px; }
  #view-shop .rating-line { flex-wrap: wrap; }
  #view-shop .store-program-grid, #view-shop .store-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px; }
  #view-shop .store-card { min-width: 0; grid-template-columns: 1fr; padding: 12px; }
  #view-shop .store-card .store-stats { flex-wrap: wrap; }
  #view-shop .store-card button { min-height: 44px; }
  .catalog-load-more { min-height: 48px; }

  /* Chat switches between the inbox and a full conversation. */
  body:has(#view-chat.is-active) .site-footer { display: none; }
  body:has(#view-chat.is-active) main { padding: 12px; }
  #view-chat.commerce-chat.is-active { height: calc(100dvh - 64px - var(--phone-nav) - var(--phone-bottom) - 24px); min-height: 320px; display: flex; flex-direction: column; overflow: hidden; }
  #view-chat .chat-nav { flex-shrink: 0; padding: 8px; }
  #view-chat .chat-nav-link { min-height: 44px; font-size: 0.875rem; }
  #view-chat .conversation-list { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 12px 0; }
  #view-chat .conversation-search { display: flex; min-height: 44px; }
  #view-chat .conversation-tabs { display: flex; }
  #conversationList { display: block; }
  #view-chat .conversation-item { width: 100%; min-height: 80px; padding: 12px; grid-template-columns: 44px minmax(0, 1fr) auto; border: 0; border-bottom: 1px solid var(--m9-line); border-radius: 0; }
  #view-chat .conversation-item b { font-size: 1.0rem; }
  #view-chat .conversation-item small { font-size: 0.875rem; }
  #view-chat .conversation-meta { display: grid; font-size: 0.75rem; }
  #view-chat .conversation-room { display: none; min-height: 0; flex: 1; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
  #view-chat.is-room-open .chat-nav, #view-chat.is-room-open .conversation-list { display: none; }
  #view-chat.is-room-open .conversation-room { display: grid; }
  .room-head { padding: 8px; min-height: 74px; gap: 8px; }
  .room-head > div:nth-child(2) { min-width: 0; }
  .room-head h2 { max-width: none; font-size: 1.0rem; line-height: 1.5; }
  .room-head span { font-size: 0.75rem; line-height: 1.5; }
  .room-avatar { flex-shrink: 0; width: 36px; height: 36px; }
  .mobile-chat-back { order: -1; display: grid; place-items: center; flex: 0 0 44px; width: 44px; height: 44px; color: var(--m9-navy); background: var(--m9-surface-secondary); border: 0; border-radius: var(--m9-radius-pill); }
  .mobile-chat-back .m9-icon { width: 22px; height: 22px; }
  .message-stream { overflow-y: auto; padding: 16px 12px; overscroll-behavior-y: contain; }
  .message-group { max-width: 94%; }
  .message-group > div { min-width: 0; }
  .message-bubble { font-size: 0.875rem; line-height: 1.6; overflow-wrap: anywhere; }
  .message-composer { min-height: 64px; padding: 8px; gap: 6px; background: var(--m9-on-primary); }
  .message-composer > button:not(.send-message) { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; height: 44px; }
  .message-composer > button[data-toast] { display: none; }
  .message-composer input { font-size: 1.0rem; height: 44px; padding: 0 12px; }
  .message-composer .send-message { flex: 0 0 44px; width: 44px; height: 44px; padding: 0; }
  body:has(#messageInput:focus) .mobile-nav { display: none; }
  body:has(#messageInput:focus) #view-chat.commerce-chat.is-active { height: calc(100dvh - 88px); }

  /* Wallet and overlays expand naturally as text wraps. */
  .wallet-hero { min-height: 0; padding: 24px 20px; }
  .wallet-balance { position: relative; inset: auto; width: 100%; padding: 0; }
  .wallet-balance > strong { font: var(--m9-type-page-title); overflow-wrap: anywhere; }
  .wallet-balance > span { font-size: 0.875rem; line-height: 1.5; }
  .wallet-substats b { font-size: 1.0rem; line-height: 1.5; }
  .quick-actions { gap: 10px; }
  .quick-actions button { min-width: 0; padding: 14px 6px; min-height: 100px; }
  .quick-actions b { font-size: 0.875rem; }
  .quick-actions button > em { top: 3px; font-size: 0.75rem; }
  .quick-actions button.recommended { padding-top: 26px; }
  .wallet-services .service-grid > button { min-height: 0; padding: 18px; display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 4px 14px; }
  .wallet-services .service-grid > button > span { grid-column: 1; grid-row: 1 / 4; margin: 0; align-self: start; }
  .wallet-services .service-grid > button > b, .wallet-services .service-grid > button > small, .wallet-services .service-grid > button > em { grid-column: 2; }
  .wallet-services .service-grid > button > em { justify-self: start; margin-top: 8px; min-height: 44px; }
  .transaction-panel, .security-standard { padding: 18px; }
  .transaction-item { grid-template-columns: 36px minmax(0, 1fr); gap: 8px; }
  .transaction-amount { grid-column: 2; justify-self: start; }
  .modal-layer { padding: 0; align-items: end; }
  .modal-card, .modal-card.modal-wide { width: 100%; max-height: calc(100dvh - 12px); border-radius: var(--m9-radius-2xl) var(--m9-radius-2xl) 0 0; overscroll-behavior-y: contain; padding-bottom: var(--phone-bottom); }
  .modal-close { position: sticky; top: 10px; display: grid; place-items: center; margin: 10px 10px 0 auto; z-index: 10; width: 44px; height: 44px; background: var(--m9-on-primary); }
  #modalContent { min-width: 0; }
  .side-sheet { width: 100%; height: 100dvh; }
  .side-sheet > header { min-height: 72px; padding: 14px 16px; }
  .side-content { padding: 16px 16px calc(20px + var(--phone-bottom)); overscroll-behavior-y: contain; }
  .pdp { padding: 14px 16px 24px; grid-template-columns: minmax(0, 1fr); }
  .pdp-main-image { min-height: 0; aspect-ratio: 1; }
  .pdp h2 { font-size: 1.25rem; line-height: 1.5; }
  .pdp-price, .pdp-rating, .detail-line { flex-wrap: wrap; }
  .seller-summary { grid-template-columns: 44px minmax(0, 1fr); }
  .seller-summary button { grid-column: 1 / -1; min-height: 44px; }
  .result-tools, .order-card-head { flex-wrap: wrap; gap: 8px; }
  .pdp-actions { grid-template-columns: 1fr; }
  .pdp-actions button { min-height: 48px; }
  .cart-line-actions { flex-wrap: wrap; gap: 10px; }
  .quantity-control button { min-width: 44px; min-height: 44px; }
  .cart-summary { bottom: calc(-20px - var(--phone-bottom)); margin: 16px -16px calc(-20px - var(--phone-bottom)); padding: 16px 16px calc(20px + var(--phone-bottom)); }
  .checkout-nav, .order-actions, .modal-actions { flex-wrap: wrap; }
  .checkout-nav button, .order-actions button, .modal-actions button { min-height: 44px; }
  .form-grid input, .form-grid textarea { min-width: 0; width: 100%; font-size: 1.0rem; }
  .checkout, .order-hub, .search-results, .settings-modal, .store-guide, .return-flow { padding: 16px 16px 24px; }
  .checkout h2, .order-hub h2, .settings-modal h2, .store-guide h2, .search-results h2 { clear: both; font-size: 1.25rem; line-height: 1.5; }
  .player-stage { min-height: 0; height: auto; aspect-ratio: auto; padding-top: 56.25%; }
  .player-stage > img { height: auto; aspect-ratio: 16 / 9; }
  .player-stage::after { display: none; }
  .player-controls { position: relative; inset: auto; padding: 16px; background: var(--m9-brand-navy); }
  .player-controls h2 { font-size: 1.25rem; line-height: 1.5; }
  .player-controls p { font-size: 0.875rem; line-height: 1.6; }
  .player-control-row button { flex: 0 0 44px; width: 44px; height: 44px; }
  .player-side-commerce { max-height: none; }
}

@media (max-width: 560px) {
  .mobile-nav button { font-size: 0.75rem; }
  .topbar { grid-template-columns: 96px minmax(0, 1fr); }
  .brand { width: 96px; }
  .primary-campaign > div:first-child { width: 85%; }
  .category-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #view-shop .store-program-grid, #view-shop .store-grid { grid-template-columns: 1fr; }
}
