/* Capa 14 · Móvil 6.0. Sólo actúa con html.is-mobile (teléfono, o pantalla baja con puntero táctil): barra inferior de pulgar, hoja «Más», Supervisor
   plegable, biblioteca como hoja inferior, diálogos a pantalla completa y barras de herramientas de una sola fila. Va después de skin.css. */

/* ── Escritorio: los elementos del móvil no existen ─────────────────────────────────────────────────────────────────── */
.mobile-bar, .mobile-sheet, .mobile-scrim, .library-scrim, .mobile-select, .mobile-selbar { display: none; }

html.is-mobile {
  --mb-h: 58px;
  --mb-safe: env(safe-area-inset-bottom, 0px);
  --mb-top: env(safe-area-inset-top, 0px);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
html.is-mobile body { overscroll-behavior: none; touch-action: manipulation; }
html.is-mobile .app.studio-shell { height: calc(var(--vh, 1vh) * 100); padding-bottom: calc(var(--mb-h) + var(--mb-safe)); padding-top: var(--mb-top); }
html.is-mobile button, html.is-mobile summary, html.is-mobile select, html.is-mobile .button { touch-action: manipulation; }

/* ── Cabecera compacta: marca, nombre del archivo, estado y huella ─────────────────────────────────────────────────── */
html.is-mobile .studio-shell .topbar { height: 46px; min-height: 46px; flex: 0 0 46px; flex-wrap: nowrap; padding: 0 10px; gap: 8px; }
html.is-mobile .topbar .brand-lockup, html.is-mobile .topbar .brand .edition { display: none; }
html.is-mobile .topbar .file-actions, html.is-mobile .topbar #connection-summary, html.is-mobile .topbar #connect-board, html.is-mobile .topbar #step, html.is-mobile .topbar #toggle-run { display: none; }
html.is-mobile .topbar .project-heading { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; margin: 0; }
html.is-mobile .topbar #project-name { flex: 1 1 auto; min-width: 0; width: auto; min-height: 36px; font-size: var(--fs-md); font-weight: 700; text-overflow: ellipsis; }
html.is-mobile .topbar #save-state { flex: none; font-size: var(--fs-2xs); max-width: 78px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html.is-mobile .topbar .identity-badge { flex: none; min-height: 34px; min-width: 34px; padding: 0 8px; }
html.is-mobile .topbar .identity-badge span { display: none; }
html.is-mobile .topbar .run-controls { flex: none; margin: 0; }
html.is-mobile .topbar #run-state { font-size: var(--fs-2xs); letter-spacing: .06em; white-space: nowrap; }

/* ── La barra de pestañas de escritorio se sustituye por la barra inferior ─────────────────────────────────────────── */
html.is-mobile .studio-shell .workspace-tabs { display: none; }

html.is-mobile .mobile-bar {
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: stretch;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  height: calc(var(--mb-h) + var(--mb-safe)); padding: 6px 6px calc(6px + var(--mb-safe));
  background: var(--n-0); border-top: 1px solid var(--n-200); box-shadow: 0 -6px 18px rgba(16, 27, 48, .08);
}
html.is-mobile .mb-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 46px; margin: 0 2px; padding: 2px 0; border: 0; border-radius: var(--r-md);
  background: transparent; color: var(--n-600); font: 600 var(--fs-2xs)/1.1 var(--font-ui); letter-spacing: .01em;
}
html.is-mobile .mb-item .i { width: 22px; height: 22px; }
html.is-mobile .mb-item[aria-pressed="true"] { color: var(--accent-600); background: var(--accent-50); }
html.is-mobile .mb-item:active { background: var(--n-100); }
html.is-mobile .mb-item.mb-run { color: var(--n-0); background: var(--accent-500); box-shadow: var(--sh-2); margin: -10px 4px 0; min-height: 56px; border-radius: 18px; font-size: var(--fs-xs); }
html.is-mobile .mb-item.mb-run .i { width: 24px; height: 24px; }
html.is-mobile .mb-item.mb-run:active { background: var(--accent-600); }
html.is-mobile .mb-item.mb-run.is-running { background: var(--fault); }
html.is-mobile .mb-item:focus-visible { outline: 2px solid var(--accent-500); outline-offset: -2px; }

/* Teléfono en horizontal: la barra pasa a un riel lateral para no robar altura. */
html.is-short .studio-shell .topbar { height: 40px; min-height: 40px; flex-basis: 40px; }
html.is-short .app.studio-shell { padding-bottom: 0; padding-left: calc(64px + env(safe-area-inset-left, 0px)); }
html.is-short .mobile-bar { top: 0; right: auto; width: calc(64px + env(safe-area-inset-left, 0px)); height: auto; bottom: 0; grid-template-columns: 1fr; grid-auto-rows: 1fr; padding: 4px 4px 4px env(safe-area-inset-left, 0px); border-top: 0; border-right: 1px solid var(--n-200); box-shadow: 6px 0 18px rgba(16, 27, 48, .08); }
html.is-short .mb-item.mb-run { margin: 2px 0; min-height: 0; }

/* ── Hoja «Más» ─────────────────────────────────────────────────────────────────────────────────────────────────────── */
html.is-mobile .mobile-scrim { display: block; position: fixed; inset: 0; z-index: 100; background: rgba(16, 27, 48, .45); opacity: 0; transition: opacity var(--dur-2) var(--ease-out); }
html.is-mobile .mobile-scrim[hidden] { display: none; }
html.is-mobile .mobile-scrim.is-in { opacity: 1; }
html.is-mobile .mobile-sheet {
  display: flex; flex-direction: column; position: fixed; left: 0; right: 0; bottom: 0; z-index: 101; max-height: 82dvh;
  background: var(--n-0); border-radius: 18px 18px 0 0; box-shadow: var(--sh-3); transform: translateY(100%); transition: transform var(--dur-3) var(--ease-out);
  padding-bottom: var(--mb-safe);
}
html.is-mobile .mobile-sheet[hidden] { display: none; }
html.is-mobile .mobile-sheet.is-in { transform: none; }
html.is-short .mobile-sheet { left: 64px; max-height: 94dvh; }
.ms-head { position: relative; display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 6px; }
.ms-head h2 { margin: 0; font: 800 var(--fs-lg)/1.2 var(--font-ui); color: var(--n-900); }
.ms-grip { position: absolute; top: 6px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 4px; background: var(--n-300); }
.ms-close { min-width: 44px; min-height: 44px; border: 0; background: transparent; border-radius: 50%; color: var(--n-700); }
.ms-body { overflow-y: auto; padding: 0 12px 16px; overscroll-behavior: contain; }
.ms-group h3 { margin: 12px 4px 6px; font: 700 var(--fs-2xs)/1 var(--font-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--n-600); }
.ms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.ms-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 76px; padding: 10px 6px; border: 1px solid var(--n-200); border-radius: var(--r-md); background: var(--n-50); color: var(--n-800); font: 600 var(--fs-xs)/1.2 var(--font-ui); text-align: center; }
.ms-item .i { width: 22px; height: 22px; color: var(--accent-600); }
.ms-item:active { background: var(--accent-50); border-color: var(--accent-200); }

/* ── Barras de herramientas: una sola fila que se desliza, con objetivos táctiles ─────────────────────────────────── */
html.is-mobile .studio-shell :is(.canvas-toolbar, .plant-toolbar) { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; gap: 4px; padding: 4px 8px; min-height: 48px; -webkit-overflow-scrolling: touch; }
html.is-mobile .studio-shell :is(.canvas-toolbar, .plant-toolbar)::-webkit-scrollbar { display: none; }
html.is-mobile .studio-shell :is(.canvas-toolbar, .plant-toolbar) :is(button, summary, select, .button) { min-height: 40px; flex: none; }
html.is-mobile .canvas-toolbar > strong, html.is-mobile .plant-toolbar > .pane-title { display: none; }
html.is-mobile .studio-shell .ladder-tools { flex: 1 1 auto; min-width: 0; flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; gap: 4px; }
html.is-mobile .studio-shell .ladder-tools::-webkit-scrollbar { display: none; }
html.is-mobile .studio-shell .zoom-controls { flex: none; flex-wrap: nowrap; }
html.is-mobile .studio-shell :is(.ladder-tools, .zoom-controls) :is(button, select, summary) { flex: none; min-height: 40px; }
html.is-mobile .studio-shell .canvas-toolbar { justify-content: flex-start; }
html.is-mobile .sheet-heading span:last-child { display: none; }
html.is-mobile .studio-shell .scene-status { display: none; }
html.is-mobile .tool-popover { max-width: calc(100vw - 16px); }

/* ── Pie de estado reducido ─────────────────────────────────────────────────────────────────────────────────────────── */
html.is-mobile .statusbar { min-height: 28px; padding-inline: 10px; gap: 8px; }
html.is-mobile .statusbar .program-credit, html.is-mobile .statusbar .app-version, html.is-mobile .statusbar #scan-time, html.is-mobile .statusbar .status-release { display: none; }
html.is-mobile #status-message { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Supervisor plegable ────────────────────────────────────────────────────────────────────────────────────────────── */
html.is-mobile .studio-shell .practice-bar { grid-template-columns: auto minmax(0, 1fr) auto; min-height: 56px; padding: 6px 10px; gap: 4px 10px; position: relative; }
html.is-mobile .practice-bar::after { content: ""; width: 10px; height: 10px; border-right: 2px solid var(--n-500); border-bottom: 2px solid var(--n-500); transform: rotate(45deg); margin: 0 6px 4px 0; transition: transform var(--dur-2) var(--ease-out); }
html.is-mobile .practice-bar.is-expanded::after { transform: rotate(-135deg); margin-bottom: -2px; }
html.is-mobile .practice-bar .pb-face { width: 40px; height: 40px; }
html.is-mobile .practice-bar .pb-say { font-size: var(--fs-sm); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
html.is-mobile .practice-bar.is-expanded .pb-say { -webkit-line-clamp: unset; display: block; }
html.is-mobile .practice-bar .pb-extra, html.is-mobile .practice-bar .pb-controls { display: none; grid-column: 1 / -1; }
html.is-mobile .practice-bar.is-expanded .pb-extra:not(:empty) { display: flex; }
html.is-mobile .practice-bar.is-expanded .pb-controls { display: flex; }
html.is-mobile .practice-bar .pb-extra { grid-column: 2 / -1; }
html.is-mobile .practice-bar[data-state="review"] .pb-extra:not(:empty) { display: flex; grid-column: 1 / -1; }
html.is-mobile .practice-bar .pb-controls { flex-wrap: wrap; }
html.is-mobile .practice-bar .pb-review { flex: 1 1 100%; min-height: 46px; }
html.is-mobile .practice-bar .pb-modes { width: 100%; }
html.is-mobile .practice-bar .pb-modes button { flex: 1; min-height: 44px; }
html.is-mobile .practice-bar .pb-extra button { min-height: 40px; }

/* ── Biblioteca de componentes como hoja inferior ───────────────────────────────────────────────────────────────────── */
html.is-mobile .library-scrim { display: none; position: fixed; inset: 0; z-index: 70; background: rgba(16, 27, 48, .35); }
html.is-mobile.library-open .library-scrim { display: block; }
html.is-mobile .studio-shell .sidebar:not([hidden]) {
  position: fixed; left: 0; right: 0; top: auto; bottom: calc(var(--mb-h) + var(--mb-safe)); width: auto; height: min(62dvh, 520px); z-index: 80;
  border: 0; border-top: 1px solid var(--n-200); border-radius: 18px 18px 0 0; box-shadow: var(--sh-3); padding-top: 14px;
}
html.is-short .studio-shell .sidebar:not([hidden]) { left: 64px; bottom: 0; height: 100dvh; border-radius: 0; }
html.is-mobile .sidebar .panel-grip { display: none; }
html.is-mobile .sidebar::before { content: ""; position: absolute; top: 6px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 4px; background: var(--n-300); }

/* ── Diálogos a pantalla completa ───────────────────────────────────────────────────────────────────────────────────── */
html.is-mobile dialog[open]:not(.mobile-sheet):not(.sup-vignette) {
  inset: 0; width: 100%; max-width: 100%; height: calc(var(--vh, 1vh) * 100); max-height: calc(var(--vh, 1vh) * 100); margin: 0; border-radius: 0;
  padding-bottom: calc(14px + var(--mb-safe)); overflow-y: auto; -webkit-overflow-scrolling: touch;
}
html.is-mobile dialog .dialog-heading { position: sticky; top: 0; z-index: 2; background: inherit; }
html.is-mobile dialog .dialog-heading button[data-close] { min-width: 44px; min-height: 44px; }
html.is-mobile dialog :is(button, .button, select, input:not([type="checkbox"]):not([type="radio"])) { min-height: 46px; }
html.is-mobile dialog .dialog-actions { position: sticky; bottom: 0; background: inherit; padding-block: 8px; }

/* ── Historieta en vivo y planta ────────────────────────────────────────────────────────────────────────────────────── */
html.is-mobile .live-comic .lc-sub { display: none; }
html.is-mobile .plant-viewport, html.is-mobile .ladder-sheet { overscroll-behavior: contain; }
html.is-mobile .plant-viewport { touch-action: none; }

@media (prefers-reduced-motion: reduce) { .mobile-sheet, .mobile-scrim, .practice-bar::after { transition: none; } }

/* ── Ajustes finos: avisos sobre la barra inferior y pantalla baja ───────────────────────────────────────────────────── */
html.is-mobile #toast { bottom: calc(var(--mb-h) + var(--mb-safe) + 38px); max-width: calc(100vw - 24px); }
html.is-short #toast { bottom: 16px; left: calc(50% + 32px); }
html.is-short .statusbar { display: none; }
html.is-short .studio-shell .practice-bar { min-height: 44px; padding-block: 3px; }
html.is-short .practice-bar .pb-face { width: 34px; height: 34px; }
html.is-short .studio-shell :is(.canvas-toolbar, .plant-toolbar) { min-height: 42px; padding-block: 2px; }
html.is-short .live-comic .lc-head { padding-block: 4px; }
html.is-mobile #diagnostics-list { position: fixed; left: 8px; right: 8px; bottom: calc(var(--mb-h) + var(--mb-safe) + 34px); width: auto; max-height: 42dvh; overflow-y: auto; z-index: 85; }
html.is-short #diagnostics-list { left: 72px; bottom: 8px; }

/* «Seleccionar» (recuadro con el dedo) */
html.is-mobile .mobile-select { display: inline-flex; align-items: center; gap: 6px; flex: none; }
html.is-mobile .mobile-select .i { width: 18px; height: 18px; }
html.is-mobile .mobile-select[aria-pressed="true"] { background: var(--accent-500); border-color: var(--accent-500); color: var(--n-0); }
html.is-mobile.select-mode .ladder-sheet { touch-action: none; }

/* Barra de acciones de la selección: sustituye a Supr, R y Ctrl C/V */
html.is-mobile .mobile-selbar { display: flex; position: fixed; left: 50%; bottom: calc(var(--mb-h) + var(--mb-safe) + 10px); transform: translateX(-50%); z-index: 88; gap: 2px; padding: 4px; border-radius: 16px; background: var(--n-900); box-shadow: var(--sh-3); max-width: calc(100vw - 16px); }
html.is-mobile .mobile-selbar[hidden] { display: none; }
html.is-mobile .mobile-selbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 56px; min-height: 48px; padding: 4px 6px; border: 0; border-radius: 12px; background: transparent; color: var(--n-0); font: 600 var(--fs-2xs)/1.1 var(--font-ui); }
html.is-mobile .mobile-selbar button .i { width: 20px; height: 20px; }
html.is-mobile .mobile-selbar button:active { background: rgba(255, 255, 255, .16); }
html.is-mobile .mobile-selbar[data-kind="ladder"] [data-sel="rotate"], html.is-mobile .mobile-selbar[data-kind="ladder"] [data-sel="duplicate"], html.is-mobile .mobile-selbar[data-kind="wire"] :is([data-sel="rotate"], [data-sel="duplicate"], [data-sel="props"]) { display: none; }
html.is-mobile .mobile-selbar [data-sel="delete"] { color: #ffb4a8; }
html.is-short .mobile-selbar { left: calc(50% + 32px); bottom: 10px; }
