:root {
  color-scheme: dark;
  --cream: #fff4d6;
  --ink: #171129;
  --night: #17112d;
  --plum: #3b2457;
  --violet: #6f4b91;
  --mint: #72d9ae;
  --mint-dark: #2d8767;
  --copper: #c77845;
  --gold: #ffd26a;
  --blue: #6fb9e8;
  --panel: rgba(24, 17, 44, 0.9);
  --glass: rgba(28, 20, 48, 0.72);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--night);
  color: var(--cream);
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", ui-rounded, system-ui, sans-serif;
  touch-action: none;
  user-select: none;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

#gameShell,
#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#gameShell {
  overflow: hidden;
  background:
    radial-gradient(circle at 76% 12%, rgba(101, 137, 191, 0.25), transparent 35%),
    linear-gradient(160deg, #2a1839, #0f1027 72%);
}

#gameCanvas {
  display: block;
  background: #17112d;
  cursor: grab;
  touch-action: none;
}

body.cameraDragging #gameCanvas {
  cursor: grabbing;
}

.cornerButton {
  position: fixed;
  z-index: 60;
  top: max(8px, env(safe-area-inset-top));
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 244, 214, 0.42);
  border-radius: 11px;
  background: rgba(22, 15, 37, 0.76);
  box-shadow: 0 4px 14px rgba(8, 5, 18, 0.3), inset 0 0 12px rgba(255, 255, 255, 0.04);
  color: #fff8e8;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.cornerButton:active {
  transform: scale(0.94);
  background: rgba(111, 75, 145, 0.9);
}

.cornerButton:disabled {
  opacity: 0.36;
  pointer-events: none;
}

.backButton {
  left: max(8px, env(safe-area-inset-left));
}

.lockButton {
  left: calc(max(8px, env(safe-area-inset-left)) + 42px);
  color: var(--gold);
  font-size: 15px;
}

.pauseButton {
  right: calc(max(8px, env(safe-area-inset-right)) + 126px);
}

.resetButton {
  right: calc(max(8px, env(safe-area-inset-right)) + 84px);
}

.fullscreenButton {
  right: calc(max(8px, env(safe-area-inset-right)) + 42px);
}

.cleanButton {
  right: max(8px, env(safe-area-inset-right));
  color: var(--gold);
}

body.controlsLocked .lockButton {
  border-color: rgba(255, 210, 106, 0.82);
  background: rgba(96, 59, 30, 0.9);
  box-shadow: 0 0 0 2px rgba(255, 210, 106, 0.12), 0 4px 14px rgba(8, 5, 18, 0.3);
}

#hud {
  position: fixed;
  z-index: 35;
  top: max(7px, env(safe-area-inset-top));
  left: calc(max(8px, env(safe-area-inset-left)) + 92px);
  right: calc(max(8px, env(safe-area-inset-right)) + 174px);
  min-height: 52px;
  display: grid;
  grid-template-columns: minmax(225px, 1.45fr) minmax(210px, 1fr) 86px;
  gap: 8px;
  pointer-events: none;
}

#hud section {
  min-width: 0;
  min-height: 52px;
  border: 1px solid rgba(255, 244, 214, 0.25);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(31, 21, 51, 0.9), rgba(20, 15, 35, 0.82));
  box-shadow: 0 6px 20px rgba(8, 5, 18, 0.22), inset 0 1px rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.missionPanel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 20px 1fr;
  align-items: center;
  padding: 6px 12px;
  column-gap: 10px;
}

.missionPanel small {
  grid-row: 1 / 3;
  align-self: stretch;
  display: grid;
  place-items: center;
  padding-right: 10px;
  border-right: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--gold);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.missionPanel strong {
  overflow: hidden;
  color: #fff8e8;
  font-size: clamp(12px, 1.3vw, 16px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.missionPanel span {
  overflow: hidden;
  color: rgba(255, 244, 214, 0.76);
  font-size: clamp(10px, 1vw, 13px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.railPanel {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 11px;
}

.railIcon {
  color: var(--copper);
  font-size: 22px;
  transform: rotate(45deg);
}

.railPanel > div {
  min-width: 0;
  flex: 1;
}

.railPanel small {
  display: block;
  overflow: hidden;
  margin-bottom: 6px;
  color: rgba(255, 244, 214, 0.75);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.railSegments {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.railSegments i {
  height: 7px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  transition: background 500ms ease, box-shadow 500ms ease;
}

.railSegments i.lit {
  border-color: rgba(255, 210, 106, 0.82);
  background: linear-gradient(90deg, var(--copper), var(--gold));
  box-shadow: 0 0 10px rgba(255, 210, 106, 0.55);
}

.ticketPanel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 5px;
}

.ticketPanel span {
  font-size: 20px;
  filter: drop-shadow(0 2px 5px rgba(255, 210, 106, 0.45));
}

.ticketPanel strong {
  color: var(--gold);
  font-size: 13px;
}

#objectiveMarker {
  position: fixed;
  z-index: 25;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 42px;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 180ms ease;
}

#objectiveMarker.visible {
  opacity: 1;
}

#objectiveMarker span {
  color: var(--gold);
  font-size: 22px;
  filter: drop-shadow(0 0 8px #ffdb79) drop-shadow(0 3px 3px rgba(0, 0, 0, 0.55));
  animation: markerBob 1.35s ease-in-out infinite;
}

#speechBubble {
  position: fixed;
  z-index: 48;
  top: calc(max(8px, env(safe-area-inset-top)) + 66px);
  left: 50%;
  max-width: min(520px, 70vw);
  padding: 10px 18px;
  border: 1px solid rgba(255, 244, 214, 0.46);
  border-radius: 18px;
  background: rgba(22, 16, 37, 0.9);
  box-shadow: 0 8px 24px rgba(8, 5, 18, 0.3);
  color: #fff8e8;
  font-size: clamp(13px, 1.5vw, 18px);
  font-weight: 850;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -10px) scale(0.96);
  transition: opacity 180ms ease, transform 180ms ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#speechBubble.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

#toast {
  position: fixed;
  z-index: 52;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  max-width: min(560px, 62vw);
  padding: 9px 18px;
  border: 1px solid rgba(255, 210, 106, 0.58);
  border-radius: 999px;
  background: rgba(25, 18, 39, 0.88);
  box-shadow: 0 7px 18px rgba(7, 5, 16, 0.28);
  color: #fff4d6;
  font-size: clamp(12px, 1.15vw, 15px);
  font-weight: 850;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#fadeCurtain {
  position: fixed;
  z-index: 80;
  inset: 0;
  background: #17112d;
  pointer-events: none;
  opacity: 0;
  transition: opacity 320ms ease;
}

#fadeCurtain.visible {
  opacity: 1;
}

#touchControls {
  position: fixed;
  z-index: 45;
  inset: 0;
  pointer-events: none;
}

#joystick {
  --knob-x: 0px;
  --knob-y: 0px;
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  width: clamp(116px, 17vw, 152px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 244, 214, 0.42);
  border-radius: 50%;
  background: rgba(26, 20, 43, 0.24);
  box-shadow: inset 0 0 30px rgba(255, 255, 255, 0.035), 0 6px 22px rgba(7, 5, 16, 0.16);
  pointer-events: auto;
  touch-action: none;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.joystickRing {
  position: absolute;
  inset: 20%;
  border: 1px dashed rgba(255, 244, 214, 0.22);
  border-radius: 50%;
}

.joystickKnob {
  width: 43%;
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.28), rgba(114, 217, 174, 0.38) 45%, rgba(45, 135, 103, 0.52));
  box-shadow: 0 6px 18px rgba(7, 5, 16, 0.24), inset 0 0 15px rgba(255, 255, 255, 0.12);
  transform: translate(var(--knob-x), var(--knob-y));
  transition: transform 70ms linear;
}

#joystick.active .joystickKnob {
  transition: none;
}

.actionButton {
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: clamp(88px, 13vw, 112px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 3px solid rgba(255, 244, 214, 0.46);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.22), rgba(92, 63, 118, 0.52) 55%, rgba(31, 23, 48, 0.7));
  box-shadow: 0 8px 22px rgba(7, 5, 16, 0.28), inset 0 0 20px rgba(255, 255, 255, 0.07);
  color: #fff;
  font-size: clamp(30px, 5vw, 45px);
  pointer-events: auto;
  touch-action: manipulation;
  opacity: 0.52;
  cursor: pointer;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  transition: opacity 150ms ease, border-color 150ms ease, background 150ms ease, transform 100ms ease;
}

.actionButton.ready {
  border-color: rgba(255, 222, 126, 0.96);
  background: radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.34), rgba(255, 196, 89, 0.68) 52%, rgba(145, 79, 49, 0.76));
  box-shadow: 0 0 0 7px rgba(255, 210, 106, 0.12), 0 0 28px rgba(255, 210, 106, 0.45), inset 0 0 20px rgba(255, 255, 255, 0.14);
  opacity: 1;
  animation: actionReady 1.4s ease-in-out infinite;
}

.actionButton:active {
  transform: scale(0.94);
}

.overlay {
  position: fixed;
  z-index: 70;
  inset: 0;
  display: none;
  place-items: center;
  padding: max(58px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 70% 20%, rgba(105, 122, 184, 0.2), transparent 38%),
    rgba(15, 10, 28, 0.76);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.overlay.visible {
  display: grid;
}

.startCard,
.storyCard,
.menuCard,
.missionCard {
  width: min(570px, 88vw);
  max-height: calc(100vh - 76px);
  overflow: auto;
  padding: clamp(22px, 4vh, 36px);
  border: 1px solid rgba(255, 244, 214, 0.34);
  border-radius: 26px;
  background:
    linear-gradient(150deg, rgba(67, 43, 91, 0.94), rgba(24, 17, 43, 0.97)),
    var(--panel);
  box-shadow: 0 24px 70px rgba(7, 4, 18, 0.52), inset 0 1px rgba(255, 255, 255, 0.12);
  text-align: center;
}

.startCard {
  position: relative;
}

.moonBadge {
  position: relative;
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  margin: 0 auto 8px;
  border: 1px solid rgba(255, 210, 106, 0.45);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, rgba(255, 238, 178, 0.24), rgba(46, 31, 73, 0.72));
  color: var(--gold);
  box-shadow: 0 0 28px rgba(255, 210, 106, 0.17);
}

.moonBadge span {
  font-size: 44px;
  line-height: 1;
  transform: translateY(-3px);
}

.moonBadge i {
  position: absolute;
  top: 11px;
  right: 11px;
  color: #fff4d6;
  font-size: 13px;
  font-style: normal;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.startCard h1 {
  margin: 0;
  color: #fff8e8;
  font-size: clamp(34px, 7vw, 58px);
  letter-spacing: 0.02em;
  line-height: 0.95;
  text-shadow: 0 5px 20px rgba(7, 4, 18, 0.4);
}

.startCard h1 span {
  display: block;
  color: var(--gold);
}

.startCard h2 {
  margin: 8px 0 0;
  color: var(--mint);
  font-size: clamp(15px, 2.6vw, 22px);
  line-height: 1.1;
}

.startCopy {
  margin: 16px auto 18px;
  color: rgba(255, 244, 214, 0.83);
  font-size: clamp(14px, 2vw, 18px);
}

.startActions,
.confirmActions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primaryButton,
.secondaryButton,
.dangerButton {
  min-width: 180px;
  min-height: 48px;
  padding: 11px 20px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.primaryButton {
  border: 2px solid rgba(255, 247, 220, 0.7);
  background: linear-gradient(180deg, #86e5bc, #48a982);
  box-shadow: 0 7px 18px rgba(30, 94, 70, 0.28), inset 0 1px rgba(255, 255, 255, 0.4);
  color: #15152a;
}

.secondaryButton {
  border: 1px solid rgba(255, 244, 214, 0.38);
  background: rgba(255, 255, 255, 0.08);
  color: #fff8e8;
}

.dangerButton {
  border: 2px solid rgba(255, 240, 220, 0.62);
  background: linear-gradient(180deg, #df7f67, #a7474c);
  color: #fff;
}

.primaryButton:active,
.secondaryButton:active,
.dangerButton:active {
  transform: translateY(1px) scale(0.98);
}

.startHint {
  margin: 14px 0 0;
  color: rgba(255, 244, 214, 0.58);
  font-size: 12px;
}

.storyCard {
  width: min(620px, 90vw);
}

.storyIllustration {
  position: relative;
  height: 130px;
  overflow: hidden;
  margin: -8px -8px 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 19px;
  background:
    radial-gradient(circle at 75% 18%, rgba(137, 168, 218, 0.3), transparent 35%),
    linear-gradient(180deg, #30264c 0 65%, #6c4860 66%, #39283e 100%);
}

.storyMoon {
  position: absolute;
  top: 5px;
  right: 40px;
  color: #ffe2a0;
  font-size: 52px;
  text-shadow: 0 0 22px rgba(255, 226, 160, 0.42);
}

.storyTrain {
  position: absolute;
  left: 48%;
  bottom: 23px;
  color: var(--copper);
  font-size: 30px;
  letter-spacing: -7px;
  transform: rotate(-11deg);
  text-shadow: 0 5px 8px rgba(0, 0, 0, 0.3);
}

.storyMikey {
  position: absolute;
  left: 30%;
  bottom: 20px;
  width: 38px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 3px solid #23324c;
  border-radius: 50% 50% 15px 15px;
  background: var(--mint);
  color: #d76c36;
  font-weight: 1000;
}

.storyCard h2,
.menuCard h2,
.missionCard h2 {
  margin: 0 0 10px;
  color: #fff8e8;
  font-size: clamp(25px, 5vw, 38px);
  line-height: 1;
}

.storyCard > p:not(.eyebrow),
.menuCard > p,
.missionCard > p:not(.eyebrow) {
  max-width: 500px;
  margin: 0 auto 20px;
  color: rgba(255, 244, 214, 0.78);
  font-size: clamp(14px, 2vw, 18px);
  line-height: 1.42;
}

.menuCard {
  width: min(500px, 88vw);
}

.menuIcon {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  margin: 0 auto 10px;
  border: 1px solid rgba(255, 210, 106, 0.45);
  border-radius: 50%;
  background: rgba(255, 210, 106, 0.1);
  color: var(--gold);
  font-size: 36px;
}

.settingsGrid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.settingButton {
  min-height: 75px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 5px;
  border: 1px solid rgba(255, 244, 214, 0.25);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.055);
  color: #fff8e8;
  cursor: pointer;
}

.settingButton span {
  color: var(--mint);
  font-size: 22px;
}

.settingButton b {
  font-size: 10px;
  letter-spacing: 0.06em;
}

.settingButton small {
  color: var(--gold);
  font-size: 10px;
}

.settingButton[aria-pressed="false"] {
  opacity: 0.62;
}

.missionCard {
  width: min(560px, 90vw);
}

.completeTower {
  width: 58px;
  height: 100px;
  display: flex;
  flex-direction: column-reverse;
  gap: 3px;
  margin: 0 auto 16px;
}

.completeTower i {
  flex: 1;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
}

.completeTower i.lit {
  border-color: #ffe39a;
  background: linear-gradient(90deg, #da734b, #ffd26a);
  box-shadow: 0 0 18px rgba(255, 210, 106, 0.62);
}

.missionStats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  width: min(330px, 100%);
  margin: 0 auto 18px;
  border: 1px solid rgba(255, 244, 214, 0.2);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.missionStats span {
  display: grid;
  padding: 10px;
  background: rgba(19, 14, 33, 0.56);
}

.missionStats b {
  color: var(--gold);
  font-size: 21px;
}

.missionStats small {
  color: rgba(255, 244, 214, 0.62);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

body.cleanMode #hud,
body.cleanMode .lockButton,
body.cleanMode .pauseButton,
body.cleanMode .resetButton,
body.cleanMode .fullscreenButton,
body.cleanMode #speechBubble:not(.show) {
  opacity: 0;
  pointer-events: none;
}

body.cleanMode .cleanButton {
  color: #fff;
  background: rgba(87, 60, 113, 0.88);
}

body.sequenceActive #joystick,
body.sequenceActive .actionButton,
body.menuOpen #touchControls {
  opacity: 0;
  pointer-events: none;
}

body.sequenceActive #touchControls {
  pointer-events: none;
}

body.calmMotion * {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  scroll-behavior: auto !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

@keyframes markerBob {
  0%, 100% { transform: translateY(0) rotate(45deg); }
  50% { transform: translateY(-8px) rotate(45deg); }
}

@keyframes actionReady {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

@media (orientation: portrait) and (max-width: 900px) {
  .cornerButton {
    top: max(7px, env(safe-area-inset-top));
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 15px;
  }

  .backButton { left: max(7px, env(safe-area-inset-left)); }
  .lockButton { left: calc(max(7px, env(safe-area-inset-left)) + 39px); }
  .pauseButton { right: calc(max(7px, env(safe-area-inset-right)) + 117px); }
  .resetButton { right: calc(max(7px, env(safe-area-inset-right)) + 78px); }
  .fullscreenButton { right: calc(max(7px, env(safe-area-inset-right)) + 39px); }
  .cleanButton { right: max(7px, env(safe-area-inset-right)); }

  #hud {
    top: calc(max(7px, env(safe-area-inset-top)) + 41px);
    left: max(6px, env(safe-area-inset-left));
    right: max(6px, env(safe-area-inset-right));
    min-height: 48px;
    grid-template-columns: minmax(132px, 1.35fr) minmax(96px, 0.95fr) 52px;
    gap: 4px;
  }

  #hud section {
    min-height: 48px;
    border-radius: 11px;
  }

  .missionPanel {
    grid-template-columns: 1fr;
    grid-template-rows: 16px 1fr;
    padding: 5px 8px;
    column-gap: 0;
  }

  .missionPanel small { display: none; }
  .missionPanel strong { font-size: 11px; }
  .missionPanel span { font-size: 8.5px; }
  .railPanel { gap: 0; padding: 5px 7px; }
  .railIcon { display: none; }
  .railPanel small { margin-bottom: 5px; font-size: 6.5px; letter-spacing: 0.03em; }
  .railSegments { gap: 2px; }
  .railSegments i { height: 6px; }
  .ticketPanel { gap: 2px; padding: 3px; }
  .ticketPanel span { font-size: 15px; }
  .ticketPanel strong { font-size: 10px; }

  #speechBubble {
    top: calc(max(7px, env(safe-area-inset-top)) + 96px);
    max-width: calc(100vw - 24px);
    padding: 8px 13px;
    font-size: 12px;
  }

  #toast {
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 122px);
    max-width: calc(100vw - 28px);
    padding: 8px 13px;
    font-size: 11px;
  }

  #joystick {
    left: max(12px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: clamp(112px, 31vw, 136px);
  }

  .actionButton {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    width: clamp(86px, 24vw, 104px);
    font-size: clamp(29px, 9vw, 39px);
  }

  .overlay {
    padding: calc(max(48px, env(safe-area-inset-top)) + 4px) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .startCard,
  .storyCard,
  .menuCard,
  .missionCard {
    width: min(92vw, 520px);
    max-height: calc(100dvh - 66px);
    padding: clamp(19px, 3.5vh, 30px) 20px;
    border-radius: 22px;
  }

  .startCard h1 { font-size: clamp(38px, 13vw, 54px); }
  .startCard h2 { font-size: clamp(16px, 5vw, 21px); }
  .settingsGrid { grid-template-columns: 1fr; }
  .settingButton { min-height: 54px; flex-direction: row; gap: 8px; }
  .settingButton span { font-size: 18px; }
}

@media (max-height: 560px) {
  .cornerButton {
    top: max(5px, env(safe-area-inset-top));
    width: 30px;
    height: 30px;
    border-radius: 9px;
    font-size: 14px;
  }

  .lockButton { left: calc(max(5px, env(safe-area-inset-left)) + 35px); }
  .backButton { left: max(5px, env(safe-area-inset-left)); }
  .pauseButton { right: calc(max(5px, env(safe-area-inset-right)) + 105px); }
  .resetButton { right: calc(max(5px, env(safe-area-inset-right)) + 70px); }
  .fullscreenButton { right: calc(max(5px, env(safe-area-inset-right)) + 35px); }
  .cleanButton { right: max(5px, env(safe-area-inset-right)); }

  #hud {
    top: max(4px, env(safe-area-inset-top));
    left: calc(max(5px, env(safe-area-inset-left)) + 74px);
    right: calc(max(5px, env(safe-area-inset-right)) + 140px);
    min-height: 40px;
    grid-template-columns: minmax(170px, 1.35fr) minmax(165px, 1fr) 66px;
    gap: 5px;
  }

  #hud section { min-height: 40px; border-radius: 10px; }
  .missionPanel { grid-template-rows: 15px 1fr; padding: 4px 8px; column-gap: 7px; }
  .missionPanel small { padding-right: 7px; font-size: 7px; }
  .missionPanel strong { font-size: 11px; }
  .missionPanel span { font-size: 8px; }
  .railPanel { gap: 5px; padding: 4px 7px; }
  .railIcon { font-size: 16px; }
  .railPanel small { margin-bottom: 3px; font-size: 7px; }
  .railSegments i { height: 5px; }
  .ticketPanel { gap: 3px; }
  .ticketPanel span { font-size: 15px; }
  .ticketPanel strong { font-size: 10px; }
  #speechBubble { top: 48px; padding: 7px 13px; font-size: 12px; }
  #joystick { left: max(10px, env(safe-area-inset-left)); bottom: max(8px, env(safe-area-inset-bottom)); width: clamp(102px, 18vw, 126px); }
  .actionButton { right: max(14px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); width: clamp(76px, 12vw, 92px); }
  .startCard, .storyCard, .menuCard, .missionCard { max-height: calc(100vh - 40px); padding: 17px 22px; }
  .moonBadge { width: 52px; height: 52px; margin-bottom: 5px; }
  .moonBadge span { font-size: 32px; }
  .startCard h1 { font-size: clamp(30px, 6.5vw, 44px); }
  .startCard h2 { font-size: 14px; }
  .startCopy { margin: 8px auto 10px; font-size: 13px; }
  .startHint { margin-top: 8px; font-size: 10px; }
  .primaryButton, .secondaryButton, .dangerButton { min-height: 40px; padding: 8px 16px; font-size: 12px; }
  .storyIllustration { height: 90px; margin-bottom: 10px; }
  .storyCard h2, .menuCard h2, .missionCard h2 { font-size: 24px; }
  .storyCard > p:not(.eyebrow), .menuCard > p, .missionCard > p:not(.eyebrow) { margin-bottom: 12px; font-size: 13px; }
  .settingsGrid { margin-top: 10px; }
  .settingButton { min-height: 60px; }
  .completeTower { height: 66px; margin-bottom: 8px; }
}

@media (max-width: 720px) and (orientation: landscape) {
  #hud {
    grid-template-columns: minmax(150px, 1.2fr) minmax(130px, 0.9fr) 58px;
  }

  .railPanel small {
    letter-spacing: 0.03em;
  }

  .missionPanel small {
    display: none;
  }

  .missionPanel {
    grid-template-columns: 1fr;
  }
}
