/* Organizar Sílabas, Montar Frase com Imagem e Completar Frase (lógica em scripts/features/syllables.js). */
/* Uma coluna só: os quadros ficam em cima e as peças embaixo. A regra geral de .choices em telas
   até 820 px (iPad em pé) dividia em duas colunas e punha quadros e peças lado a lado. */
.choices.syllable-workspace {
  grid-template-columns: minmax(0, 1fr);
}

body.training-fullscreen .syllable-workspace {
  width: min(100%, 1120px);
  min-height: calc(100vh - 170px);
}

body[data-design] .syllable-workspace[data-module="syllables"] {
  gap: clamp(18px, 2.8vh, 30px);
}

body[data-design] .syllable-workspace[data-module="syllables"] .syllable-reference {
  --syllable-reference-inset: clamp(8px, 1vw, 12px);
  width: clamp(240px, 30vw, 360px);
  height: clamp(180px, 25vh, 260px);
  margin-bottom: clamp(8px, 1.5vh, 16px);
}

body[data-design] .syllable-workspace[data-module="syllables"] .syllable-reference img {
  transform: scale(1.12);
}

body.training-fullscreen .syllable-workspace[data-module="syllables"] .syllable-reference {
  width: clamp(280px, 32vw, 420px);
  height: clamp(200px, 28vh, 300px);
}

body.training-fullscreen .syllable-slot,
body.training-fullscreen .syllable-card,
body.training-fullscreen .syllable-source-placeholder {
  min-height: clamp(118px, 18vh, 190px);
}

@media (min-width: 721px) and (max-width: 1180px) {
  body[data-design] .syllable-slot,
  body[data-design] .syllable-card,
  body[data-design] .syllable-source-placeholder {
    min-height: clamp(118px, 15vh, 174px);
  }
}

@media (max-width: 720px) {
  body[data-design] .syllable-workspace[data-count="4"],
  body[data-design] .syllable-workspace[data-count="5"] {
    --syllable-count: 2;
  }

  body[data-design] .syllable-slot,
  body[data-design] .syllable-card,
  body[data-design] .syllable-source-placeholder {
    min-height: clamp(92px, 13vh, 132px);
    border-radius: 12px;
  }
}

@media (max-width: 480px) {
  body[data-design] .syllable-workspace {
    gap: 16px;
  }
}

body[data-design] .sentence-image-workspace .syllable-card {
  padding: clamp(8px, 1.4vw, 14px);
  font-size: clamp(1.55rem, min(4.4vw, 5.6vh), 3.25rem);
  line-height: 1.05;
}

body[data-design] .sentence-image-workspace {
  --sentence-piece-height: clamp(148px, 20vh, 220px);
  width: min(100%, 1240px);
  gap: clamp(18px, 3.4vh, 34px);
}

/* A figura ocupa a área do cartão por dentro da margem e sempre cabe inteira (figuras altas,
   como o copo de leite, passavam da altura do cartão e ficavam cortadas embaixo). */
body[data-design] .sentence-image-workspace .syllable-card.is-image-piece {
  position: relative;
  padding: 0;
}

body[data-design] .sentence-image-workspace .syllable-card.is-image-piece .sentence-piece-picture {
  position: absolute;
  inset: clamp(12px, 1.8vw, 20px);
  display: block;
  width: auto;
  height: auto;
  padding: 0;
  overflow: hidden;
}

body[data-design] .sentence-image-workspace .sentence-piece-picture img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
  margin: 0;
}

body[data-design] .sentence-image-workspace .syllable-slot .syllable-card {
  height: 100%;
}

/* Quadros e peças no formato 1,35 : 1. A largura é a menor entre a coluna e a altura-padrão × 1,35:
   no iPad deitado nada muda; em pé, com 4 ou 5 peças, os cartões diminuem para caber na tela
   (antes ficavam mais largos que a coluna e se sobrepunham). */
body[data-design] .sentence-image-workspace :is(.syllable-slots, .syllable-source) {
  grid-template-columns: repeat(var(--syllable-count, 4), minmax(0, 1fr));
}

body[data-design] .sentence-image-workspace :is(.syllable-slots, .syllable-source) > :is(.syllable-slot, .syllable-card, .syllable-source-placeholder) {
  justify-self: center;
  width: min(100%, calc(var(--sentence-piece-height) * 1.35));
  height: auto;
  min-height: 0;
  aspect-ratio: 1.35 / 1;
}

body[data-design] .sentence-completion-workspace {
  width: min(100%, 1360px);
  gap: clamp(20px, 3.4vh, 42px);
}

body[data-design] .sentence-completion-workspace[data-count="1"] {
  --syllable-count: 1;
}

body[data-design] .sentence-completion-workspace[data-count="2"] {
  --syllable-count: 2;
}

body[data-design] .sentence-completion-workspace[data-count="3"] {
  --syllable-count: 3;
}

body[data-design] .sentence-completion-reference {
  justify-self: center;
  width: min(100%, 1280px);
  border: 8px solid var(--accent);
  border-radius: 26px;
  background: var(--prompt-bg);
  color: #050505;
  padding: clamp(22px, 2.5vw, 36px) clamp(26px, 3.6vw, 56px);
  text-align: center;
  font-size: clamp(1.35rem, min(2.8vw, 4.8vh), 3rem);
  font-weight: 950;
  line-height: 1.25;
  text-transform: uppercase;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
  box-shadow: var(--shadow-soft);
}

body[data-design] .sentence-completion-blank-slot {
  display: inline-grid;
  vertical-align: middle;
  width: var(--completion-piece-width, 180px);
  min-width: var(--completion-piece-width, 180px);
  min-height: clamp(72px, 10vh, 112px);
  margin: 0.08em 0.16em;
  border: 4px dashed #d8b365;
  border-radius: 18px;
  background: #ffffff;
  color: #94a3b8;
  font-size: 0.72em;
  line-height: 1;
  white-space: nowrap;
}

body[data-design] .sentence-completion-blank-slot.is-over {
  border-color: var(--blue);
  background: #eef4ff;
}

body[data-design] .sentence-completion-workspace .syllable-slots,
body[data-design] .sentence-completion-workspace .syllable-source {
  display: grid;
  justify-content: center;
  grid-template-columns: repeat(var(--syllable-count, 3), minmax(190px, 280px));
  gap: clamp(18px, 2.4vw, 34px);
  width: 100%;
}

body[data-design] .sentence-completion-workspace .syllable-source {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
}

body[data-design] .sentence-completion-workspace .syllable-source > .syllable-card,
body[data-design] .sentence-completion-workspace .syllable-source > .syllable-source-placeholder {
  flex: 0 0 var(--completion-piece-width, 180px);
  width: var(--completion-piece-width, 180px);
  max-width: 100%;
}

body[data-design] .sentence-completion-workspace .syllable-slot,
body[data-design] .sentence-completion-workspace .syllable-card,
body[data-design] .sentence-completion-workspace .syllable-source-placeholder {
  min-height: clamp(118px, 17vh, 176px);
}

body[data-design] .sentence-completion-workspace .syllable-card {
  padding: clamp(12px, 2vw, 22px);
  font-size: clamp(1.5rem, min(3vw, 4.6vh), 2.65rem);
  line-height: 1.05;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: keep-all;
}

body[data-design] .sentence-completion-workspace .syllable-card.fit-medium {
  font-size: clamp(1.35rem, min(2.6vw, 4vh), 2.25rem);
}

body[data-design] .sentence-completion-reference .syllable-card {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-color: transparent;
  box-shadow: none;
}

body.training-fullscreen .sentence-completion-workspace {
  width: min(100%, 1360px);
  min-height: calc(100dvh - 170px);
  align-content: center;
  justify-items: center;
  gap: clamp(22px, 4vh, 52px);
}

body.training-fullscreen .sentence-completion-reference {
  width: min(100%, 1320px);
}

@media (max-width: 720px) {
  body[data-design] .sentence-image-workspace {
    --sentence-piece-height: clamp(132px, 18vh, 186px);
  }

  body[data-design] .sentence-image-workspace .syllable-card {
    font-size: clamp(1.35rem, 7vw, 2.75rem);
  }

  body[data-design] .sentence-completion-workspace .syllable-slots {
    grid-template-columns: repeat(var(--syllable-count, 2), minmax(118px, 1fr));
  }

  body[data-design] .sentence-completion-blank-slot {
    width: min(var(--completion-piece-width, 180px), 34vw);
    min-width: min(var(--completion-piece-width, 180px), 34vw);
  }
}

/* Montar Frase com Imagem com 5 peças: letra um pouco menor e palavra sem quebrar ("COME" virava "COM/E"). */
body[data-design] .sentence-image-workspace .syllable-card:not(.is-image-piece) {
  overflow-wrap: normal;
  word-break: keep-all;
}

body[data-design] .sentence-image-workspace[data-count="5"] .syllable-card {
  font-size: clamp(1.3rem, min(3.4vw, 5vh), 2.9rem);
}

/* ---------- Montar Palavra: uma peça por letra, quadradas, todas numa linha ---------- */
body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) {
  gap: clamp(16px, 2.6vh, 28px);
}

body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-reference {
  width: clamp(200px, 26vw, 320px);
  height: clamp(150px, 22vh, 230px);
  margin-bottom: 0;
}

body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) :is(.syllable-slots, .syllable-source) {
  grid-template-columns: repeat(var(--syllable-count, 4), minmax(0, 124px));
  justify-content: center;
  gap: clamp(8px, 1.4vw, 16px);
}

body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) :is(.syllable-slot, .syllable-card, .syllable-source-placeholder) {
  width: 100%;
  height: auto;
  min-height: 0;
  aspect-ratio: 1;
}

body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-card {
  font-size: clamp(1.9rem, min(5.4vw, 7.4vh), 4.2rem);
}

body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-slot {
  font-size: clamp(1.1rem, 2.6vw, 2rem);
}

/* Letra encaixada: ocupa a casinha inteira e fica só a borda sólida do cartão (some o pontilhado). */
body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-slot:has(.syllable-card) {
  position: relative;
  border-color: transparent;
  background: transparent;
  overflow: visible;
}

body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-slot .syllable-card {
  position: absolute;
  inset: -3px;
  width: auto;
  height: auto;
  min-height: 0;
  aspect-ratio: auto;
  border: 2px solid #d7dde5;
  box-shadow: 0 6px 14px rgba(24, 32, 42, 0.1);
}

/* iPad em pé (fora da tela cheia): a barra de ajustes embaixo fica com metade da tela. A figura, as caixas e as
   peças não cabiam no espaço que sobra e subiam por cima do enunciado ("Organize as sílabas..."). Aqui o
   enunciado fica mais baixo, a figura menor e as peças do tamanho que cabe (Organizar Sílabas, Montar Palavra,
   Montar Frase com Imagem). */
@media (orientation: portrait) {
  body[data-app-view="treino"]:not(.training-fullscreen) .trainer:has(.syllable-workspace) .prompt-zone {
    min-height: 0;
    padding: 8px 14px;
  }

  body[data-app-view="treino"]:not(.training-fullscreen) .trainer:has(.syllable-workspace) .prompt-zone #promptText {
    font-size: clamp(1.05rem, 2.5vw, 1.4rem);
  }

  body[data-app-view="treino"]:not(.training-fullscreen) .choices.syllable-workspace {
    align-content: start;
    gap: 10px;
  }

  body[data-app-view="treino"]:not(.training-fullscreen) .choices.syllable-workspace .syllable-reference {
    width: 128px;
    height: 88px;
    margin-bottom: 0;
  }

  body[data-app-view="treino"]:not(.training-fullscreen) .choices.syllable-workspace:not(.sentence-image-workspace) :is(.syllable-slot, .syllable-card, .syllable-source-placeholder) {
    height: 62px;
    min-height: 0;
  }

  body[data-app-view="treino"]:not(.training-fullscreen) .choices.syllable-workspace:not(.sentence-image-workspace) .syllable-card {
    font-size: clamp(1.4rem, 4.4vw, 2.2rem);
  }

  body[data-app-view="treino"]:not(.training-fullscreen) .choices.sentence-image-workspace {
    --sentence-piece-height: 104px;
  }
}

/* ---------- Montar Palavra, fases 2 e 3: letras espalhadas pela área (scripts/features/syllables.js) ---------- */
/* A área tem altura fixa (cabe na tela) e as letras se ajustam a ela: o tamanho é o menor entre a largura e a
   altura de cada casa da grade (unidades cqw/cqh = largura/altura da área). */
body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-source.is-scattered {
  position: relative;
  display: block;
  width: min(100%, 980px);
  height: clamp(150px, 30vh, 280px);
  justify-self: center;
  container-type: size;
  border-radius: 22px;
  background: rgba(148, 163, 184, 0.08);
}

body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-source.is-scattered > :is(.syllable-card, .syllable-source-placeholder) {
  position: absolute;
  width: min(118px, calc(100cqw / var(--scatter-cols, 6) * 0.8), calc(100cqh / var(--scatter-rows, 2) * 0.78));
  height: auto;
  min-height: 0;
  aspect-ratio: 1;
  translate: -50% -50%;
  rotate: var(--scatter-rotation, 0deg);
  font-size: min(3.4rem, calc(100cqh / var(--scatter-rows, 2) * 0.42));
}

body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-source.is-scattered > .syllable-card.is-dragging {
  z-index: 5;
  rotate: 0deg;
}

/* Lugar da letra que já foi para a casinha: some (não mostra um buraco no meio da área). */
body[data-design] .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-source.is-scattered > .syllable-source-placeholder {
  visibility: hidden;
}

/* Fora da tela cheia, com as letras espalhadas: a figura fica menor e tudo começa do topo (não sobe por cima
   do enunciado). */
body[data-app-view="treino"]:not(.training-fullscreen) .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]):has(.syllable-source.is-scattered) {
  align-content: start;
}

body[data-app-view="treino"]:not(.training-fullscreen) .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]):has(.syllable-source.is-scattered) .syllable-reference {
  width: clamp(120px, 16vw, 190px);
  height: clamp(86px, 13vh, 140px);
}

body[data-app-view="treino"]:not(.training-fullscreen) .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-source.is-scattered {
  height: clamp(140px, 26vh, 240px);
}

/* iPad em pé fora da tela cheia: a tela do treino é baixa. As casinhas ficam em cima e, embaixo, a figura à
   esquerda e a área das letras espalhadas à direita. */
@media (orientation: portrait) {
  body[data-app-view="treino"]:not(.training-fullscreen) .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]):has(.syllable-source.is-scattered) {
    grid-template-columns: 112px minmax(0, 1fr);
    column-gap: 10px;
  }

  body[data-app-view="treino"]:not(.training-fullscreen) .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]):has(.syllable-source.is-scattered) > .syllable-slots {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  body[data-app-view="treino"]:not(.training-fullscreen) .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]):has(.syllable-source.is-scattered) > .syllable-reference {
    grid-column: 1;
    grid-row: 2;
    align-self: center;
    width: 112px;
    height: 96px;
  }

  body[data-app-view="treino"]:not(.training-fullscreen) .syllable-workspace:is([data-module="letterWord"], [data-module="sentenceBuild"]) .syllable-source.is-scattered {
    grid-column: 2;
    grid-row: 2;
    width: 100%;
    height: 158px;
  }
}

/* ---------- Montar Frase: as mesmas regras do Montar Palavra, mas as peças são palavras (cartões mais largos) ---------- */
body[data-design] .syllable-workspace[data-module="sentenceBuild"] :is(.syllable-slots, .syllable-source) {
  grid-template-columns: repeat(var(--syllable-count, 4), minmax(0, 200px));
}

body[data-design] .syllable-workspace[data-module="sentenceBuild"] :is(.syllable-slot, .syllable-card, .syllable-source-placeholder) {
  aspect-ratio: 1.7;
}

body[data-design] .syllable-workspace[data-module="sentenceBuild"] .syllable-card {
  padding: 4px 8px;
  font-size: clamp(1.15rem, min(2.8vw, 4.4vh), 2.3rem);
  white-space: nowrap;
}

body[data-design] .syllable-workspace[data-module="sentenceBuild"] .syllable-source.is-scattered > :is(.syllable-card, .syllable-source-placeholder) {
  width: min(200px, calc(100cqw / var(--scatter-cols, 6) * 0.86), calc(100cqh / var(--scatter-rows, 2) * 0.74 * 1.7));
  aspect-ratio: 1.7;
  font-size: min(2.2rem, calc(100cqh / var(--scatter-rows, 2) * 0.26));
}
