/* ============================================================
   MOBILE (<= 768px) — reescrito para navegação clara e dinâmica
   Princípios:
   1. Topo compacto em 1 linha (não come a tela)
   2. "Revisar hoje" é o CTA hero; o resto apoia
   3. Stats em carrossel horizontal (scroll-snap)
   4. Modais e menu como bottom-sheet (alcance do polegar)
   5. Alvo de toque >= 44px, inputs 16px (sem zoom no iOS)
   ============================================================ */

@media only screen and (max-width: 768px) {

  /* ---------- 1. Base global ---------- */
  body {
    padding-left: 12px;
    padding-right: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    -webkit-tap-highlight-color: transparent;
  }

  /* inputs com 16px: iOS não dá zoom forçado ao focar */
  input,
  select,
  textarea {
    font-size: 16px;
  }

  button {
    min-height: 44px;
  }

  /* botões-ícone pequenos/redondos legítimos não crescem */
  .meta-editar,
  .cred-modal-fechar,
  .ia-config-fechar,
  .update-ai-fechar,
  .onboarding-dot,
  .rev-marca,
  .hm-cell,
  .nav-arrow,
  #toggle-theme {
    min-height: 0;
  }

  #toggle-theme {
    top: 12px;
    right: 12px;
    width: 42px;
    height: 42px;
    font-size: 1.05rem;
  }

  /* ---------- 2. Topo compacto (1 linha) ---------- */
  #topo {
    width: 100%;
    margin-bottom: 16px;
    gap: 10px;
  }

  /* a logo sai: identidade fica no menu; a tela agradece */
  .topo-logo {
    display: none;
  }

  .user-menu {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .user-chip {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 48px;
    justify-content: flex-start;
  }

  .user-nome {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* insígnia compacta: medalha + pontos (o título fica pro modal) */
  .perfil-insignia-chip {
    flex: 0 0 auto;
    min-height: 48px;
    padding: 5px 12px 5px 6px;
  }

  .perfil-insignia-texto strong {
    display: none;
  }

  .perfil-insignia-texto small {
    font-size: 0.8rem;
  }

  /* ---------- 3. Menu do usuário = bottom sheet ---------- */
  .user-dropdown {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    max-height: 82dvh;
    border-radius: 22px 22px 0 0;
    padding: 6px 14px calc(16px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transform-origin: bottom center;
    transition: transform 0.3s var(--ease-out), opacity 0.2s ease;
    z-index: 1200;
  }

  .user-dropdown.aberto {
    transform: translateY(0);
  }

  .user-sheet-handle {
    display: block;
    width: 42px;
    height: 4px;
    margin: 4px auto 10px;
    border-radius: 999px;
    background: var(--border);
  }

  .user-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(8, 11, 22, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 1150;
  }

  body.menu-aberto .user-sheet-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  body.menu-aberto {
    overflow: hidden;
  }

  .user-dropdown .menu-item {
    padding: 13px 12px 13px 10px;
  }

  /* ---------- 4. Ações rápidas: hero + apoios ---------- */
  #acoes-rapidas {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
  }

  /* Revisar hoje = CTA principal, linha inteira e mais alto */
  #qa-revisar {
    grid-column: 1 / -1;
    min-height: 54px;
    font-size: 1.02rem;
  }

  .qa-menu {
    width: 100%;
  }

  .qa-btn {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    justify-content: center;
    padding-inline: 10px;
    text-align: center;
  }

  .qa-dropdown {
    width: 100%;
    min-width: 0;
  }

  /* ---------- 5. Painel: stats em carrossel ---------- */
  #painel {
    display: grid;
    gap: 12px;
    margin-bottom: 18px;
  }

  .stats-strip {
    width: 100%;
    display: flex;
    gap: 10px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    padding-bottom: 6px;
    scrollbar-width: none;
  }

  .stats-strip::-webkit-scrollbar {
    display: none;
  }

  .stat-card {
    flex: 0 0 auto;
    width: clamp(132px, 38vw, 170px);
    scroll-snap-align: start;
    padding: 13px 14px;
  }

  .stat-value {
    font-size: 1.35rem;
  }

  /* atalho de progresso: linha única, discreto */
  .progresso-atalho {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    text-align: left;
    min-height: 48px;
    margin: 0; /* o gap do #painel já espaça */
    padding-inline: 16px;
  }

  .heatmap-card {
    padding: 14px 16px;
  }

  .heatmap {
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .heatmap::-webkit-scrollbar {
    display: none;
  }

  /* ---------- 6. Baralhos ---------- */
  #baralhos-topo {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .busca {
    width: 100%;
  }

  .busca input {
    min-height: 44px;
  }

  #lista-baralhos {
    width: 100%;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .card {
    min-width: 0;
    padding: 18px 16px 16px;
  }

  .card h3 {
    padding-right: 84px;
  }

  .card-acoes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .card-acoes > * {
    width: 100%;
    justify-content: center;
  }

  .stat-card,
  .stat-card.clicavel:hover {
    transform: none;
  }

  .atualizacao-box {
    position: static;
    width: 100%;
    max-width: 440px;
    margin: 0 auto 20px;
  }

  /* chips flutuantes (créditos / indicador IA) compactos à esquerda */
  .creditos-chip {
    left: 12px;
    right: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 24px);
  }

  .cred-chip-label {
    display: none;
  }

  .ia-indicador {
    left: 12px;
    right: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 24px);
  }

  /* card de progresso da redação: canto direito, sem brigar com créditos */
  .redacao-progresso-card {
    right: 12px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    max-width: min(300px, calc(100vw - 24px));
  }

  /* ---------- 7. Modais = bottom sheet ---------- */
  .confirm-overlay:not(.onboarding-tour-overlay),
  .cred-modal,
  .cred-admin-modal,
  .update-ai-overlay {
    padding: 0;
    align-items: flex-end;
    justify-content: stretch;
  }

  .confirm-overlay:not(.onboarding-tour-overlay) .confirm-box,
  .cred-modal-box,
  .cred-admin-box,
  .update-ai-modal,
  .ia-config-box,
  .insignias-box {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  }

  /* alça visual da folha (só decorativa) */
  .confirm-overlay:not(.onboarding-tour-overlay) .confirm-box::before,
  .cred-modal-box::before,
  .cred-admin-box::before,
  .update-ai-modal::before {
    content: "";
    display: block;
    width: 42px;
    height: 4px;
    margin: 0 auto 14px;
    border-radius: 999px;
    background: var(--border);
  }

  /* entrada deslizando de baixo */
  .confirm-overlay:not(.onboarding-tour-overlay) .confirm-box,
  .update-ai-modal {
    transform: translateY(26px);
    transition: transform 0.28s var(--ease-out);
  }

  .confirm-overlay.show:not(.onboarding-tour-overlay) .confirm-box,
  .update-ai-overlay.show .update-ai-modal {
    transform: translateY(0);
  }

  .confirm-acoes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .confirm-acoes button {
    width: 100%;
  }

  .ia-config-topo,
  .insignias-topo {
    align-items: flex-start;
    gap: 12px;
  }

  .ia-modos,
  .ia-personalidades,
  .insignias-grid {
    grid-template-columns: 1fr;
  }

  .insignias-proxima {
    grid-template-columns: 1fr;
  }

  /* ---------- 8. Tour do Mandan ---------- */
  .onboarding-box {
    width: 100%;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }

  .onboarding-tour-overlay .onboarding-box {
    grid-template-columns: 1fr;
    padding: 0;
  }

  .onboarding-tour-overlay .onboarding-box.pos-direita,
  .onboarding-tour-overlay .onboarding-box.pos-esquerda,
  .onboarding-tour-overlay .onboarding-box.pos-centro {
    width: 100%;
    max-width: calc(100vw - 24px);
    grid-template-columns: 1fr;
    justify-self: center;
    align-self: center;
  }

  .mandan-tour-card,
  .mandan-tour-conteudo {
    padding: 18px;
  }

  .mandan-tour-card {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .mandan-tour-tags {
    display: none;
  }

  .onboarding-acoes,
  .onboarding-final-acoes {
    align-items: stretch;
    flex-direction: column;
  }

  .onboarding-acoes button,
  .onboarding-final-acoes button {
    width: 100%;
  }

  .onboarding-acoes-sep {
    display: none;
  }

  #onboarding-proximo {
    order: -2;
  }

  .onboarding-testar {
    order: -1;
  }

  #onboarding-pular {
    order: 9;
  }

  .onboarding-dots {
    justify-content: center;
  }

  .onboarding-grid {
    grid-template-columns: 1fr;
  }

  .onboarding-mic-linha {
    grid-template-columns: 1fr;
  }

  .onboarding-mic-linha .btn-microfone {
    width: 100%;
  }

  /* ---------- 9. Estudo / Revisar ---------- */
  #estudo-container {
    width: 100%;
    gap: 8px;
  }

  .nav-arrow {
    width: 42px;
    height: 42px;
    font-size: 1.2rem;
  }

  #card-area {
    min-width: 0;
    padding: 24px 18px;
    min-height: 260px;
  }

  #card-area > p:first-child {
    font-size: 1.16rem;
  }

  .input-resposta-linha,
  .input-ia-linha {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .input-resposta-linha input,
  .input-verificacao input,
  .input-verificacao button,
  .btn-microfone {
    width: 100%;
  }

  .acoes-estudo,
  .mandan-acoes {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .acoes-estudo button,
  .mandan-acao {
    width: 100%;
  }

  /* notas SRS: 2x2 com dedo confortável */
  .srs-avaliacao {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .srs-avaliacao button {
    min-height: 52px;
  }

  .ia-fila-detalhes {
    grid-template-columns: 1fr;
  }

  .ia-fila-cancelar {
    grid-column: auto;
    width: 100%;
  }

  /* ---------- 10. Criação manual ---------- */
  #adicionar,
  #importar {
    width: 100%;
  }

  .buttons {
    width: 100%;
  }

  .buttons #voltar {
    width: 100%;
  }

  /* ---------- 11. Criar com IA ---------- */
  .ia-criador-topo,
  .wizard-progresso-topo,
  .resultado-topo {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .form-grid,
  .mini-config,
  .resumo-lista,
  .destino-grid,
  .choice-grid,
  .qtd-grid {
    grid-template-columns: 1fr;
  }

  .wizard-card,
  .gerando-card,
  .resultado-card {
    padding: 18px;
  }

  .wizard-acoes,
  .resultado-acoes,
  .card-editor-topo {
    flex-direction: column;
    align-items: stretch;
  }

  .wizard-acoes button,
  .resultado-acoes button {
    width: 100%;
  }

  .card-editor-acoes {
    width: 100%;
    justify-content: flex-end;
  }

  .gerando-fila {
    grid-template-columns: 1fr;
  }

  .gerando-fila button {
    grid-column: auto;
    width: 100%;
  }

  /* ---------- 12. Conquistas ---------- */
  #conq-topo,
  .rank-card,
  .conq-claimaveis {
    flex-direction: column;
    align-items: stretch;
  }

  .conq-titulo {
    font-size: 1.35rem;
  }

  .rank-medalha {
    align-self: center;
  }

  .conq-filtros {
    width: 100%;
    overflow-x: auto;
    justify-content: flex-start;
    border-radius: var(--radius);
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .conq-filtros::-webkit-scrollbar {
    display: none;
  }

  .conq-filtros .filtro {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .conq-grid {
    grid-template-columns: 1fr;
  }

  .conq-card {
    min-width: 0;
  }

  .conq-claimaveis-btn {
    width: 100%;
  }

  /* ---------- 13. Login ---------- */
  .login-container {
    padding: 26px 20px;
  }
}

/* ============================================================
   Redação + revisão profunda (camada final; mantém o refinamento)
   ============================================================ */
@media only screen and (max-width: 768px) {
  #red-topo,
  #red-main,
  #rev-main,
  .rev-topo,
  .red-form,
  .red-loading,
  .red-resultado,
  .red-historico,
  .rev-cabecalho,
  .rev-loading,
  .rev-layout,
  .rev-folha,
  .rev-painel,
  .rev-painel-card,
  .rev-plano-card,
  .rev-chat-card {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  #red-topo,
  .rev-topo {
    gap: 10px;
    margin-bottom: 12px;
    flex-direction: column;
    align-items: stretch;
  }

  #red-topo #voltar,
  .rev-topo #voltar {
    width: 100%;
    min-height: 42px;
    justify-content: center;
  }

  #red-topo h1,
  .rev-topo h1 {
    flex-wrap: wrap;
    font-size: 1.18rem;
    line-height: 1.2;
  }

  .red-form,
  .red-loading,
  .red-comp,
  .red-historico,
  .red-anulada,
  .rev-cabecalho,
  .rev-loading,
  .rev-folha,
  .rev-painel-card,
  .rev-plano-card,
  .rev-chat-card {
    padding: 14px;
    border-radius: 14px;
  }

  .red-campo textarea,
  .rev-chat-form input {
    width: 100%;
    min-width: 0;
    font-size: 16px;
  }

  #red-tema {
    min-height: 88px;
  }

  #red-texto {
    min-height: 320px;
    line-height: 1.55;
  }

  .red-modo-linha,
  .red-form-rodape {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 8px;
  }

  .red-modo {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-radius: 16px;
  }

  .red-modo-btn {
    min-width: 0;
    padding: 10px 8px;
    white-space: normal;
    line-height: 1.15;
  }

  .red-modo-hint {
    width: 100%;
  }

  .red-contador {
    text-align: center;
  }

  #red-corrigir,
  .red-btn-profunda,
  #rev-chat-enviar,
  #rev-regenerar {
    width: 100%;
    min-height: 44px;
    justify-content: center;
  }

  .red-acoes-resultado {
    flex-direction: column;
    align-items: stretch;
  }

  .red-loading {
    text-align: center;
  }

  .red-loading-etapa,
  .red-loading small {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  .red-tempo {
    width: 100%;
    justify-content: center;
  }

  .red-progresso {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .red-hero {
    gap: 14px;
    padding: 16px;
    text-align: left;
  }

  .red-total {
    width: 100%;
    min-width: 0;
    padding: 12px;
  }

  .red-total b {
    font-size: 2.45rem;
  }

  .red-hero-texto {
    min-width: 0;
  }

  .red-meta-correcao {
    justify-self: stretch;
    justify-content: center;
    white-space: normal;
    text-align: center;
  }

  .red-tag,
  .red-elemento {
    width: 100%;
    justify-content: center;
    text-align: center;
    white-space: normal;
  }

  .red-comp-topo,
  .rev-paragrafo-topo,
  .rev-lista-topo,
  .rev-plano-topo {
    align-items: stretch;
    flex-direction: column;
    gap: 6px;
  }

  .red-comp-nota {
    width: max-content;
    max-width: 100%;
  }

  .red-comp-just,
  .red-cobertura span,
  .red-trecho q,
  .red-trecho span,
  .red-dicas li,
  .red-hist-tema,
  .rev-cabecalho h2,
  .rev-cabecalho p,
  .rev-topo p,
  .rev-painel-card h2,
  .rev-painel-card p,
  .rev-painel-card blockquote,
  .rev-sugestao,
  .rev-acao-texto,
  .rev-reescrita blockquote,
  .rev-lista-item b,
  .rev-lista-item span,
  .rev-chat-msg {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .red-cobertura li,
  .red-trecho,
  .red-hist-item,
  .rev-layout,
  .rev-plano-grid {
    grid-template-columns: 1fr;
  }

  .red-cobertura b {
    width: max-content;
    min-width: 0;
    max-width: 100%;
  }

  .red-trecho {
    border-left: 0;
    border-top: 3px solid var(--primary);
    border-radius: var(--radius-sm);
  }

  .red-hist-tema {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .red-hist-nota {
    justify-self: start;
  }

  .rev-cabecalho {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .rev-cabecalho h2 {
    font-size: 1.12rem;
    line-height: 1.25;
  }

  .rev-score {
    width: 100%;
    min-width: 0;
    padding: 12px;
  }

  .rev-layout {
    display: grid;
    gap: 14px;
  }

  .rev-painel {
    position: static;
    gap: 12px;
  }

  .rev-legenda,
  .rev-acoes {
    flex-wrap: wrap;
    overflow-x: visible;
    padding-bottom: 0;
  }

  .rev-legenda-item,
  .rev-chip {
    width: auto;
    max-width: 100%;
    white-space: normal;
    flex: 0 0 auto;
  }

  .rev-paragrafo {
    gap: 8px;
    padding: 12px;
  }

  .rev-paragrafo-texto {
    font-size: 0.95rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .rev-marca {
    max-width: 100%;
    padding: 1px 3px;
    border-radius: 6px;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .rev-marca:hover,
  .rev-marca.ativo {
    transform: none;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.18);
  }

  .rev-lista {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .rev-lista-topo {
    flex-direction: column;
    align-items: stretch;
  }

  .rev-lista-item {
    width: 100%;
  }

  .rev-acao-btn {
    flex: 1 1 calc(50% - 8px);
    min-height: 40px;
    justify-content: center;
    text-align: center;
  }

  .rev-chat-msgs {
    max-height: min(52dvh, 420px);
    padding-right: 0;
  }

  .rev-chat-msg {
    max-width: 100%;
  }

  .rev-chat-form {
    display: grid;
    grid-template-columns: 1fr;
  }

  .rev-chat-form input {
    min-height: 46px;
  }
}

/* ============================================================
   Telas bem estreitas (<= 430px)
   ============================================================ */
@media only screen and (max-width: 430px) {
  #card-area {
    padding: 22px 16px;
  }

  .nav-arrow {
    width: 38px;
    height: 38px;
  }

  .stat-card {
    width: clamp(124px, 42vw, 150px);
  }

  .red-form,
  .red-loading,
  .red-comp,
  .red-historico,
  .rev-cabecalho,
  .rev-loading,
  .rev-folha,
  .rev-painel-card,
  .rev-plano-card,
  .rev-chat-card {
    padding: 12px;
  }

  .red-modo {
    grid-template-columns: 1fr;
    border-radius: 14px;
  }

  .red-total b {
    font-size: 2.1rem;
  }

  .rev-acao-btn {
    flex-basis: 100%;
  }
}

/* Jornada da home: leitura vertical e alvos confortaveis no celular. */
@media only screen and (max-width: 768px) {
  .jornada-hoje {
    margin-bottom: 14px;
    padding: 18px 16px;
    border-radius: 20px;
  }

  .jornada-cabecalho {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 16px;
  }

  .jornada-hoje h1 {
    font-size: 1.38rem;
  }

  .jornada-cta {
    width: 100%;
  }

  .jornada-corpo {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .jornada-etapa {
    min-height: 68px;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 9px;
    padding: 8px;
  }

  .jornada-etapa-icone {
    width: 34px;
    height: 34px;
  }

  .jornada-etapa:not(:last-child)::after {
    left: 25px;
  }

  .jornada-etapa-conteudo strong,
  .jornada-etapa-conteudo span {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
  }

  .jornada-semana {
    padding: 14px;
  }

  .card-capa {
    min-height: 64px;
    margin: -18px -16px 16px;
    padding: 11px 14px;
  }
}
