.quiz-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.heist-summary { display: contents; }

@media (max-width: 760px), (max-width: 1024px) and (orientation: portrait) and (any-pointer: coarse), (max-height: 520px) and (any-pointer: coarse) {
  #game {
    width: min(740px, calc(100% - 12px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  #game .masthead { min-height: 44px; gap: 6px; padding: 0; }
  #game .masthead-tools { gap: 4px; }
  #game .brand { gap: 5px; font-size: .76rem; line-height: 1.1; }
  #game .brand-mark { width: 27px; height: 27px; }
  #game .brand-mark svg { width: 16px; height: 16px; }
  #game :is(#game-setup, #game-options-toggle) { min-height: 44px; padding-inline: 7px; }
  #game:is([data-state="language"], [data-state="topic"]) .layout { display: block; margin-block: 6px 10px; }
  #game:is([data-state="language"], [data-state="topic"]) .room-panel { display: none; }
  #game:is([data-state="language"], [data-state="topic"]) .quiz { max-width: 520px; margin-inline: auto; }

  #game[data-play-layout] .layout {
    --map-reserve: 325px;
    --timer-gutter: 38px;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-template-rows: auto auto auto auto;
    align-items: center;
    gap: 4px 0;
    margin: 6px 0 8px;
  }

  #game[data-play-layout] :is(.quiz, .quiz-top, #heist-hud) { display: contents; }
  #game[data-play-layout]:not(:is([data-state="playing"], [data-state="won"], [data-state^="bonus"])) #heist-hud { display: none; }
  #game[data-play-layout] .layout::before {
    content: "";
    grid-area: 1 / 1 / 2 / 13;
    align-self: stretch;
    min-height: 24px;
    border-radius: 8px;
    background: #f5f8ee;
  }

  #game[data-play-layout] .room-panel {
    grid-area: 2 / 1 / 3 / 13;
    display: grid;
    align-content: center;
    justify-items: center;
    min-width: 0;
    padding-bottom: 4px;
    border-radius: 16px;
  }
  #game[data-play-layout]:is([data-state="playing"], [data-state="lost"]:has(.cat[data-state="burst"])) .room-panel {
    padding-inline-end: var(--timer-gutter);
  }

  #game[data-play-layout] .scene-title { padding: 0 5px; }
  #game[data-play-layout] .scene-title > :not(#three-status) { display: none; }
  #game[data-play-layout] #three-status { margin: 4px 0; font-size: .65rem; }
  #game[data-play-layout] .stage {
    width: min(100%, 600px);
    width: min(100%, 600px, max(150px, calc((100svh - var(--map-reserve) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 1.3115)));
    margin: 0 auto;
  }
  #game[data-play-layout] .room-caption {
    left: 4px;
    bottom: 4px;
    max-width: calc(100% - 8px);
    gap: 3px;
    padding: 3px 5px;
    font-size: .58rem;
  }
  #game[data-play-layout] .room-caption svg { width: 10px; height: 10px; flex: none; }
  #game[data-play-layout] .room-caption span { overflow: hidden; text-overflow: ellipsis; }
  #game[data-play-layout][data-view="3d"] .room-caption { max-width: calc(100% - 55px); }
  #game[data-play-layout] .scene-actions { right: 3px; bottom: 3px; }
  #game[data-play-layout] #camera-orbit { min-height: 44px; min-width: 44px; padding: 4px; }

  #game[data-play-layout] :is(.quiz-top .eyebrow, #progress, #mistakes, .heist-summary) {
    grid-row: 1;
    margin: 0;
    min-width: 0;
  }
  #game[data-play-layout] .quiz-top .eyebrow {
    grid-column: 1 / 4;
    padding: 3px 2px;
    font-size: .66rem;
    letter-spacing: .03em;
    text-align: center;
    white-space: nowrap;
  }
  #game[data-play-layout] #progress { grid-column: 4 / 6; gap: 2px; padding-inline: 4px; }
  #game[data-play-layout] .progress-dot { height: 5px; }
  #game[data-play-layout] #mistakes { grid-column: 11 / 13; align-self: center; justify-content: center; font-size: .7rem; }
  #game[data-play-layout] .heist-summary {
    grid-column: 6 / 11;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px 6px;
    padding: 3px 1px;
    font-size: .66rem;
    font-weight: 750;
    line-height: 1.15;
  }
  #game[data-play-layout] #heist-stamps { display: none; }
  #game[data-play-layout] .heist-streak { margin: 0; }

  #game[data-play-layout] .quiz-actions {
    grid-area: 3 / 9 / 4 / 13;
    align-self: start;
    min-width: 0;
    gap: 3px;
  }
  #game[data-play-layout][data-state="bonus-ready"] .quiz-actions {
    grid-column: 6 / 13;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #game[data-play-layout] :is(#restart, #bonus-skip, #purr-boost) {
    width: 100%;
    min-height: 44px;
    border-radius: 10px;
    padding: 3px 2px;
    font-size: .68rem;
    line-height: 1.15;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  #game[data-play-layout] .timer {
    grid-area: 2 / 1 / 3 / 13;
    z-index: 2;
    align-self: start;
    justify-self: end;
    width: calc(var(--timer-gutter) - 5px);
    margin: 5px 3px;
    padding: 5px 2px;
    font-size: .65rem;
    text-align: center;
    pointer-events: none;
  }
  #game[data-play-layout] .timer-label { justify-content: center; }
  #game[data-play-layout] .timer-label :is(.timer-name, .timer-warning) { display: none; }
  #game[data-play-layout] .timer-label strong { font-size: .82rem; white-space: nowrap; }
  #game[data-play-layout] .timer-label strong > :last-child { display: none; }
  #game[data-play-layout] .timer-label strong::after { content: " s"; }
  #game[data-play-layout] .timer-track { height: 4px; margin-top: 4px; }
  #game[data-play-layout] #purr-boost { grid-area: 3 / 6 / 4 / 9; width: auto; margin-inline: 3px; }

  #game[data-play-layout] .message {
    grid-area: 3 / 1 / 4 / 9;
    align-items: center;
    min-height: 0;
    margin: 0 4px 0 0;
    padding: 4px 6px;
    gap: 4px;
    font-size: .72rem;
    line-height: 1.2;
  }
  #game[data-play-layout]:is([data-state="bonus-ready"], :has(#purr-boost:not([hidden]))) .message { grid-column-end: 6; }
  #game[data-play-layout] .message svg { width: 13px; height: 13px; flex-basis: 13px; margin: 0; }
  #game[data-play-layout] .quiz-content {
    grid-area: 4 / 1 / 5 / -1;
    padding: 8px;
    border: 1px solid #fff;
    border-radius: 15px;
    background: var(--paper);
    box-shadow: var(--panel-shadow);
  }
  #game[data-play-layout] #question { margin: 0 0 7px; font-size: clamp(1.05rem, 4.5vw, 1.35rem); line-height: 1.12; }
  #game[data-play-layout] .answers { gap: 4px; }
  #game[data-play-layout] .answer { min-height: 44px; padding: 4px 7px; gap: 7px; font-size: .86rem; line-height: 1.15; }
  #game[data-play-layout] .answer-key { width: 21px; height: 21px; flex-basis: 21px; border-radius: 6px; }
  #game[data-play-layout] .bonus-controls { gap: 4px; }
  #game[data-play-layout] #bonus-phase { min-height: 34px; padding: 4px 6px; }
  #game[data-play-layout] #bonus-move { min-height: 44px; padding: 4px 6px; }
}

@media (orientation: landscape) and (max-height: 520px) and (min-width: 500px) and (max-width: 760px), (orientation: landscape) and (max-height: 520px) and (min-width: 500px) and (any-pointer: coarse) {
  #game[data-play-layout] { width: min(1050px, calc(100% - 12px - env(safe-area-inset-left) - env(safe-area-inset-right))); }
  #game[data-play-layout] .layout {
    --map-reserve: 165px;
    grid-template-columns: repeat(12, minmax(0, 1fr)) minmax(205px, 12fr);
    grid-template-rows: auto auto auto;
  }
  #game[data-play-layout] .quiz-content { grid-area: 1 / 13 / 4 / 14; align-self: stretch; justify-content: center; margin-left: 5px; }
  #game[data-play-layout] #question { font-size: clamp(1rem, 3.4vw, 1.22rem); }
}

@media (orientation: landscape) and (max-height: 360px) and (min-width: 500px) and (max-width: 690px) {
  #game[data-play-layout] .layout {
    grid-template-columns: repeat(12, minmax(0, 1fr)) minmax(235px, 13fr);
  }
  #game[data-play-layout] .quiz-content { justify-content: start; padding: 6px; }
  #game[data-play-layout] #question { margin-bottom: 5px; line-height: 1.09; }
}

@media (orientation: portrait) and (max-height: 500px) and (max-width: 760px) {
  #game[data-play-layout] .layout {
    --map-reserve: 316px;
    row-gap: 2px;
    margin-block: 3px 4px;
  }
  #game[data-play-layout] .message { padding-block: 3px; }
  #game[data-play-layout] .quiz-content { padding: 6px; }
  #game[data-play-layout] #question { margin-bottom: 5px; font-size: clamp(1rem, 4vw, 1.22rem); }
  #game[data-play-layout] .answers { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
  #game[data-play-layout] .answer:last-child { grid-column: 1 / -1; }
  #game[data-play-layout] .answer-label { overflow-wrap: anywhere; }
}

@media (orientation: portrait) {
  #game[data-play-layout][data-state="ready"] .layout { --map-reserve: 225px; }
}
