html, body {
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button { -webkit-tap-highlight-color: transparent; }
.rotate-device { display: none; }
.mobile-utility-controls { display: none; }
@media (pointer: coarse), (max-width: 760px) {
  #storyControls > span { display: none; }
}

@media (pointer: coarse) {
  html, body { width: 100%; height: 100%; min-height: 100dvh; overflow: hidden; }
  button, canvas { touch-action: none; }
}

@media (pointer: coarse) and (orientation: portrait) {
  body { display: grid; min-height: 100dvh; place-items: center; background: #08070d; }
  .game-shell { visibility: hidden; pointer-events: none; }
  .rotate-device {
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 30px;
    color: #fff3bf;
    text-align: center;
    background: radial-gradient(circle, #392347 0, #15101d 48%, #08070d 100%);
  }
  .rotate-phone {
    display: block;
    color: #ffc63d;
    font: 900 92px/1 monospace;
    text-shadow: 5px 5px 0 #7b2538;
    transform: rotate(90deg);
    animation: phone-turn 1.5s ease-in-out infinite alternate;
  }
  .rotate-device strong { font-size: clamp(22px, 7vw, 34px); letter-spacing: .08em; text-shadow: 3px 3px 0 #7b2538; }
  .rotate-device small { color: #cdbddd; font-size: 11px; letter-spacing: .12em; }
  @keyframes phone-turn { from { transform: rotate(0deg); } to { transform: rotate(90deg); } }
}

@media (pointer: coarse) and (orientation: landscape) {
  body { width: 100vw; height: 100dvh; overflow: hidden; background: #050409; }
  .rotate-device { display: none !important; }
  .game-shell {
    position: fixed;
    inset: 0;
    display: block;
    width: 100vw;
    height: 100dvh;
    margin: 0;
    padding: 0 max(4px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left));
  }
  .game-header, footer { display: none !important; }
  .game-frame {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: #050409;
    box-shadow: none;
  }
  .screen-wrap,
  .screen-wrap.choosing {
    position: absolute;
    inset: 0;
    min-height: 0 !important;
    border: 0;
    background: #050409;
    box-shadow: none;
  }
  canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    object-fit: contain;
    background: #050409;
  }
  .hud {
    position: absolute;
    z-index: 18;
    top: max(4px, env(safe-area-inset-top));
    left: 50%;
    width: min(620px, 72vw);
    min-height: 0;
    padding: 0;
    transform: translateX(-50%);
    pointer-events: none;
  }
  .hud > div { height: 34px !important; padding: 3px 7px !important; opacity: .9; }
  .hud span, .hud small { font-size: 6px !important; }
  .hud strong, .hud .portrait b { font-size: 11px !important; }
  .hud .mini-boki { width: 28px; height: 28px; }
  .hud .health-track { height: 10px; margin-top: 1px; border-width: 1px; }
  .mobile-controls {
    position: absolute;
    z-index: 30;
    inset: 0;
    display: block;
    padding: 0;
    pointer-events: none;
  }
  .mobile-controls button { pointer-events: auto; opacity: .72; box-shadow: 0 3px 10px #000b; }
  .mobile-utility-controls {
    position: absolute;
    z-index: 42;
    inset: 0;
    display: block;
    pointer-events: none;
  }
  .mobile-utility-controls button {
    position: absolute;
    pointer-events: auto;
    border: 1px solid #d7b568;
    border-radius: 8px;
    padding: 8px 11px;
    color: #fff1cf;
    background: #17101ddb;
    font: 800 9px/1 RumaPixel, sans-serif;
    letter-spacing: .04em;
    box-shadow: 0 3px 10px #000b;
  }
  .mobile-utility-controls button[hidden] { display: none; }
  #touchSkipIntro {
    left: 50%;
    bottom: max(9px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
  }
  #touchPause {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
  }
  .dpad {
    position: absolute;
    left: max(10px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
    width: 132px;
    grid-template-columns: repeat(3, 42px);
    grid-template-rows: repeat(2, 40px);
    gap: 3px;
  }
  .dpad button { font-size: 14px; border-radius: 9px; }
  .round {
    position: absolute;
    width: 58px;
    height: 50px;
    border-radius: 14px;
    font-size: 8px;
  }
  .round.attack {
    right: max(78px, calc(env(safe-area-inset-right) + 66px));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 72px;
    height: 64px;
    border-radius: 20px;
    font-size: 11px;
    opacity: .88;
  }
  .round.jump { right: max(78px, calc(env(safe-area-inset-right) + 66px)); bottom: max(86px, calc(env(safe-area-inset-bottom) + 74px)); }
  .round.interact {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 54px;
    height: 48px;
  }
  .round.crouch { right: max(12px, env(safe-area-inset-right)); bottom: max(69px, calc(env(safe-area-inset-bottom) + 57px)); }
  .round.special { right: max(12px, env(safe-area-inset-right)); bottom: max(126px, calc(env(safe-area-inset-bottom) + 114px)); }
  .overlay { padding: 5px 88px; }
  .panel { max-height: 94dvh; padding: 8px 16px; overflow: auto; }
  #startScreen .fighter-grid { gap: 6px; }
  #startScreen .fighter-card { min-height: 112px; }
  #startScreen h2 { font-size: clamp(18px, 5dvh, 29px) !important; }
  #startScreen .kicker, #startScreen .intro { margin-block: 3px; }
  #startScreen .primary-button { padding: 7px 15px; }
  #storyControls { padding-bottom: max(5px, env(safe-area-inset-bottom)); }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 390px) {
  .hud { width: min(560px, 68vw); }
  .hud > div { height: 30px !important; }
  .round { width: 52px; height: 44px; }
  .dpad { width: 120px; grid-template-columns: repeat(3, 38px); grid-template-rows: repeat(2, 36px); }
  .round.jump { right: 70px; bottom: 76px; }
  .round.attack { right: 64px; width: 66px; height: 56px; }
  .round.interact { right: 8px; width: 50px; height: 44px; }
  .round.crouch { bottom: 63px; }
  .round.special { bottom: 114px; }
}

/* Compact character select: every choice, skin and confirm button fits on one iPhone screen. */
@media (pointer: coarse) and (orientation: landscape) {
  body:has(.screen-wrap.choosing) .hud,
  .screen-wrap.choosing + .mobile-controls { display: none !important; }
  #startScreen {
    align-items: center;
    padding: 3px max(70px, env(safe-area-inset-left)) 3px max(70px, env(safe-area-inset-right));
    overflow: hidden;
  }
  #startScreen .select-panel {
    display: flex;
    flex-direction: column;
    width: min(760px, 100%);
    max-height: calc(100dvh - 6px);
    padding: 5px 12px 6px;
    overflow: hidden;
  }
  #startScreen .kicker { margin: 0 0 1px; font-size: 6px; }
  #startScreen h2 { margin: 0 0 4px; font-size: clamp(17px, 5.5dvh, 24px) !important; line-height: 1; }
  #startScreen .fighter-grid { gap: 7px; margin: 0 0 5px; }
  #startScreen .fighter-card {
    height: 166px;
    min-height: 0;
    border-width: 2px;
    box-shadow: 3px 3px 0 #09060e;
  }
  #startScreen .fighter-art { height: 80px; background-size: auto 112%; background-position: calc(50% + 12px) bottom; }
  #startScreen .fighter-card::before { height: 80px; }
  #startScreen .fighter-card strong,
  #startScreen .fighter-card[data-hero="heroine"] strong {
    top: 75px;
    padding: 2px 0;
    font-size: 16px;
  }
  #startScreen .fighter-stats { top: 101px; left: 5px; right: 5px; gap: 1px; }
  #startScreen .stat-row { display: flex; justify-content: space-between; font-size: 6px; line-height: 1; }
  #startScreen .stars { font-size: 8px; letter-spacing: 0; }
  #startScreen .skin-row { min-height: 24px; gap: 6px; font-size: 7px; }
  #startScreen .skin-row > span { padding-top: 0; }
  #startScreen #skinChoices { flex-wrap: nowrap; gap: 4px; }
  #startScreen .skin-chip { padding: 4px 7px; font-size: 7px; }
  #startScreen .intro,
  #startScreen .controls-copy { display: none; }
  #startScreen .primary-button {
    position: relative;
    z-index: 2;
    min-width: 190px;
    margin-top: 4px;
    padding: 6px 18px;
    font-size: 11px;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 340px) {
  #startScreen .fighter-card { height: 145px; }
  #startScreen .fighter-art,
  #startScreen .fighter-card::before { height: 66px; }
  #startScreen .fighter-card strong,
  #startScreen .fighter-card[data-hero="heroine"] strong { top: 62px; }
  #startScreen .fighter-stats { top: 88px; }
  #startScreen .skin-row { min-height: 21px; }
  #startScreen .skin-chip { padding: 3px 6px; }
}
