/* Touch targets have their own owner; desktop density remains unchanged. */
@media (max-width:700px), (pointer:coarse) {
  #game { position:relative; gap:6px; padding-top:4px; }
  #game h1 { position:absolute; left:52px; right:52px; top:11px; width:auto; margin:0; font-size:clamp(18px,5.5vw,24px); pointer-events:none; }
  #game.start-mode, #game.menu-mode { min-height:228px; height:calc(100dvh - 12px); grid-template-rows:44px minmax(0,1fr); gap:6px; }
  #game.start-mode.replay-mode { min-height:0; height:auto; grid-template-rows:none; }
  #game:not(.start-mode):not(.menu-mode):not(.replay-mode) #feature-nav { display:none; }
  #game-toolbar { min-height:44px; }
  #game-toolbar button, #game-toolbar #sound-toggle { min-width:44px; min-height:44px; }
  #game-toolbar #sound-toggle { width:44px; height:44px; }
  .menu-confirm, .start-choice, .panel-close, .feature-button, #feature-nav button,
  #feature-nav .import-label, #feature-panel select, .cf-replay-controls button,
  .cf-replay-controls select, .cf-replay-controls input[type="number"], .cf-replay-options summary {
    min-height:44px; padding:8px; font-size:12px;
  }
  .cf-replay-controls input[type="range"], #volume, [aria-label="Settings volume"] { min-height:44px; }
  .cf-replay-audio label:has(input[type="checkbox"]) { min-height:44px; cursor:pointer; }
  .cf-replay-audio input[type="checkbox"] { width:24px; height:24px; }
  .cf-replay-transport { flex-wrap:wrap; }
  .replay-stage { position:relative; }
  .cf-replay-options-content { position:absolute; top:0; left:0; right:0; height:var(--cf-replay-board-size,160px); max-height:none; overflow:auto; overscroll-behavior:contain; padding:6px; background:#020607; border:1px solid #1e655f; z-index:2; }
  #controls { height:174px; aspect-ratio:auto; }
  #controls .dpad { width:162px; height:162px; left:8px; top:6px; }
  #controls .dpad .control { width:54px; height:54px; }
  #controls .control-up { left:50%; top:16.6667%; }
  #controls .control-down { left:50%; top:83.3333%; }
  #controls .control-left { left:16.6667%; top:50%; }
  #controls .control-right { left:83.3333%; top:50%; }
  #controls .wait-control, #controls .wait-button-visual { width:64px; height:64px; left:auto; right:18px; top:22px; transform:none; }
  #controls .wait-mount { left:auto; right:10px; top:14px; width:80px; height:80px; }
  #controls .wait-label { left:auto; right:24px; top:90px; transform:none; font-size:14px; }
  #controls .reset-control, #controls .reset-pill { width:64px; height:44px; left:auto; right:18px; top:116px; transform:none; }
  #controls .reset-label { left:auto; right:25px; top:130px; transform:none; font-size:12px; pointer-events:none; z-index:5; }
}
@media (min-width:520px) and (max-height:380px) and (pointer:coarse) {
  #game.replay-mode { position:relative; padding-top:0; }
  .replay-mode h1 { position:absolute; left:52px; right:52px; top:9px; font-size:20px; pointer-events:none; }
  #game.replay-mode { width:min(96vw,760px) !important; }
  .replay-stage { position:relative; grid-template-columns:minmax(0,1fr) minmax(0,1.7fr); }
  .cf-replay-controls { gap:1px; }
  .cf-replay-transport { flex-wrap:nowrap; }
  .cf-replay-transport button, .cf-replay-transport select { flex:1; }
  .cf-replay-controls output { font-size:10px; }
  .cf-replay-options-content { position:absolute; left:0; top:0; bottom:0; width:calc(100% / 2.7 - 8px); max-height:none; background:#020607; border:1px solid #1e655f; z-index:2; padding:4px; }
  .cf-replay-timing, .cf-replay-audio { grid-template-columns:1fr; }
  #replay-area .panel-actions { gap:4px; }
  #replay-area .feature-button { padding:5px; font-size:11px; }
}

@media (min-width:520px) and (max-height:380px) and (pointer:coarse) {
  #game:not(.start-mode):not(.menu-mode):not(.replay-mode) { position:relative; }
  #game:not(.start-mode):not(.menu-mode):not(.replay-mode) h1 { position:absolute; left:52px; right:52px; top:9px; font-size:20px; pointer-events:none; }
  #game:not(.start-mode):not(.menu-mode):not(.replay-mode) #feature-nav { display:none; }
  #game:not(.start-mode):not(.menu-mode):not(.replay-mode) #hud { grid-column:1; grid-row:2; }
  #game:not(.start-mode):not(.menu-mode):not(.replay-mode) #board { grid-column:1; grid-row:3; }
  #game:not(.start-mode):not(.menu-mode):not(.replay-mode) #controls { grid-row:2 / 4; height:162px; }
  #game:not(.start-mode):not(.menu-mode):not(.replay-mode) #save-status { grid-column:1 / -1; grid-row:4; }
  #controls .dpad { width:150px; height:150px; }
  #controls .dpad .control { width:50px; height:50px; }
  #controls .reset-control, #controls .reset-pill { top:110px; }
  #controls .reset-label { top:124px; }
}

@media (min-width:520px) and (max-height:380px) and (pointer:coarse) {
  #game.start-mode:not(.replay-mode), #game.menu-mode:not(.replay-mode) { position:relative; grid-template-rows:44px minmax(0,1fr); gap:4px; }
  .start-mode h1, .menu-mode h1 { position:absolute; left:52px; right:52px; top:9px; font-size:20px; pointer-events:none; }
  .start-choices { width:162px; height:132px; }
}

@media (min-width:520px) and (max-height:380px) and (pointer:coarse) {
  #game.replay-mode { gap:0; }
  .cf-replay-guidance { font-size:10px; line-height:1.1; }
}
