* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  touch-action: manipulation;
}

#game-container, #gameCanvas {
  touch-action: none;
}

html {
  height: 100%;
  height: 100dvh;
  height: -webkit-fill-available;
  overflow: hidden;
}

body {
  background: radial-gradient(circle at top, #1f3b7b 0%, #152347 45%, #0f1530 100%);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  overscroll-behavior: none;
  padding: 0;
}

#game-container {
  position: relative;
  width: 95%;
  max-width: 100vw;
  aspect-ratio: 16 / 9;
  background: #000;
  border: 4px solid #0066cc;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
}

/* Fullscreen button (PC only). Must stay above the .overlay screens (z-index 100)
   or it is unclickable; keep below #secret-credits-screen (130). */
.fullscreen-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 120;
  display: none;
  border-radius: 18px;
  border: 2px solid rgba(255, 215, 0, 0.85);
  background: radial-gradient(circle at top, #004499 0%, #001933 100%);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 10px;
  cursor: pointer;
  opacity: 0.9;
  transition: opacity 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.fullscreen-btn:hover {
  opacity: 1;
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
  transform: scale(1.06);
}

.fullscreen-btn:active {
  transform: scale(0.94);
}

@media (hover: hover) and (pointer: fine) and (min-width: 1025px) {
  .fullscreen-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

.mobile-menu-btn {
  position: absolute;
  top: max(0px, env(safe-area-inset-top));
  right: max(12px, calc(env(safe-area-inset-right) + 12px));
  z-index: 65;
  width: 44px;
  height: 44px;
  display: none;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  cursor: pointer;
  pointer-events: auto;
  touch-action: none;
}

.mobile-menu-btn img {
  width: 31px;
  height: 31px;
  display: block;
  opacity: 0.88;
  pointer-events: none;
  transform: translateY(-3px);
  filter: drop-shadow(0 1px 2px rgba(0, 18, 44, 0.54));
}

.mobile-menu-btn:active {
  transform: scale(0.94);
  background: rgba(0, 86, 173, 0.12);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  /* Keep the 16:9 game undistorted when the container fills a wider phone screen */
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.84);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 16px 20px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: opacity 0.35s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#title-screen {
  background:
    linear-gradient(to bottom, rgba(0,0,0,0.75) 0%, rgba(15,21,48,0.88) 100%),
    url('../assets/backgrounds/bg-level1-os.jpg') center/cover no-repeat;
}

@keyframes floatUp {
  0% { transform: translateY(0) scale(1); opacity: 0.6; }
  100% { transform: translateY(-100%) scale(0.5); opacity: 0; }
}

#title-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 15% 80%, #ffd700 50%, transparent 50%),
    radial-gradient(2px 2px at 45% 90%, #fff 50%, transparent 50%),
    radial-gradient(2px 2px at 75% 85%, #ffd700 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 30% 70%, #fff 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 85% 75%, #ffd700 50%, transparent 50%),
    radial-gradient(1.5px 1.5px at 55% 95%, #ffd700 50%, transparent 50%),
    radial-gradient(2px 2px at 10% 60%, #fff 50%, transparent 50%);
  background-size: 100% 100%;
  animation: floatUp 8s linear infinite;
  pointer-events: none;
  z-index: 0;
}

/* Ensure title content is above the ::before sparkles */
#title-screen .title-step {
  position: relative;
  z-index: 1;
}

@keyframes titleGlow {
  0%, 100% { text-shadow: 2px 2px 0 #0059b3, 0 0 20px rgba(255, 215, 0, 0.3); }
  50% { text-shadow: 2px 2px 0 #0059b3, 0 0 36px rgba(255, 215, 0, 0.6); }
}

#title-screen h1 {
  color: #ffd700;
  text-shadow: 2px 2px 0 #0059b3;
  animation: titleGlow 3s ease-in-out infinite;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

#secret-credits-screen {
  z-index: 130;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 215, 0, 0.18), transparent 34%),
    linear-gradient(to bottom, rgba(0, 12, 28, 0.9), rgba(0, 33, 70, 0.88)),
    url('../assets/backgrounds/bg-level1-os.jpg') center/cover no-repeat;
}

.secret-credits-card {
  position: relative;
  z-index: 1;
  width: min(92%, 520px);
  max-height: calc(100% - 18px);
  overflow-y: auto;
  padding: 18px 20px;
  border: 2px solid rgba(255, 215, 0, 0.78);
  border-radius: 10px;
  background: rgba(4, 18, 43, 0.86);
  box-shadow:
    0 0 0 2px rgba(97, 213, 255, 0.2) inset,
    0 18px 42px rgba(0, 0, 0, 0.42);
}

.secret-kicker {
  margin: 0 0 4px;
  color: #61d5ff;
  font-size: 0.66rem;
  font-weight: 800;
}

.secret-credits-card h1 {
  margin: 0 0 10px;
  color: #ffd700;
  font-size: clamp(1.45rem, 5vw, 2.15rem);
  line-height: 1;
  text-shadow: 2px 2px 0 #0059b3, 0 0 22px rgba(255, 215, 0, 0.4);
}

.secret-credits-lead,
.secret-credits-copy,
.secret-credits-small {
  margin: 0 auto 8px;
  max-width: 420px;
  line-height: 1.5;
}

.secret-credits-lead {
  color: #fff;
  font-size: 0.95rem;
  font-weight: 800;
}

.secret-credits-copy {
  color: #d9e2ff;
  font-size: 0.82rem;
}

.secret-credits-small {
  color: #6ee276;
  font-size: 0.74rem;
  font-weight: 700;
}

.secret-close-btn {
  margin-top: 4px;
}

.secret-sparkles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.secret-sparkles span {
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  opacity: 0;
  background: radial-gradient(circle at 35% 32%, #fff8a8 0 18%, #ffd700 19% 68%, #b57900 69% 100%);
  box-shadow: 0 0 14px rgba(255, 215, 0, 0.66);
}

.secret-burst .secret-sparkles span {
  animation: secretSparkle 1.2s ease-out both;
}

.secret-sparkles span:nth-child(1) { left: 20%; top: 60%; animation-delay: 0.02s; }
.secret-sparkles span:nth-child(2) { left: 34%; top: 44%; animation-delay: 0.14s; background: #61d5ff; }
.secret-sparkles span:nth-child(3) { left: 49%; top: 30%; animation-delay: 0.06s; }
.secret-sparkles span:nth-child(4) { left: 63%; top: 45%; animation-delay: 0.18s; background: #fff; }
.secret-sparkles span:nth-child(5) { left: 76%; top: 62%; animation-delay: 0.1s; }
.secret-sparkles span:nth-child(6) { left: 52%; top: 68%; animation-delay: 0.24s; background: #6ee276; }

@keyframes secretSparkle {
  0% { transform: translateY(26px) scale(0.55) rotate(0deg); opacity: 0; }
  22% { opacity: 1; }
  100% { transform: translateY(-88px) scale(1.05) rotate(210deg); opacity: 0; }
}

.high-score-display {
  color: #ffd700;
  font-weight: 700;
}

.en-sub {
  display: block;
  color: #9fb7df;
  font-size: 0.66em;
  font-weight: 600;
  line-height: 1.22;
  margin-top: 2px;
}

.story {
  font-size: 0.85rem;
  line-height: 1.5;
  max-width: 460px;
  color: #d9e2ff;
}

.story-large {
  max-width: 540px;
  font-size: 1rem;
  line-height: 1.55;
  font-weight: 700;
}

.step-kicker {
  color: #6ee276;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
}

.step-kicker .en-sub,
.high-score-display .en-sub {
  color: #8fb1e5;
  font-size: 0.72em;
}

.audio-controls,
.control-layout-setting {
  width: min(100%, 430px);
  border: 2px solid rgba(255, 215, 0, 0.5);
  border-radius: 10px;
  background: rgba(8, 20, 44, 0.7);
  padding: 10px;
}

.how-to-play-card {
  width: min(100%, 620px);
  border: 2px solid rgba(255, 215, 0, 0.5);
  border-radius: 10px;
  background: rgba(8, 20, 44, 0.9);
  padding: 12px;
  color: #d9e2ff;
  text-align: left;
}

.how-to-play-card h2 {
  margin-bottom: 10px;
  font-size: 1.2rem;
  color: #ffd700;
  text-align: center;
}

.title-step {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.title-step-hidden {
  display: none;
}

/* Row of side-by-side menu buttons (main menu sub-actions, settings start/back) */
.title-menu-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

/* Keyboard hints are meaningless on touch devices and cost menu height */
@media (pointer: coarse) {
  #title-step-3 .instructions {
    display: none;
  }
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}

.controls-column {
  flex: 1 1 160px;
  font-size: 0.78rem;
}

.controls-label {
  font-weight: 700;
  color: #cfe0ff;
  margin-bottom: 2px;
}

.controls-detail span {
  color: #ffd700;
}

.controls-note {
  font-size: 0.78rem;
  color: #cfe0ff;
  margin-top: 4px;
}

.compact-instructions {
  padding: 12px;
}

.instruction-flow {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.instruction-card {
  min-height: 146px;
  border: 2px solid rgba(97, 213, 255, 0.45);
  border-radius: 8px;
  background: rgba(0, 32, 76, 0.68);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  text-align: center;
}

.instruction-icon {
  width: 48px;
  height: 48px;
  border: 3px solid #ffd700;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #0066cc;
  color: #fff;
  font-size: 1rem;
  font-weight: 900;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.25);
}

.instruction-card strong {
  color: #ffd700;
  font-size: 1.08rem;
}

.instruction-card span {
  color: #e5edff;
  font-size: 0.84rem;
  line-height: 1.35;
}

.instruction-card .en-sub {
  color: #aac3f4;
  font-size: 0.72em;
  font-weight: 600;
}

.audio-controls {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px 10px;
}

.audio-controls button {
  border: 2px solid #ffd700;
  border-radius: 6px;
  background: #0056ad;
  color: #fff;
  font-weight: 700;
  padding: 6px 10px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.audio-controls button:hover {
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
  transform: scale(1.05);
}

.audio-controls button:active {
  transform: scale(0.94);
}

.audio-controls label {
  justify-self: start;
  color: #cfe0ff;
  font-size: 0.85rem;
}

.audio-controls input[type="range"] {
  width: 100%;
}

.control-layout-setting {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}

.control-layout-label {
  color: #cfe0ff;
  font-size: 0.85rem;
  font-weight: 700;
}

.control-layout-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(48px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 2px solid rgba(97, 213, 255, 0.45);
  border-radius: 8px;
  background: rgba(0, 32, 76, 0.55);
}

.control-layout-option {
  min-width: 48px;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #cfe0ff;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

.control-layout-option.is-active,
.control-layout-option[aria-pressed="true"] {
  background: #ffd700;
  color: #07326a;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.mobile-install-hint {
  width: min(100%, 430px);
  border: 2px solid rgba(97, 213, 255, 0.5);
  border-radius: 8px;
  background: rgba(0, 32, 76, 0.68);
  padding: 7px 10px;
  color: #d9e2ff;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.25;
}

.mobile-install-hint small {
  display: block;
  color: #9fb7df;
  font-size: 0.68em;
  margin-top: 2px;
}

.mobile-install-hint.hidden {
  display: none;
}

.start-btn {
  border: 3px solid #ffd700;
  border-radius: 8px;
  background: linear-gradient(180deg, #0066cc 0%, #004499 100%);
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 10px 32px;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.12;
  min-height: 46px;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.start-btn .en-sub,
.coupon-button .en-sub {
  color: #dce8ff;
  font-size: 0.58em;
  font-weight: 600;
  margin-top: 3px;
}

.start-btn:hover {
  box-shadow: 0 0 16px rgba(255, 215, 0, 0.5);
  transform: scale(1.04);
}

.start-btn:active {
  transform: scale(0.95);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

.start-btn.secondary {
  background: linear-gradient(180deg, #666 0%, #444 100%);
  border-color: #888;
}

.mobile-fullscreen-action.hidden {
  display: none;
}

.instructions {
  color: #8da2cc;
  font-size: 0.75rem;
}

.instructions span {
  color: #ffd700;
}

#level-transition h1 {
  color: #4caf50;
  font-size: 1.7rem;
}

#level-name {
  color: #ffd700;
  font-size: 1.15rem;
  font-weight: 700;
}

#level-intro {
  color: #dfe8ff;
  max-width: 460px;
  line-height: 1.5;
}

#transition-skip-hint {
  min-height: 18px;
  color: #9fc0ff;
  font-size: 0.78rem;
}

#retry-overlay h1 {
  color: #ffd700;
}

#retry-message {
  color: #e2ecff;
}

#result-screen h1 {
  color: #ffd700;
}

.completion-subtitle {
  color: #6ee276;
  font-size: 1.1rem;
  font-weight: 700;
}

.stats {
  display: grid;
  gap: 4px;
  color: #ffd700;
}

#touch-controls {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 50;
  pointer-events: none;
}

#dpad {
  display: flex;
  gap: 18px;
  pointer-events: auto;
}

#dpad button,
#jump-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 3px solid #ffd700;
  background: rgba(255, 215, 0, 0.75);
  color: #fff;
  font-weight: 700;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  transition: transform 0.1s ease, background 0.1s ease, box-shadow 0.1s ease;
}

#dpad button:active,
#jump-btn:active {
  transform: scale(0.88);
  background: rgba(255, 215, 0, 1);
  box-shadow: 0 0 12px rgba(255, 215, 0, 0.6);
}

#jump-btn {
  width: 80px;
  border-radius: 40px;
}

#game-container.controls-vertical #dpad {
  flex-direction: column;
  gap: 10px;
}

#loading {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background:
    radial-gradient(circle at 50% 20%, rgba(97, 213, 255, 0.22), transparent 34%),
    linear-gradient(180deg, #153d7a 0%, #102653 52%, #0b1430 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.loading-card {
  position: relative;
  width: min(88vw, 420px);
  border: 3px solid #0066cc;
  border-radius: 12px;
  background: rgba(5, 18, 46, 0.82);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.4), inset 0 0 0 2px rgba(255, 215, 0, 0.2);
  padding: 24px 24px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.loading-card::before {
  content: "";
  position: absolute;
  inset: auto -20% 0;
  height: 38%;
  background:
    linear-gradient(90deg, transparent 0 8%, rgba(97, 213, 255, 0.24) 8% 10%, transparent 10% 18%),
    linear-gradient(180deg, transparent 0 46%, rgba(255, 255, 255, 0.1) 46% 49%, transparent 49%);
  background-size: 82px 100%, 100% 18px;
  opacity: 0.48;
  pointer-events: none;
}

.loading-emblem {
  position: relative;
  width: 68px;
  height: 68px;
  border: 3px solid #ffd700;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 25%, #fff7a8 0%, #ffd700 38%, #bc7d00 100%);
  display: grid;
  place-items: center;
  box-shadow: 0 0 22px rgba(255, 215, 0, 0.35);
  animation: loadingCoinFloat 1.8s ease-in-out infinite;
}

.loading-emblem img {
  width: 54px;
  height: 54px;
  image-rendering: pixelated;
}

.loading-kicker {
  color: #61d5ff;
  font-size: 0.72rem;
  font-weight: 900;
}

#loading h2 {
  position: relative;
  color: #ffd700;
  font-size: 1.15rem;
  line-height: 1.25;
  text-align: center;
  text-shadow: 2px 2px 0 #0056ad;
}

.loading-sparkles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.loading-sparkles span {
  position: absolute;
  width: 5px;
  height: 5px;
  background: #ffd700;
  image-rendering: pixelated;
  animation: loadingSparkle 2s ease-in-out infinite;
}

.loading-sparkles span:nth-child(1) { left: 18%; top: 25%; }
.loading-sparkles span:nth-child(2) { left: 78%; top: 30%; animation-delay: 0.35s; background: #61d5ff; }
.loading-sparkles span:nth-child(3) { left: 25%; top: 76%; animation-delay: 0.7s; background: #fff; }
.loading-sparkles span:nth-child(4) { left: 83%; top: 72%; animation-delay: 1.05s; }

.loading-bar {
  position: relative;
  width: min(100%, 300px);
  height: 18px;
  border: 2px solid #61d5ff;
  border-radius: 9px;
  overflow: hidden;
  background: #13264d;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25);
}

.loading-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #0066cc 0%, #61d5ff 45%, #ffd700 100%);
  transition: width 0.3s ease-out;
}

#loading-text {
  position: relative;
  min-height: 34px;
  color: #e6f1ff;
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
}

@keyframes loadingCoinFloat {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-5px) rotate(3deg); }
}

@keyframes loadingSparkle {
  0%, 100% { opacity: 0.18; transform: scale(0.7); }
  45%, 65% { opacity: 1; transform: scale(1.2); }
}

#rotate-prompt {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  color: #fff;
  background: radial-gradient(circle at top, #1f3b7b 0%, #0f1530 80%);
  padding: 24px;
}

#rotate-prompt h2 {
  color: #ffd700;
  line-height: 1.25;
}

#rotate-prompt p {
  max-width: 360px;
  line-height: 1.45;
}

.rotate-icon {
  width: 126px;
  height: 126px;
}

.rotate-icon svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.rotate-orbit {
  fill: none;
  stroke: rgba(97, 213, 255, 0.18);
  stroke-width: 5;
}

.rotate-sweep,
.rotate-head {
  fill: none;
  stroke: #61d5ff;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: rotateArrowPulse 1.8s ease-in-out infinite;
}

.rotate-sweep-b,
.rotate-head-b {
  stroke: #ffd700;
  animation-delay: 0.22s;
}

.phone-tilt {
  animation: phoneFlipCue 2.25s cubic-bezier(0.45, 0, 0.2, 1) infinite;
  transform-origin: 64px 64px;
}

.phone-shadow {
  fill: rgba(0, 0, 0, 0.3);
  transform: translate(4px, 5px);
}

.phone-body {
  fill: #0b1e42;
  stroke: #ffd700;
  stroke-width: 5;
}

.phone-screen {
  fill: #102c63;
  stroke: #61d5ff;
  stroke-width: 2;
}

.phone-dot {
  fill: #ffd700;
}

.landscape-target {
  fill: none;
  stroke: rgba(255, 215, 0, 0.42);
  stroke-width: 4;
  stroke-dasharray: 8 6;
  animation: targetPulse 2.25s ease-in-out infinite;
}

@keyframes phoneFlipCue {
  0%, 16% { transform: rotate(0deg) scale(1); }
  42% { transform: rotate(90deg) scale(1.06); }
  68%, 100% { transform: rotate(90deg) scale(1); }
}

@keyframes rotateArrowPulse {
  0%, 100% { opacity: 0.42; stroke-width: 5; }
  45%, 70% { opacity: 1; stroke-width: 7; }
}

@keyframes targetPulse {
  0%, 30% { opacity: 0.16; }
  55%, 100% { opacity: 0.72; }
}

@media (prefers-reduced-motion: reduce) {
  .phone-tilt,
  .rotate-sweep,
  .rotate-head,
  .landscape-target,
  .loading-emblem,
  .loading-sparkles span,
  .secret-sparkles span,
  .completion-celebration span,
  #result-screen.celebrating h1 {
    animation: none;
  }
}

@media (max-width: 1024px), (hover: none) and (pointer: coarse) {
  body {
    background: #000;
  }
  #game-container {
    /* Fit the largest 16:9 rectangle inside the mobile viewport */
    width: min(100vw, calc(100vh * 16 / 9));
    width: min(100vw, calc(100dvh * 16 / 9));
    height: min(100vh, calc(100vw * 9 / 16));
    height: min(100dvh, calc(100vw * 9 / 16));
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    aspect-ratio: 16 / 9;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
  #game-container.is-playing #touch-controls {
    display: flex;
  }
  #game-container.is-playing .mobile-menu-btn {
    display: grid;
  }
}

@media (max-width: 1024px) and (orientation: landscape), (hover: none) and (pointer: coarse) and (orientation: landscape) {
  body {
    align-items: stretch;
    justify-content: center;
  }
  #game-container {
    /*
      Mobile Safari with browser chrome has very little vertical space. Filling
      the visible viewport keeps gameplay readable instead of shrinking a 16:9
      rectangle into the middle of the screen.
    */
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    aspect-ratio: auto;
  }
}

/* Scale touch controls on very short landscape screens (small phones) */
@media (max-height: 500px) {
  #dpad {
    gap: 16px;
  }
  #dpad button,
  #jump-btn {
    width: 56px;
    height: 56px;
    font-size: 0.85rem;
  }
  #jump-btn {
    width: 74px;
  }
  #game-container.controls-vertical #dpad {
    gap: 10px;
  }
  #touch-controls {
    bottom: max(10px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
  }
  .instruction-flow {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .instruction-card {
    min-height: 116px;
    padding: 8px;
  }
  .instruction-icon {
    width: 38px;
    height: 38px;
    font-size: 0.8rem;
  }
  .instruction-card strong {
    font-size: 0.92rem;
  }
  .instruction-card span {
    font-size: 0.68rem;
  }
  .start-btn {
    min-height: 40px;
    padding: 7px 20px;
    font-size: 0.9rem;
  }
}

@media (min-width: 1025px) and (hover: hover) and (pointer: fine) {
  body {
    padding: 8px;
  }
  #game-container {
    width: min(100vw - 16px, calc((100vh - 16px) * 16 / 9));
    max-width: none;
    max-height: calc(100vh - 16px);
  }
}

.line-section {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 2px solid #06c755;
  border-radius: 10px;
  background: rgba(6, 199, 85, 0.12);
  padding: 8px 12px;
  width: min(100%, 420px);
}

.line-section img {
  width: 64px;
  height: 64px;
  border-radius: 6px;
}

.line-section .line-text {
  color: #fff;
  font-size: 0.82rem;
  text-align: left;
}

.line-section .line-text strong {
  color: #06c755;
}

.coupon-section {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px 12px;
  width: min(100%, 470px);
  border: 2px solid #06c755;
  border-radius: 10px;
  background: rgba(6, 199, 85, 0.13);
  padding: 10px 12px;
}

.coupon-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
}

.coupon-copy strong {
  color: #06c755;
  font-size: 0.95rem;
}

.coupon-copy span {
  color: #fff;
  font-size: 0.8rem;
  line-height: 1.35;
}

.coupon-copy small,
.coupon-used {
  color: #b6ffc9;
  font-size: 0.68rem;
  line-height: 1.35;
}

#coupon-qr {
  grid-row: span 2;
  width: 86px;
  height: 86px;
  border-radius: 8px;
  background: #fff;
  padding: 4px;
}

.coupon-button {
  grid-column: 1 / -1;
  justify-self: stretch;
  border: 2px solid #06c755;
  border-radius: 8px;
  background: #06c755;
  color: #06240f;
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
  padding: 8px 12px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.coupon-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 14px rgba(6, 199, 85, 0.35);
}

.coupon-claimed {
  border-color: rgba(255, 215, 0, 0.65);
  background: rgba(255, 215, 0, 0.1);
}

.coupon-used {
  grid-column: 1 / -1;
  margin: 0;
}

.coupon-section.hidden,
.coupon-button.hidden,
#coupon-qr.hidden,
.coupon-used.hidden {
  display: none;
}

/* Small LINE banner for title menu */
.line-banner-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 2px solid #06c755;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(6, 199, 85, 0.15), rgba(0, 70, 35, 0.2));
  padding: 9px 10px;
  width: min(100%, 430px);
  text-align: left;
}

.line-banner-mini img {
  width: 48px;
  height: 48px;
  border-radius: 4px;
}

.line-banner-mini span {
  color: #06c755;
  font-size: 0.78rem;
  font-weight: 700;
}

.line-banner-mini small {
  color: #6ee276;
  font-size: 0.7rem;
}

.line-cta-button {
  flex: 0 0 auto;
  min-width: 142px;
  border: 2px solid #b6ffc9;
  border-radius: 8px;
  background: #06c755;
  color: #06240f;
  font-size: 0.82rem;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  padding: 8px 10px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.line-cta-button .en-sub {
  color: #063d18;
  font-size: 0.62em;
  margin-top: 3px;
}

.line-cta-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 14px rgba(6, 199, 85, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.18);
}

.completion-celebration {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.completion-celebration::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 17%;
  width: 280px;
  height: 110px;
  background: radial-gradient(circle, rgba(255, 215, 0, 0.26) 0%, rgba(97, 213, 255, 0.16) 42%, transparent 72%);
  transform: translate(-50%, -50%);
  animation: resultBurst 0.95s ease-out;
}

.completion-celebration span {
  position: absolute;
  top: -18px;
  width: 12px;
  height: 18px;
  background: #ffd700;
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.45);
  animation: celebrationDrop 1.35s ease-out 2;
}

.completion-celebration span:nth-child(1) { left: 14%; animation-delay: 0.05s; background: #ffd700; }
.completion-celebration span:nth-child(2) { left: 29%; animation-delay: 0.18s; background: #61d5ff; }
.completion-celebration span:nth-child(3) { left: 43%; animation-delay: 0.02s; background: #06c755; }
.completion-celebration span:nth-child(4) { left: 58%; animation-delay: 0.28s; background: #ffffff; }
.completion-celebration span:nth-child(5) { left: 73%; animation-delay: 0.1s; background: #0066cc; }
.completion-celebration span:nth-child(6) { left: 87%; animation-delay: 0.22s; background: #ffd700; }

#result-screen.celebrating h1 {
  animation: resultPop 0.6s ease-out;
}

#result-screen > :not(.completion-celebration) {
  position: relative;
  z-index: 1;
}

@keyframes celebrationDrop {
  0% { transform: translateY(0) rotate(0deg); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translateY(105vh) rotate(240deg); opacity: 0; }
}

@keyframes resultPop {
  0% { transform: scale(0.92); opacity: 0.75; }
  55% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes resultBurst {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.65); }
  45% { opacity: 1; transform: translate(-50%, -50%) scale(1.08); }
  100% { opacity: 0.42; transform: translate(-50%, -50%) scale(1); }
}

#game-container.is-playing .fullscreen-btn,
#game-container.fullscreen-unavailable .fullscreen-btn {
  display: none;
}

@media (max-width: 650px) and (orientation: portrait) {
  #rotate-prompt {
    display: flex;
  }
}

@media (max-height: 390px) and (orientation: landscape) {
  .overlay {
    padding: 10px;
  }
  #title-screen {
    justify-content: flex-start;
  }
  #title-screen .title-step {
    gap: 6px;
    padding-top: max(4px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .story {
    font-size: 0.72rem;
  }
  .audio-controls,
  .control-layout-setting {
    padding: 6px 8px;
  }
  .audio-controls {
    gap: 5px 8px;
  }
  .audio-controls button {
    padding: 4px 10px;
    min-height: 34px;
  }
  .control-layout-option {
    min-height: 30px;
  }
  .mobile-install-hint {
    padding: 5px 8px;
  }
  #secret-credits-screen {
    padding: 8px 10px;
  }
  .secret-credits-card {
    width: min(92%, 500px);
    padding: 12px 14px;
  }
  .secret-kicker {
    font-size: 0.58rem;
  }
  .secret-credits-card h1 {
    font-size: 1.25rem;
    margin-bottom: 7px;
  }
  .secret-credits-lead,
  .secret-credits-copy,
  .secret-credits-small {
    margin-bottom: 6px;
    line-height: 1.35;
  }
  .secret-credits-lead {
    font-size: 0.82rem;
  }
  .secret-credits-copy {
    font-size: 0.74rem;
  }
  .secret-credits-small {
    font-size: 0.68rem;
  }
  .secret-close-btn {
    min-height: 38px;
    padding: 6px 18px;
    font-size: 0.82rem;
  }
  #title-step-3 .instructions {
    display: none;
  }
  .how-to-play-card h2 {
    font-size: 0.95rem;
    margin-bottom: 6px;
  }
  .step-kicker {
    font-size: 0.62rem;
  }
  #result-screen {
    justify-content: flex-start;
    gap: 6px;
    padding: max(28px, calc(env(safe-area-inset-top) + 28px)) 12px max(8px, env(safe-area-inset-bottom));
  }
  #result-screen h1 {
    font-size: clamp(1.55rem, 5.2vw, 2rem);
    line-height: 1.02;
    margin: 0;
    max-width: 96%;
  }
  .completion-subtitle {
    font-size: 0.84rem;
    line-height: 1.1;
  }
  .stats {
    grid-template-columns: repeat(4, auto);
    justify-content: center;
    gap: 6px 14px;
    font-size: 0.7rem;
    line-height: 1.1;
  }
  #result-screen .coupon-section {
    width: min(100%, 470px);
    gap: 6px 10px;
    padding: 8px 10px;
  }
  #result-screen .coupon-copy {
    gap: 1px;
  }
  #result-screen .coupon-copy strong {
    font-size: 0.78rem;
  }
  #result-screen .coupon-copy span {
    font-size: 0.7rem;
    line-height: 1.25;
  }
  #result-screen .coupon-copy small,
  #result-screen .coupon-used {
    font-size: 0.6rem;
    line-height: 1.2;
  }
  #result-screen .coupon-button {
    min-height: 38px;
    padding: 6px 10px;
    font-size: 0.78rem;
  }
  #play-again-btn {
    min-height: 40px;
    padding: 7px 22px;
    font-size: 0.9rem;
  }
  .coupon-section {
    grid-template-columns: 1fr;
  }
  .line-banner-mini {
    align-items: center;
    flex-direction: row;
    text-align: center;
    padding: 7px 8px;
  }
  .line-cta-button {
    width: auto;
  }
  #coupon-qr {
    grid-row: auto;
    justify-self: center;
    width: 70px;
    height: 70px;
  }
}
