/* ═══════════════════════════════════════════════════════
   MOBILE — @media (max-width: 768px) · sin duplicar menús
   ═══════════════════════════════════════════════════════ */

.detail-back-mobile,
.ds-detail-back-mobile {
  display: none;
}

@media (max-width: 768px) {
  /* ─── Cabecera fija (P3 + DS) ─── */
  .menu-header-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 60;
    margin: 0;
    padding: max(0.45rem, env(safe-area-inset-top)) 0.6rem 0.55rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 0.4rem 0.55rem;
    pointer-events: none;
    background: linear-gradient(
      180deg,
      rgba(3, 31, 100, 0.97) 0%,
      rgba(3, 31, 100, 0.88) 72%,
      transparent 100%
    );
  }

  [data-theme="ds"] .menu-header-bar {
    background: linear-gradient(
      180deg,
      rgba(4, 3, 2, 0.96) 0%,
      rgba(4, 3, 2, 0.85) 72%,
      transparent 100%
    );
  }

  .menu-header-bar > * {
    pointer-events: auto;
  }

  .theme-switch {
    order: 1;
    flex-shrink: 0;
  }

  .menu-lang {
    order: 2;
    flex-shrink: 0;
  }

  .menu-identity-wrap {
    order: 3;
    width: 100%;
    justify-content: flex-end;
    gap: 0.4rem;
    margin-top: 0.05rem;
  }

  .menu-identity {
    font-size: 0.58rem;
    letter-spacing: 0.04em;
    max-width: calc(100vw - 8rem);
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .social-link {
    width: 1.45rem;
    height: 1.45rem;
  }

  .theme-btn,
  .lang-btn {
    font-size: 0.68rem;
    padding: 0.22rem 0.45rem;
  }

  /* ─── P3: menú 1 SVG diagonal escalado (sin transform que recorte) ─── */
  [data-theme="p3"] html,
  [data-theme="p3"] body {
    overflow: hidden;
    height: 100%;
    min-height: 100dvh;
  }

  [data-theme="p3"] .main-menu {
    position: fixed;
    inset: 0;
    overflow: hidden;
  }

  [data-theme="p3"] .menu-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 12;
  }

  [data-theme="p3"] .char-portrait {
    display: block !important;
    position: fixed;
    top: calc(3.65rem + env(safe-area-inset-top));
    left: 0;
    z-index: 14;
    max-height: none;
    padding: 0 0 0 0.15rem;
    opacity: 0.9;
    pointer-events: none;
    width: min(46vw, 11.5rem);
  }

  [data-theme="p3"] .char-portrait img {
    display: block;
    width: 100%;
    height: auto;
    max-width: min(46vw, 11.5rem);
    max-height: min(46dvh, 14.5rem);
    object-fit: contain;
    object-position: left top;
    animation: none;
    filter: drop-shadow(0 6px 18px rgba(3, 31, 100, 0.5));
  }

  [data-theme="p3"] .main-menu.detail-open .char-portrait {
    display: none !important;
  }

  [data-theme="p3"] .index-display {
    display: none !important;
  }

  [data-theme="p3"] .menu-side {
    position: absolute;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    transform: none !important;
    will-change: auto !important;
    padding: calc(4.15rem + env(safe-area-inset-top)) 0.35rem calc(6.25rem + env(safe-area-inset-bottom)) 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  [data-theme="p3"] .menu-column {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    width: min(960px, 100vw) !important;
    height: auto !important;
    min-height: 0;
    flex-shrink: 0;
    transform: scale(1.14) translateX(2vw) !important;
    transform-origin: center center;
    justify-content: center !important;
    align-items: stretch;
    margin: 0 auto;
    padding: 0;
    overflow: visible;
  }

  [data-theme="p3"] .menu-svg {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    margin: 0 auto;
  }

  [data-theme="p3"] .menu-text {
    font-size: clamp(38px, 12.2vw, 66px) !important;
  }

  [data-theme="p3"] .menu-option-wrap {
    margin-top: -3.85rem;
    overflow: visible;
  }

  [data-theme="p3"] .menu-option-wrap:first-child {
    margin-top: 0;
  }

  [data-theme="p3"] .menu-hit {
    height: 3.85rem;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  [data-theme="p3"] .menu-option-wrap.is-selected .menu-text {
    transform: scale(1.34);
  }

  [data-theme="p3"] .menu-prompt {
    display: block !important;
    position: fixed;
    left: 0.65rem;
    right: 0.65rem;
    bottom: calc(4.85rem + env(safe-area-inset-bottom));
    top: auto;
    max-width: none;
    text-align: center;
    z-index: 25;
    pointer-events: none;
  }

  [data-theme="p3"] .menu-prompt .command-desc {
    font-size: clamp(0.78rem, 3.4vw, 0.95rem);
    line-height: 1.35;
    color: rgba(255, 255, 255, 0.82);
    text-shadow: 0 1px 6px rgba(3, 31, 100, 0.9);
  }

  [data-theme="p3"] .main-menu.detail-open .menu-prompt {
    opacity: 1;
    visibility: visible;
  }

  /* P3 menú 2: pantalla completa + volver */
  [data-theme="p3"] .menu-stage.detail-open .menu-side {
    display: none !important;
  }

  [data-theme="p3"] .menu-stage.detail-open .detail-panel {
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 100dvh !important;
    padding: calc(3.85rem + env(safe-area-inset-top)) 0.85rem calc(4.75rem + env(safe-area-inset-bottom)) 0.85rem;
    z-index: 35;
    transform: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    overflow: hidden;
    background: linear-gradient(160deg, rgba(1, 50, 130, 0.98) 0%, rgba(3, 31, 100, 0.99) 100%);
  }

  [data-theme="p3"] .menu-stage.detail-open .detail-header {
    flex-shrink: 0;
  }

  [data-theme="p3"] .menu-stage.detail-open .detail-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
  }

  [data-theme="p3"] .menu-stage.detail-open .detail-back-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    width: 100%;
    margin-bottom: 0.85rem;
    padding: 0.7rem 0.85rem;
    border: 2px solid var(--border);
    background: rgba(3, 31, 100, 0.85);
    color: var(--button-2);
    font-family: var(--font-menu);
    font-size: 0.72rem;
    letter-spacing: 0.14em;
    cursor: pointer;
    box-shadow: var(--shadow-border);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  [data-theme="p3"] .menu-stage.detail-open .detail-back-mobile::before {
    content: "◀";
    font-size: 0.65rem;
    color: var(--pink);
  }

  [data-theme="p3"] .command-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 55;
    padding: 0.45rem 0.75rem max(0.6rem, env(safe-area-inset-bottom));
    background: linear-gradient(0deg, rgba(3, 31, 100, 0.96) 35%, transparent);
  }

  /* ─── DS: menú 1 compacto ─── */
  [data-theme="ds"] html,
  [data-theme="ds"] body {
    overflow-x: hidden;
    overflow-y: auto;
    height: auto;
    min-height: 100dvh;
  }

  [data-theme="ds"] .main-menu {
    position: relative;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  [data-theme="ds"] .menu-stage {
    position: relative;
    overflow: visible;
    min-height: auto;
  }

  [data-theme="ds"] .menu-side {
    position: relative !important;
    left: auto !important;
    top: auto !important;
    transform: none !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    padding: calc(3.85rem + env(safe-area-inset-top)) 0.45rem 1.25rem !important;
    filter: none;
  }

  [data-theme="ds"] .menu-side::before {
    display: none;
  }

  [data-theme="ds"] .ds-screen:not(.detail-open) .ds-col-mid,
  [data-theme="ds"] .ds-screen:not(.detail-open) .ds-col-right {
    display: none !important;
  }

  [data-theme="ds"] .ds-screen:not(.detail-open) .ds-section-label--params,
  [data-theme="ds"] .ds-screen:not(.detail-open) .ds-list {
    display: none !important;
  }

  [data-theme="ds"] .ds-mobile-stats:not(:empty) {
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
    list-style: none;
    margin: 0.35rem 0 0.5rem;
    padding: 0;
  }

  [data-theme="ds"] .ds-mobile-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.32rem 0.4rem;
    font-size: 0.74rem;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(168, 138, 72, 0.15);
    color: var(--ds-text-dim);
  }

  [data-theme="ds"] .ds-mobile-stat-val {
    color: var(--ds-gold-bright);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  /* DS menú 2 móvil: panel en body (evita recorte por overflow de menu-stage) */
  [data-theme="ds"] .menu-stage.detail-open .menu-side {
    display: none !important;
  }

  [data-theme="ds"] .ds-screen.detail-open .ds-col-detail {
    display: none !important;
  }

  body.ds-mobile-detail-open {
    overflow: hidden !important;
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail {
    display: flex !important;
    flex-direction: column;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 !important;
    padding: calc(3.75rem + env(safe-area-inset-top)) 0.85rem calc(0.85rem + env(safe-area-inset-bottom)) 0.85rem !important;
    z-index: 200 !important;
    transform: none !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
    background:
      url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='6' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.08'/%3E%3C/svg%3E"),
      linear-gradient(180deg, rgba(14, 10, 8, 0.98) 0%, rgba(6, 4, 3, 0.99) 100%) !important;
    color: var(--ds-text);
    font-family: var(--ds-font);
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-index,
  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-codename,
  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-slash,
  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-pointer,
  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-title-red {
    display: none !important;
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-header {
    flex-shrink: 0;
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-title-wrap {
    transform: none;
    margin-left: 0;
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-title {
    font-family: var(--ds-font-display);
    color: var(--ds-gold-bright);
    font-size: clamp(1.05rem, 4.8vw, 1.45rem);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    transform: none;
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-back-mobile {
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    width: 100%;
    margin-bottom: 0.75rem;
    padding: 0.75rem 0.85rem;
    min-height: 2.9rem;
    border: 1px solid rgba(168, 138, 72, 0.45);
    background: rgba(0, 0, 0, 0.45);
    color: var(--ds-gold-bright);
    font-family: var(--ds-font-display);
    font-size: 0.74rem;
    letter-spacing: 0.14em;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-back-mobile::before {
    content: "◀";
    font-size: 0.62rem;
    color: var(--ds-gold);
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    font-family: var(--ds-font);
    font-size: 0.9rem;
    line-height: 1.48;
    color: var(--ds-text);
    padding: 0 0.15rem 0.5rem;
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-body a {
    color: var(--ds-gold-bright);
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-body .entry-year {
    color: var(--ds-gold-dim);
  }

  [data-theme="ds"] .detail-panel.is-ds-mobile-detail .detail-body .entry h3 {
    color: var(--ds-gold-bright);
  }

  [data-theme="ds"] .main-menu.detail-open {
    overflow: hidden;
  }

  /* ─── DG3 — Tenkaichi 3 mobile ─── */
  [data-theme="dg3"] .menu-header-bar {
    background: linear-gradient(
      180deg,
      rgba(0, 40, 100, 0.92) 0%,
      rgba(0, 40, 100, 0.75) 72%,
      transparent 100%
    );
  }

  [data-theme="dg3"] .menu-side {
    position: fixed;
    inset: 0;
    padding-top: calc(3rem + env(safe-area-inset-top));
    overflow: hidden;
  }

  [data-theme="dg3"] .menu-column {
    overflow: hidden;
  }

  [data-theme="dg3"] .dg3-header {
    padding-top: 0.25rem;
    min-height: 3.5rem;
  }

  [data-theme="dg3"] .dg3-emblem {
    top: 0.15rem;
    width: 44px;
    height: 44px;
  }

  [data-theme="dg3"] .dg3-cloud-deco--tl {
    top: 2.8rem;
    left: 3.5rem;
    width: 60px;
    height: 36px;
  }

  [data-theme="dg3"] .dg3-cloud-deco--tr {
    display: none;
  }

  [data-theme="dg3"] .dg3-body {
    position: relative;
    min-height: clamp(280px, 48dvh, 420px);
    padding: 0 0.25rem;
  }

  [data-theme="dg3"] .dg3-char-portrait {
    right: 0;
    width: min(68vw, 340px);
    height: min(52dvh, 400px);
    transform: translateY(-46%);
    justify-content: center;
    opacity: 0.95;
  }

  [data-theme="dg3"] .dg3-char-portrait img {
    object-position: center center;
  }

  [data-theme="dg3"] .dg3-left {
    position: relative;
    z-index: 3;
    width: min(88%, 100%);
    max-width: 88%;
    padding-left: 0.2rem;
    overflow: hidden;
  }

  [data-theme="dg3"] .dg3-roulette-viewport {
    width: 100%;
    max-width: 100%;
    height: calc(64px * 7);
  }

  [data-theme="dg3"] .dg3-label {
    font-size: clamp(1rem, 4.8vw, 1.2rem);
    white-space: nowrap;
    max-width: none;
    line-height: 1.15;
  }

  [data-theme="dg3"] .dg3-item.is-selected .dg3-label {
    font-size: clamp(1.15rem, 5.4vw, 1.45rem);
  }

  [data-theme="dg3"] .dg3-highlight-bar {
    left: 0;
    width: 100%;
  }

  [data-theme="dg3"] .dg3-footer {
    padding-bottom: calc(0.65rem + env(safe-area-inset-bottom));
    z-index: 4;
  }

  [data-theme="dg3"] .dg3-footer-text {
    font-size: clamp(0.78rem, 3.4vw, 0.92rem);
  }

  [data-theme="dg3"] .menu-stage.detail-open .menu-side {
    width: 40%;
    max-width: 40%;
    right: auto;
    left: 0;
    transform: none !important;
    justify-content: flex-start;
    overflow: hidden;
    z-index: 12;
  }

  [data-theme="dg3"] .menu-stage.detail-open .dg3-left {
    width: 100%;
    max-width: 100%;
  }

  [data-theme="dg3"] .menu-stage.detail-open .dg3-left,
  [data-theme="dg3"] .menu-stage.detail-open .dg3-footer {
    opacity: 1;
    pointer-events: auto;
  }

  [data-theme="dg3"] .main-menu.detail-open .dg3-char-portrait {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }

  [data-theme="dg3"] .menu-stage.detail-open .detail-panel {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 40% !important;
    width: auto !important;
    height: 100dvh !important;
    transform: none !important;
    border-left: 3px solid var(--dg3-footer-border, #4ad4ff) !important;
    padding: calc(3.5rem + env(safe-area-inset-top)) 0.65rem calc(0.65rem + env(safe-area-inset-bottom)) !important;
    z-index: 200 !important;
    background: linear-gradient(180deg, rgba(6, 24, 64, 0.98) 0%, rgba(4, 18, 52, 0.99) 100%) !important;
  }

  [data-theme="dg3"] .menu-stage.detail-open .dg3-label {
    font-size: clamp(0.72rem, 3.2vw, 0.95rem);
  }

  [data-theme="dg3"] .menu-stage.detail-open .dg3-item.is-selected .dg3-label {
    font-size: clamp(0.82rem, 3.6vw, 1.05rem);
  }

  [data-theme="dg3"] .menu-stage.detail-open .dg3-footer-box {
    padding: 0.5rem 0.65rem;
  }

  [data-theme="dg3"] .menu-stage.detail-open .dg3-footer-text {
    font-size: clamp(0.68rem, 2.8vw, 0.8rem);
    line-height: 1.35;
  }

  [data-theme="dg3"] .menu-stage.detail-open .detail-header {
    padding: 0 0 0.85rem;
    border-bottom: 2px solid rgba(74, 212, 255, 0.35);
  }

  [data-theme="dg3"] .menu-stage.detail-open .detail-back-mobile {
    display: inline-flex !important;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
    padding: 0.45rem 0.85rem;
    border: 2px solid var(--dg3-footer-border, #4ad4ff);
    border-radius: 2px;
    background: rgba(8, 28, 72, 0.9);
    color: #ffe44a;
    font-family: var(--dg3-font, "Nunito", sans-serif);
    font-weight: 800;
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    cursor: pointer;
  }

  [data-theme="dg3"] .menu-stage.detail-open .detail-body {
    padding: 0.5rem 0 1rem;
    -webkit-overflow-scrolling: touch;
  }

  [data-theme="dg3"] .main-menu.detail-open {
    overflow: hidden;
  }
}

@media (max-width: 480px) {
  [data-theme="p3"] .char-portrait {
    width: min(50vw, 10rem);
  }

  [data-theme="p3"] .char-portrait img {
    max-width: min(50vw, 10rem);
    max-height: min(42dvh, 12.5rem);
  }

  [data-theme="p3"] .menu-column {
    transform: scale(1.1) translateX(1.5vw) !important;
  }

  [data-theme="p3"] .menu-text {
    font-size: clamp(34px, 11.5vw, 58px) !important;
  }

  [data-theme="p3"] .menu-option-wrap {
    margin-top: -3.55rem;
  }

  [data-theme="ds"] .menu-identity {
    max-width: calc(100vw - 7rem);
  }

  [data-theme="dg3"] .dg3-title {
    font-size: clamp(1.35rem, 7vw, 1.75rem);
  }

  [data-theme="dg3"] .menu-identity {
    max-width: calc(100vw - 8.5rem);
    font-size: 0.62rem;
  }
}

@media (min-width: 769px) {
  .detail-back-mobile,
  .ds-detail-back-mobile {
    display: none !important;
  }
}