:root {
  --panel-shadow: 0 8px 0 var(--toy-shadow);
  --button-shadow: 0 4px 0 var(--toy-line);
  --soft-line: rgb(49 68 111 / 0.2);
}

body {
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 8%, rgb(255 255 255 / 0.86) 0 32px, transparent 33px),
    radial-gradient(circle at 88% 14%, rgb(255 255 255 / 0.68) 0 46px, transparent 47px),
    linear-gradient(180deg, var(--toy-sky) 0 28%, var(--toy-sky-soft) 72% 100%);
  background-attachment: fixed;
}

body.dialog-open { overflow: hidden; }

/* Dialogs are document-level UI. Keep the game inert while the global layer
   is open so no canvas, touch control, or stacking context can intercept it. */
body.dialog-open > .game-shell { pointer-events: none; }
body.dialog-open > .overlay.visible { pointer-events: auto; }

/* The canvas creates its own stacking context. Hide gameplay controls while a
   full-screen menu/dialog is open so they can never paint above that dialog. */
body.dialog-open .mobile-gamepad {
  display: none !important;
  pointer-events: none;
}

body.dialog-open .topbar::before,
body.dialog-open .topbar::after { display: none !important; }

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.game-shell {
  width: min(1240px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* Game HUD */
.topbar {
  position: relative;
  min-height: 58px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  background: var(--toy-paper);
  box-shadow: var(--panel-shadow);
}

/* Optional visual beat: four quiet dots, one active step. */
body[data-visual-sound="true"] .topbar::before,
body[data-visual-sound="true"] .topbar::after {
  content: "";
  position: absolute;
  bottom: 3px;
  z-index: 1;
  pointer-events: none;
}

body[data-visual-sound="true"] .topbar::before {
  left: calc(50% - 26px);
  width: 52px;
  height: 7px;
  background: radial-gradient(circle, #b7c5d9 0 3px, transparent 3.5px) 0 50% / 13px 7px repeat-x;
  opacity: 0.72;
}

body[data-visual-sound="true"] .topbar::after {
  left: calc(50% - 23px);
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--toy-coral);
  box-shadow: 0 0 0 2px rgb(255 255 255 / 0.8);
  transition: left 70ms linear;
}

body[data-music-beat="0"] .topbar::after { left: calc(50% - 23px); }
body[data-music-beat="1"] .topbar::after { left: calc(50% - 10px); }
body[data-music-beat="2"] .topbar::after { left: calc(50% + 3px); }
body[data-music-beat="3"] .topbar::after { left: calc(50% + 16px); }

.brand {
  color: var(--toy-ink);
  font-size: 0.98rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand-mark {
  display: inline-block;
  margin-right: 3px;
  color: var(--toy-coral);
  font-size: 1.35rem;
  vertical-align: -2px;
}

.mission-copy { min-width: 0; }

.mission-copy span,
.mission-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mission-copy span {
  color: var(--toy-ink);
  font-size: 0.82rem;
  font-weight: 900;
}

.mission-copy small {
  margin-top: 1px;
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 700;
}

.hud-cluster {
  display: flex;
  align-items: stretch;
  gap: 4px;
}

.hud-stat {
  min-width: 64px;
  padding: 4px 8px;
  text-align: center;
  border: 1px solid var(--soft-line);
  border-radius: var(--radius-sm);
  background: #eef8ff;
}

.hud-stat span,
.hud-stat strong { display: block; }

.hud-stat span {
  color: var(--text-secondary);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.hud-stat strong {
  margin-top: 1px;
  color: var(--toy-ink);
  font-family: var(--font-mono);
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timer-stat {
  border-color: rgb(239 98 98 / 0.34);
  background: #fff0ec;
}

.timer-stat strong { color: #b3444c; }

/* Play field */
.canvas-wrap {
  position: relative;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  aspect-ratio: 12 / 7;
  border: 3px solid var(--toy-line);
  border-radius: var(--radius-md);
  background: #17243d;
  box-shadow: var(--panel-shadow);
  isolation: isolate;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.alert-meter {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 6;
  width: min(270px, 56%);
  padding: 6px 9px;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateX(-50%);
  border: 2px solid var(--state-danger);
  border-radius: 9px;
  background: #fff4ef;
  box-shadow: 0 3px 0 rgb(118 35 51 / 0.38);
  transition: opacity 90ms linear;
  pointer-events: none;
}

.alert-meter.active { opacity: 1; }

.alert-meter > span {
  color: var(--state-danger);
  font-size: 0.66rem;
  font-weight: 900;
}

.alert-track {
  flex: 1;
  height: 9px;
  overflow: hidden;
  border: 1px solid rgb(133 34 57 / 0.35);
  border-radius: 999px;
  background: #f7d8d8;
}

.alert-track i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--state-danger);
  transition: width 60ms linear;
}

.toast,
.sound-caption {
  position: absolute;
  z-index: 7;
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  color: var(--toy-ink);
  border: 2px solid var(--toy-line);
  border-radius: 10px;
  background: var(--toy-paper);
  box-shadow: 0 4px 0 rgb(38 54 95 / 0.38);
  font-size: 0.78rem;
  font-weight: 900;
  text-align: center;
  pointer-events: none;
}

.toast {
  max-width: min(230px, calc(100% - 24px));
  padding: 5px 8px;
  border-width: 1px;
  border-radius: 8px;
  box-shadow: 0 2px 0 rgb(38 54 95 / 0.3);
  font-size: 0.67rem;
}

.toast {
  left: 50%;
  bottom: 13px;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 110ms linear, transform 110ms linear;
}

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

.sound-caption {
  top: 12px;
  left: 12px;
  opacity: 0;
  color: #2e416c;
  border-color: var(--toy-blue);
  background: #eaf8ff;
  font-family: var(--font-ui);
}

.sound-caption.show { animation: sound-caption-pop 1.25s ease-out both; }
body[data-visual-sound="false"] .sound-caption { display: none; }

@keyframes sound-caption-pop {
  0% { opacity: 0; transform: translateY(-6px) scale(0.96); }
  12%, 78% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-3px) scale(0.98); }
}

/* Bright clockwork overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  overflow: auto;
  overscroll-behavior: contain;
  place-items: start center;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 10% 15%, rgb(255 255 255 / 0.92) 0 34px, transparent 35px),
    radial-gradient(circle at 90% 22%, rgb(255 255 255 / 0.75) 0 52px, transparent 53px),
    radial-gradient(circle at 72% 92%, rgb(98 217 173 / 0.28) 0 95px, transparent 96px),
    linear-gradient(180deg, var(--toy-sky) 0 58%, var(--toy-sky-soft) 100%);
}

body > .overlay {
  width: 100vw;
  min-width: 100vw;
  min-height: 100dvh;
  isolation: isolate;
}

.overlay::before,
.overlay::after {
  content: "";
  position: fixed;
  z-index: -1;
  border: 14px dashed rgb(61 114 220 / 0.22);
  border-radius: 50%;
  pointer-events: none;
}

.overlay::before {
  width: 130px;
  height: 130px;
  right: 3vw;
  bottom: 5vh;
  animation: gear-turn 20s linear infinite;
}

.overlay::after {
  width: 82px;
  height: 82px;
  left: 4vw;
  bottom: 9vh;
  border-color: rgb(239 98 98 / 0.2);
  animation: gear-turn 15s linear infinite reverse;
}

.overlay.visible { display: grid; }

@keyframes gear-turn { to { transform: rotate(360deg); } }

.panel {
  width: min(1060px, 100%);
  max-height: calc(100dvh - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: auto;
  padding: clamp(14px, 2vw, 22px);
  overflow: auto;
  scrollbar-gutter: stable;
  border: 3px solid var(--toy-line);
  border-radius: var(--radius-lg);
  background: var(--toy-cream);
  box-shadow: 0 9px 0 var(--toy-shadow);
}

/* Dialog headings receive script focus for announcement, not keyboard navigation. */
[data-dialog-title]:focus {
  outline: none;
  box-shadow: none;
}

.toy-button,
.arcade-play,
.pixel-button,
.profile-chip,
.round-tool,
.world-node,
.profile-color,
.profile-face,
.record-stage-tab,
.mobile-action,
.utility-action {
  min-width: var(--control-size);
  min-height: var(--control-size);
  border: 2px solid var(--toy-line);
  font-weight: 900;
  cursor: pointer;
  transition: transform 100ms ease, filter 100ms ease, box-shadow 100ms ease;
}

.toy-button,
.arcade-play,
.pixel-button {
  padding: 10px 18px;
  border-radius: 12px;
  background: var(--toy-paper);
  box-shadow: var(--button-shadow);
}

.toy-button--primary,
.arcade-play {
  color: var(--toy-ink);
  background: var(--toy-gold);
}

.toy-button:active,
.arcade-play:active,
.pixel-button:active,
.profile-chip:active,
.round-tool:active,
.world-node:not(:disabled):active,
.profile-color:active,
.profile-face:active,
.record-stage-tab:active,
.mobile-action:active,
.utility-action:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--toy-line);
}

/* Avatar component */
.toy-avatar {
  --avatar-color: var(--toy-blue);
  position: relative;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  color: var(--toy-ink);
  border: 2px solid var(--toy-line);
  border-radius: 47% 47% 42% 42%;
  background: var(--avatar-color);
  box-shadow: inset 0 -7px 0 rgb(38 54 95 / 0.14), 0 3px 0 rgb(38 54 95 / 0.26);
  vertical-align: middle;
}

.toy-avatar::before,
.toy-avatar::after {
  content: "";
  position: absolute;
  top: -6px;
  width: 11px;
  height: 12px;
  border: 2px solid var(--toy-line);
  background: var(--avatar-color);
  transform: rotate(35deg);
}

.toy-avatar::before { left: 4px; }
.toy-avatar::after { right: 4px; transform: rotate(-35deg); }

.toy-avatar i {
  position: relative;
  z-index: 2;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  display: block;
  font-style: normal;
  font-size: 1.25rem;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  transform: scaleX(var(--face-scale, 1));
  transform-origin: center;
}

.toy-avatar[data-face-index="1"],
.toy-avatar[data-face-index="2"],
.toy-avatar[data-face-index="5"] { --face-scale: 0.88; }
.toy-avatar[data-face-index="3"] { --face-scale: 0.64; }

.toy-avatar b {
  position: absolute;
  right: 7px;
  bottom: -8px;
  left: 7px;
  height: 12px;
  z-index: -1;
  border: 2px solid var(--toy-line);
  border-radius: 4px 4px 8px 8px;
  background: var(--avatar-color);
}

.toy-avatar--tiny {
  width: 28px;
  height: 28px;
  border-width: 1px;
  box-shadow: 0 2px 0 rgb(38 54 95 / 0.22);
}

.toy-avatar--tiny::before,
.toy-avatar--tiny::after { top: -4px; width: 7px; height: 8px; border-width: 1px; }
.toy-avatar--tiny i { font-size: 0.82rem; }
.toy-avatar--tiny b { right: 5px; bottom: -5px; left: 5px; height: 8px; border-width: 1px; }

.toy-avatar--large { width: 92px; height: 92px; border-width: 4px; }
.toy-avatar--large::before,
.toy-avatar--large::after { top: -11px; width: 22px; height: 24px; border-width: 3px; }
.toy-avatar--large i { font-size: 3rem; }
.toy-avatar--large b { right: 16px; bottom: -18px; left: 16px; height: 26px; border-width: 3px; }

.toy-avatar.is-echo,
.is-echo .toy-avatar {
  opacity: 0.72;
  filter: saturate(1.25);
  box-shadow: inset 0 0 0 4px rgb(255 255 255 / 0.36), 0 0 0 3px rgb(37 169 218 / 0.2);
}

/* Main menu */
.arcade-menu,
.toy-menu {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 11px;
}

.toy-menu__top {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(260px, 1.6fr) minmax(150px, 1fr);
  align-items: center;
  gap: 12px;
}

.profile-chip {
  justify-self: start;
  max-width: 190px;
  padding: 6px 10px 7px 8px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--toy-ink);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 4px 0 rgb(38 54 95 / 0.22);
  text-align: left;
}

.profile-chip > span:not(.toy-avatar) { min-width: 0; }
.profile-chip b,
.profile-chip small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-chip b { font-size: 0.78rem; }
.profile-chip small { color: var(--text-secondary); font-size: 0.65rem; }

.arcade-logo,
.toy-logo { text-align: center; }

.arcade-logo p,
.arcade-logo strong,
.arcade-logo h1 { margin: 0; }

.toy-logo p {
  color: var(--toy-blue);
  font-family: var(--font-display-en);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.toy-logo h1 {
  margin-top: 1px;
  color: var(--toy-ink);
  font-family: var(--font-ui);
  font-size: clamp(2.15rem, 5vw, 3.55rem);
  font-weight: 900;
  letter-spacing: -0.08em;
  line-height: 1;
  text-shadow: 0 4px 0 rgb(255 255 255 / 0.9), 0 7px 0 rgb(38 54 95 / 0.16);
}

.toy-logo h1 span { color: var(--toy-coral); }

.toy-logo strong {
  display: block;
  margin-top: 5px;
  color: #386f62;
  font-size: 0.84rem;
  font-weight: 900;
}

.player-tools {
  justify-self: end;
  display: flex;
  gap: 7px;
}

.round-tool {
  width: 68px;
  padding: 5px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  color: var(--toy-ink);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 4px 0 rgb(38 54 95 / 0.22);
}

.round-tool > span { color: var(--toy-violet); font-size: 1.25rem; line-height: 1; }
.round-tool small { max-width: 100%; overflow: hidden; color: var(--text-secondary); font-size: 0.6rem; text-overflow: ellipsis; white-space: nowrap; }

.core-loop-strip {
  min-height: 58px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 2px solid #7bb7d8;
  border-radius: 14px;
  background: #eaf8ff;
}

.core-loop-strip > span {
  min-width: 142px;
  min-height: 42px;
  padding: 4px 9px;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 6px;
  border: 1px solid rgb(49 68 111 / 0.16);
  border-radius: 10px;
  background: #ffffff;
}

.core-loop-strip > span > b {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  color: #ffffff;
  border-radius: 50%;
  background: var(--toy-blue);
  font-family: var(--font-mono);
  font-size: 0.68rem;
}

.core-loop-strip small { font-size: 0.72rem; font-weight: 900; }
.core-loop-strip > i { color: var(--toy-coral); font-style: normal; font-size: 1.15rem; font-weight: 900; }
.core-loop-strip em { color: var(--toy-gold); font-size: 1.35rem; font-style: normal; text-shadow: 0 2px 0 var(--toy-line); }
.core-loop-strip kbd { margin: 0; }

/* Stage card and original clockwork diorama */
.arcade-stage-card,
.toy-stage-card {
  min-height: 302px;
  display: grid;
  grid-template-columns: minmax(330px, 0.92fr) minmax(0, 1.08fr);
  overflow: hidden;
  border: 3px solid var(--toy-line);
  border-radius: 18px;
  background: var(--toy-paper);
  box-shadow: 0 6px 0 rgb(38 54 95 / 0.2);
}

.stage-diorama {
  --scene-sky: #92e3ff;
  --scene-ground: #f2c87a;
  position: relative;
  min-height: 296px;
  overflow: hidden;
  border-right: 3px solid var(--toy-line);
  background:
    linear-gradient(90deg, transparent 0 48%, rgb(255 255 255 / 0.22) 48% 50%, transparent 50% 100%),
    linear-gradient(180deg, var(--scene-sky) 0 67%, var(--scene-ground) 67% 100%);
  isolation: isolate;
}

.toy-stage-card[data-theme="warehouse"] .stage-diorama { --scene-sky: #ffd59c; --scene-ground: #62b8a9; }
.toy-stage-card[data-theme="casino"] .stage-diorama { --scene-sky: #f6bfe0; --scene-ground: #9270ce; }
.toy-stage-card[data-theme="lab"] .stage-diorama { --scene-sky: #baf0de; --scene-ground: #69b7ba; }
.toy-stage-card[data-theme="station"] .stage-diorama { --scene-sky: #a9c9ff; --scene-ground: #6e79bd; }
.toy-stage-card[data-theme="castle"] .stage-diorama { --scene-sky: #dac8ff; --scene-ground: #9a70bb; }
.toy-stage-card[data-theme="vault"] .stage-diorama { --scene-sky: #ffe09a; --scene-ground: #bd7f5d; }
.toy-stage-card[data-theme="clocktower"] .stage-diorama { --scene-sky: #a28fcb; --scene-ground: #61344e; }
.toy-stage-card[data-theme="inferno"] .stage-diorama { --scene-sky: #5b2028; --scene-ground: #27131a; }

.stage-diorama::before {
  content: "";
  position: absolute;
  right: -30px;
  bottom: -42px;
  left: -30px;
  height: 92px;
  z-index: -1;
  border: 4px solid rgb(38 54 95 / 0.28);
  border-radius: 50% 50% 0 0;
  background:
    repeating-linear-gradient(90deg, rgb(255 255 255 / 0.18) 0 24px, transparent 24px 48px),
    var(--scene-ground);
}

.diorama-cloud {
  position: absolute;
  width: 62px;
  height: 22px;
  z-index: -1;
  border: 2px solid rgb(49 68 111 / 0.18);
  border-radius: 999px;
  background: rgb(255 255 255 / 0.84);
}

.diorama-cloud::before,
.diorama-cloud::after {
  content: "";
  position: absolute;
  bottom: -2px;
  border: 2px solid rgb(49 68 111 / 0.18);
  border-bottom: 0;
  border-radius: 50% 50% 0 0;
  background: #ffffff;
}

.diorama-cloud::before { left: 10px; width: 25px; height: 26px; }
.diorama-cloud::after { right: 8px; width: 20px; height: 20px; }
.diorama-cloud--one { top: 34px; left: 8%; }
.diorama-cloud--two { top: 68px; right: 8%; transform: scale(0.76); }

.diorama-gear {
  position: absolute;
  top: 30px;
  right: 24%;
  width: 62px;
  height: 62px;
  z-index: -1;
  border: 10px dashed rgb(255 255 255 / 0.42);
  border-radius: 50%;
  animation: gear-turn 12s linear infinite;
}

.diorama-gear::after {
  content: "";
  position: absolute;
  inset: 10px;
  border: 3px solid rgb(49 68 111 / 0.18);
  border-radius: 50%;
}

.diorama-route {
  position: absolute;
  z-index: 1;
  height: 0;
  border-top: 4px dashed;
  border-radius: 50%;
  transform-origin: left center;
}

.diorama-route::after {
  content: "›";
  position: absolute;
  top: -17px;
  right: -2px;
  font-family: var(--font-display-en);
  font-size: 1.5rem;
  font-weight: 900;
}

.diorama-route--hero {
  left: 23%;
  bottom: 34%;
  width: 54%;
  color: var(--toy-blue);
  transform: rotate(-8deg);
}

.diorama-route--echo {
  left: 25%;
  top: 40%;
  width: 34%;
  color: #138fb9;
  transform: rotate(12deg);
}

.diorama-radar {
  position: absolute;
  right: 19%;
  bottom: 25%;
  width: 130px;
  height: 100px;
  z-index: 1;
  clip-path: polygon(100% 50%, 0 0, 0 100%);
  background: rgb(239 98 98 / 0.28);
  transform: rotate(8deg);
}

.diorama-hero,
.diorama-echo,
.diorama-guard,
.diorama-gem,
.diorama-exit,
.diorama-copy { position: absolute; z-index: 3; }

.diorama-hero { left: 13%; bottom: 15%; transform: scale(1.15); }
.diorama-echo { left: 23%; top: 36%; transform: scale(0.92); }

.diorama-guard {
  right: 16%;
  bottom: 19%;
  width: 62px;
  height: 72px;
  display: grid;
  place-items: center;
  color: #ffffff;
  border: 3px solid var(--toy-line);
  border-radius: 28px 28px 15px 15px;
  background: var(--toy-coral);
  box-shadow: 0 6px 0 rgb(38 54 95 / 0.26);
}

.diorama-guard::before,
.diorama-guard::after {
  content: "";
  position: absolute;
  bottom: -13px;
  width: 21px;
  height: 17px;
  border: 3px solid var(--toy-line);
  border-radius: 5px;
  background: #d94a5b;
}

.diorama-guard::before { left: 4px; }
.diorama-guard::after { right: 4px; }

.diorama-guard i {
  position: absolute;
  top: -24px;
  width: 8px;
  height: 25px;
  border: 3px solid var(--toy-line);
  background: var(--toy-gold);
}

.diorama-guard i::after {
  content: "";
  position: absolute;
  top: -8px;
  left: -7px;
  width: 16px;
  height: 9px;
  border: 3px solid var(--toy-line);
  border-radius: 50%;
  background: var(--toy-gold);
}

.diorama-guard b { font-family: var(--font-ui); font-size: 1rem; font-weight: 900; }

.diorama-guard.is-boss {
  right: 10%;
  bottom: 17%;
  width: 96px;
  height: 118px;
  border-radius: 48px 48px 18px 18px;
  background: #633458;
  box-shadow: 0 9px 0 rgb(38 22 55 / 0.36);
}

.diorama-guard.is-boss::before,
.diorama-guard.is-boss::after { width: 30px; height: 22px; background: #4b2948; }
.diorama-guard.is-boss i { top: -36px; height: 38px; width: 12px; }
.diorama-guard.is-boss i::after { top: -13px; left: -12px; width: 30px; height: 14px; }
.diorama-guard.is-boss b { max-width: 78px; color: var(--toy-gold); font-size: 0.76rem; text-align: center; }

.diorama-gem {
  right: 8%;
  top: 25%;
  color: var(--toy-gold);
  font-family: var(--font-display-en);
  font-size: 2.4rem;
  text-shadow: 0 4px 0 var(--toy-line);
  transform: rotate(45deg);
}

.diorama-exit {
  right: 5%;
  bottom: 5%;
  padding: 4px 7px;
  color: #ffffff;
  border: 2px solid var(--toy-line);
  border-radius: 7px;
  background: #238c69;
  font-family: var(--font-display-en);
  font-size: 0.68rem;
}

.diorama-copy {
  left: 23%;
  top: 18%;
  padding: 4px 7px;
  color: #ffffff;
  border: 2px solid var(--toy-line);
  border-radius: 8px;
  background: var(--toy-blue);
  font-family: var(--font-display-en);
  font-size: 0.7rem;
  box-shadow: 0 3px 0 rgb(38 54 95 / 0.3);
  transform: rotate(-4deg);
}

.arcade-stage-info {
  min-width: 0;
  padding: clamp(14px, 2.4vw, 24px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: 8px;
  background: var(--toy-paper);
}

.arcade-rule {
  align-self: flex-start;
  padding: 5px 8px;
  color: #704c00;
  border: 1px solid #d6a322;
  border-radius: 999px;
  background: #fff2b4;
  font-size: 0.7rem;
  font-weight: 900;
}

.stage-title {
  margin: 0;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 5px 10px;
  color: var(--toy-ink);
  line-height: 1.05;
}

.stage-title__local {
  font-family: var(--font-ui);
  font-size: clamp(1.65rem, 3.2vw, 2.35rem);
  font-weight: 900;
  letter-spacing: -0.055em;
}

.stage-title small[lang="en"] {
  color: var(--toy-coral);
  font-family: var(--font-display-en);
  font-size: clamp(0.76rem, 1.25vw, 0.95rem);
  letter-spacing: 0.02em;
}

.stage-mission,
.stage-next {
  padding: 8px 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 9px;
  border: 1px solid var(--soft-line);
  border-radius: 10px;
}

.stage-mission { background: #eaf8ff; }
.stage-next { background: #fff6db; }

.radar-rule {
  margin: 0;
  padding: 6px 9px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #963449;
  border: 1px solid rgb(204 53 79 / 0.3);
  border-radius: 10px;
  background: #fff0f1;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.35;
}

.radar-rule > i {
  position: relative;
  width: 35px;
  height: 19px;
  flex: 0 0 35px;
  font-style: normal;
}

.radar-rule > i::before {
  content: "";
  position: absolute;
  inset: 2px 9px 2px 0;
  clip-path: polygon(0 50%, 100% 0, 100% 100%);
  background: rgb(204 53 79 / 0.68);
}

.radar-rule > i::after {
  content: "";
  position: absolute;
  top: 0;
  right: 4px;
  width: 5px;
  height: 19px;
  border-radius: 2px;
  background: var(--toy-blue);
  box-shadow: 2px 0 0 var(--toy-line);
}

.stage-mission span,
.stage-next span {
  color: var(--text-secondary);
  font-size: 0.66rem;
  font-weight: 800;
  white-space: nowrap;
}

.stage-mission b,
.stage-next b {
  overflow: hidden;
  color: var(--toy-ink);
  font-size: 0.8rem;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arcade-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.arcade-stats span {
  padding: 4px 7px;
  color: var(--text-secondary);
  border: 1px solid var(--soft-line);
  border-radius: 999px;
  background: #ffffff;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 800;
}

.arcade-play {
  width: 100%;
  margin-top: auto;
  font-size: 1rem;
}

/* Toy railway world map */
.world-map,
.toy-rail {
  position: relative;
  min-height: 76px;
  padding: 7px 10px;
  display: grid;
  grid-template-columns: repeat(var(--stage-count, 9), minmax(58px, 1fr));
  align-items: start;
  gap: 4px;
  border: 2px solid #b68a47;
  border-radius: 14px;
  background:
    repeating-linear-gradient(90deg, transparent 0 29px, rgb(182 138 71 / 0.16) 29px 32px),
    #fff3c9;
}

.world-map::before {
  content: "";
  position: absolute;
  top: 31px;
  right: 5%;
  left: 5%;
  height: 5px;
  border-block: 1px solid #8b6b3b;
  background: #c99d58;
}

.world-node {
  position: relative;
  z-index: 1;
  padding: 1px 2px;
  display: grid;
  justify-items: center;
  gap: 1px;
  color: var(--toy-ink);
  border-color: transparent;
  border-radius: 10px;
  background: transparent;
}

.world-node__coin {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  color: var(--toy-ink);
  border: 2px solid var(--toy-line);
  border-radius: 14px;
  background: #ffffff;
  box-shadow: 0 3px 0 rgb(38 54 95 / 0.26);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 900;
}

.world-node b {
  min-height: 15px;
  color: var(--text-secondary);
  font-size: 0.61rem;
  font-weight: 900;
}

.world-node small {
  overflow: hidden;
  width: 100%;
  min-height: 14px;
  color: var(--toy-ink);
  font-size: 0.62rem;
  font-weight: 800;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.world-node.is-cleared .world-node__coin { background: #8ee4c3; }

.world-node.is-current .world-node__coin {
  width: 52px;
  height: 52px;
  margin-top: -3px;
  border-color: var(--toy-blue);
  background: var(--toy-gold);
  box-shadow: 0 4px 0 var(--toy-line);
}

.world-node.is-boss .world-node__coin {
  color: #ffffff;
  border-radius: 50% 50% 12px 12px;
  background: #633458;
}

.world-node:disabled {
  cursor: not-allowed;
  filter: grayscale(0.7);
  opacity: 0.54;
}

.arcade-keys {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 18px;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 800;
}

kbd {
  display: inline-grid;
  min-width: 28px;
  min-height: 26px;
  margin-right: 4px;
  padding: 2px 6px;
  place-items: center;
  color: var(--toy-ink);
  border: 2px solid var(--toy-line);
  border-bottom-width: 4px;
  border-radius: 7px;
  background: #ffffff;
  font-family: var(--font-mono);
  font-weight: 900;
}

/* Profile, settings and records dialogs */
.toy-dialog {
  width: min(620px, 100%);
  padding: clamp(18px, 4vw, 30px);
}

.profile-dialog { width: min(560px, 100%); }
.settings-dialog { width: min(620px, 100%); }
.records-dialog { width: min(780px, 100%); }

.game-guide {
  margin-bottom: 12px;
  padding: 11px;
  color: var(--toy-ink);
  border: 2px solid #7fc2e8;
  border-radius: 12px;
  background: #eefaff;
}

.game-guide h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  font-weight: 900;
}

.game-guide__flow {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  list-style: none;
}

.game-guide__flow li {
  position: relative;
  min-height: 38px;
  padding: 6px 4px;
  display: grid;
  place-items: center;
  border: 1px solid rgb(49 68 111 / 0.22);
  border-radius: 8px;
  background: #ffffff;
  font-size: 0.65rem;
  font-weight: 900;
  text-align: center;
}

.game-guide__summary {
  margin: 7px 0;
  font-size: 0.72rem;
  font-weight: 900;
  text-align: center;
}

.game-guide__actions {
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  list-style: none;
}

.game-guide__actions li {
  min-height: 44px;
  padding: 5px 7px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  border: 1px solid rgb(49 68 111 / 0.18);
  border-radius: 8px;
  background: #ffffff;
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1.3;
}

.game-guide__actions li.is-wide { grid-column: 1 / -1; }
.game-guide__actions kbd { margin: 0; }
.game-guide__actions b { width: 28px; text-align: center; }

.game-guide__items,
.game-guide__note {
  margin: 6px 0 0;
  padding: 6px 8px;
  border-radius: 7px;
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1.35;
}

.game-guide__items { background: #fff2bd; }
.game-guide__note { color: #73364a; background: #ffe6eb; }

.toy-dialog h2 {
  margin: 2px 0 14px;
  color: var(--toy-ink);
  font-family: var(--font-ui);
  font-size: clamp(1.7rem, 5vw, 2.45rem);
  font-weight: 900;
  letter-spacing: -0.055em;
}

.dialog-kicker {
  margin: 0;
  color: var(--toy-coral);
  font-family: var(--font-display-en);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.profile-preview {
  min-height: 132px;
  margin-bottom: 16px;
  display: grid;
  place-items: center;
  border: 2px solid #78b9dc;
  border-radius: 16px;
  background:
    radial-gradient(circle at 15% 25%, #fff 0 18px, transparent 19px),
    radial-gradient(circle at 82% 72%, rgb(255 210 74 / 0.45) 0 34px, transparent 35px),
    #dff6ff;
}

.field-label {
  display: block;
  margin: 10px 0 6px;
  color: var(--toy-ink);
  font-size: 0.76rem;
  font-weight: 900;
}

.toy-input,
.toy-select {
  width: 100%;
  min-height: var(--control-size);
  padding: 9px 11px;
  color: var(--toy-ink);
  border: 2px solid var(--toy-line);
  border-radius: 10px;
  background: #ffffff;
  font-family: var(--font-ui);
  font-weight: 800;
}

.profile-options {
  margin: 13px 0 0;
  padding: 10px 12px 12px;
  border: 1px solid var(--soft-line);
  border-radius: 12px;
  background: rgb(255 255 255 / 0.54);
}

.profile-options legend {
  padding-inline: 5px;
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 900;
}

.profile-colors,
.profile-faces {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-color {
  width: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 -7px 0 rgb(38 54 95 / 0.15);
}

.profile-face {
  width: 48px;
  padding: 0;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 3px 0 rgb(38 54 95 / 0.2);
  font-size: 1.3rem;
}

.profile-face[data-face-index="1"],
.profile-face[data-face-index="2"],
.profile-face[data-face-index="5"] { font-size: 1.12rem; }
.profile-face[data-face-index="3"] { font-size: 0.96rem; }

.profile-color.is-selected,
.profile-face.is-selected {
  outline: 4px solid var(--toy-gold);
  outline-offset: 2px;
}

.dialog-actions {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  gap: 9px;
}

.records-reset {
  min-height: 44px;
  margin: 5px 0 -8px auto;
  padding: 7px 10px;
  display: block;
  color: var(--state-danger);
  border: 1px solid rgb(204 53 79 / 0.35);
  border-radius: 9px;
  background: #fff0f1;
  font-size: 0.68rem;
  font-weight: 900;
  cursor: pointer;
}

.setting-row {
  min-height: 66px;
  margin-top: 9px;
  padding: 9px 11px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--soft-line);
  border-radius: 12px;
  background: #ffffff;
  cursor: pointer;
}

.setting-row span { min-width: 0; }
.setting-row b,
.setting-row small { display: block; }
.setting-row b { font-size: 0.82rem; font-weight: 900; }
.setting-row small { margin-top: 2px; color: var(--text-secondary); font-size: 0.7rem; }
.setting-row .toy-select { width: min(180px, 38vw); }

.setting-row input[type="checkbox"] {
  width: 60px;
  height: 44px;
  margin: 0;
  appearance: none;
  position: relative;
  border: 2px solid var(--toy-line);
  border-radius: 999px;
  background: #d9e0e8;
  cursor: pointer;
}

.setting-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 32px;
  height: 32px;
  border: 2px solid var(--toy-line);
  border-radius: 50%;
  background: #ffffff;
  transition: transform 120ms ease;
}

.setting-row input[type="checkbox"]:checked { background: var(--toy-mint); }
.setting-row input[type="checkbox"]:checked::after { transform: translateX(16px); }

.caption-demo {
  margin-top: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--toy-ink);
  border: 2px dashed #75a8c7;
  border-radius: 12px;
  background: #eaf8ff;
  font-size: 0.75rem;
}

.caption-demo span { color: var(--toy-blue); font-family: var(--font-display-en); }
.caption-demo strong { font-weight: 900; }

.records-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.records-heading h2 { margin-bottom: 8px; }

.stat-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.stat-strip div {
  min-width: 0;
  padding: 8px;
  text-align: center;
  border: 1px solid var(--soft-line);
  border-radius: 10px;
  background: #ffffff;
}

.stat-strip span,
.stat-strip b { display: block; }
.stat-strip span { overflow: hidden; color: var(--text-secondary); font-size: 0.65rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.stat-strip b { margin-top: 2px; color: var(--toy-blue); font-family: var(--font-mono); font-size: 1.18rem; }

.record-stage-tabs {
  margin-top: 11px;
  padding: 4px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  border: 1px solid var(--soft-line);
  border-radius: 12px;
  background: #f7e8b8;
}

.record-stage-tab {
  padding: 4px;
  color: var(--toy-ink);
  border-radius: 8px;
  background: #ffffff;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  box-shadow: 0 2px 0 rgb(38 54 95 / 0.2);
}

.record-stage-tab.is-current {
  color: #ffffff;
  border-color: var(--toy-blue);
  background: var(--toy-blue);
}

.ranking-title {
  margin-top: 10px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 10px;
  background: #eaf8ff;
}

.ranking-title span { color: var(--text-secondary); font-size: 0.68rem; font-weight: 900; }
.ranking-title b { overflow: hidden; font-size: 0.75rem; text-overflow: ellipsis; white-space: nowrap; }

.ranking-list {
  margin: 7px 0 0;
  padding: 0;
  display: grid;
  gap: 5px;
  list-style: none;
}

.ranking-row {
  min-height: 48px;
  padding: 5px 9px;
  display: grid;
  grid-template-columns: 26px 30px minmax(0, 1fr) 82px;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--soft-line);
  border-radius: 10px;
  background: #ffffff;
}

.ranking-row > b:first-child { color: var(--toy-coral); font-family: var(--font-mono); }
.ranking-row > strong { color: var(--toy-blue); font-family: var(--font-mono); font-size: 0.75rem; text-align: right; }
.ranking-row.is-me { border-color: #d7a91d; background: #fff5c8; }

.ranking-player {
  min-width: 0;
  display: grid;
  gap: 1px;
  line-height: 1.2;
}

.ranking-player b,
.ranking-player small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-player b { font-size: 0.78rem; font-weight: 900; }
.ranking-player small { color: var(--text-secondary); font-family: var(--font-mono); font-size: 0.62rem; font-weight: 700; }

.empty-record {
  min-height: 74px;
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  border: 2px dashed #b9a369;
  border-radius: 12px;
  background: rgb(255 255 255 / 0.46);
  font-weight: 900;
}

.ranking-note {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 800;
  text-align: center;
}

/* Clear screen */
.arcade-clear {
  width: min(500px, 100%);
  padding: clamp(22px, 5vw, 40px);
  display: grid;
  justify-items: center;
  gap: 10px;
  color: var(--toy-ink);
  text-align: center;
  background:
    radial-gradient(circle at 15% 20%, rgb(255 210 74 / 0.35) 0 24px, transparent 25px),
    var(--toy-paper);
}

.toy-clear {
  border-color: #b07a2f;
}

.arcade-clear p,
.arcade-clear h2 { margin: 0; }

.arcade-clear__world,
.arcade-unlock {
  color: var(--toy-coral);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.07em;
}

.arcade-clear h2 {
  color: #238c69;
  font-family: var(--font-ui);
  font-size: clamp(3rem, 12vw, 5.5rem);
  line-height: 0.9;
  text-shadow: 0 5px 0 #ffffff, 0 8px 0 rgb(38 54 95 / 0.2);
}

.arcade-clear > strong { font-size: 0.95rem; font-weight: 900; }

.arcade-clear__stars {
  color: #e8a900;
  font-size: clamp(1.8rem, 8vw, 3rem);
  letter-spacing: 0.07em;
  line-height: 1;
  text-shadow: 0 2px 0 var(--toy-line);
}

.clear-grade {
  width: min(310px, 100%);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #805b00;
  border: 2px solid #d5a729;
  border-radius: 12px;
  background: #fff2b2;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.025em;
  text-shadow: none;
}

.clear-grade > b {
  font-size: clamp(1.5rem, 6vw, 2rem);
  white-space: nowrap;
}

.clear-grade > span {
  color: #6d540e;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0;
  text-align: right;
}

.clear-grade > span strong {
  display: block;
  margin-top: 2px;
  color: #805b00;
  font-family: var(--font-mono);
  font-size: 1.05rem;
}

.grade-criteria {
  width: min(310px, 100%);
  padding: 7px 8px;
  border: 1px solid #d8c681;
  border-radius: 10px;
  background: #fff9dc;
}

.grade-criteria p {
  margin: 0 0 6px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.66rem;
}

.grade-criteria p b { color: var(--toy-ink); }

.grade-criteria > div {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.grade-rule {
  padding: 4px 2px;
  color: #617184;
  border: 1px solid #ccd7df;
  border-radius: 6px;
  background: #ffffff;
  font-family: var(--font-mono);
  font-size: 0.61rem;
  font-weight: 900;
  text-align: center;
  white-space: nowrap;
}

.grade-rule.is-current {
  color: #6d4f00;
  border-color: #d5a729;
  background: #ffe88a;
}

.arcade-score {
  width: min(310px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.arcade-score div {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--soft-line);
  border-radius: 10px;
  background: #eaf8ff;
  text-align: center;
}

.arcade-score span,
.arcade-score b { display: block; }
.arcade-score span { overflow: hidden; color: var(--text-secondary); font-family: var(--font-ui); font-size: 0.68rem; text-overflow: ellipsis; white-space: nowrap; }
.arcade-score b { margin-top: 2px; color: var(--toy-ink); font-family: var(--font-mono); font-size: 1.25rem; }

:root:lang(en) .arcade-clear__world,
:root:lang(en) .arcade-unlock,
:root:lang(en) .arcade-clear h2,
:root:lang(en) .arcade-score span { font-family: var(--font-display-en); }

.clear-record {
  width: min(310px, 100%);
  min-height: 48px;
  margin: 0;
  padding: 7px 10px;
  display: grid;
  place-items: center;
  gap: 2px;
  color: var(--toy-ink);
  border: 1px solid #8fc7e2;
  border-radius: 11px;
  background: #eaf8ff;
  box-shadow: 0 3px 0 rgb(38 54 95 / 0.14);
}

.clear-record b {
  font-size: 0.8rem;
  font-weight: 900;
}

.clear-record span {
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 800;
}

.clear-record.is-best {
  color: #805b00;
  border-color: #d5a729;
  background: #fff2b2;
  box-shadow: 0 3px 0 rgb(160 105 0 / 0.2);
}

.clear-record.is-best b::before {
  content: "★ ";
  color: #d39300;
}

.arcade-clear__actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 8px;
}

.arcade-clear__actions .arcade-play { margin-top: 0; }
.pixel-button { color: var(--toy-ink); background: #ffffff; }

/* Desktop control legend */
.mobile-gamepad { display: none; }

.controls {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px 18px;
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 800;
}

.controls i { font-style: normal; }

/* Touch gamepad */
@media (max-width: 900px), (pointer: coarse) {
  .game-shell {
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .mobile-gamepad {
    min-height: 150px;
    padding: 7px;
    display: grid;
    grid-template-columns: 126px minmax(0, 1fr);
    grid-template-rows: minmax(88px, 1fr) 48px;
    gap: 6px 10px;
    border-radius: var(--radius-md);
    background: var(--toy-paper);
    box-shadow: var(--panel-shadow);
  }

  .virtual-stick {
    position: relative;
    grid-column: 1;
    grid-row: 1 / 3;
    width: 124px;
    height: 124px;
    place-self: center;
    border: 3px solid var(--toy-line);
    border-radius: 50%;
    background: #cfeeff;
    box-shadow: inset 0 0 0 9px #ffffff, 0 4px 0 rgb(38 54 95 / 0.28);
    touch-action: none;
    user-select: none;
  }

  .virtual-stick__tick {
    position: absolute;
    width: 12px;
    height: 5px;
    border-radius: 999px;
    background: rgb(38 54 95 / 0.4);
  }

  .virtual-stick__tick--up { top: 8px; left: calc(50% - 6px); }
  .virtual-stick__tick--right { top: calc(50% - 2px); right: 5px; transform: rotate(90deg); }
  .virtual-stick__tick--down { bottom: 8px; left: calc(50% - 6px); }
  .virtual-stick__tick--left { top: calc(50% - 2px); left: 5px; transform: rotate(90deg); }

  .virtual-stick__knob {
    position: absolute;
    top: calc(50% - 25px);
    left: calc(50% - 25px);
    width: 50px;
    height: 50px;
    display: grid;
    place-items: center;
    border: 3px solid var(--toy-line);
    border-radius: 50%;
    background: var(--toy-gold);
    box-shadow: 0 4px 0 rgb(38 54 95 / 0.34);
    will-change: transform;
  }

  .virtual-stick__knob i {
    width: 16px;
    height: 16px;
    border: 3px solid rgb(38 54 95 / 0.45);
    border-radius: 5px;
  }

  .virtual-stick__label {
    position: absolute;
    right: 0;
    bottom: -15px;
    left: 0;
    color: var(--text-secondary);
    font-family: var(--font-display-en);
    font-size: 0.58rem;
    font-weight: 900;
    text-align: center;
  }

  .virtual-stick.is-active .virtual-stick__knob { background: var(--toy-mint); }

  .mobile-primary-actions {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-action {
    min-height: 80px;
    padding: 5px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 2px;
    color: var(--toy-ink);
    border-width: 3px;
    border-radius: 18px;
    box-shadow: var(--button-shadow);
  }

  .mobile-action strong {
    font-family: var(--font-display-en);
    font-size: clamp(1.55rem, 7vw, 2.1rem);
    line-height: 1;
  }

  .mobile-action span { font-size: 0.65rem; font-weight: 900; }
.mobile-action--noise { background: var(--toy-gold); }
  .mobile-action--echo { background: #82dcf1; }

  .mobile-utility-actions {
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(48px, 1fr));
    gap: 4px;
  }

  .utility-action {
    min-height: 48px;
    padding: 2px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 0;
    color: var(--toy-ink);
    border: 1px solid var(--soft-line);
    border-radius: 9px;
    background: #ffffff;
  }

  .utility-action > span { font-size: 0.92rem; font-weight: 900; }
  .utility-action small { color: var(--text-secondary); font-size: 0.57rem; font-weight: 900; }
  .utility-action[aria-pressed="true"] { color: #875500; background: #fff1b2; }

  .mobile-action:disabled,
  .utility-action:disabled {
    cursor: not-allowed;
    filter: grayscale(0.65);
    opacity: 0.42;
  }

  .controls { display: none; }
}

/* Tablet and compact menu */
@media (max-width: 780px) {
  .panel { padding: 13px; }

  .toy-menu__top {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 8px;
  }

  .profile-chip { max-width: 135px; }
  .profile-chip > span:not(.toy-avatar) { display: none; }
  .profile-chip { padding: 5px; }
  .player-tools { gap: 5px; }
  .round-tool { width: 50px; }
  .round-tool small { display: none; }

  .core-loop-strip > span { min-width: 0; flex: 1; padding-inline: 5px; }
  .core-loop-strip small { font-size: 0.66rem; }

  .toy-stage-card { grid-template-columns: 1fr; }
  .stage-diorama { min-height: 190px; border-right: 0; border-bottom: 3px solid var(--toy-line); }
}

/* Phone portrait */
@media (orientation: portrait) and (max-width: 600px) {
  .game-shell { gap: 6px; }

  .topbar {
    min-height: 52px;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    gap: 7px;
    padding: 5px 7px;
    border-radius: 11px;
  }

  .brand {
    width: 36px;
    overflow: hidden;
    font-size: 0;
  }

  .brand-mark { font-size: 1.25rem; }
  .mission-copy small { display: none; }
  .mission-copy span { font-size: 0.7rem; }
  .hud-cluster { gap: 2px; }

  .hud-stat {
    min-width: 42px;
    padding: 3px 4px;
  }

  .hud-stat span { font-size: 0.5rem; }
  .hud-stat strong { font-size: 0.84rem; }

  .canvas-wrap {
    height: clamp(240px, 40dvh, 340px);
    aspect-ratio: auto;
    border-radius: 11px;
  }

  .alert-meter { top: 6px; width: min(220px, 70%); }
  .toast { bottom: 7px; max-width: min(210px, calc(100% - 16px)); padding: 4px 7px; font-size: 0.6rem; }
  .sound-caption { top: 7px; left: 7px; max-width: 48%; padding: 6px 8px; font-size: 0.65rem; }

  .overlay {
    padding:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
  }

  .panel {
    max-height: calc(100dvh - 12px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border-radius: 14px;
  }

  .toy-menu { gap: 8px; }
  .toy-logo p { display: none; }
  .toy-logo h1 { font-size: clamp(1.6rem, 8.5vw, 2.15rem); }
  .toy-logo strong { margin-top: 2px; font-size: 0.68rem; }
  .profile-chip .toy-avatar { width: 38px; height: 38px; }
  .round-tool { width: 46px; min-height: 46px; }

  .core-loop-strip {
    min-height: 50px;
    padding: 5px;
    gap: 3px;
  }

  .core-loop-strip > i { display: none; }
  .core-loop-strip > span { min-height: 40px; grid-template-columns: auto auto; justify-content: center; gap: 3px; }
  .core-loop-strip > span > b { width: 18px; height: 18px; font-size: 0.58rem; }
  .core-loop-strip small { grid-column: 1 / -1; font-size: 0.61rem; text-align: center; }
  .core-loop-strip .toy-avatar--tiny { width: 23px; height: 23px; }

  .stage-diorama { min-height: 166px; }
  .diorama-cloud--two { display: none; }
  .diorama-gear { top: 18px; right: 20%; width: 45px; height: 45px; border-width: 7px; }
  .diorama-radar { width: 100px; height: 72px; }
  .diorama-hero { left: 12%; bottom: 15%; transform: scale(0.9); }
  .diorama-echo { left: 24%; top: 31%; transform: scale(0.75); }
  .diorama-guard { right: 14%; bottom: 17%; transform: scale(0.78); transform-origin: bottom center; }
  .diorama-guard.is-boss { right: 7%; transform: scale(0.68); }
  .diorama-gem { right: 7%; top: 20%; font-size: 1.75rem; }
  .diorama-copy { left: 21%; top: 12%; font-size: 0.56rem; }

  .arcade-stage-info { padding: 11px; gap: 6px; }
  .arcade-rule { padding: 3px 7px; font-size: 0.63rem; }
  .stage-title__local { font-size: 1.5rem; }
  .stage-title small[lang="en"] { font-size: 0.7rem; }
  .stage-mission,
  .stage-next { padding: 6px 8px; gap: 6px; }
  .radar-rule { padding: 5px 7px; font-size: 0.64rem; }
  .stage-mission span,
  .stage-next span { font-size: 0.6rem; }
  .stage-mission b,
  .stage-next b { font-size: 0.7rem; }
  .arcade-stats span { padding: 3px 6px; font-size: 0.57rem; }
  .arcade-play { min-height: 52px; }

  .toy-rail {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 62px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
  }

  .world-node { scroll-snap-align: center; }
  .world-node small { display: none; }
  .arcade-keys { min-height: 28px; gap: 4px 10px; font-size: 0.62rem; }

  .toy-dialog { padding: 16px 13px; }
  .toy-dialog h2 { margin-bottom: 10px; font-size: 1.75rem; }
  .profile-preview { min-height: 116px; }
  .profile-options { padding-inline: 9px; }
  .profile-colors,
  .profile-faces { gap: 6px; }
  .profile-color { width: 44px; }

  .setting-row { min-height: 62px; gap: 8px; }
  .setting-row .toy-select { width: 126px; }
  .setting-row small { font-size: 0.63rem; }

  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .record-stage-tabs {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 46px;
    overflow-x: auto;
  }
  .ranking-row { grid-template-columns: 22px 28px minmax(0, 1fr) 72px; gap: 5px; }
  .ranking-player small { font-size: 0.56rem; }
  .ranking-title { align-items: flex-start; flex-direction: column; gap: 2px; }

  .arcade-clear__actions { grid-template-columns: 1fr 1fr; }
  .arcade-clear__actions .arcade-play { grid-column: 1 / -1; }
}

@media (orientation: portrait) and (max-width: 350px) {
  .mobile-gamepad {
    grid-template-columns: 112px minmax(0, 1fr);
    grid-template-rows: 108px 48px;
    gap: 5px 7px;
  }

  .virtual-stick { width: 108px; height: 108px; grid-row: 1; }
  .mobile-primary-actions { grid-column: 2; grid-row: 1; }
  .mobile-utility-actions { grid-column: 1 / -1; grid-row: 2; }
  .virtual-stick__label { display: none; }
  .mobile-action { min-height: 72px; }
  .mobile-action strong { font-size: 1.45rem; }
  .toy-logo strong { display: none; }
  .round-tool { width: 44px; }
}

/* Short landscape phones: canvas, joystick and action buttons remain together. */
@media (orientation: landscape) and (max-height: 520px) and (max-width: 950px) {
  body { overflow: hidden; }

  .game-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding:
      max(4px, env(safe-area-inset-top))
      max(4px, env(safe-area-inset-right))
      max(4px, env(safe-area-inset-bottom))
      max(4px, env(safe-area-inset-left));
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px;
    grid-template-rows: 44px minmax(0, 1fr);
    gap: 4px 6px;
  }

  .topbar {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 0;
    padding: 3px 8px;
    gap: 10px;
    border-radius: 9px;
    box-shadow: 0 3px 0 var(--toy-shadow);
  }

  .brand { font-size: 0.73rem; }
  .brand-mark { font-size: 1rem; }
  .mission-copy small { display: none; }
  .mission-copy span { font-size: 0.67rem; }
  .hud-stat { min-width: 43px; padding: 2px 4px; }
  .hud-stat span { font-size: 0.48rem; }
  .hud-stat strong { font-size: 0.8rem; }

  .canvas-wrap {
    grid-column: 1;
    grid-row: 2;
    width: auto;
    height: 100%;
    max-width: 100%;
    aspect-ratio: 12 / 7;
    justify-self: center;
    border-radius: 9px;
    box-shadow: 0 3px 0 var(--toy-shadow);
  }

  .mobile-gamepad {
    grid-column: 2;
    grid-row: 2;
    min-height: 0;
    padding: 5px;
    grid-template-columns: 104px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 48px;
    gap: 5px;
    border-radius: 9px;
    box-shadow: 0 3px 0 var(--toy-shadow);
  }

  .virtual-stick { width: 100px; height: 100px; }

  .virtual-stick__knob {
    top: calc(50% - 22px);
    left: calc(50% - 22px);
    width: 44px;
    height: 44px;
  }

  .mobile-primary-actions {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(2, minmax(62px, 1fr));
    gap: 6px;
  }

  .mobile-action {
    min-height: 62px;
    grid-template-columns: auto 1fr;
    align-content: center;
    column-gap: 5px;
    border-radius: 13px;
  }

  .mobile-action strong { font-size: 1.4rem; }
  .mobile-utility-actions { grid-column: 1 / -1; }
  .utility-action { min-height: 48px; }
  .controls { display: none; }

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

  .toy-menu {
    width: 100%;
    max-height: calc(100dvh - 8px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    padding: 7px;
    grid-template-columns: 156px minmax(0, 1fr);
    grid-template-rows: 50px minmax(0, 1fr) 52px;
    gap: 6px 8px;
  }

  .toy-menu__top {
    grid-column: 1 / -1;
    grid-row: 1;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .profile-chip { min-height: 44px; padding: 2px; }
  .profile-chip .toy-avatar { width: 36px; height: 36px; }
  .toy-logo p,
  .toy-logo strong { display: none; }
  .toy-logo h1 { font-size: 1.7rem; }
  .round-tool { width: 44px; min-height: 44px; padding: 2px; }

  .core-loop-strip {
    grid-column: 1;
    grid-row: 2;
    min-height: 0;
    padding: 5px;
    flex-direction: column;
    gap: 3px;
  }

  .core-loop-strip > span {
    width: 100%;
    min-height: 0;
    flex: 1;
    grid-template-columns: auto auto 1fr;
    padding: 2px 4px;
  }

  .core-loop-strip > i { display: none; }
  .core-loop-strip small { font-size: 0.58rem; }
  .core-loop-strip .toy-avatar--tiny { width: 22px; height: 22px; }

  .toy-stage-card {
    grid-column: 2;
    grid-row: 2;
    min-height: 0;
    grid-template-columns: minmax(155px, 0.8fr) minmax(0, 1.2fr);
  }

  .stage-diorama { min-height: 0; border-right: 3px solid var(--toy-line); border-bottom: 0; }
  .diorama-cloud--two { display: none; }
  .diorama-guard { transform: scale(0.72); transform-origin: bottom center; }
  .diorama-guard.is-boss { transform: scale(0.58); }
  .diorama-copy { font-size: 0.52rem; }

  .arcade-stage-info { padding: 7px 9px; gap: 4px; }
  .arcade-rule { padding: 2px 6px; font-size: 0.55rem; }
  .stage-title__local { font-size: 1.08rem; }
  .stage-title small[lang="en"] { font-size: 0.58rem; }
  .stage-mission,
  .stage-next { padding: 4px 6px; }
  .radar-rule { padding: 3px 5px; gap: 5px; font-size: 0.56rem; }
  .radar-rule > i { width: 28px; height: 16px; flex-basis: 28px; }
  .radar-rule > i::after { height: 16px; }
  .stage-mission span,
  .stage-next span { font-size: 0.52rem; }
  .stage-mission b,
  .stage-next b { font-size: 0.62rem; }
  .stage-next { display: none; }
  .arcade-stats span { padding: 2px 5px; font-size: 0.5rem; }
  .arcade-play { min-height: 44px; padding: 5px 10px; font-size: 0.8rem; }

  .toy-rail {
    grid-column: 1 / -1;
    grid-row: 3;
    min-height: 0;
    padding: 2px 8px;
  }

  .world-map::before { top: 23px; }
  .world-node { min-height: 44px; grid-template-columns: 40px auto; align-items: center; justify-content: center; }
  .world-node__coin { width: 40px; height: 40px; border-radius: 11px; }
  .world-node.is-current .world-node__coin { width: 44px; height: 44px; margin-top: 0; }
  .world-node small { display: none; }
  .arcade-keys { display: none; }

  .toy-dialog,
  .arcade-clear {
    max-height: calc(100dvh - 8px);
    padding: 10px 14px;
  }

  .toy-dialog h2 { margin-bottom: 7px; font-size: 1.55rem; }
  .profile-preview { min-height: 90px; margin-bottom: 7px; }
  .profile-preview .toy-avatar--large { transform: scale(0.7); }
  .profile-options { margin-top: 7px; padding-block: 6px; }
  .setting-row { min-height: 52px; margin-top: 5px; padding: 5px 8px; }
  .caption-demo { margin-top: 6px; padding: 5px; }
  .dialog-actions { margin-top: 8px; }
  .stat-strip div { padding: 4px; }
  .record-stage-tabs { margin-top: 5px; }
  .ranking-row { min-height: 44px; }
  .ranking-note { margin-top: 3px; }

  .arcade-clear { gap: 5px; }
  .arcade-clear h2 { font-size: 2.8rem; }
  .arcade-clear__stars { font-size: 1.65rem; }
  .arcade-clear__actions { gap: 6px; }
  .clear-grade { padding-block: 5px; font-size: 1.45rem; }
  .arcade-score { gap: 5px; }
  .arcade-score div { padding: 5px; }
  .arcade-clear__actions button { min-height: 48px; padding-block: 5px; }
}

/* Fill each portrait device without leaving a dead strip under the controls. */
@media (orientation: portrait) and (max-width: 600px) {
  .game-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(268px, 1.6fr) minmax(168px, 1fr);
    align-content: stretch;
  }

  .canvas-wrap {
    height: auto;
    min-height: 0;
  }

  .mobile-gamepad {
    height: auto;
    min-height: 0;
    padding-bottom: max(7px, env(safe-area-inset-bottom));
    grid-template-columns: clamp(126px, 38vw, 170px) minmax(0, 1fr);
    grid-template-rows: minmax(96px, 1fr) 50px;
  }

  .virtual-stick {
    width: clamp(124px, min(38vw, 19dvh), 168px);
    height: clamp(124px, min(38vw, 19dvh), 168px);
    border-width: 4px;
    background: #8ed8ff;
    box-shadow: inset 0 0 0 9px #eefaff, 0 5px 0 rgb(38 54 95 / 0.38);
  }

  .virtual-stick__tick {
    width: 15px;
    height: 6px;
    background: #26366f;
    opacity: 0.9;
  }

  .virtual-stick__knob {
    top: calc(50% - 29px);
    left: calc(50% - 29px);
    width: 58px;
    height: 58px;
    border-width: 4px;
    background: #ffd34d;
    box-shadow: 0 5px 0 rgb(38 54 95 / 0.42);
  }

  .virtual-stick__knob i {
    width: 20px;
    height: 20px;
    border-color: #26366f;
  }

  .virtual-stick__label {
    bottom: -18px;
    color: #26366f;
    font-size: 0.72rem;
  }

  .mobile-primary-actions,
  .mobile-action { min-height: 0; height: 100%; }

  .settings-dialog { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .game-guide { padding: 9px; }
  .game-guide__flow li { min-height: 34px; font-size: 0.61rem; }
  .game-guide__summary,
  .game-guide__actions li,
  .game-guide__items,
  .game-guide__note { font-size: 0.64rem; }
}

@media (orientation: portrait) and (max-width: 350px) {
  .game-shell { grid-template-rows: auto minmax(250px, 1.45fr) minmax(154px, 1fr); }
  .mobile-gamepad {
    grid-template-columns: 112px minmax(0, 1fr);
    grid-template-rows: minmax(100px, 1fr) 48px;
  }
  .virtual-stick { width: 108px; height: 108px; }
  .virtual-stick__knob {
    top: calc(50% - 25px);
    left: calc(50% - 25px);
    width: 50px;
    height: 50px;
  }
  .game-guide__actions { grid-template-columns: 1fr; }
  .game-guide__actions li.is-wide { grid-column: 1; }
}

@media (hover: hover) {
  .toy-button:hover,
  .arcade-play:hover,
  .pixel-button:hover,
  .profile-chip:hover,
  .round-tool:hover,
  .profile-face:hover,
  .record-stage-tab:hover { transform: translateY(-2px); filter: brightness(1.03); }

  .world-node:not(:disabled):hover .world-node__coin { transform: translateY(-2px); filter: brightness(1.04); }
}

@media (prefers-reduced-motion: reduce) {
  .overlay::before,
  .overlay::after,
  .diorama-gear { animation: none; }

  .alert-meter,
  .alert-track i,
  .toast,
  body[data-visual-sound="true"] .topbar::after,
  .setting-row input[type="checkbox"]::after { transition: none; }
}

@media (forced-colors: active) {
  .topbar,
  .canvas-wrap,
  .panel,
  .toy-button,
  .arcade-play,
  .pixel-button,
  .profile-chip,
  .round-tool,
  .core-loop-strip,
  .toy-stage-card,
  .stage-diorama,
  .world-node__coin,
  .toy-input,
  .toy-select,
  .profile-color,
  .profile-face,
  .setting-row,
  .record-stage-tab,
  .ranking-row,
  .mobile-gamepad,
  .virtual-stick,
  .mobile-action,
  .utility-action {
    border-color: CanvasText;
    forced-color-adjust: auto;
  }
}

/* Korean display copy uses the bundled game face; body copy stays highly readable. */
:root:lang(ko) .toy-logo h1,
:root:lang(ko) .stage-title__local,
:root:lang(ko) .toy-button,
:root:lang(ko) .world-node__coin {
  font-family: var(--font-game-ko);
  font-weight: 700;
}

/* v0.7 — one screen, one goal, one primary action. */
.overlay::before,
.overlay::after { display: none; }

.arcade-menu,
.toy-menu {
  width: min(760px, 100%);
  min-width: 0;
  max-width: 100%;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: clamp(14px, 2.2vw, 22px);
}

.toy-menu__top {
  grid-template-columns: minmax(110px, 1fr) minmax(230px, 1.5fr) minmax(110px, 1fr);
  gap: 8px;
}

.toy-logo h1 {
  margin: 0;
  font-size: clamp(2.08rem, 4.9vw, 3.25rem);
  letter-spacing: -0.045em;
  text-shadow: 0 3px 0 #ffffff;
}

.player-tools { gap: 6px; }
.round-tool { width: 52px; min-height: 50px; padding: 4px; }
.round-tool small { display: none; }
.profile-chip { min-height: 50px; box-shadow: 0 3px 0 rgb(38 54 95 / 0.2); }

.arcade-stage-card,
.toy-stage-card {
  min-height: 0;
  grid-template-columns: 1fr;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgb(38 54 95 / 0.18);
}

.stage-diorama {
  min-height: 320px;
  background: linear-gradient(180deg, var(--scene-sky) 0 68%, var(--scene-ground) 68% 100%);
}

.stage-diorama::before { display: none; }

.diorama-hero,
.diorama-echo {
  width: 112px;
  height: 112px;
  display: grid;
  place-items: center;
  transform: none;
}

.diorama-hero { left: 10%; bottom: 9%; }
.diorama-echo { left: 28%; top: 16%; width: 82px; height: 82px; opacity: 0.48; filter: saturate(1.35) hue-rotate(10deg); }
.diorama-hero img,
.diorama-echo img,
.diorama-guard img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  image-rendering: pixelated;
}

.diorama-guard:not(.is-boss) { right: 18%; bottom: 16%; }
.diorama-guard.is-boss {
  right: 5%;
  bottom: 5%;
  width: 168px;
  height: 168px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.diorama-guard.is-boss::before,
.diorama-guard.is-boss::after { display: none; }
.diorama-gem { top: 20%; right: 10%; }
.diorama-exit { right: 4%; bottom: 4%; }

.arcade-stage-info {
  padding: clamp(18px, 3vw, 30px);
  justify-content: center;
  gap: 10px;
}

.stage-heading {
  min-width: 0;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}

.stage-heading__copy { min-width: 0; }
.stage-mascot,
.stage-boss-preview { display: grid; place-items: center; }
.stage-mascot { width: 88px; height: 88px; }
.stage-boss-preview { width: 110px; height: 92px; }
.stage-mascot img,
.stage-boss-preview img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  image-rendering: pixelated;
}

.arcade-rule {
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.7rem;
}

.stage-title__local {
  font-size: clamp(1.88rem, 3.9vw, 2.85rem);
  letter-spacing: -0.035em;
}

.stage-summary {
  margin: -2px 0 2px;
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 800;
}

.stage-mission {
  min-height: 58px;
  padding: 10px 12px;
  grid-template-columns: 74px minmax(0, 1fr);
  border: 2px solid #8bc5e5;
  border-radius: 9px;
  background: #eaf8ff;
}

.stage-mission span { font-size: 0.74rem; }
.stage-mission b { font-size: 0.96rem; white-space: normal; }

.arcade-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.arcade-stats span {
  min-height: 40px;
  padding: 8px 10px;
  display: grid;
  place-items: center;
  border: 2px solid var(--soft-line);
  border-radius: 8px;
  font-family: var(--font-ui);
  font-size: 0.8rem;
}

.arcade-play {
  min-height: 60px;
  margin-top: 2px;
  border-radius: 10px;
  font-size: 1.14rem;
}

.world-map,
.toy-rail {
  min-height: 62px;
  padding: 5px 9px;
  border-radius: 10px;
  background: #fff3c9;
}

.world-map::before { top: 26px; }
.world-node { min-width: 50px; min-height: 52px; }
.world-node__coin { width: 42px; height: 42px; border-radius: 10px; }
.world-node.is-current .world-node__coin { width: 46px; height: 46px; margin-top: 0; }

.toy-stage-card,
.arcade-stage-info,
.toy-rail { min-width: 0; max-width: 100%; }

.toy-rail { scrollbar-width: none; }
.toy-rail::-webkit-scrollbar { display: none; }

@media (max-width: 780px) {
  .arcade-menu,
  .toy-menu { gap: 9px; }
  .toy-menu__top { grid-template-columns: 48px minmax(0, 1fr) auto; }
  .player-tools { width: auto; }
  .toy-stage-card { grid-template-columns: 1fr; }
  .arcade-stage-info { padding: 14px; gap: 7px; }
  .stage-heading { grid-template-columns: 72px minmax(0, 1fr) auto; gap: 9px; }
  .stage-mascot { width: 72px; height: 72px; }
  .stage-boss-preview { width: 78px; height: 70px; }
}

@media (orientation: portrait) and (max-width: 600px) {
  .arcade-menu,
  .toy-menu { padding: 10px; grid-template-rows: auto auto auto; gap: 8px; }
  .toy-menu__top { gap: 8px; }
  .toy-logo h1 { font-size: clamp(1.68rem, 8.3vw, 2.13rem); }
  .profile-chip { max-width: 48px; padding: 4px; }
  .profile-chip > span:not(.toy-avatar) { display: none; }
  .round-tool { width: 50px; min-height: 50px; }
  .stage-heading { grid-template-columns: 62px minmax(0, 1fr) auto; }
  .stage-mascot { width: 62px; height: 62px; }
  .stage-boss-preview { width: 66px; height: 58px; }
  .arcade-rule { font-size: 0.6rem; }
  .stage-title__local { font-size: 1.53rem; }
  .stage-summary { font-size: 0.72rem; }
  .stage-mission { min-height: 52px; grid-template-columns: 62px minmax(0, 1fr); padding: 7px 9px; }
  .stage-mission b { font-size: 0.82rem; }
  .arcade-stats span { min-height: 36px; padding: 6px; font-size: 0.7rem; }
  .arcade-play { min-height: 54px; }
  .toy-rail { min-height: 58px; }
}

@media (orientation: portrait) and (max-width: 350px) {
  .toy-menu__top { gap: 6px; }
  .toy-logo h1 { font-size: 1.38rem; letter-spacing: -0.09em; white-space: nowrap; }
  .round-tool { width: 50px; }
  .stage-heading { grid-template-columns: 44px minmax(0, 1fr) 46px; gap: 4px; }
  .stage-mascot { width: 44px; height: 44px; }
  .stage-boss-preview { width: 46px; height: 44px; }
  .stage-title__local { font-size: 1.25rem; word-break: keep-all; }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 950px) {
  .toy-menu {
    grid-template-columns: 1fr;
    grid-template-rows: 50px minmax(0, 1fr) 62px;
    gap: 6px 8px;
    padding: 7px;
  }
  .toy-menu__top { grid-column: 1; grid-row: 1; }
  .toy-logo h1 { font-size: 2.59rem; letter-spacing: -0.052em; }
  .toy-stage-card { grid-column: 1; grid-row: 2; grid-template-columns: 1fr; }
  .arcade-stage-info { padding: 7px 9px; gap: 3px; }
  .stage-heading { grid-template-columns: 52px minmax(0, 1fr) auto; gap: 7px; }
  .stage-mascot { width: 52px; height: 52px; }
  .stage-boss-preview { width: 60px; height: 50px; }
  .arcade-rule { padding: 2px 6px; font-size: 0.54rem; }
  .stage-title__local { font-size: 1.22rem; }
  .stage-summary { margin: 0; font-size: 0.58rem; }
  .stage-mission { min-height: 36px; padding: 3px 6px; grid-template-columns: 54px minmax(0, 1fr); }
  .stage-mission span { font-size: 0.58rem; }
  .stage-mission b { font-size: 0.7rem; }
  .arcade-stats { gap: 4px; }
  .arcade-stats span { min-height: 28px; padding: 2px 5px; font-size: 0.58rem; }
  .arcade-play { min-height: 48px; margin-top: 0; padding: 4px 8px; font-size: 0.84rem; }
  .toy-rail { grid-column: 1; grid-row: 3; }
}

/* v0.10.0 mobile density and legibility pass. */
@media (max-width: 900px), (pointer: coarse) {
  .panel { scrollbar-gutter: auto; }
  .virtual-stick__label { font-size: 0.68rem; }
  .mobile-action span { font-size: 0.75rem; }
  .utility-action small { font-size: 0.68rem; }
}

@media (orientation: portrait) and (max-width: 600px) {
  .game-shell { gap: 6px; }

  .topbar {
    min-height: 82px;
    grid-template-columns: 30px minmax(0, 1fr) auto;
    gap: 7px;
  }

  .brand { width: 30px; }
  .brand-mark { font-size: 1.12rem; }

  .mission-copy {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .mission-copy span {
    font-size: 0.78rem;
    line-height: 1.2;
  }

  .mission-copy small {
    margin-top: 3px;
    display: -webkit-box;
    overflow: hidden;
    color: #3f517d;
    font-size: 0.68rem;
    line-height: 1.25;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
  }

  .hud-stat {
    min-width: 44px;
    padding: 4px;
  }

  .hud-stat span { font-size: 0.63rem; }
  .hud-stat strong { font-size: 0.9rem; }

  .canvas-wrap { height: clamp(272px, 50dvh, 430px); }
  .mobile-gamepad { min-height: clamp(168px, 26dvh, 210px); }

  .panel { margin: 0 auto; }

  .arcade-menu,
  .toy-menu {
    min-height: calc(100dvh - 12px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .toy-stage-card { height: 100%; }
  .arcade-stage-info { height: 100%; justify-content: space-evenly; }
  .arcade-rule { font-size: 0.72rem; }
  .stage-summary { font-size: 0.82rem; }
  .stage-mission span { font-size: 0.75rem; }
  .stage-mission b { font-size: 0.9rem; }
  .arcade-stats span { font-size: 0.78rem; }

  .grade-criteria p { font-size: 0.75rem; }
  .grade-rule { font-size: 0.7rem; }
  .arcade-score span { font-size: 0.75rem; }
  .clear-record span { font-size: 0.72rem; }

  .arcade-clear__actions {
    position: sticky;
    bottom: -1px;
    z-index: 4;
    padding: 8px 0 2px;
    background: linear-gradient(180deg, rgb(255 253 243 / 0), var(--toy-paper) 8px);
    box-shadow: 0 -2px 0 rgb(38 54 95 / 0.08);
  }

  /* 메뉴는 내용 높이만 사용한다. 작은 화면에서 카드가 뷰포트 전체를
     억지로 채우며 생기던 큰 빈 공간을 없앤다. */
  .arcade-menu,
  .toy-menu {
    min-height: 0;
    height: auto;
    align-self: start;
    grid-template-rows: auto auto auto;
  }

  .toy-stage-card { height: auto; }
  .arcade-stage-info {
    height: auto;
    justify-content: flex-start;
    gap: 10px;
  }
}

@media (orientation: portrait) and (min-width: 351px) and (max-width: 600px) {
  .arcade-score { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (orientation: portrait) and (max-width: 350px) {
  .topbar { min-height: 88px; }
  .canvas-wrap { height: clamp(268px, 48dvh, 430px); }
  .mission-copy small { flex-shrink: 0; }

  .toy-menu__top {
    grid-template-columns: 48px minmax(0, 1fr) auto;
    grid-template-areas:
      "profile spacer tools"
      "logo logo logo";
    row-gap: 6px;
  }

  .profile-chip { grid-area: profile; }
  .toy-logo { grid-area: logo; }
  .player-tools { grid-area: tools; }
  .toy-logo h1 { font-size: 1.65rem; letter-spacing: -0.055em; white-space: normal; }
  .round-tool { width: 46px; min-height: 46px; }
}

@media (orientation: portrait) and (min-width: 351px) and (max-width: 370px) {
  .mobile-utility-actions {
    grid-template-columns: repeat(4, minmax(44px, 1fr));
    gap: 3px;
  }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 950px) {
  .game-shell { grid-template-rows: 52px minmax(0, 1fr); }

  .mission-copy span { font-size: 0.78rem; }
  .mission-copy small {
    margin-top: 1px;
    display: block;
    color: #3f517d;
    font-size: 0.68rem;
    line-height: 1.15;
  }

  .hud-stat span { font-size: 0.62rem; }
  .hud-stat strong { font-size: 0.9rem; }

  .arcade-rule { font-size: 0.68rem; }
  .stage-summary { font-size: 0.72rem; }
  .stage-mission span { font-size: 0.68rem; }
  .stage-mission b { font-size: 0.78rem; }
  .arcade-stats span { font-size: 0.68rem; }
  .arcade-play { font-size: 0.95rem; }

  .grade-criteria p { font-size: 0.72rem; }
  .grade-rule { font-size: 0.7rem; }
  .arcade-score { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .arcade-score span { font-size: 0.72rem; }
  .clear-record span { font-size: 0.7rem; }

  .arcade-clear__actions {
    position: sticky;
    bottom: -1px;
    z-index: 4;
    padding: 6px 0 2px;
    background: linear-gradient(180deg, rgb(255 253 243 / 0), var(--toy-paper) 6px);
    box-shadow: 0 -2px 0 rgb(38 54 95 / 0.08);
  }

  .arcade-clear__actions button { font-size: 0.9rem; }
}

/* Final device-fit overrides: keep exactly one visual gap between the field
   and controls, and prevent an implicit empty grid row in short landscape. */
@media (orientation: portrait) and (max-width: 600px) {
  .canvas-wrap { height: auto; }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 950px) {
  .virtual-stick { grid-row: 1; }
  .mobile-utility-actions { grid-row: 2; }
  .virtual-stick__tick {
    background: #26366f;
    opacity: 0.9;
  }
}

@media (orientation: portrait) and (max-width: 600px) {
  .mission-copy span {
    display: block;
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    word-break: keep-all;
  }
}

@media (orientation: portrait) and (max-width: 350px) {
  .topbar { min-height: 104px; }

  .mission-copy span {
    display: block;
    overflow: visible;
    font-size: 0.7rem;
    line-height: 1.18;
    text-overflow: clip;
    white-space: normal;
    word-break: keep-all;
  }

  .mission-copy small {
    display: block;
    overflow: visible;
    font-size: 0.61rem;
    line-height: 1.22;
    -webkit-line-clamp: unset;
  }

  .hud-stat { min-width: 40px; }

  .virtual-stick__label {
    right: auto;
    bottom: 7px;
    left: 7px;
    display: block;
    width: auto;
    padding: 1px 5px;
    color: #26366f;
    border: 1px solid rgb(38 54 111 / 0.35);
    border-radius: 999px;
    background: rgb(255 255 255 / 0.9);
    line-height: 1.2;
  }
}

/* Keep the complete play field and keyboard legend visible on short desktop
   windows. The canvas keeps its native 12:7 ratio and yields width before it
   pushes the controls below the viewport. */
@media (min-width: 901px) and (max-height: 820px) and (pointer: fine) {
  .game-shell {
    height: 100dvh;
    min-height: 0;
    align-items: center;
    overflow: hidden;
  }

  .topbar,
  .controls {
    width: 100%;
    flex: 0 0 auto;
  }

  .canvas-wrap {
    width: min(100%, calc((100dvh - 132px) * 12 / 7));
    flex: 0 0 auto;
  }

  .controls {
    flex-wrap: nowrap;
    gap: 4px 14px;
    white-space: nowrap;
  }
}

/* One compact entry point keeps play controls separate from secondary actions. */
.game-menu-trigger {
  min-width: 58px;
  min-height: 46px;
  padding: 3px 7px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  color: var(--toy-ink);
  border: 2px solid var(--toy-line);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 3px 0 rgb(38 54 95 / 0.26);
}

.game-menu-trigger > span { font-size: 1rem; font-weight: 900; line-height: 1; }
.game-menu-trigger small { color: var(--text-secondary); font-size: 0.56rem; font-weight: 900; }
.game-menu-trigger[aria-expanded="true"] { color: #704500; background: var(--toy-gold); }
.game-menu-trigger:disabled { opacity: 0.38; }

.game-menu-dialog {
  position: relative;
  width: min(480px, 100%);
  padding-top: clamp(24px, 5vw, 34px);
}

.game-menu-dialog h2 { margin-bottom: 4px; text-align: center; }
.game-menu-dialog__hint { margin: 0 42px 14px; color: var(--text-secondary); font-size: 0.72rem; font-weight: 800; text-align: center; }

.dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--toy-ink);
  border: 2px solid var(--toy-line);
  border-radius: 50%;
  background: #ffffff;
  font: 900 1.35rem/1 var(--font-ui);
  box-shadow: 0 3px 0 rgb(38 54 95 / 0.24);
}

.game-menu-options { display: grid; gap: 8px; }
.game-menu-option {
  min-height: 64px;
  padding: 8px 12px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  column-gap: 9px;
  color: var(--toy-ink);
  border: 2px solid var(--toy-line);
  border-radius: 12px;
  background: #ffffff;
  text-align: left;
  box-shadow: 0 3px 0 rgb(38 54 95 / 0.2);
}
.game-menu-option > span { grid-row: 1 / 3; font-size: 1.35rem; font-weight: 900; text-align: center; }
.game-menu-option b { font-size: 0.9rem; }
.game-menu-option small { color: var(--text-secondary); font-size: 0.66rem; font-weight: 800; }
.game-menu-option--restart { border-color: #df6b67; background: #fff1ef; }

.overlay[data-view="caught"] {
  place-items: center;
  background: rgb(74 8 22 / 0.88);
}
.overlay[data-view="caught"]::before,
.overlay[data-view="caught"]::after { display: none; }

.caught-dialog {
  width: min(440px, 100%);
  display: grid;
  place-items: center;
  gap: 10px;
  color: #5d0f1e;
  border-color: #a9223b;
  background: #fff5f3;
  box-shadow: 0 9px 0 #621126;
  text-align: center;
}
.caught-dialog__mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  color: #ffffff;
  border: 4px solid #7f152c;
  border-radius: 50%;
  background: #e83f4f;
  font: 900 2rem/1 var(--font-display-en);
}
.caught-dialog h2 { margin: 0; color: #a41530; font-size: clamp(1.8rem, 8vw, 2.8rem); }
.caught-dialog p { margin: 0; font-size: 0.8rem; font-weight: 900; }
.caught-dialog__restart {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 58px;
  margin-top: 4px;
  color: #ffffff;
  border-color: #6f1025;
  background: #dc3348;
  pointer-events: auto;
  touch-action: manipulation;
}

@media (max-width: 900px), (pointer: coarse) {
  .mobile-gamepad { grid-template-rows: minmax(120px, 1fr); }
  .virtual-stick { grid-row: 1; }
  .mobile-primary-actions { grid-row: 1; }
}

@media (orientation: portrait) and (max-width: 600px) {
  .game-menu-trigger { min-width: 42px; min-height: 42px; padding: 2px 4px; }
  .game-menu-trigger small { display: none; }
  .game-menu-dialog__hint { margin-inline: 34px; }
  .game-menu-option { min-height: 60px; }
}

@media (orientation: portrait) and (max-width: 350px) {
  .topbar {
    min-height: 68px;
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .brand { display: none; }
  .mission-copy small { display: none; }
  .mission-copy span { font-size: 0.67rem; line-height: 1.2; }
  .hud-stat { min-width: 38px; }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 950px) {
  .mobile-gamepad { grid-template-rows: minmax(0, 1fr); }
  .virtual-stick,
  .mobile-primary-actions { grid-row: 1; }
  .game-menu-trigger { min-width: 42px; min-height: 38px; padding: 1px 4px; }
  .game-menu-trigger small { display: none; }
  .game-menu-dialog { width: min(560px, 100%); }
  .game-menu-options { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .game-menu-option { min-height: 82px; grid-template-columns: 1fr; place-items: center; text-align: center; }
  .game-menu-option > span { grid-row: auto; }
}
