html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 0;
}

main {
  height: calc(100dvh - 82px);
  overflow: hidden;
}

.screen,
.screen.active {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

#home {
  padding-block: clamp(18px, 4vh, 52px);
}

.scene {
  height: min(540px, 68vh);
}

.game-screen {
  grid-template-rows: auto minmax(0, 1fr);
  padding-block: clamp(10px, 2vh, 20px);
}

.game-grid {
  min-height: 0;
  height: 100%;
}

.workspace,
.coach {
  min-height: 0;
  overflow: hidden;
}

#sqlEditor {
  height: clamp(72px, 14vh, 126px);
}

.tokens {
  min-height: 0;
  max-height: 11vh;
  overflow: hidden;
}

.result-body {
  min-height: 48px;
  max-height: 16vh;
}

.avatar-stage {
  height: min(285px, 34vh);
}

.coach-avatar {
  height: min(280px, 33vh);
}

/* Em telas de uma coluna, o conteúdo rola em vez de ser recortado. */
@media (max-width: 980px) {
  #game.game-screen {
    height: 100%;
    overflow-y: auto;
    align-content: start;
  }

  #game .game-grid {
    height: auto;
    min-height: 0;
    margin: 0 auto;
  }

  #game .workspace,
  #game .coach {
    overflow: visible;
  }
}

.donation-card {
  max-height: 100%;
  padding-block: clamp(20px, 4vh, 48px);
}

.celebration-frames {
  max-height: min(490px, 64vh);
}

.success > img {
  max-height: 42vh;
}

@media (max-height: 760px) {
  .game-meta {
    margin-bottom: 8px;
  }

  .workspace {
    padding: 12px;
  }

  .brief {
    margin-bottom: 8px;
    padding-block: 8px;
    font-size: 0.86rem;
  }

  .builder,
  .result {
    margin-top: 8px;
  }

  .builder-title,
  .result-head {
    padding-block: 7px;
  }

  .tab,
  .token {
    padding-block: 6px;
  }

  .coach {
    padding: 12px;
  }

  .speech {
    min-height: 68px;
    padding: 10px;
  }

  .stats div {
    padding: 6px;
  }

  .donation-card {
    gap: 24px;
  }

  .donation-copy > p:not(.eyebrow):not(.disclaimer):not(.gratitude) {
    font-size: 0.94rem;
    line-height: 1.45;
  }

  .disclaimer {
    margin-top: 18px;
    padding-top: 12px;
  }
}

@media (max-width: 620px) {
  main {
    height: calc(100dvh - 70px);
  }

  #home.active {
    grid-template-rows: auto minmax(0, 1fr);
    padding-block: 18px;
  }

  .hero-copy h1 {
    font-size: clamp(2.65rem, 14vw, 4rem);
  }

  .lead {
    margin-top: 14px;
    font-size: 0.95rem;
    line-height: 1.4;
  }

  .actions,
  .features {
    margin-top: 14px;
  }

  .scene {
    height: 100%;
    min-height: 150px;
    border-radius: 24px;
  }

  .game-screen {
    padding-block: 8px;
  }

  .game-meta h2 {
    font-size: 1.2rem;
  }

  .coach {
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 4px 8px;
    padding: 8px;
  }

  .avatar-stage {
    width: 86px;
    height: 105px;
  }

  .coach-avatar {
    height: 102px;
  }

  .avatar-stage i {
    width: 78px;
    height: 78px;
  }

  .speech {
    min-height: 52px;
    font-size: 0.75rem;
    line-height: 1.3;
  }

  .stats,
  .progress {
    display: none;
  }

  #sqlEditor {
    height: 66px;
  }

  .tokens {
    max-height: 58px;
  }

  .result-body {
    max-height: 72px;
  }

  .donation-card {
    height: 100%;
    grid-template-rows: auto minmax(110px, 1fr);
    gap: 8px;
    padding-block: 16px;
  }

  .donation-copy h2 {
    font-size: clamp(2rem, 11vw, 2.65rem);
  }

  .donation-copy > .eyebrow {
    margin-bottom: 8px;
  }

  .donation-copy > p:not(.eyebrow):not(.disclaimer):not(.gratitude) {
    margin-block: 8px;
    font-size: 0.82rem;
    line-height: 1.35;
  }

  .donation-link {
    margin-top: 2px;
    padding: 11px 15px;
  }

  .continue-learning {
    margin-top: 9px;
    font-size: 0.76rem;
  }

  .disclaimer {
    margin-top: 10px;
    padding-top: 8px;
    font-size: 0.62rem;
    line-height: 1.3;
  }

  .gratitude {
    margin-top: 8px;
  }

  .donation-avatars {
    width: min(100%, 230px);
    height: 100%;
  }

  .celebration-frames {
    width: auto;
    height: 100%;
    max-height: 100%;
    aspect-ratio: 1145 / 1374;
  }

  .donation-avatars p {
    display: none;
  }
}

/* Página inicial no celular: proporções próprias, sem herdar o feedback. */
@media (max-width: 620px) {
  #home.active {
    grid-template-rows: auto minmax(190px, 1fr);
  }

  #home .scene {
    min-height: 190px;
  }

  #home .hero-avatar {
    width: min(210px, 52vw);
    bottom: 58px;
  }

  #home .desk {
    height: 102px;
  }

  #home .laptop {
    bottom: 18px;
    height: 74px;
    border-width: 7px;
    border-radius: 14px;
  }

  #home .window {
    top: 20px;
    right: 22px;
    width: 132px;
    height: 84px;
    border-width: 8px;
  }

  #home .plant {
    top: 74px;
    left: 18px;
    font-size: 40px;
  }

  #home .chip {
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 0.62rem;
  }

  #home .chip.select {
    top: 15px;
  }

  #home .chip.where {
    bottom: 66px;
  }
}

/* Somente o desafio no celular: terminal maior e construtor acessível por toque. */
@media (max-width: 620px) {
  #game.game-screen {
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
    max-width: 100%;
  }

  #game .game-grid {
    width: 100%;
    max-width: 100%;
    min-height: 0;
    min-width: 0;
    height: auto;
    overflow: visible;
  }

  #game .coach {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    grid-template-columns: 70px minmax(0, 1fr);
    flex: 0 0 auto;
    min-height: 92px;
    padding: 6px 8px;
  }

  #game .coach > .eyebrow {
    margin-bottom: 0;
    font-size: 0.56rem;
  }

  #game .avatar-stage {
    width: 70px;
    height: 74px;
  }

  #game .coach-avatar {
    height: 72px;
  }

  #game .avatar-stage i {
    width: 62px;
    height: 62px;
  }

  #game .mood {
    margin-bottom: 2px;
    font-size: 0.72rem;
  }

  #game .speech {
    min-width: 0;
    overflow-wrap: anywhere;
    min-height: 42px;
    padding: 7px;
    font-size: 0.68rem;
  }

  #game .workspace {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 0;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
  }

  #game .brief,
  #game .terminal {
    flex: 0 0 auto;
  }

  #game textarea#sqlEditor {
    display: block;
    height: clamp(170px, 22dvh, 220px) !important;
    min-height: clamp(170px, 22dvh, 220px) !important;
    max-height: none !important;
    block-size: clamp(170px, 22dvh, 220px) !important;
    resize: none;
  }

  #game .terminal-head {
    height: 29px;
  }

  #game .terminal-actions {
    padding-block: 6px;
  }

  #game .brief {
    gap: 7px;
    margin-bottom: 6px;
    padding: 6px 9px;
    font-size: 0.74rem;
    line-height: 1.25;
  }

  #game .brief b {
    font-size: 0.72rem;
  }

  #game .builder {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 122px;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
  }

  #game .builder-title,
  #game .tabs {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 0 0 auto;
  }

  #game .tokens {
    min-height: 52px;
    max-height: none;
    flex: 1 1 auto;
    flex-wrap: nowrap;
    align-items: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  #game .tokens::-webkit-scrollbar {
    display: none;
  }

  #game .token {
    flex: 0 0 auto;
  }
}
