/* Hallmark · responsive pass · customer surfaces only
 * Loaded after the established visual layers so this file owns mobile geometry,
 * safe areas, touch targets, and containment without changing application flow.
 */

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

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

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

main,
section,
article,
aside,
form,
nav,
[role="dialog"] {
  min-width: 0;
}

:where(button, a, input, select, textarea, [role="button"]):focus-visible {
  outline: 2px solid var(--nv-cyan, #67e8f9);
  outline-offset: 3px;
}

@media (max-width: 900px) {
  :where(button, input, select, textarea, [role="button"]) {
    min-height: 44px;
  }

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

  /* Storefront header: brand/actions, full-width search, then reachable nav. */
  body:has(#marketplace-section) > header.sticky {
    padding-top: env(safe-area-inset-top);
  }

  body:has(#marketplace-section) > header.sticky .nexus-header-inner {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto auto;
    align-items: center;
    gap: 7px 8px;
    width: 100%;
    min-height: 0;
    padding: 8px max(10px, env(safe-area-inset-left)) 8px max(10px, env(safe-area-inset-right)) !important;
  }

  body:has(#marketplace-section) > header.sticky .nexus-brand {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    gap: 7px;
  }

  body:has(#marketplace-section) > header.sticky .nexus-brand-logo {
    width: 44px !important;
    height: 44px !important;
    flex: 0 0 44px;
  }

  body:has(#marketplace-section) > header.sticky .nexus-brand-title {
    max-width: 100%;
    overflow: hidden;
    font-size: clamp(9px, 2.7vw, 12px) !important;
    letter-spacing: .06em !important;
    text-overflow: ellipsis;
  }

  body:has(#marketplace-section) > header.sticky .nexus-header-center {
    display: contents !important;
  }

  body:has(#marketplace-section) > header.sticky .nexus-search {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
  }

  body:has(#marketplace-section) > header.sticky .nexus-search-input {
    width: 100%;
    height: 44px;
    min-height: 44px;
    font-size: 13px;
  }

  body:has(#marketplace-section) > header.sticky .nexus-primary-nav {
    grid-column: 1 / -1;
    grid-row: 3;
    display: flex !important;
    align-items: stretch;
    gap: 4px;
    width: 100%;
    min-width: 0;
    padding-bottom: 1px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  body:has(#marketplace-section) > header.sticky .nexus-primary-nav::-webkit-scrollbar {
    display: none;
  }

  body:has(#marketplace-section) > header.sticky .nexus-nav-link {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 0 9px;
    font-size: 10px;
  }

  body:has(#marketplace-section) > header.sticky .nexus-deck-link {
    display: none !important;
  }

  body:has(#marketplace-section) > header.sticky .nexus-header-actions {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: 0;
    gap: 4px !important;
  }

  body:has(#marketplace-section) > header.sticky .nexus-language {
    display: flex;
    min-width: 0;
  }

  body:has(#marketplace-section) > header.sticky .nexus-language > i {
    display: none;
  }

  body:has(#marketplace-section) > header.sticky .nexus-language select {
    width: 46px;
    min-width: 46px;
    height: 40px;
    padding: 0 3px !important;
    font-size: 9px;
  }

  body:has(#marketplace-section) > header.sticky #auth-buttons > button,
  body:has(#marketplace-section) > header.sticky .nexus-cart-button,
  body:has(#marketplace-section) > header.sticky .nexus-notification-toggle,
  body:has(#marketplace-section) > header.sticky #wishlist-nav-button {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0 !important;
  }

  body:has(#marketplace-section) > header.sticky #auth-buttons > button > span,
  body:has(#marketplace-section) > header.sticky #auth-buttons > button > i + span,
  body:has(#marketplace-section) > header.sticky .nexus-account-copy,
  body:has(#marketplace-section) > header.sticky .nexus-cart-label,
  body:has(#marketplace-section) > header.sticky #wishlist-nav-button > span:nth-child(2) {
    display: none !important;
  }

  body:has(#marketplace-section) > header.sticky #user-info {
    width: 40px;
    max-width: 40px;
    min-height: 40px;
    padding: 0 2px;
  }

  body:has(#marketplace-section) > header.sticky .nexus-account-trigger {
    width: 36px;
    min-height: 36px;
  }

  /* Shop rhythm and the two-column card system. */
  body:has(#marketplace-section) #main-app-content > main {
    width: 100%;
    max-width: none;
    padding: 22px 12px calc(48px + env(safe-area-inset-bottom)) !important;
  }

  body:has(#marketplace-section) .nexus-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: 0;
    padding: 28px 16px 0 !important;
    overflow: hidden;
  }

  body:has(#marketplace-section) .nexus-hero-copy {
    position: relative;
    z-index: 2;
  }

  body:has(#marketplace-section) .nexus-hero h2 {
    max-width: 100%;
    font-size: clamp(2rem, 9vw, 3rem) !important;
    line-height: 1.04;
    overflow-wrap: anywhere;
  }

  body:has(#marketplace-section) .nexus-hero p {
    max-width: 34rem;
    font-size: 12px;
    line-height: 1.65;
  }

  body:has(#marketplace-section) .nexus-hero-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  body:has(#marketplace-section) .nexus-hero-actions > * {
    min-height: 46px;
    padding-inline: 10px;
    text-align: center;
  }

  body:has(#marketplace-section) .nexus-hero-art {
    position: relative;
    right: auto;
    bottom: auto;
    width: 100%;
    min-height: clamp(190px, 55vw, 280px);
    margin-top: -8px;
    opacity: .82;
  }

  body:has(#marketplace-section) .nexus-trust-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
  }

  body:has(#marketplace-section) .nexus-trust-bar > div {
    min-width: 0;
    padding: 10px 8px;
  }

  body:has(#marketplace-section) .nexus-trust-bar strong,
  body:has(#marketplace-section) .nexus-trust-bar small {
    overflow-wrap: anywhere;
  }

  body:has(#marketplace-section) .nexus-trade-terminal {
    align-items: stretch;
    padding: 14px !important;
  }

  body:has(#marketplace-section) .nexus-filter-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  body:has(#marketplace-section) .nexus-filter-field,
  body:has(#marketplace-section) .nexus-filter-field select {
    width: 100%;
    min-width: 0;
  }

  body:has(#marketplace-section) .nexus-filter-field--sort {
    grid-column: 1 / -1;
  }

  body:has(#marketplace-section) #card-list {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }

  body:has(#marketplace-section) #card-list .card-hover {
    min-width: 0;
    padding: 8px !important;
  }

  body:has(#marketplace-section) #card-list .card-hover > div:first-child > div.relative {
    min-height: 0 !important;
    height: auto !important;
    aspect-ratio: 2 / 3;
    padding: 4px !important;
  }

  body:has(#marketplace-section) #card-list .card-hover > div:first-child > div.relative img {
    width: 100%;
    height: 100% !important;
    object-fit: contain;
    transform: none !important;
  }

  body:has(#marketplace-section) #card-list .card-hover h4,
  body:has(#marketplace-section) #card-list .card-hover h3 {
    font-size: 11px !important;
    line-height: 1.3;
  }

  body:has(#marketplace-section) #card-list .card-hover button {
    min-height: 40px;
    padding-inline: 5px;
    font-size: 9px;
  }

  body:has(#marketplace-section) .card-pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
  }

  body:has(#marketplace-section) .card-pagination__button {
    min-width: 40px;
    min-height: 40px;
  }

  /* Wallet and purchase history become readable, stacked records. */
  body:has(#marketplace-section) #rewards-panel {
    padding: 14px !important;
  }

  body:has(#marketplace-section) #purchase-history-list,
  body:has(#marketplace-section) #reward-history-list {
    max-height: min(48dvh, 420px);
  }

  body:has(#marketplace-section) #purchase-history-list > div {
    display: grid;
    gap: 4px;
    padding: 10px !important;
  }

  body:has(#marketplace-section) #purchase-history-list > div > .flex {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  body:has(#marketplace-section) #purchase-history-list button {
    width: 100%;
    min-height: 42px;
  }

  /* Customer modals and checkout: bottom sheets with one clear scroll owner. */
  body:has(#marketplace-section) #auth-modal,
  body:has(#marketplace-section) #access-required-modal,
  body:has(#marketplace-section) #wishlist-modal,
  body:has(#marketplace-section) #card-detail-modal,
  body:has(#marketplace-section) #complaint-modal,
  body:has(#marketplace-section) #guide-modal,
  body:has(#marketplace-section) #discord-modal,
  body:has(#marketplace-section) #security-modal,
  body:has(#marketplace-section) #edit-card-modal {
    align-items: flex-end;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  body:has(#marketplace-section) #cart-modal {
    align-items: flex-end;
    justify-content: stretch;
    padding: 0;
  }

  body:has(#marketplace-section) #cart-modal > .checkout-modal-shell {
    width: 100%;
    max-width: none;
    height: auto;
    max-height: 100dvh;
    min-height: 0;
    padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    border-top: 1px solid var(--nv-line, rgba(103, 232, 249, .25));
    border-left: 0;
    border-radius: 18px 18px 0 0;
  }

  body:has(#marketplace-section) #cart-items-container {
    max-height: 28dvh;
  }

  body:has(#marketplace-section) .checkout-modal-form {
    min-height: 0;
  }

  body:has(#marketplace-section) .checkout-shipping-fields {
    max-height: none;
  }

  body:has(#marketplace-section) #wishlist-modal > div,
  body:has(#marketplace-section) #auth-modal > div,
  body:has(#marketplace-section) #access-required-modal > div,
  body:has(#marketplace-section) #complaint-modal > div,
  body:has(#marketplace-section) #guide-modal > div,
  body:has(#marketplace-section) #discord-modal > div,
  body:has(#marketplace-section) #security-modal > div,
  body:has(#marketplace-section) #edit-card-modal > div {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 20px);
    overflow-y: auto;
  }

  body:has(#marketplace-section) #card-detail-modal:not(.hidden) .card-detail-shell {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 20px);
    padding: 14px !important;
    overflow-y: auto;
  }

  body:has(#marketplace-section) #card-detail-modal:not(.hidden) #detail-card-image {
    height: min(330px, 40dvh) !important;
    max-height: 40dvh;
  }

  body:has(#marketplace-section) .card-detail-navigation {
    display: flex;
    justify-content: space-between;
    gap: 8px;
  }

  body:has(#marketplace-section) .card-detail-navigation__button {
    width: 44px !important;
    min-width: 44px;
    height: 44px !important;
  }

  /* Lucky Spin: keep the game module proportional to its available stage. */
  body:has(#marketplace-section) #spin-wheel-section {
    min-width: 0;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-stage {
    min-height: 0;
    padding: 18px 8px 20px;
    overflow: visible;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-wheel-shell {
    width: min(100%, calc(100vw - 32px), 680px);
    max-width: 100%;
    height: auto;
    aspect-ratio: 1;
    margin-inline: auto;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-wheel {
    width: 100% !important;
    max-width: 100%;
    height: 100% !important;
    aspect-ratio: 1;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-pointer {
    top: clamp(-1.55rem, -4vw, -1rem);
    left: 50%;
    transform: translateX(-50%) !important;
    transform-origin: center top;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-button {
    width: min(100%, 320px);
    min-height: 52px;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-exclusive {
    min-height: 0;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-bottom-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    align-items: stretch;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-list-panel {
    height: auto !important;
    max-height: none !important;
    min-height: 0;
    overflow: visible;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-list-panel > div {
    max-height: none !important;
    overflow: visible;
    scrollbar-width: thin;
  }

  body:has(#marketplace-section) #spin-result-modal:not(.hidden),
  body:has(#marketplace-section) #pack-result-modal:not(.hidden) {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  body:has(#marketplace-section) #spin-result-modal:not(.hidden) .nexus-spin-result-dialog,
  body:has(#marketplace-section) #pack-result-modal:not(.hidden) .pack-result-shell {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 20px);
    overflow-x: hidden;
    overflow-y: auto;
  }

  /* Mystery Pack: responsive stage/result sizing only; lifecycle positioning
     and hidden-state cleanup remain owned by nexus-polish/ui-polish. */
  body:has(#marketplace-section) #mystery-pack-panel {
    overflow: hidden;
  }

  body:has(#marketplace-section) .mystery-pack-section__header {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  body:has(#marketplace-section) .mystery-pack-layout {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body:has(#marketplace-section) .mystery-pack-received-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  body:has(#marketplace-section) #mystery-pack-panel .mystery-pack-opening__stage {
    width: min(380px, calc(100vw - 20px));
    min-height: min(560px, calc(100dvh - 20px));
    max-height: calc(100dvh - 20px);
    padding: 18px;
  }

  body:has(#marketplace-section) #mystery-pack-panel .mystery-pack-opening__pack {
    width: min(142px, 42vw);
  }

  body:has(#marketplace-section) #pack-result-modal.is-nexus-active .pack-result-shell {
    width: min(100%, 1160px);
    max-height: calc(100dvh - 20px);
  }

  /* AI advisor must clear the safe area and the keyboard-visible viewport. */
  body:has(#marketplace-section) .ai-chat-toggle {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    min-width: 48px;
    min-height: 48px;
  }

  body:has(#marketplace-section) .ai-chat-panel {
    right: max(8px, env(safe-area-inset-right));
    bottom: calc(68px + env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
    width: auto;
    max-width: none;
    max-height: min(74dvh, 640px);
    border-radius: 16px;
  }

  body:has(#marketplace-section) .ai-chat-actions button,
  body:has(#marketplace-section) .ai-chat-form button {
    min-width: 44px;
    min-height: 44px;
  }

  body:has(#marketplace-section) .ai-chat-quick-questions button {
    min-height: 36px;
  }

  body:has(#marketplace-section) .ai-chat-messages {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  /* On phones the wheel uses the full viewport-safe width and the read-only
     result panels become a straightforward vertical list. */
  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-wheel-shell {
    width: min(100%, calc(100vw - 24px));
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-stage {
    padding-inline: 0;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-segment span {
    width: clamp(58px, 19vw, 88px);
    min-height: clamp(48px, 15vw, 66px);
    padding: 4px 3px;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-segment b {
    max-width: 100%;
    font-size: clamp(.43rem, 1.9vw, .58rem);
    overflow-wrap: anywhere;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-segment i {
    font-size: clamp(.76rem, 3.6vw, 1rem);
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-wheel-core {
    inset: 32% !important;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-wheel-core strong {
    font-size: clamp(.5rem, 2.1vw, .72rem);
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-wheel-core span {
    font-size: clamp(.34rem, 1.5vw, .48rem);
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-bottom-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-reward-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 359px) {
  body:has(#marketplace-section) > header.sticky .nexus-header-inner {
    padding-inline: 7px !important;
  }

  body:has(#marketplace-section) > header.sticky .nexus-brand-logo {
    width: 36px !important;
    height: 36px !important;
    flex-basis: 36px;
  }

  body:has(#marketplace-section) > header.sticky .nexus-brand-title {
    font-size: 8px !important;
  }

  body:has(#marketplace-section) > header.sticky #auth-buttons > button,
  body:has(#marketplace-section) > header.sticky .nexus-cart-button,
  body:has(#marketplace-section) > header.sticky .nexus-notification-toggle,
  body:has(#marketplace-section) > header.sticky #wishlist-nav-button,
  body:has(#marketplace-section) > header.sticky #user-info {
    width: 36px;
    min-width: 36px;
  }

  body:has(#marketplace-section) .nexus-hero-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  body:has(#marketplace-section) .nexus-trust-bar {
    grid-template-columns: minmax(0, 1fr);
  }

  body:has(#marketplace-section) .nexus-filter-controls {
    grid-template-columns: minmax(0, 1fr);
  }

  body:has(#marketplace-section) .nexus-filter-field--sort {
    grid-column: auto;
  }

  body:has(#marketplace-section) .mystery-pack-received-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-segment span {
    width: 56px;
    min-height: 46px;
    padding: 3px 2px;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-segment b {
    font-size: .42rem;
    line-height: 1.1;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-segment i {
    font-size: .76rem;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-wheel-core strong {
    font-size: .48rem;
  }

  body:has(#marketplace-section) #spin-wheel-section .nexus-spin-wheel-core span {
    font-size: .34rem;
  }
}

/* Deck Lab: maintain the three-workbench areas as a deliberate vertical stack. */
@media (max-width: 767px) {
  body:has(#deck-name-input) > header {
    padding-top: env(safe-area-inset-top);
  }

  body:has(#deck-name-input) > header > div {
    align-items: center;
    flex-wrap: wrap;
    padding: 10px 12px !important;
  }

  body:has(#deck-name-input) > header > div > a {
    min-width: 0;
  }

  body:has(#deck-name-input) > header > div > a > div {
    min-width: 0;
  }

  body:has(#deck-name-input) > header > div > a > div > div:last-child {
    overflow-wrap: anywhere;
  }

  body:has(#deck-name-input) > header #deck-home-btn {
    min-height: 44px;
    padding-inline: 11px;
  }

  body:has(#deck-name-input) > main {
    width: 100%;
    max-width: none;
    padding: 18px 12px calc(36px + env(safe-area-inset-bottom)) !important;
  }

  body:has(#deck-name-input) > main > section:first-child {
    padding: 14px !important;
  }

  body:has(#deck-name-input) #deck-name-input,
  body:has(#deck-name-input) #create-deck-btn,
  body:has(#deck-name-input) #save-deck-btn,
  body:has(#deck-name-input) #deck-select,
  body:has(#deck-name-input) #card-search,
  body:has(#deck-name-input) select,
  body:has(#deck-name-input) input {
    width: 100%;
    min-width: 0;
    min-height: 44px;
  }

  body:has(#deck-name-input) #my-deck-panel {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px;
  }

  body:has(#deck-name-input) #my-deck-panel > section,
  body:has(#deck-name-input) #my-deck-panel > aside {
    padding: 14px !important;
  }

  body:has(#deck-name-input) #card-list {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    max-height: 48dvh;
    gap: 8px !important;
  }

  body:has(#deck-name-input) .card-item img {
    height: auto;
    aspect-ratio: .7;
    object-fit: contain;
  }

  body:has(#deck-name-input) .card-item > div:nth-child(2) {
    padding: 9px !important;
  }

  body:has(#deck-name-input) .card-item button {
    min-height: 40px;
    padding-inline: 4px !important;
    font-size: 9px !important;
  }

  body:has(#deck-name-input) #deck-sections .deck-drop-zone {
    min-width: 0;
  }

  body:has(#deck-name-input) #deck-card-detail-modal,
  body:has(#deck-name-input) #deck-missing-modal,
  body:has(#deck-name-input) #deck-suggestion-viewer {
    align-items: flex-end;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  body:has(#deck-name-input) #deck-card-detail-modal > div {
    max-height: calc(100dvh - 20px);
    padding: 14px !important;
  }

  body:has(#deck-name-input) #deck-card-detail-modal > div > .grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 14px;
  }

  body:has(#deck-name-input) #deck-card-detail-image {
    max-height: 42dvh;
    object-fit: contain;
  }

  body:has(#deck-name-input) .deck-viewer-shell,
  body:has(#deck-name-input) .deck-missing-shell {
    width: 100%;
    max-height: calc(100dvh - 20px);
  }

  body:has(#deck-name-input) .deck-missing-footer {
    align-items: stretch;
  }

  body:has(#deck-name-input) .deck-missing-footer > div:last-child,
  body:has(#deck-name-input) .deck-missing-footer > div:last-child button {
    width: 100%;
  }

  body:has(#deck-name-input) .deck-missing-footer > div:last-child {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 359px) {
  body:has(#deck-name-input) #card-list {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  body:has(#deck-name-input) .deck-missing-footer > div:last-child {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Showcase: keep nav local, collections dense, and dialogs viewport bounded. */
@media (max-width: 767px) {
  .showcase-page {
    min-width: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .showcase-header {
    min-height: 64px;
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  }

  .showcase-brand {
    min-width: 0;
    max-width: calc(100% - 64px);
  }

  .showcase-brand > span:last-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .showcase-header nav {
    justify-content: flex-start;
    gap: 2px;
    padding-bottom: 2px;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .showcase-header nav::-webkit-scrollbar {
    display: none;
  }

  .showcase-header nav a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 8px 10px;
  }

  .showcase-language select {
    min-width: 44px;
    min-height: 40px;
  }

  .showcase-shell {
    width: min(100% - 24px, 600px);
    padding: 28px 0 calc(48px + env(safe-area-inset-bottom));
  }

  .showcase-hero {
    margin-bottom: 26px;
  }

  .showcase-hero h1 {
    font-size: clamp(28px, 10vw, 48px);
    overflow-wrap: anywhere;
  }

  .showcase-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .profile-panel,
  .featured-panel,
  .stats-panel {
    min-width: 0;
    padding: 18px;
  }

  .featured-panel {
    min-height: 0;
    padding: 20px 30px 26px;
  }

  .featured-stage {
    height: min(390px, 92vw);
  }

  .featured-card-wrap {
    width: min(220px, 68vw);
  }

  .magic-circle {
    width: min(280px, 76vw);
    height: min(280px, 76vw);
  }

  .orbit-button {
    width: 44px;
    min-height: 48px;
  }

  .orbit-button--prev { left: 2px; }
  .orbit-button--next { right: 2px; }

  .collection-heading {
    align-items: stretch;
  }

  .collection-heading h2 {
    font-size: 22px;
    overflow-wrap: anywhere;
  }

  .collection-filter-groups {
    display: grid;
    gap: 10px;
  }

  .collection-filters button {
    min-height: 40px;
  }

  .collection-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .showcase-card strong,
  .showcase-card span {
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .showcase-modal {
    align-items: flex-end;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .editor-shell,
  .showcase-detail-shell {
    width: 100%;
    max-height: calc(100dvh - 20px);
    padding: 18px;
  }

  .editor-footer {
    align-items: stretch;
  }

  .editor-footer .showcase-button {
    width: 100%;
    min-height: 44px;
  }
}

@media (max-width: 359px) {
  .collection-cards,
  .editor-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .featured-panel {
    padding-inline: 20px;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  body:has(#marketplace-section) #mystery-pack-panel .mystery-pack-opening__stage {
    min-height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
  }

  body:has(#marketplace-section) #card-detail-modal:not(.hidden) .card-detail-shell,
  body:has(#marketplace-section) #cart-modal > .checkout-modal-shell,
  body:has(#deck-name-input) #deck-card-detail-modal > div,
  .showcase-detail-shell,
  .editor-shell {
    max-height: calc(100dvh - 12px);
  }

  body:has(#marketplace-section) #card-detail-modal:not(.hidden) #detail-card-image {
    height: min(250px, 48dvh) !important;
    max-height: 48dvh;
  }
}

@media (hover: none), (pointer: coarse) {
  #card-list .card-hover:hover,
  #card-list .card-hover:hover img,
  .showcase-card:hover .showcase-card-image,
  .featured-card-wrap:hover {
    transform: none !important;
  }

  #card-list .card-hover:hover::after,
  #card-list .card-hover:hover > div:first-child > div.relative::before {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Mystery Pack viewport contract: the cinematic and reveal are viewport
   surfaces, never layout children of the section that launches them. */
#mystery-pack-panel .mystery-pack-opening {
  position: fixed !important;
  inset: 0 !important;
  z-index: 1200 !important;
  display: grid !important;
  place-items: center;
  align-content: center;
  box-sizing: border-box;
  width: 100vw;
  height: 100dvh;
  min-height: 100dvh !important;
  max-height: none !important;
  padding: max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden !important;
  overscroll-behavior: none;
  isolation: isolate;
}

#mystery-pack-panel .mystery-pack-opening.hidden {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  filter: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* The section reveal animation leaves a translated transform on the panel.
   A transformed ancestor changes the containing block for position:fixed. */
#mystery-pack-panel:has(.mystery-pack-opening:not(.hidden)) {
  transform: none !important;
  transition: none !important;
}

#mystery-pack-panel .mystery-pack-opening__stage {
  width: min(420px, calc(100vw - 32px), calc(100dvh - 48px));
  height: min(620px, calc(100dvh - 48px));
  min-height: 0 !important;
  max-height: calc(100dvh - 48px) !important;
  box-sizing: border-box;
  padding: clamp(16px, 3vw, 32px);
  overflow: hidden !important;
}

#mystery-pack-panel .mystery-pack-opening__pack {
  width: min(164px, calc(100vw - 64px), max(96px, calc(70dvh - 154px)));
  max-width: calc(100vw - 64px);
  max-height: calc(100dvh - 220px);
}

#pack-result-modal:not(.hidden) {
  position: fixed !important;
  inset: 0 !important;
  z-index: 1000 !important;
  display: grid !important;
  place-items: center;
  box-sizing: border-box;
  width: 100vw !important;
  height: 100dvh !important;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden !important;
  overscroll-behavior: none;
}

#pack-result-modal.hidden {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

#pack-result-modal:not(.is-summary):not(.is-history) .pack-result-shell {
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: min(1160px, calc(100vw - 24px));
  height: min(900px, calc(100dvh - 24px));
  max-height: calc(100dvh - 24px) !important;
  min-height: 0;
  overflow: hidden !important;
}

#pack-result-modal:not(.is-summary):not(.is-history) .pack-result-content {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#pack-result-modal:not(.is-summary):not(.is-history) .pack-result-heading,
#pack-result-modal:not(.is-summary):not(.is-history) #pack-result-summary {
  flex: 0 0 auto;
}

#pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items {
  flex: 1 1 auto;
  min-height: 0;
  overflow: visible;
}

#pack-result-modal:not(.is-summary):not(.is-history) .pack-result-close {
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 30;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
}

#pack-result-modal:not(.is-summary):not(.is-history) .pack-skip-button {
  min-height: 44px;
}

#pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed {
  display: grid !important;
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  grid-template-rows: minmax(0, 1fr);
  gap: clamp(4px, 1vw, 16px) !important;
  place-items: center;
  align-items: center;
  height: 100%;
  min-height: 0 !important;
  perspective: none !important;
  overflow: visible !important;
}

#pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed .pack-reveal-card {
  grid-area: auto !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  max-width: none !important;
  max-height: 100%;
  aspect-ratio: .69;
  transform: rotate(var(--nexus-card-angle, 0deg)) translateY(var(--nexus-card-y, 0px)) !important;
}

#pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed .pack-reveal-card:nth-child(1) { --nexus-card-angle: -4deg; --nexus-card-y: 8px; }
#pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed .pack-reveal-card:nth-child(2) { --nexus-card-angle: -2deg; --nexus-card-y: 3px; }
#pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed .pack-reveal-card:nth-child(3) { --nexus-card-angle: 0deg; --nexus-card-y: 0px; }
#pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed .pack-reveal-card:nth-child(4) { --nexus-card-angle: 2deg; --nexus-card-y: 3px; }
#pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed .pack-reveal-card:nth-child(5) { --nexus-card-angle: 4deg; --nexus-card-y: 8px; }

@media (max-width: 640px) {
  #mystery-pack-panel .mystery-pack-opening__stage {
    width: min(380px, calc(100vw - 24px), calc(100dvh - 32px));
    height: min(560px, calc(100dvh - 32px));
    max-height: calc(100dvh - 32px) !important;
    padding: 18px;
  }

  #pack-result-modal:not(.is-summary):not(.is-history) .pack-result-shell {
    width: min(100%, calc(100vw - 16px));
    height: min(760px, calc(100dvh - 16px));
    max-height: calc(100dvh - 16px) !important;
  }

  #pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed {
    gap: 3px !important;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  #pack-result-modal:not(.is-summary):not(.is-history) .pack-result-heading {
    gap: 8px;
    padding-right: 52px;
  }

  #pack-result-modal:not(.is-summary):not(.is-history) .pack-result-title {
    font-size: clamp(16px, 4vw, 24px);
  }

  #pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed {
    gap: 3px !important;
  }
}

/* Card Image is a separate body-level lightbox. Only this surface gets the
   strict single-card viewport treatment. */
#card-image-lightbox.hidden {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

#card-image-lightbox:not(.hidden) {
  position: fixed !important;
  inset: 0 !important;
  z-index: var(--nexus-layer-modal-secondary, 1050) !important;
  display: grid !important;
  place-items: center;
  box-sizing: border-box;
  width: 100vw;
  height: 100dvh;
  padding: max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden !important;
}

#card-image-lightbox:not(.hidden) .card-image-lightbox-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: fit-content;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  padding: 52px 12px 12px;
  overflow: hidden;
}

#card-image-lightbox:not(.hidden) .card-image-lightbox-frame {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  flex: none;
  width: min(clamp(280px, 32vw, 520px), 53.48dvh, calc((100dvh - 120px) * .6857), calc(100vw - 48px));
  aspect-ratio: 421 / 614;
  overflow: hidden;
  border: 1px solid rgba(103, 232, 249, .55);
  border-radius: .75rem;
  background: #050b14;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .65), 0 0 30px rgba(34, 211, 238, .18);
}

#card-image-lightbox:not(.hidden) .card-image-lightbox-image {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  max-width: calc(100vw - 48px);
  max-height: calc(100dvh - 96px);
  object-fit: contain;
  border: 0 !important;
  border-radius: 0;
  background: transparent;
  box-shadow: none !important;
}

#card-image-lightbox:not(.hidden) .card-image-lightbox-close {
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
}

@media (prefers-reduced-motion: reduce) {
  #card-image-lightbox:not(.hidden) .card-image-lightbox-content,
  #pack-result-modal:not(.is-summary):not(.is-history) #pack-result-items.is-nexus-primed .pack-reveal-card {
    animation: none !important;
    transition: none !important;
  }
}
