/* ==========================================================
   The Studio — mobile layout (≤ 760px)
   Se carga al final de app.html. No toca el escritorio.
   ========================================================== */
@media (max-width: 760px) {

  :root { --mtop: calc(58px + env(safe-area-inset-top, 0px)); --mbot: calc(66px + env(safe-area-inset-bottom, 0px)); }
  html, body { overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
  body.m-lock { overflow: hidden; }
  .tempt, #temptlane, #temptlane2 { display: none !important; }

  /* ---------- Barra superior ---------- */
  nav {
    position: sticky; top: 0; z-index: 30;
    background: rgba(255, 253, 247, .94);
    -webkit-backdrop-filter: saturate(1.4) blur(10px); backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: var(--b);
  }
  nav > .wrap {
    height: 58px; padding: env(safe-area-inset-top, 0px) 12px 0 14px !important;
    box-sizing: content-box; display: flex; align-items: center; gap: 8px; max-width: none;
  }
  nav .bar { display: flex !important; background: none !important; border: 0 !important; box-shadow: none !important; padding: 0 !important; margin: 0 !important; min-width: 0; }
  nav .bar .tabs { display: none !important; }
  nav .bar .logo { font-size: 19px !important; white-space: nowrap; }
  nav .rightcol { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-direction: row !important; }
  nav .chiprow { gap: 6px; align-items: center; }
  nav #tune { display: none !important; }
  #money > .chipbtn:not(#balBtn) { display: none !important; }
  nav .chipbtn { height: 38px; min-height: 0; padding: 0 12px; font-size: 13px; box-shadow: 0 3px 0 var(--ink) !important; }
  nav #balBtn .unit { font-size: 9px; }
  nav #ntBtn { width: 38px; padding: 0; justify-content: center; }
  nav #walletbtn { width: 38px; padding: 0; font-size: 0 !important; color: transparent; position: relative; overflow: hidden; }
  nav #walletbtn::before {
    content: ""; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px; background: var(--ink);
    -webkit-mask: var(--m-user) center / contain no-repeat; mask: var(--m-user) center / contain no-repeat;
  }
  .walletmenu, .nt-panel { position: fixed !important; top: calc(var(--mtop) + 6px) !important; left: 10px !important; right: 10px !important; width: auto !important; max-width: none !important; z-index: 70; }
  .nt-panel { max-height: calc(100dvh - var(--mtop) - var(--mbot) - 24px); overflow-y: auto; }

  /* ---------- Tab bar ---------- */
  #mbar {
    left: 0 !important; right: 0 !important; bottom: 0 !important;
    display: grid !important; grid-template-columns: repeat(5, 1fr); gap: 0;
    height: auto; padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)) !important;
    border: 0 !important; border-top: var(--b) !important; border-radius: 20px 20px 0 0 !important;
    box-shadow: 0 -6px 24px rgba(26, 24, 20, .12) !important; background: var(--paper);
  }
  #mbar .tab, #msheet .tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: none !important; border: 0 !important; box-shadow: none !important;
    padding: 4px 0 !important; min-height: 52px; font-size: 10.5px; font-weight: 700; letter-spacing: .02em; color: var(--dim);
  }
  #mbar .tab .ic {
    width: 44px; height: 30px; border-radius: 15px; display: grid; place-items: center; font-size: 0; line-height: 0;
    transition: background .18s ease;
  }
  #mbar .tab .ic svg, #msheet .tab .ic svg { width: 22px; height: 22px; }
  #mbar .tab[aria-current="true"] { color: var(--ink); }
  #mbar .tab[aria-current="true"] .ic { background: var(--beak); box-shadow: inset 0 0 0 2.5px var(--ink); }

  /* Hoja "More" */
  #msheet .sheet {
    left: 0 !important; right: 0 !important; bottom: 0 !important; top: auto !important;
    display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 10px;
    padding: 12px 14px calc(var(--mbot) + 14px) !important; border-radius: 24px 24px 0 0 !important;
    border: 0 !important; border-top: var(--b) !important; background: var(--paper);
  }
  #msheet .sheet::before {
    content: ""; grid-column: 1 / -1; justify-self: center; width: 44px; height: 5px; border-radius: 3px; background: #D6D0C2; margin-bottom: 4px;
  }
  #msheet .tab {
    background: var(--cream) !important; border: var(--b) !important; border-radius: 18px !important;
    box-shadow: var(--sh-s) !important; min-height: 86px; color: var(--ink); font-size: 12px;
  }
  #msheet .tab .ic { font-size: 0; line-height: 0; }
  #msheet .tab .ic svg { width: 26px; height: 26px; }
  #msheet .tab[aria-current="true"] { background: var(--beak) !important; }

  /* ---------- Pantallas: marco general ---------- */
  .screen > .wrap, #pond > .wrap { padding: 18px 14px calc(var(--mbot) + 28px) !important; }
  #bank > div { padding: 18px 14px calc(var(--mbot) + 28px) !important; box-sizing: border-box; }
  #bank h1, #bank h2 { font-size: clamp(34px, 11vw, 44px) !important; }
  .screen .sticker { display: none !important; }
  .screen h2.title { font-size: clamp(34px, 11vw, 44px) !important; line-height: .95; margin: 8px 0 6px; }
  .screen p.sub { font-size: 14px; line-height: 1.45; margin: 0 0 16px; max-width: 34ch; }

  /* Héroes con ilustración: banda baja, título abajo, sin párrafo */
  .sechero {
    min-height: 0 !important; height: 150px; padding: 16px 18px !important; margin-bottom: 14px;
    display: flex !important; flex-direction: column; justify-content: flex-end;
    background-position: 70% 40% !important; position: relative; overflow: hidden; border-radius: 20px !important;
  }
  .sechero::before { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(26,24,20,.55), rgba(26,24,20,0) 70%); }
  .sechero > * { position: relative; z-index: 1; }
  .sechero h2.title { margin: 0 !important; font-size: 40px !important; }
  .sechero p.sub { display: none !important; }

  /* Filtros: una sola fila deslizable */
  .toolbar { display: flex !important; flex-direction: column; gap: 8px !important; margin: 0 -14px 12px !important; }
  .toolbar .cats, .toolbar .rest {
    display: flex !important; flex-wrap: nowrap !important; gap: 6px !important; overflow-x: auto; overscroll-behavior-x: contain;
    padding: 2px 14px 6px !important; scrollbar-width: none; scroll-snap-type: x proximity;
  }
  .toolbar .cats::-webkit-scrollbar, .toolbar .rest::-webkit-scrollbar { display: none; }
  .toolbar .cats, .toolbar .rest { justify-content: flex-start !important; }
  .toolbar .cats > *, .toolbar .rest > * { flex: 0 0 auto; scroll-snap-align: start; }
  .toolbar button, .toolbar select { font-size: 12.5px !important; padding: 8px 14px !important; min-height: 38px; box-shadow: var(--sh-s) !important; }
  .toolbar select { padding-right: 30px !important; }

  /* ---------- The Pond ---------- */
  #pond .hello { display: block !important; margin-bottom: 14px; }
  #pond .hello #c_hello { display: none; }
  #pond .hello h2.title { margin: 0 0 12px !important; }
  #pond .moneystrip { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 8px !important; width: 100%; }
  #pond .mstat { min-width: 0 !important; padding: 10px 10px 9px !important; border-radius: 16px !important; text-align: left; }
  #pond .mstat .n { font-size: 24px !important; line-height: 1; }
  #pond .mstat .l { font-size: 8px !important; letter-spacing: .06em; margin-top: 5px; line-height: 1.3; }

  #lg_banner {
    display: grid !important; grid-template-columns: 52px 1fr; grid-template-areas: "img txt" "cta cta";
    gap: 10px 12px; padding: 14px !important; align-items: center; text-align: left; margin-bottom: 14px; border-radius: 20px !important;
  }
  #lg_banner img { grid-area: img; width: 52px !important; height: 52px !important; }
  #lg_banner > div { grid-area: txt; min-width: 0; }
  #lg_banner > div * { font-size: revert; }
  #lg_banner .lg_cta { grid-area: cta; justify-self: stretch; justify-content: center; text-align: center; padding: 12px !important; }

  .promos { display: grid !important; grid-template-columns: 1fr !important; gap: 14px !important; margin-bottom: 14px; }
  .promo.hasart {
    min-height: 270px !important; padding: 18px !important; justify-content: flex-end !important;
    background-position: 60% 30% !important; position: relative; overflow: hidden; border-radius: 20px !important;
  }
  .promo.hasart::before {
    content: "" !important; position: absolute !important; inset: 0 !important; z-index: 0 !important;
    background: linear-gradient(0deg, rgba(20,18,14,.88) 0%, rgba(20,18,14,.55) 40%, rgba(20,18,14,0) 72%) !important;
  }
  .promo.hasart > * { position: relative; z-index: 1; color: #FFFDF7 !important; }
  .promo.hasart .ptag { opacity: .8; }
  .promo.hasart h3 { font-size: 34px !important; line-height: .95; margin: 4px 0 6px !important; }
  .promo.hasart .stockline { font-size: 22px !important; }
  .promo.hasart .pd { font-size: 13px !important; max-width: 30ch; margin-bottom: 12px; }
  .promo.hasart .cta { align-self: stretch; justify-content: center; }
  .promo.hasart .cta.dark { background: var(--beak) !important; color: var(--ink) !important; }

  .smallgrid { display: grid !important; grid-template-columns: 1fr !important; gap: 14px !important; }
  .card.big { border-radius: 20px !important; }
  .card.big .band { height: 150px !important; }
  .card.big .triple { gap: 10px !important; }
  .card.big .triple .n { font-size: 30px !important; }
  .statusline { margin-top: 14px; }

  /* ---------- My Flock ---------- */
  #flocklist { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 12px !important; }
  #flocklist .duckcard { border-radius: 18px !important; box-shadow: var(--sh-s) !important; min-width: 0; }
  #flocklist .duckcard .meta { padding: 10px 11px 11px !important; }
  #flocklist .duckcard .name { font-size: 14px !important; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #flocklist .duckcard .id { font-size: 10px !important; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #flocklist .duckcard .foot { margin-top: 8px !important; gap: 4px; flex-wrap: wrap; }
  #flocklist .duckcard .earn { font-size: 11px !important; }
  #flocklist .duckcard .chip { font-size: 9.5px !important; padding: 3px 8px !important; }

  /* ---------- Perfil del pato ---------- */
  #profile .cols { display: block !important; }
  #profile .artwrap { max-width: 100% !important; margin: 4px 0 18px; }
  #profile .back { margin-bottom: 10px; }

  /* ---------- Grillas de traits / market / packs ---------- */
  .tgrid, .mgrid { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }
  .tgrid > *, .mgrid > * { min-width: 0; }

  /* Packs: una columna, los disponibles primero */
  #packgrid, .packgrid { display: grid !important; grid-template-columns: 1fr !important; gap: 14px !important; }
  #packgrid .pack { min-height: 0 !important; }
  #packgrid .pack.soldout { order: 2; }

  /* Travel: cabecera como banda con título */
  .tvhead { position: relative; display: block !important; overflow: hidden; border-radius: 20px !important; margin-bottom: 14px !important; }
  .tvhead img { display: block; width: 100%; aspect-ratio: 2.1 / 1 !important; height: auto !important; object-fit: cover; border: 0 !important; }
  .tvhead .tvhtxt { position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 18px 14px !important; background: linear-gradient(0deg, rgba(26,24,20,.6), rgba(26,24,20,0)); }
  .tvhead .tvhtxt h2 { margin: 0 !important; font-size: 40px !important; }
  .tvhead .tvhtxt p { display: none !important; }
  #mk_tabs { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 6px !important; margin-bottom: 12px !important; }
  #mk_tabs button { font-size: 14px !important; padding: 10px 4px !important; min-width: 0; white-space: nowrap; }

  /* Tab bar: solo la pestaña activa se resalta (evita hover/focus pegado tras el toque) */
  #mbar .tab:not([aria-current="true"]) .ic { background: none !important; box-shadow: none !important; }
  #mbar .tab:not([aria-current="true"]) { color: var(--dim) !important; }

  /* Filtros: la fila ocupa el ancho y desliza (antes se centraba y se corría) */
  .toolbar { align-items: stretch !important; }
  .toolbar > .cats, .toolbar > .rest { width: auto !important; max-width: none !important; min-width: 0 !important; align-self: stretch !important; box-sizing: border-box; }

  /* My Traits */
  .tgrid button { font-size: 11px !important; letter-spacing: 0 !important; padding: 10px 4px !important; white-space: nowrap; }
  #tr_tools .rest > button { order: -1; background: var(--beak) !important; }

  /* Perfil del pato: stats parejos y acciones en grilla */
  #profile .statrow { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 8px !important; }
  #profile .statrow .stat { min-width: 0 !important; padding: 12px 6px !important; transform: none !important; }
  #profile .actions { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 8px !important; }
  #profile .actions > button { min-width: 0; min-height: 46px; padding: 10px 6px !important; font-size: 12.5px !important; justify-content: center; text-align: center; }
  #profile .actions > #p_edit { grid-column: 1 / -1; min-height: 52px; font-size: 14px !important; }

  /* Games: mesa en dos filas */
  #games .gtables { grid-template-columns: 1fr !important; width: 100%; }
  #games .gtable { display: grid !important; grid-template-columns: auto minmax(0,1fr) auto; grid-template-areas: "seats seats seats" "pot n btn"; gap: 10px 12px; align-items: center; min-width: 0; width: auto !important; padding: 12px !important; box-sizing: border-box; }
  #games .gtable .gseats { grid-area: seats; display: flex; gap: 6px; }
  #games .gtable .gpot { grid-area: pot; }
  #games .gtable .n { grid-area: n; font-size: 11px !important; line-height: 1.35; min-width: 0; }
  #games .gtable button { grid-area: btn; height: 44px; padding: 0 16px !important; border-radius: 22px !important; white-space: nowrap; }
  #games .gnew { display: grid !important; grid-template-columns: 1fr auto; gap: 8px; }
  #games .gnew select, #games .gnew button { height: 44px; width: 100% !important; }
  #games .gcard { border-radius: 20px !important; }

  /* Castings: menos margen anidado, pasos compactos */
  #castings .ep { border-radius: 20px !important; overflow: hidden; }
  #castings .ep > .body { padding: 16px 14px !important; }
  #castings .how { gap: 8px !important; margin-bottom: 14px !important; }
  #castings .hstep { display: grid !important; grid-template-columns: 26px 1fr; column-gap: 10px; align-items: baseline; padding: 11px 12px !important; border-radius: 14px !important; }
  #castings .hstep > :first-child { grid-row: span 2; font-size: 22px !important; line-height: 1; margin: 0 !important; }
  #castings .hstep b { font-size: 14px !important; }
  #castings .hstep p, #castings .hstep span:not(:first-child) { font-size: 12.5px !important; line-height: 1.4; margin: 2px 0 0 !important; }
  #castings .roles { gap: 12px !important; }
  #castings .role { padding: 14px !important; border-radius: 16px !important; }
  #castings .role .top { flex-wrap: wrap; gap: 8px; }
  #castings .role button { min-height: 44px; }

  /* ======================================================
     EDITOR — pantalla completa
     ====================================================== */
  #editor.on {
    position: fixed !important; inset: 0 !important; z-index: 60; height: auto !important;
    background: var(--sky);
  }
  body.m-editing #mbar { display: none !important; }
  #editor .frame {
    height: 100% !important; box-sizing: border-box; max-width: 560px; margin: 0 auto;
    padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px calc(env(safe-area-inset-bottom, 0px) + 10px) !important;
    display: grid !important; gap: 10px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(120px, 1fr) auto auto minmax(190px, 36%);
    grid-template-areas: "head head" "duck duck" "tools pub" "cats cats" "grid grid";
  }
  #editor .stage, #editor .tray { display: contents !important; }

  #editor .ehead { grid-area: head; height: 42px; padding: 0 !important; display: flex; align-items: center; gap: 10px; min-width: 0; }
  #editor .ehead .back {
    flex: 0 0 auto; height: 40px; padding: 0 14px !important; border: var(--b) !important; border-radius: 20px !important;
    background: var(--paper) !important; box-shadow: var(--sh-s) !important; font-size: 13px; font-weight: 700;
  }
  #editor #e_who { flex: 1 1 auto; min-width: 0; font-size: 24px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #editor #pubchip { flex: 0 0 auto; font-size: 9px !important; padding: 5px 9px !important; }

  #editor .duckwrap {
    grid-area: duck; justify-self: center; align-self: center;
    width: auto !important; height: 100% !important; max-height: calc(100vw - 24px); max-width: 100%;
    aspect-ratio: 1 / 1; margin: 0 !important;
  }
  #editor .duckwrap > * { border-radius: 20px; }

  #editor .toolcol { grid-area: tools; position: static !important; display: flex !important; flex-direction: row !important; gap: 8px !important; align-items: center; }
  #editor .toolcol .tool {
    width: 44px !important; height: 44px !important; min-width: 0; padding: 0 !important; display: grid; place-items: center;
    font-size: 0 !important; box-shadow: var(--sh-s) !important;
  }
  #editor .toolcol .tool svg { width: 21px; height: 21px; }

  #editor .pubbar { grid-area: pub; margin: 0 !important; display: flex; align-items: center; }
  #editor .pubbar .pubact {
    min-width: 0 !important; height: 48px; padding: 0 18px !important; border-radius: 24px !important;
    display: flex; flex-direction: column; justify-content: center; align-items: center; line-height: 1;
  }
  #editor .pubbar .pubact .lbl { font-size: 17px !important; }
  #editor .pubbar .pubact .amt { font-size: 8.5px !important; margin-top: 3px; }

  #editor #cats {
    grid-area: cats; display: flex !important; flex-wrap: nowrap !important; gap: 6px !important; overflow-x: auto;
    margin: 0 -12px !important; padding: 2px 12px 4px !important; scrollbar-width: none; overscroll-behavior-x: contain;
  }
  #editor #cats::-webkit-scrollbar { display: none; }
  #editor #cats button {
    flex: 0 0 auto; height: 36px; padding: 0 14px !important; margin: 0 !important;
    border: var(--b) !important; border-radius: 18px !important; background: var(--paper) !important;
    box-shadow: 0 3px 0 var(--ink) !important; font-size: 12.5px !important; font-weight: 700; white-space: nowrap;
  }
  #editor #cats button > span:first-child { display: none; }
  #editor #cats button[aria-pressed="true"] { background: var(--ink) !important; color: var(--paper) !important; }

  #editor #grid {
    grid-area: grid; display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: max-content;
    align-content: start; gap: 10px !important; height: auto !important; min-height: 0;
    overflow-x: hidden !important; overflow-y: auto !important; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    padding: 12px !important; background: var(--paper); border: var(--b); border-radius: 20px; box-shadow: var(--sh-s);
  }
  #editor #grid > * { width: auto !important; height: auto !important; min-width: 0; margin: 0 !important; position: relative; }
  #editor #grid .tile .box { width: 100% !important; height: auto !important; aspect-ratio: 1 / 1; border-radius: 14px !important; }
  #editor #grid .tile .own { top: -6px !important; left: -4px !important; font-size: 9px !important; padding: 2px 6px !important; }
  #editor #grid .tile .rare { margin-top: 5px !important; display: flex; justify-content: center; }
  #editor #grid .tile .rchip { font-size: 8px !important; padding: 2px 6px !important; letter-spacing: .03em; white-space: nowrap; }
  #editor #grid .tile .nm { font-size: 10px !important; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
}

/* Pantallas muy bajas (iPhone SE, Safari con barras) */
@media (max-width: 760px) and (max-height: 640px) {
  #editor .frame { gap: 8px; grid-template-rows: auto minmax(110px, 1fr) auto auto minmax(160px, 34%); }
  #editor #e_who { font-size: 20px !important; }
  #editor .toolcol .tool { width: 40px !important; height: 40px !important; }
  #editor .pubbar .pubact { height: 44px; }
  #editor #grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px !important; padding: 10px !important; }
  #editor #grid .tile .rchip { font-size: 7px !important; padding: 2px 4px !important; }
}

/* Íconos SVG de las herramientas del editor (reemplazan emojis en todos los tamaños) */
.toolcol .tool svg { width: 22px; height: 22px; display: block; margin: auto; }
