*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0a0012;
  --bg-panel: #12001f;
  --pink: #ff4fd8;
  --pink-dim: #c93aa8;
  --pink-glow: rgba(255, 79, 216, 0.65);
  --cyan: #7ef9ff;
  --text: #ffe8f8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --controls-h: 8.75rem;
  --chrome-w: 5.2rem;
  --chrome-gap: 0.55rem;
  --vh: 1vh;
  --app-height: 100dvh;
}

html,
body {
  height: var(--app-height, 100dvh);
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Arial, sans-serif;
}

body {
  padding-top: var(--safe-top);
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(255, 79, 216, 0.15), transparent 60%),
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(126, 249, 255, 0.08), transparent 50%),
    var(--bg);
}

body.game-active {
  background:
    linear-gradient(to bottom, rgba(7, 0, 14, 0.56), rgba(7, 0, 14, 0.46)),
    radial-gradient(ellipse 88% 60% at 50% 24%, rgba(255, 79, 216, 0.24), transparent 68%),
    var(--game-bg-image) center center / cover no-repeat fixed,
    var(--bg);
}

body.game-active .hud {
  display: none;
}

body.title-screen {
  background: #06000d;
}

.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: calc(var(--app-height, 100dvh) - var(--safe-top));
  max-height: calc(var(--app-height, 100dvh) - var(--safe-top));
  padding: 0.35rem 0.6rem 0;
  gap: 0.35rem;
}

/* HUD */
.hud {
  display: flex;
  justify-content: space-around;
  width: 100%;
  max-width: min(100%, 320px);
  flex-shrink: 0;
}

.hud-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
}

.label {
  font-size: 0.55rem;
  letter-spacing: 0.12em;
  color: var(--pink-dim);
  text-shadow: 0 0 8px var(--pink-glow);
}

.value {
  font-size: clamp(0.95rem, 4.2vw, 1.1rem);
  font-weight: 700;
  color: var(--cyan);
  text-shadow:
    0 0 6px rgba(126, 249, 255, 0.8),
    0 0 14px rgba(126, 249, 255, 0.4);
  font-variant-numeric: tabular-nums;
}

/* Stage — 下部固定コントロール分を除いた領域 */
.stage-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
  max-width: min(100%, 320px);
  padding-bottom: calc(var(--controls-h) + var(--safe-bottom) + 0.25rem);
}

#board {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  border: 2px solid rgba(255, 79, 216, 0.92);
  border-radius: 4px;
  box-shadow:
    0 0 14px rgba(255, 79, 216, 0.72),
    0 0 34px rgba(255, 79, 216, 0.28),
    inset 0 0 22px rgba(255, 79, 216, 0.1);
  background: rgba(12, 0, 22, 0.38);
  touch-action: none;
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(10, 0, 18, 0.88);
  border-radius: 4px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#overlay {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--safe-top);
  bottom: calc(var(--controls-h) + var(--safe-bottom));
  z-index: 25;
  border-radius: 0;
  background: rgba(6, 0, 12, 0.74);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.game-over-panel {
  width: min(90vw, 20rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  padding: 0.85rem 0.9rem 0.95rem;
  border: 1px solid rgba(255, 79, 216, 0.72);
  border-radius: 1rem;
  background: rgba(14, 0, 24, 0.9);
  box-shadow:
    0 0 24px rgba(255, 79, 216, 0.35),
    0 0 48px rgba(255, 79, 216, 0.18),
    inset 0 0 16px rgba(255, 79, 216, 0.14);
}

.game-over-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  width: 100%;
}

.game-over-actions .neon-btn,
.game-over-actions .home-btn {
  width: 100%;
  min-height: 2.55rem;
  margin: 0;
}

#start-screen {
  background: none;
  overflow: hidden;
}

#start-screen::before,
#start-screen::after {
  content: "";
  position: absolute;
  inset: 0;
}

#start-screen::before {
  background: none;
}

#start-screen::after {
  background: rgba(10, 0, 18, 0.62);
  z-index: 1;
  pointer-events: none;
}

#start-screen .title-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  z-index: 0;
}

#start-screen > * {
  position: relative;
  z-index: 2;
}

#start-screen > .title-image {
  z-index: 0;
}

#start-screen > .tap-gate {
  position: absolute;
  inset: 0;
  z-index: 20;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(10, 0, 18, 0.28);
  color: #ffd3f4;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tap-gate-label {
  position: absolute;
  left: 50%;
  bottom: clamp(5.5rem, 14vh, 7.5rem);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  width: max-content;
  max-width: calc(100% - 2rem);
  pointer-events: none;
}

.tap-gate-text {
  font-size: clamp(1.35rem, 6.5vw, 2rem);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-shadow:
    0 0 12px rgba(255, 79, 216, 0.95),
    0 0 28px rgba(255, 79, 216, 0.55);
  animation: tap-gate-pulse 1.6s ease-in-out infinite;
}

.tap-gate-sub {
  font-size: clamp(0.72rem, 3.2vw, 0.9rem);
  letter-spacing: 0.24em;
  color: rgba(255, 211, 244, 0.82);
}

@keyframes tap-gate-pulse {
  0%,
  100% {
    opacity: 0.72;
    transform: scale(0.98);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

body.title-locked #start-screen > :not(.title-image):not(.tap-gate) {
  visibility: hidden;
  pointer-events: none;
}

.overlay.hidden {
  display: none;
}

.home-btn {
  position: relative;
  z-index: 2;
  min-width: 3.1rem;
  min-height: 2.5rem;
  padding: 0.35rem 0.6rem;
  border: 1px solid rgba(255, 79, 216, 0.75);
  border-radius: 999px;
  background: rgba(10, 0, 18, 0.85);
  color: var(--pink);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow: 0 0 8px var(--pink-glow);
  box-shadow: 0 0 10px rgba(255, 79, 216, 0.28);
  touch-action: manipulation;
}

.home-btn:active {
  background: rgba(255, 79, 216, 0.22);
}

.hidden {
  display: none !important;
}

.logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.08rem;
  margin: 0;
  font-weight: 900;
  line-height: 0.9;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  filter: drop-shadow(0 0 14px rgba(255, 79, 216, 0.75));
}

.logo-line {
  display: block;
}

.logo-line--miu {
  font-size: 1em;
  letter-spacing: 0.1em;
  background: linear-gradient(180deg, #ffffff 0%, #ffd9f7 38%, #ff4fd8 72%, #ff2fc8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow:
    0 0 12px rgba(255, 79, 216, 0.95),
    0 0 28px rgba(255, 79, 216, 0.65);
}

.logo-heart {
  display: inline-block;
  margin-left: 0.06em;
  font-size: 0.82em;
  color: #ff8ee8;
  text-shadow:
    0 0 10px rgba(255, 79, 216, 1),
    0 0 20px rgba(255, 79, 216, 0.8);
  -webkit-text-fill-color: #ff8ee8;
}

.logo-line--blocks {
  font-size: 0.74em;
  letter-spacing: 0.24em;
  padding-left: 0.24em;
  background: linear-gradient(180deg, #ffffff 0%, #c8f8ff 35%, #7ef9ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow:
    0 0 10px rgba(126, 249, 255, 0.85),
    0 0 22px rgba(126, 249, 255, 0.45);
}

.tagline {
  font-size: 0.65rem;
  letter-spacing: 0.3em;
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(126, 249, 255, 0.6);
}

.overlay-title {
  font-size: 1rem;
  letter-spacing: 0.2em;
  color: var(--pink);
  text-shadow: 0 0 12px var(--pink-glow);
}

.overlay-score {
  font-size: 0.8rem;
  color: var(--text);
}

.music-ad-card {
  width: 100%;
  display: grid;
  gap: 0.35rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid rgba(255, 79, 216, 0.65);
  border-radius: 0.75rem;
  background: rgba(18, 1, 30, 0.58);
  box-shadow:
    0 0 14px rgba(255, 79, 216, 0.26),
    inset 0 0 10px rgba(255, 79, 216, 0.18);
}

.music-ad-image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 0.55rem;
  border: 1px solid rgba(255, 79, 216, 0.55);
  box-shadow:
    0 0 12px rgba(255, 79, 216, 0.3),
    inset 0 0 8px rgba(255, 79, 216, 0.2);
}

.music-ad-title {
  text-align: center;
  color: #ffd7f6;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow: 0 0 8px rgba(255, 79, 216, 0.55);
}

.music-ad-track {
  text-align: center;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-shadow:
    0 0 10px rgba(255, 79, 216, 0.58),
    0 0 16px rgba(255, 79, 216, 0.34);
}

.music-ad-copy {
  text-align: center;
  color: #ffdff8;
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  opacity: 0.92;
}

.music-ad-btn {
  min-height: 2.4rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid rgba(255, 79, 216, 0.85);
  border-radius: 999px;
  background: rgba(255, 79, 216, 0.2);
  color: #ffe8fb;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-shadow: 0 0 8px rgba(255, 79, 216, 0.6);
  box-shadow:
    0 0 12px rgba(255, 79, 216, 0.4),
    inset 0 0 10px rgba(255, 79, 216, 0.2);
  touch-action: manipulation;
}

.music-ad-btn:active {
  transform: scale(0.97);
}

.neon-btn {
  padding: 0.55rem 1.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--pink);
  background: transparent;
  border: 2px solid var(--pink);
  border-radius: 999px;
  cursor: pointer;
  box-shadow:
    0 0 10px var(--pink-glow),
    inset 0 0 10px rgba(255, 79, 216, 0.1);
  text-shadow: 0 0 8px var(--pink-glow);
  transition: background 0.15s, transform 0.1s;
}

.neon-btn:active {
  background: rgba(255, 79, 216, 0.2);
  transform: scale(0.96);
}

body.title-screen .app {
  position: relative;
  height: calc(var(--app-height, 100dvh) - var(--safe-top));
  max-height: calc(var(--app-height, 100dvh) - var(--safe-top));
  padding: 0;
  gap: 0;
}

body.title-screen .hud {
  display: none;
}

body.title-screen .controls {
  display: none;
}

body.title-screen .stage-wrap {
  width: 0;
  height: 0;
  max-width: none;
  padding: 0;
  overflow: visible;
}

body.title-screen #board {
  display: none;
}

body.title-screen #start-screen {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--safe-top);
  bottom: 0;
  z-index: 15;
  border-radius: 0;
  gap: 0.8rem;
  justify-content: flex-start;
  padding-top: clamp(42dvh, 46dvh, 50dvh);
  background: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

body.title-screen #start-screen::before {
  background: none;
}

body.title-screen #start-screen::after {
  background:
    radial-gradient(ellipse 85% 45% at 50% 32%, rgba(255, 79, 216, 0.16), transparent 62%),
    linear-gradient(to bottom, rgba(6, 0, 13, 0.16), rgba(6, 0, 13, 0.42) 62%, rgba(6, 0, 13, 0.56));
}

body.title-screen .logo {
  font-size: clamp(2.6rem, 13vw, 4.4rem);
  line-height: 0.88;
  filter:
    drop-shadow(0 0 18px rgba(255, 79, 216, 0.95))
    drop-shadow(0 0 36px rgba(255, 79, 216, 0.55));
}

body.title-screen .logo-line--miu {
  text-shadow:
    0 0 14px rgba(255, 79, 216, 1),
    0 0 30px rgba(255, 79, 216, 0.9),
    0 0 52px rgba(255, 79, 216, 0.6);
}

body.title-screen .logo-line--blocks {
  text-shadow:
    0 0 12px rgba(126, 249, 255, 0.95),
    0 0 26px rgba(126, 249, 255, 0.55);
}

body.title-screen .tagline {
  margin-top: 0.1rem;
  font-size: clamp(0.72rem, 3.8vw, 1rem);
  letter-spacing: 0.35em;
  text-shadow: 0 0 12px rgba(126, 249, 255, 0.75);
}

body.title-screen .level-select {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.45rem;
  width: min(82vw, 22rem);
  margin-top: 0.45rem;
}

body.title-screen .audio-settings {
  width: min(82vw, 22rem);
  display: grid;
  gap: 0.3rem;
  margin-top: 0.2rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid rgba(255, 79, 216, 0.42);
  border-radius: 0.7rem;
  background: rgba(16, 2, 28, 0.45);
  box-shadow:
    0 0 12px rgba(255, 79, 216, 0.22),
    inset 0 0 8px rgba(255, 79, 216, 0.12);
}

body.title-screen .settings-btn {
  width: min(82vw, 22rem);
  min-height: 2rem;
  border: 1px solid rgba(255, 79, 216, 0.62);
  border-radius: 999px;
  background: rgba(16, 2, 28, 0.5);
  color: #ffd6f6;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-shadow: 0 0 8px rgba(255, 79, 216, 0.5);
  box-shadow:
    0 0 11px rgba(255, 79, 216, 0.28),
    inset 0 0 8px rgba(255, 79, 216, 0.16);
}

body.title-screen .settings-btn:active {
  transform: scale(0.98);
}

body.title-screen .audio-row {
  display: grid;
  grid-template-columns: 2.2rem 1fr 2.1rem;
  align-items: center;
  gap: 0.4rem;
}

body.title-screen .audio-label {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #ffa6e8;
  text-shadow: 0 0 7px rgba(255, 79, 216, 0.45);
}

body.title-screen .audio-slider {
  width: 100%;
  accent-color: #ff4fd8;
  touch-action: pan-x;
  -webkit-user-select: none;
  user-select: none;
}

body.title-screen .audio-value {
  font-size: 0.6rem;
  text-align: right;
  color: #ffe8f8;
  font-variant-numeric: tabular-nums;
}

body.title-screen .level-btn {
  min-height: 2.15rem;
  border: 1px solid rgba(255, 79, 216, 0.58);
  border-radius: 999px;
  background: rgba(13, 2, 22, 0.55);
  color: #ffc8ef;
  font-size: clamp(0.82rem, 3.8vw, 1rem);
  font-weight: 700;
  text-shadow: 0 0 8px rgba(255, 79, 216, 0.58);
  box-shadow:
    0 0 10px rgba(255, 79, 216, 0.25),
    inset 0 0 8px rgba(255, 79, 216, 0.16);
  touch-action: manipulation;
}

body.title-screen .level-btn.is-active {
  color: #ffe8f9;
  border-color: rgba(255, 79, 216, 0.95);
  background: rgba(255, 79, 216, 0.28);
  box-shadow:
    0 0 14px rgba(255, 79, 216, 0.55),
    inset 0 0 10px rgba(255, 79, 216, 0.3);
}

body.title-screen .level-btn:active {
  transform: scale(0.96);
}

body.title-screen #btn-start.neon-btn {
  margin-top: 0.55rem;
  min-width: min(80vw, 21rem);
  padding: 1.1rem 3.2rem;
  font-size: clamp(1.15rem, 5.8vw, 1.55rem);
  letter-spacing: 0.14em;
  border-width: 1.5px;
  color: #ffd3f4;
  background: rgba(255, 79, 216, 0.12);
  box-shadow:
    0 0 16px rgba(255, 79, 216, 0.9),
    0 0 32px rgba(255, 79, 216, 0.55),
    inset 0 0 14px rgba(255, 79, 216, 0.2);
}

/* 画面下固定コントロール */
.controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem calc(0.35rem + var(--safe-bottom));
  background: linear-gradient(
    to top,
    rgba(10, 0, 18, 0.98) 55%,
    rgba(10, 0, 18, 0.85) 80%,
    transparent
  );
  border-top: 1px solid rgba(255, 79, 216, 0.25);
  box-shadow: 0 -4px 24px rgba(255, 79, 216, 0.12);
}

body.game-active .controls {
  background: linear-gradient(
    to top,
    rgba(10, 0, 18, 0.58) 44%,
    rgba(10, 0, 18, 0.34) 76%,
    rgba(10, 0, 18, 0.12) 100%
  );
  border-top: 1px solid rgba(255, 79, 216, 0.38);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

body.game-active .controls-row {
  position: relative;
  left: -4px;
  top: -3px;
}

body.game-active .stage-wrap {
  position: relative;
  max-width: 100%;
  width: 100%;
}

body.game-active .stage-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background:
    radial-gradient(ellipse 75% 48% at 50% 50%, rgba(255, 79, 216, 0.12), transparent 72%),
    linear-gradient(to bottom, rgba(10, 0, 18, 0.16), rgba(10, 0, 18, 0.08));
  pointer-events: none;
  z-index: 0;
}

body.game-active #board,
body.game-active .home-btn {
  position: relative;
  z-index: 1;
}

body.game-active #overlay {
  position: fixed;
  z-index: 25;
}

.game-chrome {
  display: none;
}

body.game-active .game-chrome {
  position: absolute;
  top: 0.25rem;
  bottom: calc(var(--controls-h) + var(--safe-bottom) + 0.5rem);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: var(--chrome-w);
  z-index: 3;
}

body.game-active .game-chrome--left {
  left: calc(50% - (var(--board-render-width, 200px) / 2) - var(--chrome-gap) - var(--chrome-w));
}

body.game-active .game-chrome--right {
  right: calc(50% - (var(--board-render-width, 200px) / 2) - var(--chrome-gap) - var(--chrome-w));
  align-items: stretch;
  justify-content: flex-end;
  gap: 0.42rem;
}

body.game-active .game-chrome--right .chrome-card {
  margin-bottom: auto;
}

body.game-active .chrome-card {
  border: 1px solid rgba(255, 79, 216, 0.55);
  border-radius: 0.9rem;
  background: rgba(18, 0, 30, 0.44);
  box-shadow:
    0 0 14px rgba(255, 79, 216, 0.24),
    inset 0 0 10px rgba(255, 79, 216, 0.12);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  padding: 0.45rem;
}

body.game-active .chrome-title,
body.game-active .chrome-label {
  color: #ffa6e8;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  text-shadow: 0 0 8px rgba(255, 79, 216, 0.55);
}

body.game-active .chrome-stats {
  display: flex;
  flex-direction: column;
  gap: 0.36rem;
}

body.game-active .chrome-stat {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding-bottom: 0.26rem;
  border-bottom: 1px solid rgba(255, 79, 216, 0.25);
}

body.game-active .chrome-stat:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

body.game-active .chrome-value {
  color: #f7eeff;
  text-align: center;
  font-size: clamp(0.95rem, 3.4vw, 1.15rem);
  font-weight: 700;
  text-shadow:
    0 0 10px rgba(255, 79, 216, 0.6),
    0 0 16px rgba(255, 79, 216, 0.35);
  font-variant-numeric: tabular-nums;
}

body.game-active .preview-grid {
  position: relative;
  width: 3.65rem;
  height: 3.65rem;
  margin: 0.3rem auto 0;
}

body.game-active .preview-cell {
  position: absolute;
  width: 0.78rem;
  height: 0.78rem;
  left: calc(var(--px) * 0.82rem + 0.18rem);
  top: calc(var(--py) * 0.82rem + 0.18rem);
  border-radius: 0.34rem;
  background:
    radial-gradient(120% 95% at 26% 16%, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 50%),
    linear-gradient(155deg, color-mix(in srgb, var(--pc) 88%, #fff 12%) 0%, var(--pc) 55%, color-mix(in srgb, var(--pc) 80%, #000 20%) 100%);
  border: 1.5px solid rgba(255, 252, 255, 0.95);
  box-shadow:
    0 0 14px color-mix(in srgb, var(--pc) 85%, transparent),
    0 0 5px rgba(255, 255, 255, 0.35),
    inset 0 2px 7px rgba(255, 255, 255, 0.38),
    inset 0 -3px 7px rgba(0, 0, 0, 0.18);
}

body.game-active .game-chrome .home-btn {
  align-self: center;
  width: 100%;
  min-height: 2.85rem;
  border-radius: 0.8rem;
  background: rgba(16, 1, 27, 0.58);
  font-size: 0.68rem;
}

body.game-active .retry-btn {
  min-height: 2.55rem;
  background: rgba(18, 2, 30, 0.62);
}

body.game-active .ctrl-btn {
  background: rgba(255, 79, 216, 0.14);
  border: 1px solid rgba(255, 79, 216, 0.62);
  box-shadow:
    0 0 12px rgba(255, 79, 216, 0.24),
    inset 0 0 8px rgba(255, 79, 216, 0.18);
}

.controls-row {
  display: grid;
  gap: 0.35rem;
  width: 100%;
  max-width: var(--board-render-width, 320px);
  margin: 0 auto;
}

.controls-row:first-child {
  grid-template-columns: 1fr 1.1fr 1fr;
}

.controls-row:last-child {
  grid-template-columns: 1fr 1fr;
}

.ctrl-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  min-height: 2.75rem;
  height: clamp(2.75rem, 12vw, 3.25rem);
  padding: 0.2rem;
  font: inherit;
  color: var(--pink);
  background: rgba(255, 79, 216, 0.1);
  border: 1px solid rgba(255, 79, 216, 0.5);
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(255, 79, 216, 0.18);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.ctrl-btn--main {
  background: rgba(255, 79, 216, 0.16);
  border-color: var(--pink);
  box-shadow: 0 0 14px rgba(255, 79, 216, 0.35);
}

.ctrl-icon {
  font-size: 1.15rem;
  line-height: 1;
  text-shadow: 0 0 8px var(--pink-glow);
}

.ctrl-label {
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  color: var(--pink-dim);
  text-shadow: 0 0 6px var(--pink-glow);
}

.ctrl-btn:active,
.ctrl-btn.is-pressed {
  background: rgba(255, 79, 216, 0.32);
  box-shadow: 0 0 16px var(--pink-glow);
  transform: scale(0.97);
}

/* Smartphone-only layout (iPhone Safari優先) */
@media (max-width: 768px) {
  :root {
    --controls-h: 8.45rem;
  }

  body.title-screen {
    padding-top: 0;
  }

  body.title-screen .app {
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
  }

  html,
  body {
    overflow: hidden;
  }

  .app {
    padding: 0.04rem 0.3rem 0;
    gap: 0.06rem;
  }

  .stage-wrap {
    max-width: 100%;
    padding-bottom: calc(var(--controls-h) + var(--safe-bottom) + 0.03rem);
  }

  /* Title screen compact layout */
  body.title-screen #start-screen {
    top: 0;
    bottom: 0;
    height: var(--app-height, 100dvh);
    min-height: var(--app-height, 100dvh);
    gap: 0.2rem;
    justify-content: center;
    padding: max(0.15rem, var(--safe-top)) 0.7rem max(0.55rem, var(--safe-bottom));
  }

  body.title-screen .logo {
    font-size: clamp(1.85rem, 9vw, 2.55rem);
    line-height: 0.9;
    filter:
      drop-shadow(0 0 12px rgba(255, 79, 216, 0.85))
      drop-shadow(0 0 24px rgba(255, 79, 216, 0.45));
  }

  body.title-screen .logo-line--blocks {
    letter-spacing: 0.2em;
    padding-left: 0.18em;
  }

  body.title-screen .tagline {
    margin-top: 0;
    font-size: clamp(0.5rem, 2.5vw, 0.64rem);
    letter-spacing: 0.18em;
  }

  body.title-screen .title-image {
    width: 100%;
    height: 100%;
    inset: 0;
    object-fit: cover;
    object-position: center center;
    transform: scale(1.14);
  }

  body.title-screen #start-screen > :not(.title-image):not(.tap-gate) {
    transform: translateY(9.35rem);
  }

  body.title-screen .level-select,
  body.title-screen .audio-settings,
  body.title-screen .settings-btn {
    width: min(84vw, 17rem);
  }

  body.title-screen .audio-row {
    grid-template-columns: 2rem 1fr 2rem;
    gap: 0.32rem;
  }

  body.title-screen .audio-slider {
    height: 1.5rem;
    touch-action: pan-x;
  }

  body.title-screen .level-btn {
    min-height: 1.62rem;
    font-size: clamp(0.62rem, 3vw, 0.78rem);
  }

  body.title-screen .settings-btn {
    min-height: 1.62rem;
    font-size: 0.56rem;
  }

  body.title-screen #btn-start.neon-btn {
    margin-top: 0.55rem;
    min-width: min(72vw, 14.8rem);
    padding: 0.56rem 1.2rem;
    font-size: clamp(0.78rem, 4vw, 0.98rem);
    letter-spacing: 0.08em;
  }

  body.title-screen .tap-gate-label {
    bottom: clamp(6.5rem, 17vh, 8.5rem);
  }

  /* Game screen smartphone layout */
  body.game-active {
    background-size: auto, auto, 108% auto, auto;
    --chrome-w: 3.05rem;
    --chrome-gap: 0.1rem;
  }

  body.game-active .game-chrome {
    top: -0.22rem;
    bottom: calc(var(--controls-h) + var(--safe-bottom) + 0.04rem);
  }

  body.game-active .game-chrome--left {
    justify-content: flex-start;
    gap: 0.26rem;
  }

  body.game-active .game-chrome--right {
    justify-content: flex-start;
    gap: 0.26rem;
    align-items: stretch;
  }

  body.game-active .game-chrome--right .chrome-card {
    margin-bottom: 0;
  }

  body.game-active .game-chrome--right .retry-btn {
    margin-top: 0;
  }

  body.game-active .game-chrome--right .home-btn {
    margin-bottom: 0;
  }

  body.game-active .chrome-card {
    border-radius: 0.66rem;
    padding: 0.3rem;
  }

  body.game-active .chrome-title,
  body.game-active .chrome-label {
    font-size: 0.58rem;
    letter-spacing: 0.09em;
  }

  body.game-active .chrome-stats {
    gap: 0.26rem;
  }

  body.game-active .chrome-stat {
    gap: 0.1rem;
    padding-bottom: 0.18rem;
  }

  body.game-active .chrome-value {
    font-size: clamp(0.9rem, 3.6vw, 1.12rem);
  }

  body.game-active .preview-grid {
    width: 2.55rem;
    height: 2.55rem;
    margin-top: 0.12rem;
  }

  body.game-active .preview-cell {
    width: 0.56rem;
    height: 0.56rem;
    left: calc(var(--px) * 0.6rem + 0.1rem);
    top: calc(var(--py) * 0.6rem + 0.1rem);
    border-radius: 0.22rem;
  }

  body.game-active #board {
    max-width: 100%;
    max-height: 100%;
    transform: none;
  }

  body.game-active .game-chrome .home-btn {
    min-height: 2.5rem;
    padding: 0.26rem 0.22rem;
    font-size: 0.72rem;
    border-radius: 0.72rem;
  }

  body.game-active .retry-btn {
    min-height: 2.36rem;
  }

  .controls {
    gap: 0.24rem;
    padding: 0.18rem 0.22rem calc(0.18rem + var(--safe-bottom));
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    transform: none;
    z-index: 30;
  }

  .controls-row {
    gap: 0.82rem;
    width: min(100%, 24.6rem);
    max-width: min(100%, 24.6rem);
  }

  .controls-row:first-child {
    gap: 1.38rem;
  }

  .controls-row:last-child {
    gap: 1.92rem;
    width: min(100%, 21.6rem);
    max-width: min(100%, 21.6rem);
    grid-template-columns: repeat(2, minmax(0, 8.25rem));
    justify-content: center;
  }

  .ctrl-btn {
    min-height: 3.2rem;
    height: clamp(3.08rem, 14vw, 3.5rem);
    border-radius: 13px;
    padding: 0.38rem 0.28rem;
    border-width: 1.5px;
  }

  .ctrl-icon {
    font-size: 1.32rem;
  }

  .ctrl-label {
    font-size: 0.68rem;
  }


  #overlay {
    bottom: calc(var(--controls-h) + var(--safe-bottom) + 0.02rem);
  }

  .game-over-panel {
    width: min(88vw, 16.8rem);
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - var(--controls-h) - 0.52rem);
    gap: 0.35rem;
    padding: 0.48rem 0.5rem 0.54rem;
  }

  .overlay-title {
    font-size: 0.82rem;
  }

  .overlay-score {
    font-size: 0.66rem;
  }

  .music-ad-card {
    gap: 0.18rem;
    padding: 0.34rem 0.4rem;
  }

  .music-ad-title {
    font-size: 0.58rem;
  }

  .music-ad-track {
    font-size: 0.56rem;
  }

  .music-ad-copy {
    font-size: 0.5rem;
  }

  .music-ad-btn {
    min-height: 1.75rem;
    padding: 0.26rem 0.4rem;
    font-size: 0.54rem;
  }

  .game-over-actions {
    gap: 0.28rem;
  }

  .game-over-actions .neon-btn,
  .game-over-actions .home-btn {
    min-height: 2.26rem;
    font-size: 0.64rem;
    padding: 0.3rem 0.34rem;
  }
}

@media (max-width: 430px) and (max-height: 740px) {
  :root {
    --controls-h: 7.6rem;
  }

  body.title-screen #start-screen {
    gap: 0.16rem;
    padding: max(0.08rem, var(--safe-top)) 0.56rem max(0.42rem, var(--safe-bottom));
  }

  body.title-screen #start-screen > :not(.title-image):not(.tap-gate) {
    transform: translateY(8.95rem);
  }

  body.title-screen #btn-start.neon-btn {
    margin-top: 0.6rem;
    padding: 0.62rem 1.55rem;
    font-size: clamp(0.85rem, 4.3vw, 1.04rem);
  }

  body.title-screen .tap-gate-label {
    bottom: clamp(6rem, 16vh, 8rem);
  }

  .ctrl-btn {
    min-height: 2.9rem;
    height: clamp(2.78rem, 13vw, 3.15rem);
  }

  body.game-active {
    --chrome-w: 2.9rem;
  }

  body.game-active .game-chrome {
    top: -0.16rem;
  }

  body.game-active .chrome-title,
  body.game-active .chrome-label {
    font-size: 0.54rem;
  }

  body.game-active .chrome-value {
    font-size: clamp(0.84rem, 3.2vw, 1.04rem);
  }

  body.game-active .preview-grid {
    width: 2.35rem;
    height: 2.35rem;
  }

  .controls-row {
    gap: 0.74rem;
    width: min(100%, 23.4rem);
    max-width: min(100%, 23.4rem);
  }

  .controls-row:first-child {
    gap: 1.28rem;
  }

  .controls-row:last-child {
    gap: 1.64rem;
    width: min(100%, 20.5rem);
    max-width: min(100%, 20.5rem);
    grid-template-columns: repeat(2, minmax(0, 7.6rem));
    justify-content: center;
  }
}
