/* Camada de celular do visual novo. Tudo aqui vale apenas para telas de até 820 px de largura
   (celular e tablet em pé); o computador não é afetado — conferido por tools/desktop-invariance.mjs. */

@media (max-width: 820px) {
  /* Toque: sem atraso de duplo toque, sem realce azul, sem zoom automático do iOS nos campos. */
  button, a, input, select, label, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  input, select, textarea { font-size: 16px !important; }
  .text-link { min-height: 44px; }
  .check-button { min-width: 44px; min-height: 44px; }

  /* Cabeçalho fixo e enxuto, respeitando o recorte da câmera (notch). */
  .topbar {
    position: sticky; top: 0; z-index: 12;
    height: calc(58px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 18px 0;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  }
  .topbar-left strong { font-family: var(--display); font-stretch: 82%; font-weight: 800; font-size: 19px; letter-spacing: 0; }
  .topbar-actions { gap: 6px; }
  .icon-button, .topbar .avatar { width: 40px; height: 40px; }

  /* Conteúdo com respiro para a barra de abas e para a barra de gestos. */
  .view { padding: 22px 18px calc(96px + env(safe-area-inset-bottom)); }

  /* Barra de abas no estilo de app, acima da barra de gestos. */
  .mobile-nav {
    height: calc(64px + env(safe-area-inset-bottom)); padding: 6px 8px env(safe-area-inset-bottom);
    align-items: flex-start; justify-content: space-between;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .18);
  }
  .mobile-nav .nav-item { flex: 1; min-width: 0; height: 52px; padding: 6px 2px; border-radius: 14px; font-size: 10.5px; justify-content: center; }
  .mobile-nav .nav-item svg { width: 22px; height: 22px; }
  .toast { left: 16px; right: 16px; max-width: none; bottom: calc(80px + env(safe-area-inset-bottom)); }

  /* Guia do exercício e textos legais como painéis que sobem de baixo. */
  .guide-overlay, .account-legal-overlay { align-items: end; padding: 0; }
  .guide-dialog, .account-legal {
    width: 100%; max-width: none; max-height: 90vh; max-height: 90dvh;
    border-radius: 26px 26px 0 0; padding: 30px 20px calc(24px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }
  .guide-dialog::before, .account-legal::before {
    content: ""; position: sticky; top: -18px; display: block; width: 44px; height: 5px; border-radius: 5px;
    margin: -16px auto 14px; background: var(--line);
  }
  .guide-close { top: 18px; right: 16px; width: 40px; height: 40px; }

  /* Questionário: botões de navegação presos no rodapé, sempre ao alcance do polegar. */
  .wizard-actions {
    position: sticky; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 5;
    margin: 18px -22px -22px; padding: 12px 22px;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-top: 1px solid var(--line); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  }
  .wizard-panel { padding: 22px; }
  .wizard-actions .btn { flex: 1; min-height: 50px; }
  .option-card { min-height: 56px; }

  /* Perfil: os links de termos e privacidade ficam juntos numa linha. */
  .account-panel .pref-row > span:last-child:not(:first-child) { display: flex; align-items: center; gap: 4px; white-space: nowrap; flex: none; }
  .account-panel .pref-row > span:last-child .text-link { min-height: 40px; }

  /* Alimentação: campos em coluna única quando a tela é estreita. */
  .nutrition-fields input, .nutrition-fields select { height: 48px; }
}

@media (max-width: 560px) {
  .nutrition-fields { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}

/* ---------- Modo foco do treino (celular) ---------- */
@media (max-width: 820px) {
  /* No modo foco o deslize horizontal troca de exercício: o navegador não pode tratá-lo como "voltar página". */
  html:has(body.gm-focus), body.gm-focus { overscroll-behavior-x: none; }
  body.gm-focus .session-card { touch-action: pan-y; }
  body.gm-focus .mobile-nav { display: none; }
  body.gm-focus .view { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
  body.gm-focus .session-card { display: none; }
  body.gm-focus .session-card.gm-focus-active { display: block; }
  body.gm-focus .session-actions [data-action="finish-session"] { display: none; }
  body.gm-focus .session-adjust { margin-bottom: 12px; }
  body.gm-focus .session-top { position: sticky; top: calc(58px + env(safe-area-inset-top)); z-index: 6; margin-bottom: 12px; padding: 14px 16px; }
  body.gm-focus .session-top h1 { font-size: 26px; }
  body.gm-focus .session-top p { display: none; }

  .gm-focus-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 14;
    padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
    background: var(--sidebar); color: #fff; box-shadow: 0 -12px 34px rgba(0, 0, 0, .28);
    display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  }
  .gm-focus-bar button { border: 0; color: inherit; font: inherit; cursor: pointer; }
  .gm-focus-prev { width: 52px; height: 52px; border-radius: 14px; background: rgba(255, 255, 255, .08); display: grid; place-items: center; }
  .gm-focus-prev:disabled { opacity: .35; }
  .gm-focus-prev svg, .gm-focus-next svg { width: 20px; height: 20px; }
  .gm-focus-info { min-width: 0; display: grid; gap: 7px; justify-items: center; }
  .gm-focus-info strong { font-size: 12px; font-weight: 700; color: #9DB7BE; letter-spacing: .04em; white-space: nowrap; }
  .gm-focus-dots { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; max-width: 100%; }
  .gm-focus-dot { width: 22px; height: 22px; border-radius: 50%; padding: 0; display: grid; place-items: center; background: transparent; }
  .gm-focus-dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, .25); transition: none; }
  .gm-focus-dot.done::after { background: var(--teal-bright, #46B8CE); }
  .gm-focus-dot.current::after { width: 18px; border-radius: 6px; background: #fff; }
  .gm-focus-next {
    height: 52px; padding: 0 18px; border-radius: 14px; display: inline-flex; align-items: center; gap: 8px;
    background: rgba(255, 255, 255, .12); font-weight: 700; font-size: 14px; white-space: nowrap;
  }
  .gm-focus-next.ready { background: var(--accent, #FF6A3D); color: var(--accent-text, #1A0B05); }
}
