.rotate-hint,
.touch-controls {
  display: none;
}

@media (pointer: coarse), (hover: none) {
  html,
  body {
    overscroll-behavior: none;
  }

  body {
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
  }

  button {
    touch-action: manipulation;
  }

  .rotate-hint {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: none;
    place-items: center;
    padding: 24px;
    background: linear-gradient(180deg, rgba(3, 8, 17, .92), rgba(3, 8, 17, .98));
    text-align: center;
  }

  .rotate-hint b,
  .rotate-hint span {
    display: block;
    font-family: "Noto Sans SC", "Chakra Petch", sans-serif;
  }

  .rotate-hint b {
    color: #fff2a6;
    font-size: 28px;
    font-weight: 900;
    letter-spacing: .08em;
    text-shadow: 0 0 20px #ffc72c;
  }

  .rotate-hint span {
    margin-top: 10px;
    color: #a9bdd4;
    font-size: 14px;
    font-weight: 800;
  }

  .touch-controls {
    --touch-size: 56px;
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
  }

  html[data-game-state="playing"] .touch-controls,
  html[data-game-state="countdown"] .touch-controls {
    display: block;
  }

  .touch-stick,
  .touch-actions,
  .touch-system {
    pointer-events: auto;
  }

  .touch-stick {
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: calc(var(--touch-size) * 3);
    height: calc(var(--touch-size) * 3);
    display: grid;
    grid-template-columns: repeat(3, var(--touch-size));
    grid-template-rows: repeat(3, var(--touch-size));
  }

  .touch-actions {
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, var(--touch-size));
    grid-template-rows: repeat(2, var(--touch-size));
    gap: 8px;
    align-items: center;
  }

  .touch-btn {
    width: var(--touch-size);
    height: var(--touch-size);
    border: 2px solid rgba(210, 232, 255, .64);
    border-bottom: 5px solid rgba(0, 0, 0, .45);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(22, 45, 70, .8), rgba(5, 13, 24, .9));
    color: #eaf5ff;
    box-shadow: 0 0 18px rgba(0, 0, 0, .42), inset 0 0 0 1px rgba(255, 255, 255, .08);
    display: grid;
    place-items: center;
    padding: 0;
    font: 900 18px "Chakra Petch", "Noto Sans SC", sans-serif;
  }

  .touch-btn span {
    display: block;
    margin-top: -5px;
    color: #abc3db;
    font: 900 9px "Noto Sans SC", "Chakra Petch", sans-serif;
    line-height: 1;
  }

  .touch-btn.is-pressed,
  .touch-btn:active {
    transform: translateY(3px);
    border-bottom-width: 2px;
    filter: brightness(1.22);
    box-shadow: 0 0 24px rgba(255, 216, 82, .38), inset 0 0 18px rgba(255, 255, 255, .12);
  }

  .touch-up {
    grid-column: 2;
    grid-row: 1;
  }

  .touch-left {
    grid-column: 1;
    grid-row: 2;
  }

  .touch-down {
    grid-column: 2;
    grid-row: 3;
  }

  .touch-right {
    grid-column: 3;
    grid-row: 2;
  }

  .touch-main {
    grid-column: 2;
    grid-row: 1 / span 2;
    width: 68px;
    height: 68px;
    margin: auto;
    border-color: #ffd96a;
    background: linear-gradient(180deg, rgba(255, 202, 64, .92), rgba(157, 84, 16, .92));
    color: #08111e;
    font-size: 22px;
  }

  .touch-ult {
    border-color: #ff8bb5;
    background: linear-gradient(180deg, rgba(255, 82, 111, .9), rgba(77, 12, 38, .94));
    color: #fff;
  }

  .touch-skill {
    border-color: #7fc8ff;
  }

  .touch-pause {
    position: absolute;
    right: max(18px, env(safe-area-inset-right));
    top: max(12px, env(safe-area-inset-top));
    min-width: 58px;
    height: 34px;
    border: 1px solid rgba(218, 236, 255, .52);
    border-radius: 8px;
    background: rgba(7, 15, 27, .72);
    color: #cfe2f7;
    box-shadow: 0 0 16px rgba(0, 0, 0, .35);
    font: 900 12px "Noto Sans SC", "Chakra Petch", sans-serif;
  }
}

@media (pointer: coarse) and (orientation: portrait), (hover: none) and (orientation: portrait) {
  .rotate-hint {
    display: grid;
  }

  .touch-controls {
    display: none !important;
  }
}

@media (pointer: coarse) and (orientation: landscape), (hover: none) and (orientation: landscape) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .shell {
    width: 100vw;
    height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    display: grid;
    place-items: center;
  }

  .topbar,
  .footer-note {
    display: none;
  }

  .game-frame {
    width: min(100vw, calc(100dvh * 16 / 9));
    height: min(100dvh, calc(100vw * 9 / 16));
    min-height: 0;
    aspect-ratio: 16 / 9;
    border: 0;
    box-shadow: 0 0 0 1px #263d5a, 0 0 42px rgba(0, 0, 0, .75);
  }

  canvas {
    width: 100%;
    height: 100%;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 430px), (hover: none) and (orientation: landscape) and (max-height: 430px) {
  .touch-controls {
    --touch-size: 50px;
  }

  .touch-actions {
    gap: 6px;
  }

  .touch-main {
    width: 62px;
    height: 62px;
  }

  .touch-btn span {
    font-size: 8px;
  }
}

@media (orientation: landscape) {
  html.touch-device,
  html.touch-device body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  html.touch-device body {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }

  html.touch-device .topbar,
  html.touch-device .footer-note {
    display: none;
  }

  html.touch-device .shell {
    width: 100vw;
    height: 100dvh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    display: grid;
    place-items: center;
  }

  html.touch-device .game-frame {
    width: min(100vw, calc(100dvh * 16 / 9));
    height: min(100dvh, calc(100vw * 9 / 16));
    min-height: 0;
    aspect-ratio: 16 / 9;
    border: 0;
  }

  html.touch-device .touch-controls {
    --touch-size: 56px;
    position: absolute;
    inset: 0;
    z-index: 6;
    pointer-events: none;
  }

  html.touch-device[data-game-state="playing"] .touch-controls,
  html.touch-device[data-game-state="countdown"] .touch-controls {
    display: block;
  }

  html.touch-device .touch-stick,
  html.touch-device .touch-actions,
  html.touch-device .touch-system {
    pointer-events: auto;
  }

  html.touch-device .touch-stick {
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: calc(var(--touch-size) * 3);
    height: calc(var(--touch-size) * 3);
    display: grid;
    grid-template-columns: repeat(3, var(--touch-size));
    grid-template-rows: repeat(3, var(--touch-size));
  }

  html.touch-device .touch-actions {
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, var(--touch-size));
    grid-template-rows: repeat(2, var(--touch-size));
    gap: 8px;
  }

  html.touch-device .touch-btn {
    width: var(--touch-size);
    height: var(--touch-size);
    border: 2px solid rgba(210, 232, 255, .64);
    border-bottom: 5px solid rgba(0, 0, 0, .45);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(22, 45, 70, .8), rgba(5, 13, 24, .9));
    color: #eaf5ff;
    box-shadow: 0 0 18px rgba(0, 0, 0, .42), inset 0 0 0 1px rgba(255, 255, 255, .08);
    display: grid;
    place-items: center;
    padding: 0;
    font: 900 18px "Chakra Petch", "Noto Sans SC", sans-serif;
    touch-action: none;
  }

  html.touch-device .touch-btn span {
    display: block;
    margin-top: -5px;
    color: #abc3db;
    font: 900 9px "Noto Sans SC", "Chakra Petch", sans-serif;
    line-height: 1;
  }

  html.touch-device .touch-up {
    grid-column: 2;
    grid-row: 1;
  }

  html.touch-device .touch-left {
    grid-column: 1;
    grid-row: 2;
  }

  html.touch-device .touch-down {
    grid-column: 2;
    grid-row: 3;
  }

  html.touch-device .touch-right {
    grid-column: 3;
    grid-row: 2;
  }

  html.touch-device .touch-main {
    grid-column: 2;
    grid-row: 1 / span 2;
    width: 68px;
    height: 68px;
    margin: auto;
    border-color: #ffd96a;
    background: linear-gradient(180deg, rgba(255, 202, 64, .92), rgba(157, 84, 16, .92));
    color: #08111e;
    font-size: 22px;
  }

  html.touch-device .touch-ult {
    border-color: #ff8bb5;
    background: linear-gradient(180deg, rgba(255, 82, 111, .9), rgba(77, 12, 38, .94));
    color: #fff;
  }

  html.touch-device .touch-pause {
    position: absolute;
    right: max(18px, env(safe-area-inset-right));
    top: max(12px, env(safe-area-inset-top));
    min-width: 58px;
    height: 34px;
    border: 1px solid rgba(218, 236, 255, .52);
    border-radius: 8px;
    background: rgba(7, 15, 27, .72);
    color: #cfe2f7;
    box-shadow: 0 0 16px rgba(0, 0, 0, .35);
    font: 900 12px "Noto Sans SC", "Chakra Petch", sans-serif;
  }
}

@media (orientation: landscape) {
  html.touch-device[data-game-state="playing"] .shell,
  html.touch-device[data-game-state="countdown"] .shell {
    background:
      linear-gradient(90deg, #02060b 0 15vw, transparent 15vw 85vw, #02060b 85vw 100%),
      radial-gradient(circle at 50% 50%, #101d2f 0, #02060b 80%);
  }

  html.touch-device[data-game-state="playing"] .game-frame,
  html.touch-device[data-game-state="countdown"] .game-frame {
    width: min(70vw, calc(100dvh * 16 / 9)) !important;
    height: min(100dvh, calc(70vw * 9 / 16)) !important;
    box-shadow: 0 0 0 2px #263d5a, 0 0 44px rgba(0,0,0,.82) !important;
  }

  html.touch-device[data-game-state="playing"] .game-frame #touchControls,
  html.touch-device[data-game-state="countdown"] .game-frame #touchControls,
  html[data-game-state="playing"] .game-frame #touchControls,
  html[data-game-state="countdown"] .game-frame #touchControls {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 9999 !important;
    pointer-events: none !important;
    --touch-size: clamp(50px, 8vh, 70px);
  }

  .game-frame #touchControls .touch-stick {
    position: fixed !important;
    left: calc(max(0px, env(safe-area-inset-left)) + 12.2vw) !important;
    top: auto !important;
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 3px) !important;
    width: min(18vw, 154px) !important;
    height: min(18vw, 154px) !important;
    transform: translateX(-50%) !important;
    display: grid !important;
    place-items: center !important;
    pointer-events: auto !important;
  }

  .game-frame #touchControls .touch-stick .stick-base {
    position: relative !important;
    width: min(15.5vw, 128px) !important;
    height: min(15.5vw, 128px) !important;
    border: 4px solid rgba(149, 206, 255, .78) !important;
    border-radius: 50% !important;
    background:
      radial-gradient(circle at 50% 50%, rgba(255,242,166,.16) 0 30%, transparent 31%),
      radial-gradient(circle, rgba(14,30,51,.92), rgba(3,8,17,.95)) !important;
    box-shadow: 0 0 0 5px rgba(5,12,24,.62), 0 0 30px rgba(91,177,255,.36), inset 0 0 24px rgba(255,255,255,.08) !important;
    transition: box-shadow .12s ease, border-color .12s ease, filter .12s ease !important;
  }

  .game-frame #touchControls .touch-stick .stick-base:before,
  .game-frame #touchControls .touch-stick .stick-base:after {
    content: "" !important;
    position: absolute !important;
    background: rgba(218, 237, 255, .32) !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
  }

  .game-frame #touchControls .touch-stick .stick-base:before {
    width: 70% !important;
    height: 3px !important;
  }

  .game-frame #touchControls .touch-stick .stick-base:after {
    width: 3px !important;
    height: 70% !important;
  }

  .game-frame #touchControls .touch-stick .stick-knob {
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    width: min(7.8vw, 58px) !important;
    height: min(7.8vw, 58px) !important;
    transform: translate(-50%, -50%) !important;
    border: 3px solid #fff2a6 !important;
    border-radius: 50% !important;
    background: radial-gradient(circle at 35% 28%, #f7fbff, #74bfff 38%, #102238 100%) !important;
    box-shadow: 0 0 18px rgba(255, 242, 166, .5), inset 0 0 0 3px rgba(4,11,20,.45) !important;
    transition: box-shadow .08s ease, filter .08s ease !important;
  }

  .game-frame #touchControls .touch-stick.is-active .stick-base {
    border-color: #fff2a6 !important;
    filter: brightness(1.18) !important;
    box-shadow: 0 0 0 6px rgba(255, 242, 166, .32), 0 0 42px rgba(91,177,255,.55), inset 0 0 30px rgba(255,242,166,.12) !important;
  }

  .game-frame #touchControls .touch-stick.is-active .stick-knob {
    filter: brightness(1.22) saturate(1.2) !important;
    box-shadow: 0 0 26px rgba(255, 242, 166, .85), 0 0 36px rgba(116,191,255,.45), inset 0 0 0 3px rgba(4,11,20,.45) !important;
  }

  .game-frame #touchControls .touch-stick:after {
    content: attr(data-dir) !important;
    position: absolute !important;
    left: 50% !important;
    top: -28px !important;
    transform: translateX(-50%) !important;
    min-width: 42px !important;
    padding: 3px 8px !important;
    border: 1px solid rgba(255,242,166,.72) !important;
    border-radius: 999px !important;
    background: rgba(5,12,24,.72) !important;
    color: #fff2a6 !important;
    font: 900 11px "Noto Sans SC", "Chakra Petch", sans-serif !important;
    text-align: center !important;
    opacity: 0 !important;
  }

  .game-frame #touchControls .touch-stick.is-active:after {
    opacity: 1 !important;
  }

  .game-frame #touchControls .touch-stick b {
    position: absolute !important;
    left: 50% !important;
    bottom: -18px !important;
    transform: translateX(-50%) !important;
    color: #dff0ff !important;
    font: 900 12px "Noto Sans SC", "Chakra Petch", sans-serif !important;
    letter-spacing: .14em !important;
  }

  .game-frame #touchControls .touch-actions {
    position: fixed !important;
    right: calc(max(0px, env(safe-area-inset-right)) + 8.8vw) !important;
    top: auto !important;
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 18px) !important;
    transform: translateX(50%) !important;
    display: grid !important;
    grid-template-columns: repeat(2, var(--touch-size)) !important;
    grid-template-rows: repeat(3, var(--touch-size)) !important;
    gap: 10px !important;
    pointer-events: auto !important;
  }

  .game-frame #touchControls .touch-system {
    pointer-events: auto !important;
  }

  .game-frame #touchControls .touch-btn {
    width: var(--touch-size) !important;
    height: var(--touch-size) !important;
    min-width: 0 !important;
    padding: 0 !important;
    display: grid !important;
    place-items: center !important;
    border: 3px solid rgba(229, 244, 255, .95) !important;
    border-bottom: 7px solid rgba(3, 8, 17, .82) !important;
    border-radius: 14px !important;
    background: rgba(10, 22, 37, .88) !important;
    color: #ffffff !important;
    text-shadow: 0 2px 0 #06111f, 0 0 12px rgba(255, 242, 166, .65) !important;
    box-shadow: 0 0 0 3px rgba(5, 12, 24, .55), 0 0 24px rgba(75, 177, 255, .42) !important;
    font: 900 clamp(17px, 2.5vh, 24px) "Noto Sans SC", "Chakra Petch", sans-serif !important;
    line-height: 1 !important;
    opacity: .96 !important;
    touch-action: none !important;
  }

  .game-frame #touchControls .touch-btn span {
    display: block !important;
    margin-top: 2px !important;
    color: #d9edff !important;
    font: 900 clamp(8px, 1.25vh, 11px) "Noto Sans SC", "Chakra Petch", sans-serif !important;
    text-shadow: none !important;
  }

  .game-frame #touchControls .touch-main {
    grid-column: 1 / span 2 !important;
    grid-row: 2 !important;
    width: calc(var(--touch-size) * 1.16) !important;
    height: calc(var(--touch-size) * 1.16) !important;
    margin: auto !important;
    border-color: #fff2a6 !important;
    background: linear-gradient(180deg, rgba(255, 211, 77, .96), rgba(184, 91, 21, .94)) !important;
    color: #07101b !important;
  }

  .game-frame #touchControls .touch-ult {
    border-color: #ffc0d6 !important;
    background: linear-gradient(180deg, rgba(255, 82, 111, .96), rgba(96, 13, 47, .96)) !important;
  }

  .game-frame #touchControls .touch-pause {
    position: fixed !important;
    top: max(12px, env(safe-area-inset-top)) !important;
    right: max(14px, env(safe-area-inset-right)) !important;
    height: 36px !important;
    min-width: 64px !important;
    border: 2px solid rgba(218, 236, 255, .72) !important;
    border-radius: 9px !important;
    background: rgba(7, 15, 27, .86) !important;
    color: #ffffff !important;
    font: 900 13px "Noto Sans SC", "Chakra Petch", sans-serif !important;
  }

  .game-frame #touchControls .touch-sound {
    position: fixed !important;
    top: calc(max(12px, env(safe-area-inset-top)) + 46px) !important;
    right: max(14px, env(safe-area-inset-right)) !important;
    height: 34px !important;
    min-width: 76px !important;
    border: 2px solid rgba(255, 242, 166, .75) !important;
    border-radius: 9px !important;
    background: rgba(25, 20, 8, .86) !important;
    color: #fff2a6 !important;
    box-shadow: 0 0 16px rgba(255, 214, 88, .2) !important;
    font: 900 12px "Noto Sans SC", "Chakra Petch", sans-serif !important;
  }

  .game-frame #touchControls .touch-menu {
    position: fixed !important;
    top: calc(max(12px, env(safe-area-inset-top)) + 88px) !important;
    right: max(14px, env(safe-area-inset-right)) !important;
    height: 34px !important;
    min-width: 76px !important;
    border: 2px solid rgba(129, 201, 255, .82) !important;
    border-radius: 9px !important;
    background: rgba(8, 23, 42, .88) !important;
    color: #dff0ff !important;
    box-shadow: 0 0 16px rgba(75, 177, 255, .22) !important;
    font: 900 12px "Noto Sans SC", "Chakra Petch", sans-serif !important;
  }

  html.touch-device[data-game-state="menu"] .touch-controls {
    display: none !important;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  html.touch-device[data-game-state="menu"] .shell {
    grid-template-rows: 52px minmax(0, 1fr) 30px;
    place-items: stretch;
    row-gap: 4px;
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  html.touch-device[data-game-state="menu"] .topbar {
    display: flex !important;
    min-height: 0;
    height: 52px;
    padding: 0 8px;
    border: 1px solid rgba(66, 90, 120, .6);
    background: rgba(8, 17, 30, .78);
  }

  html.touch-device[data-game-state="menu"] .brand {
    gap: 8px;
  }

  html.touch-device[data-game-state="menu"] .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }

  html.touch-device[data-game-state="menu"] .brand b {
    font-size: 18px;
  }

  html.touch-device[data-game-state="menu"] .brand small {
    font-size: 10px;
  }

  html.touch-device[data-game-state="menu"] .top-actions {
    gap: 6px;
  }

  html.touch-device[data-game-state="menu"] .top-actions .icon-btn {
    height: 34px;
    min-width: 58px;
    padding: 0 10px;
    font-size: 12px;
  }

  html.touch-device[data-game-state="menu"] .game-frame {
    width: 100%;
    height: 100%;
    max-height: none;
    aspect-ratio: auto;
    border: 1px solid rgba(66, 90, 120, .55);
  }

  html.touch-device[data-game-state="menu"] .footer-note {
    display: flex !important;
    height: 30px;
    min-height: 0;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 0 8px;
    font-size: 10px;
    border: 1px solid rgba(66, 90, 120, .45);
    background: rgba(5, 12, 24, .62);
  }

  html.touch-device .start-screen {
    justify-content: flex-start;
    padding: 10px 12px 12px;
    overflow: auto;
  }

  html.touch-device .start-screen .eyebrow,
  html.touch-device .start-screen .subtitle,
  html.touch-device .start-screen .controls-grid,
  html.touch-device .start-screen .microcopy {
    display: none;
  }

  html.touch-device .start-screen h1 {
    margin: 0 0 6px;
    font-size: clamp(24px, 5.5vh, 38px);
  }

  html.touch-device .roster-select {
    width: 96%;
    max-height: 46vh;
    grid-template-columns: 1fr 1fr;
    overflow: auto;
  }

  html.touch-device .play-mode-panel {
    width: 96%;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin-top: 6px;
  }

  html.touch-device .mode-tile {
    min-height: 50px;
    padding: 7px 8px;
  }

  html.touch-device .mode-tile b {
    font-size: 13px;
  }

  html.touch-device .mode-tile span {
    font-size: 9px;
  }
}
