/* Responsive screen layout and unscaled touch controls. */
html { line-height: 1.3; min-height: 100%; background-size: cover; background-attachment: fixed; }
body { margin: 8px; }
button, input, select { touch-action: manipulation; }
button { cursor: pointer; }
button:focus-visible { outline: 3px solid #f4d35e; outline-offset: 2px; }
[hidden] { display: none !important; }

/* Title and settings remain scrollable on small or short screens. */
#titleScreen { max-width: 900px; margin: 0 auto; }
#titleLogo { position: relative; width: 100%; height: auto; aspect-ratio: 900 / 323; top: auto; left: auto; transform: none; }
#legalContainer { top: auto; padding: 12px; background: #162c24e8; border-radius: 12px; }
#legalBanner, #legalTextContainer, #byUsingThisP, #acceptTermsButton { position: static; }
#legalBanner { font-size: clamp(20px, 5vw, 30px); }
#legalBannerBox, #legalTextSubBox, #settingsInputSubstage { display: none; }
#legalTextContainer > br { display: none; }
#legalTextContainer .button { margin: 6px; min-height: 44px; }
#acceptTermsButton { max-width: 100%; font-size: 12px; line-height: 1.5; margin-top: 16px; min-height: 48px; }

#settingsStage { width: min(650px, 100%); height: auto; box-sizing: border-box; padding: clamp(170px, 50vw, 350px) 16px 20px; isolation: isolate; background-color: #153a37; background-repeat: no-repeat; background-size: 100% auto; }
/* Extend the lower fire half without stretching the logo above it. */
#settingsStage::before { content: ""; position: absolute; inset: clamp(170px, 50vw, 350px) 0 0; z-index: -1; pointer-events: none; background: url("img/settingsAndTitle/settingStageBG.jpg") center bottom / 100% 200% no-repeat; border-radius: 0 0 15px 15px; }
#settingsHeaderSection { position: static; width: auto; height: auto; padding: 4px; }
#settingsHeader { position: static; font-family: "Press Start 2P", monospace; font-weight: 400; }
.settingsColumns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin: 20px 0; }
#difficultyStage, #soundContainer { position: static; width: auto; min-width: 0; }
#difficultyStage h2, #soundContainer h2 { font-size: 14px; line-height: 1.5; }
#soundContainer .master-sound-div, #soundContainer .music-sound-div,
#soundContainer .zombie-sound-div, #soundContainer .tank-sound-div { position: static; display: grid; grid-template-columns: 1fr 48px 44px; gap: 6px; align-items: center; margin-bottom: 12px; }
#soundContainer label { grid-column: 1 / -1; text-align: left; }
#soundContainer input[type=range] { width: 100%; min-width: 0; height: 36px; }
#soundContainer .sound-number, #soundContainer .zombie-test-btn, #soundContainer .tank-test-btn { position: static; width: 100%; height: 40px; box-sizing: border-box; }
.zombie-test-btn, .tank-test-btn { background-repeat: no-repeat; background-position: center; }
.settingsLinks { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 16px 0; }
.settingsLinks > button { position: static !important; width: auto !important; min-height: 44px; font-size: 11px !important; }
#settingsStage #settingsPrimaryActions { position: static; width: 100%; transform: none; }
#populationSlider { max-width: 100%; height: 36px; }
.speedLabel { display: inline-flex; align-items: center; min-height: 44px; }

/* A fixed-size combat canvas is scaled; the HUD uses ordinary CSS pixels. */
#playingStage { position: relative; left: auto; width: var(--board-width, 500px); max-width: 100%; height: auto; margin: 0 auto; }
.battlefieldViewport { position: relative; width: var(--board-width); height: var(--board-height); overflow: hidden; }
.battlefieldCanvas { position: absolute; width: 500px; height: 750px; transform-origin: top left; }
#firingStage { touch-action: none; }
.gameControls { position: relative; min-width: 0; padding: 8px; box-sizing: border-box; background: #162c24f5; border: 2px solid #489178; border-radius: 0 0 10px 10px; }
.gameStats { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 28px; }
#waveDisplay, #livesDisplay, #repPointsDisplay { position: static; font-size: clamp(14px, 3.5vw, 20px); line-height: 1.2; }
#repPointsDisplay::before { content: '◆ '; color: #f4d35e; }
#waveBackground, #repPointsBackground, #livesBackground, #ammoBackground, #freezeBackground, #nukeBackground,
#playingStage > .repPointsCoin, #output { display: none; }
.gameAbilities { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 8px 0; }
.gameAbilities > button, .ammoMenu > button, .gameToolbar > button, #resumeButton {
    min-height: 48px; min-width: 0; border: 2px solid #489178; border-radius: 6px;
    color: #f2fff8; background-color: #24463d; font: bold 14px Georgia, serif;
}
#ammoToggle { display: flex; align-items: center; justify-content: center; gap: 4px; }
#ammoToggle::after { content: '▾'; }
#ammoDisplay, #ammoImage { position: static; font-size: 15px; }
#ammoImage { flex: 0 0 26px; background-repeat: no-repeat; }
#freezeCounter, #nukeCounter { position: static; display: inline-flex; align-items: center; gap: 4px; }
#freezeCounterImg, #nukeCounterImg, #freezeCounterNumber, #nukeCounterNumber { position: static; display: inline-block; font-size: 18px; }
#freezeCounterImg, #nukeCounterImg { background-repeat: no-repeat; background-position: center; }
.ammoMenu { position: absolute; bottom: calc(100% - 30px); left: 0; right: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px; background: #102d27; border: 2px solid #82ffd5; border-radius: 8px; z-index: 100; }
.ammoMenu [aria-pressed=true] { background: #70531e; border-color: #f4d35e; }
.gameToolbar { display: grid; grid-template-columns: 1fr 48px 48px 1fr; gap: 6px; }
.gameToolbar #audioSettingsButton, .gameToolbar #shotLogButton, .gameToolbar #resetButton { position: static; width: auto; height: auto; min-height: 44px; z-index: auto; background-repeat: no-repeat; background-position: center; }
.gameToolbar #resetButton { background-color: #71312c; font-size: 11px; }
#speechBubble { position: static; width: auto; height: auto; margin-top: 8px; padding: 8px; background: #e7eed8; border-radius: 8px; }
#speechBubbleText { position: static; width: auto; font-size: 12px !important; line-height: 1.25; }
.bossStatus:empty { display: none; }
.bossNameLabel { position: static; width: auto; transform: none; font-size: 10px; line-height: 1.5; white-space: normal; margin: 4px 0; }
#bossHealthBarShell { box-sizing: border-box; }
#playingStage.wideLayout { grid-template-columns: var(--board-width) 220px; gap: 12px; width: calc(var(--board-width) + 232px); align-items: start; }
#playingStage.wideLayout[style*="display: block"] { display: grid !important; }
.wideLayout .gameAbilities { grid-template-columns: 1fr; }
.wideLayout .gameStats { flex-wrap: wrap; }
.wideLayout .gameToolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.wideLayout .ammoMenu { bottom: auto; top: 35px; grid-template-columns: 1fr; }

/* Dialogs stay inside the viewport, independent of combat scale. */
#pauseWindow, #howToPlayWindow, #playingSoundContainer, #shotLog { position: fixed; inset: auto; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); height: auto; box-sizing: border-box; overflow-y: auto; background: #123c43; border: 2px solid #82ffd5; padding: 16px; z-index: 2000; opacity: 1; }
#pauseWindow { text-align: center; }
#pauseWindow h2 { font-size: 18px; }
#playingSoundContainer { height: 260px; }
#playingSoundBackground { display: none !important; }
#playingSoundHeader { position: static; font-size: 16px; }
#playingSoundContainer .master-sound-div { top: 75px; }
#playingSoundContainer .music-sound-div { top: 115px; }
#playingSoundContainer .zombie-sound-div { top: 155px; }
#playingSoundContainer .tank-sound-div { top: 195px; }
#soundSettingsCloseButton, #closeButtonShotLog { min-width: 44px; min-height: 44px; background-repeat: no-repeat; background-position: center; }
#howToPlayWindow p { line-height: 1.5; }
#confirmMilitiaTankType { padding-top: 24px; overflow-y: auto; }
#shopStage { max-width: calc(100vw - 16px); }
.shopRow { width: 100%; box-sizing: border-box; grid-template-columns: 52px minmax(0, 1fr); }
.shopRowText { min-width: 0; }
.shopLabel, .shopDescription { overflow-wrap: anywhere; white-space: normal; }
#logContainer { height: min(55dvh, 623px); }
.finalButtons { flex-wrap: wrap; }
.finalButtons button { min-height: 44px; }
@media (max-width: 540px) {
    .settingsColumns { grid-template-columns: 1fr; }
    #settingsStage { padding-inline: 12px; }
    #settingsStage #settingsPrimaryActions { grid-template-columns: 1fr; }
    .shopRow { gap: 8px; }
    .shopRowText { grid-template-columns: minmax(0, 1fr); row-gap: 6px; }
    .shopPrice { justify-self: start; }
    .shopLabel { font-size: 16px; }
    .shopPrice { font-size: 16px; }
    .finalCard { padding: 16px; }
}

/* Keep number inputs legible and avoid focus zoom on mobile browsers. */
#settingsStage input[type=number], #playingSoundContainer input[type=number] { font-size: 16px; min-height: 44px; box-sizing: border-box; }
#confirmationPopup { box-sizing: border-box; max-height: calc(100dvh - 32px); overflow-y: auto; }
#confirmMilitiaTankType { position: fixed; }
.militiaTankPromptCard { box-sizing: border-box; max-height: calc(100dvh - 32px); overflow-y: auto; }

.gameToolbar #resetButton:disabled { opacity: .45; cursor: not-allowed; }
