/* Mobile play uses the available viewport; the controls stay within thumb reach. */
@media (max-width: 900px), (pointer: coarse) {
  html { -webkit-text-size-adjust: 100%; }
  body { min-width: 0; overflow-x: clip; }
  .app {
    width: 100%; min-width: 0;
    padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right));
  }
  main, .game-shell, .hud, .mobile-controls, .below-game { min-width: 0; }
  .header { height: calc(72px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); gap: 16px; }
  .brand { gap: 9px; flex-shrink: 0; }
  .brand svg { width: 33px; height: 33px; }
  .brand > span { font-size: 21px; letter-spacing: 4px; }
  .brand small { font-size: 6px; letter-spacing: 2.8px; }
  .nav-label { display: none; }
  .text-button { min-height: 44px; font-size: 11px; padding: 8px 2px; }
  main { padding-top: 16px; }
  .game-shell {
    height: clamp(350px, calc(100svh - 178px), 650px);
    min-height: 0; border-radius: 14px;
  }
  .stage-top { top: 20px; left: 20px; right: 20px; }
  .zone { font-size: 9px; gap: 7px; }
  .zone > span:last-child { font-size: 9px; padding-left: 8px; }
  .stage-code { font-size: 8px; gap: 7px; }
  .stage-code i { width: 15px; height: 15px; }
  .stage-code i:after { inset: 5px; }
  .intro { top: 15%; left: 7%; }
  .eyebrow { font-size: 8px; letter-spacing: 2px; margin-bottom: 16px; }
  h1 { font-size: clamp(31px, 8.8vw, 50px); line-height: 1.3; margin-bottom: 14px; }
  .intro p { font-size: 11px; line-height: 1.9; margin-bottom: 20px; }
  .primary-button { min-height: 48px; padding: 13px 20px; font-size: 13px; gap: 24px; }
  .start-note { max-width: 180px; font-size: 9px; line-height: 1.7; margin-top: 9px; }
  .character-tag { left: auto; right: 7%; top: auto; bottom: 12.5%; text-align: right; }
  .tag-line { display: none; }
  .character-tag small { font-size: 7px; letter-spacing: 1px; }
  .character-tag strong { font-size: 18px; }
  .ready-bottom { left: 20px; right: 20px; bottom: 20px; font-size: 6px; letter-spacing: 1px; gap: 12px; }
  .best-label { font-size: 9px; letter-spacing: .5px; gap: 4px; }
  .best-label svg { display: none; }
  .mobile-controls { display: none; }
  .below-game { padding: 20px 2px; }
  .mission { gap: 12px; }
  .mission-icon { width: 36px; height: 36px; font-size: 22px; flex-shrink: 0; }
  .mission h2 { font-size: 12px; letter-spacing: .5px; }
  .mission p { font-size: 9px; line-height: 1.8; letter-spacing: .4px; }
  .controls { display: none; }
  .detail-line { padding: 16px 2px; gap: 10px; font-size: 8px; }
  footer { font-size: 7px; padding-block: 18px max(18px, env(safe-area-inset-bottom)); gap: 20px; }
  footer > span:last-child { max-width: 140px; line-height: 1.8; text-align: right; }
  .footer-star { display: none; }
  .hud { top: 68px; left: 18px; right: 18px; gap: 8px; align-items: center; }
  .hud-distance { min-width: 0; }
  .hud-distance small { font-size: 9px; letter-spacing: 1px; }
  .hud-distance strong { font-size: clamp(25px, 7vw, 34px); font-variant-numeric: tabular-nums; }
  .hud-distance strong span { font-size: 11px; margin-left: 3px; }
  .hud-energy { gap: 5px; padding: 5px 10px; font-size: 18px; margin: 0; }
  .hud-energy small { display: none; }
  .energy-gem { font-size: 25px; }
  .hud-actions { gap: 6px; }
  .hud-actions button { width: 44px; height: 44px; flex-shrink: 0; }
  .hud-actions svg { width: 20px; height: 20px; }
  .message { top: 29%; max-width: calc(100% - 28px); white-space: normal; font-size: 14px; line-height: 1.8; }
  .level-tag { bottom: 18px; left: 20px; font-size: 9px; }
  .modal-backdrop { padding: 12px; }
  .dialog { width: min(380px, 100%); max-height: 100%; overflow-y: auto; overscroll-behavior: contain; padding: 28px 24px; }
  .dialog-kicker { font-size: 8px; line-height: 1.6; }
  .dialog h2 { font-size: 26px; margin: 13px 0; }
  .dialog p { margin-bottom: 20px; }
  .dialog .primary-button { margin-top: 20px; }
  .secondary-button { min-height: 44px; margin-top: 10px; font-size: 12px; }
  .result-distance { font-size: 58px; margin: 15px 0 20px; }
  .result-stats { gap: 20px; }
  .charge { left: 10px; right: 10px; bottom: 3px; }
  dialog { width: min(480px, calc(100% - 24px)); max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 32px); padding: 24px; overflow-y: auto; overscroll-behavior: contain; }
  .help-header button { min-width: 44px; min-height: 44px; }
  dialog h2 { font-size: 21px; margin-top: 14px; }
  .help-row { gap: 14px; margin-top: 18px; }
  .help-row > .key, .gem-symbol { min-width: 76px; width: 76px; flex-shrink: 0; }
  .help-row p { font-size: 11px; }
  body.playing { height: 100dvh; overflow: hidden; overscroll-behavior: none; }
  body.playing .app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
  body.playing .header { height: calc(56px + env(safe-area-inset-top)); flex: 0 0 calc(56px + env(safe-area-inset-top)); }
  body.playing main { display: flex; flex: 1; flex-direction: column; min-height: 0; padding-top: 10px; }
  body.playing .game-shell { height: auto; min-height: 0; flex: 1; }
  body.playing .below-game, body.playing .detail-line, body.playing footer { display: none; }
  body.playing .mobile-controls {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    flex: 0 0 64px; gap: 12px; margin: 12px 0 max(14px, env(safe-area-inset-bottom));
    touch-action: none; -webkit-user-select: none; user-select: none;
  }
  .mobile-controls button {
    width: 100%; min-width: 0; min-height: 64px; display: flex; align-items: center; justify-content: center; gap: 10px;
    border: 1px solid #749db640; border-radius: 10px; background: #102139; color: #c6e8ff;
    font-size: 15px; font-weight: 500; touch-action: none; -webkit-user-select: none; user-select: none;
  }
  .mobile-controls button > span { font-size: 27px; }
  .mobile-controls button > small { font-size: 10px; color: #86a9c6; }
  .mobile-controls button:last-child { background: #173e54; border-color: #76cee963; color: #c6f3ff; }
  .mobile-controls button:active, .mobile-controls button.active { background: #30738e; }
}

@media (max-width: 360px) {
  .app { padding-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right)); }
  .intro { left: 6%; }
  .intro p { font-size: 10px; }
  .eyebrow { font-size: 7px; letter-spacing: 1.5px; }
  .stage-top { left: 16px; right: 16px; }
  .stage-code { display: none; }
  .hud { left: 14px; right: 14px; gap: 6px; }
  .hud-energy { padding-inline: 8px; }
  .hud-actions { gap: 4px; }
  .mobile-controls button { gap: 7px; }
  .mobile-controls button > small { font-size: 9px; }
  .ready-bottom > span:first-child { letter-spacing: .4px; font-size: 5px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .app { padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right)); }
  .header { height: 54px; }
  main { padding-top: 10px; }
  .game-shell { height: max(270px, calc(100svh - 100px)); }
  .intro { top: 20%; left: 7%; }
  .eyebrow { margin-bottom: 10px; font-size: 7px; }
  h1 { font-size: clamp(28px, 5vw, 40px); line-height: 1.25; margin-bottom: 12px; }
  .intro p, .character-tag, .start-note { display: none; }
  .primary-button { min-height: 44px; padding-block: 10px; }
  .ready-bottom { bottom: 15px; }
  body.playing .app { position: relative; }
  body.playing .header { height: 44px; flex-basis: 44px; }
  body.playing .header .brand svg { width: 27px; height: 27px; }
  body.playing .header .brand > span { font-size: 17px; }
  body.playing .header .brand small { display: none; }
  body.playing main { padding-top: 6px; }
  body.playing .game-shell { margin-bottom: max(8px, env(safe-area-inset-bottom)); }
  body.playing .stage-top { display: none; }
  body.playing .hud { top: 12px; left: 18px; right: 18px; }
  body.playing .hud-distance small { display: none; }
  body.playing .hud-distance strong { font-size: 26px; }
  body.playing .hud-energy { margin-left: auto; margin-right: 10px; font-size: 17px; padding-block: 3px; }
  body.playing .hud-actions button { width: 44px; height: 44px; }
  body.playing .message { top: 25%; font-size: 12px; }
  body.playing .level-tag { display: none; }
  body.playing .mobile-controls {
    position: absolute; left: max(30px, env(safe-area-inset-left)); right: max(30px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom));
    display: flex; justify-content: space-between; margin: 0; pointer-events: none;
  }
  .mobile-controls button { width: 150px; min-height: 52px; background: #102139d9; backdrop-filter: blur(6px); pointer-events: auto; }
  .mobile-controls button:last-child { background: #173e54d9; }
  .dialog { padding: 18px 24px; width: min(380px, 85%); }
  .dialog h2 { font-size: 23px; margin: 7px 0; }
  .dialog p { margin-bottom: 14px; }
  .dialog .primary-button { margin-top: 12px; }
  .secondary-button { margin-top: 3px; }
  .result-dialog { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; align-items: center; width: min(520px, 90%); }
  .result-dialog > .dialog-kicker, .result-dialog > h2, .result-dialog > .result-note { grid-column: 1 / -1; }
  .dialog .result-note { margin: 0; }
  .result-distance { grid-column: 1; font-size: 42px; margin: 4px 0; }
  .result-stats { grid-column: 2; gap: 16px; }
  .result-dialog .primary-button { grid-column: 1; margin: 4px 0; }
  .result-dialog .secondary-button { grid-column: 2; margin: 4px 0; }
}
