/* PLABS_MOBILE_SHELL_V2 — shell estable en móvil (Kids / Pro) */
:root {
  --pl-vvh: 100dvh;
  --pl-safe-top: env(safe-area-inset-top, 0px);
  --pl-safe-bottom: env(safe-area-inset-bottom, 0px);
  --pl-safe-left: env(safe-area-inset-left, 0px);
  --pl-safe-right: env(safe-area-inset-right, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  overscroll-behavior-y: none;
}

#starfield {
  height: var(--pl-vvh);
  width: 100%;
}

/* Desktop: keep natural scroll. Mobile: one locked viewport shell. */
@media (max-width: 860px) {
  html.pl-mobile,
  html.pl-mobile body {
    height: var(--pl-vvh);
    max-height: var(--pl-vvh);
    overflow: hidden;
    position: fixed;
    inset: 0;
    width: 100%;
    touch-action: manipulation;
  }

  html.pl-mobile body {
    padding-left: var(--pl-safe-left);
    padding-right: var(--pl-safe-right);
  }

  /* Each top-level view is the only scroll surface */
  html.pl-mobile .welcome,
  html.pl-mobile .worlds,
  html.pl-mobile .app {
    position: fixed;
    inset: 0;
    z-index: 2;
    width: 100%;
    height: var(--pl-vvh);
    max-height: var(--pl-vvh);
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding-top: max(12px, var(--pl-safe-top));
    padding-bottom: max(16px, var(--pl-safe-bottom));
    box-sizing: border-box;
  }

  html.pl-mobile .welcome {
    display: grid;
    place-items: center;
    justify-items: center;
    padding-left: 16px;
    padding-right: 16px;
  }

  html.pl-mobile .welcome__grid,
  html.pl-mobile .welcome__grid--solo {
    width: min(100%, 420px);
    max-width: 100%;
    margin: 0 auto;
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  html.pl-mobile .welcome.hidden,
  html.pl-mobile .worlds.hidden,
  html.pl-mobile .app.hidden {
    display: none !important;
  }

  /* Welcome / auth cards */
  html.pl-mobile .welcome__card,
  html.pl-mobile .auth__card {
    width: min(100%, 420px);
    max-width: 100%;
    margin: 0 auto;
    padding: 28px 18px 24px;
    border-radius: 22px;
  }

  html.pl-mobile .welcome__title { font-size: clamp(1.55rem, 7vw, 1.9rem); }
  html.pl-mobile .welcome__sub { font-size: 0.95rem; }
  html.pl-mobile .welcome__mascot {
    width: 96px;
    height: 96px;
    animation: none;
  }
  html.pl-mobile .welcome__hub {
    display: inline-flex;
    align-self: flex-start;
    margin-bottom: 8px;
    font-weight: 800;
    font-size: 0.85rem;
    color: var(--muted);
    text-decoration: none;
  }
  html.pl-mobile .btn--xl {
    width: 100%;
    justify-content: center;
    padding: 14px 18px;
    font-size: 1rem;
  }
  html.pl-mobile .field {
    font-size: 16px; /* evita zoom iOS al enfocar */
  }

  /* Worlds / tracks */
  html.pl-mobile .worlds {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding-left: 14px;
    padding-right: 14px;
    gap: 10px;
  }

  html.pl-mobile .worlds__head {
    position: sticky;
    top: 0;
    z-index: 3;
    margin: 0 0 4px;
    padding: 10px 8px 12px;
    background: linear-gradient(180deg, rgba(11, 7, 20, 0.96), rgba(11, 7, 20, 0.88));
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
  }

  html.pl-mobile .worlds__back {
    position: static;
    display: inline-flex;
    margin: 0 0 8px;
    padding: 8px 12px;
  }

  html.pl-mobile .worlds__logo {
    width: 56px;
    height: 56px;
    border-radius: 16px;
  }

  html.pl-mobile .worlds__title {
    font-size: 1.45rem;
    line-height: 1.15;
  }

  html.pl-mobile .worlds__sub {
    font-size: 0.9rem;
  }

  html.pl-mobile .worlds__grid,
  html.pl-mobile .tracks__grid {
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    padding-bottom: 24px;
  }

  html.pl-mobile .worldcard {
    min-height: 0;
    padding: 18px 16px;
    border-radius: 20px;
  }

  html.pl-mobile .worldcard:hover,
  html.pl-mobile .worldcard:active {
    transform: none;
  }

  html.pl-mobile .worldcard__emoji { font-size: 40px; }
  html.pl-mobile .worldcard__name { font-size: 1.15rem; }

  /* App shell: HUD fixed strip + map scrolls under it */
  html.pl-mobile .app {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
  }

  html.pl-mobile .hud {
    position: sticky;
    top: 0;
    z-index: 30;
    flex-shrink: 0;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand right"
      "stats stats";
    gap: 8px 10px;
    align-items: center;
    padding: calc(8px + var(--pl-safe-top)) 12px 10px;
    background: rgba(11, 7, 20, 0.94);
    border-bottom: 1px solid var(--border);
  }

  html.pl-mobile .hud__brand { grid-area: brand; min-width: 0; gap: 8px; }
  html.pl-mobile .hud__stats {
    grid-area: stats;
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
    gap: 6px;
  }
  html.pl-mobile .hud__right {
    grid-area: right;
    gap: 6px;
  }

  html.pl-mobile .hud__name { display: none; }
  html.pl-mobile .hud__logo { width: 32px; height: 32px; }
  html.pl-mobile .hud__back { width: 34px; height: 34px; font-size: 15px; }

  html.pl-mobile .stat {
    padding: 5px 9px;
    font-size: 13px;
    flex: 1 1 auto;
    justify-content: center;
  }

  html.pl-mobile .xpbar { width: min(110px, 28vw); height: 24px; }
  html.pl-mobile .lang,
  html.pl-mobile .planbadge {
    padding: 6px 9px;
    font-size: 12px;
    border-radius: 9px;
  }
  html.pl-mobile .account { width: 34px; height: 34px; font-size: 13px; }

  html.pl-mobile .mapwrap {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 12px 10px calc(28px + var(--pl-safe-bottom));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  html.pl-mobile .unit-banner {
    margin: 14px 8px 6px;
    padding: 12px 14px;
    font-size: 0.95rem;
    border-radius: 14px;
  }

  html.pl-mobile .node { margin: 14px 0; }
  html.pl-mobile .node__btn {
    width: 72px;
    height: 72px;
    font-size: 30px;
  }
  html.pl-mobile .node--boss .node__btn {
    width: 84px;
    height: 84px;
    font-size: 36px;
  }
  html.pl-mobile .node__label {
    max-width: min(160px, 70vw);
    font-size: 12px;
  }

  /* Lesson as full-screen sheet */
  html.pl-mobile .modal {
    padding: 0;
    align-items: stretch;
    justify-items: stretch;
    inset: 0;
    height: var(--pl-vvh);
  }

  html.pl-mobile .lesson,
  html.pl-mobile .plans,
  html.pl-mobile .teacher,
  html.pl-mobile .tips,
  html.pl-mobile .ethics,
  html.pl-mobile .acctcard {
    width: 100%;
    max-width: 100%;
    height: var(--pl-vvh);
    max-height: var(--pl-vvh);
    border-radius: 0;
    margin: 0;
    padding: calc(14px + var(--pl-safe-top)) 14px calc(18px + var(--pl-safe-bottom));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    box-sizing: border-box;
  }

  html.pl-mobile .lesson__close {
    top: calc(10px + var(--pl-safe-top));
    right: 10px;
    z-index: 5;
  }

  html.pl-mobile .lesson__head {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
    padding-right: 44px;
  }

  html.pl-mobile .lesson__title { font-size: 1.2rem; line-height: 1.2; }
  html.pl-mobile .lesson__goal { font-size: 0.85rem; }

  html.pl-mobile .lesson__tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    margin-bottom: 12px;
  }

  html.pl-mobile .ltab {
    flex: 0 0 auto;
    padding: 9px 12px;
    font-size: 13px;
    border-radius: 11px;
  }

  html.pl-mobile .studio {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  html.pl-mobile .studio__blocks {
    height: min(42dvh, 320px);
    min-height: 220px;
  }

  html.pl-mobile .studio__actions {
    position: sticky;
    bottom: 0;
    z-index: 4;
    padding: 8px 0 calc(4px + var(--pl-safe-bottom));
    background: linear-gradient(180deg, transparent, var(--panel-solid) 30%);
  }

  html.pl-mobile .studio__actions .btn {
    min-height: 44px;
  }

  html.pl-mobile .video,
  html.pl-mobile .video.video--embed {
    aspect-ratio: 16 / 9;
    border-radius: 14px;
  }

  html.pl-mobile .quizmodal {
    padding: 10px;
    height: var(--pl-vvh);
    align-content: center;
  }
}

@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  html.pl-mobile .welcome__mascot,
  html.pl-mobile .worldcard,
  html.pl-mobile .node--active .node__btn::after {
    animation: none !important;
  }
}

@media (max-width: 380px) {
  html.pl-mobile .hud__right .planbadge { display: none; }
  html.pl-mobile .stat--streak .stat__ico { margin-right: 0; }
}


/* ===== PLABS_EMBED_ADAZHA_V1 — cards legibles dentro del iframe de Adazha ===== */
html.pl-embed,
html.pl-embed body {
  min-height: 100%;
}

html.pl-embed .gate {
  min-height: 100%;
  align-items: flex-start;
  padding: 16px 12px 28px;
  box-sizing: border-box;
}

html.pl-embed .gate__inner {
  width: 100%;
  max-width: 100%;
}

html.pl-embed .gate__logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
}

html.pl-embed .gate__title {
  font-size: clamp(1.45rem, 6.5vw, 1.85rem);
  margin: 6px 0;
}

html.pl-embed .gate__sub {
  font-size: 0.92rem;
  margin: 0 0 16px;
  line-height: 1.4;
}

html.pl-embed .gate__cards,
html.pl-embed .gate__cards--2 {
  display: grid !important;
  grid-template-columns: 1fr !important;
  gap: 10px !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
}

html.pl-embed .gate__card {
  width: 100%;
  box-sizing: border-box;
  padding: 16px 14px !important;
  border-radius: 16px;
  min-height: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "ico title"
    "ico desc";
  column-gap: 12px;
  row-gap: 2px;
  align-items: center;
  text-align: left;
}

html.pl-embed .gate__card:hover,
html.pl-embed .gate__card:active {
  transform: none;
}

html.pl-embed .gate__ico {
  grid-area: ico;
  font-size: 28px !important;
  margin: 0 !important;
  line-height: 1;
}

html.pl-embed .gate__card strong {
  grid-area: title;
  font-size: 1.05rem !important;
  margin: 0 !important;
}

html.pl-embed .gate__card span:last-child {
  grid-area: desc;
  font-size: 0.82rem !important;
  line-height: 1.35 !important;
}

/* Mundos / tracks dentro de Adazha */
html.pl-embed .worlds {
  padding: 12px 12px 24px !important;
  align-items: stretch !important;
}

html.pl-embed .worlds__head {
  position: sticky;
  top: 0;
  z-index: 4;
  padding: 8px 4px 10px;
  margin-bottom: 8px;
  background: linear-gradient(180deg, rgba(11,7,20,.98), rgba(11,7,20,.9));
}

html.pl-embed .worlds__title { font-size: 1.35rem !important; }
html.pl-embed .worlds__sub { font-size: 0.88rem !important; }
html.pl-embed .worlds__logo { width: 52px; height: 52px; }

html.pl-embed .worlds__grid,
html.pl-embed .tracks__grid {
  grid-template-columns: 1fr !important;
  width: 100% !important;
  gap: 10px !important;
}

html.pl-embed .worldcard {
  min-height: 0 !important;
  padding: 16px 14px !important;
  border-radius: 18px;
  /* fallback si color-mix falla en WebView viejo */
  background: linear-gradient(180deg, rgba(167,139,250,.18), rgba(255,255,255,.03)) !important;
  border: 1px solid rgba(167,139,250,.35) !important;
}

html.pl-embed .worldcard:hover { transform: none; }
html.pl-embed .worldcard__emoji { font-size: 36px !important; }
html.pl-embed .worldcard__name { font-size: 1.1rem !important; }
html.pl-embed .worldcard__desc { font-size: 0.85rem !important; }

/* En Adazha siempre 1 columna: el iframe suele ser estrecho aunque el device sea tablet */
html.pl-embed .gate__cards,
html.pl-embed .gate__cards--2 {
  grid-template-columns: 1fr !important;
}
@media (min-width: 700px) and (min-height: 700px) {
  html.pl-embed:not(.pl-force-stack) .gate__cards--2 {
    grid-template-columns: 1fr 1fr !important;
  }
}
