:root {
  font-family: system-ui, sans-serif;
  color: #253e29;
  background: #e9eedc;
  --surface: #fff9e8;
  --muted: #53694f;
  --accent: #366748;
  --accent-strong: #285337;
  --line: #dce3ce;
}
* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
button:focus-visible { outline: 3px solid #377b65; outline-offset: 3px; }
#game {
  --joystick-size: clamp(89px, 28vh, 124px);
  --joystick-bottom: calc(clamp(18px, 6vh, 42px) + env(safe-area-inset-bottom));
  position: fixed;
  inset: 0;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: linear-gradient(#badfe7 54%, #93ad78 54%);
}
#game[data-level="snow"] {
  color: #233a4d;
  --surface: #f2fafc;
  --muted: #456075;
  --accent: #366981;
  --accent-strong: #265369;
  --line: #d4e6ed;
  background: linear-gradient(#bdd8e5 54%, #d7e7ee 54%);
}
#game[data-level="wooden-house"] {
  color: #4a342a;
  --surface: #fff3df;
  --muted: #765b4a;
  --accent: #9e523d;
  --accent-strong: #7a402e;
  --line: #ecdbc6;
  background: #e7c8a4;
}
#game[data-level="frozen-castle"] {
  color: #273754;
  --surface: #f0f6ff;
  --muted: #4c6084;
  --accent: #485793;
  --accent-strong: #374679;
  --line: #cfdbf2;
  background: #b1c7eb;
}
#game[data-level="arendelle-village"] {
  color: #383b2f;
  --surface: #fff1d9;
  --muted: #575e48;
  --accent: #3c685c;
  --accent-strong: #2d5148;
  --line: #e5d6b6;
  background: #c4dedc;
}
#view { width: 100%; height: 100%; display: block; touch-action: none; }
[data-view-mode="night-vision"] #view { filter: grayscale(1) brightness(1.85) contrast(1.12) sepia(1) hue-rotate(65deg) saturate(2.5); }
[data-view-mode="cctv"] #view { filter: saturate(.64) contrast(1.08); }

.hud {
  position: absolute;
  z-index: 3;
  inset: 0 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right))
           0 calc(20px + env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) auto;
  align-items: start;
  gap: 6px 10px;
  pointer-events: none;
}
.wordmark, .hud-actions { display: flex; align-items: center; gap: 8px; }
.wordmark {
  justify-self: start;
  padding: 7px 13px 7px 8px;
  border-radius: 50px;
  background: var(--surface);
  box-shadow: 0 3px 12px #253e2922;
  font-size: 15px;
  font-weight: 850;
  line-height: 1.08;
}
.wordmark small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; font-weight: 750; }
.hud-actions { grid-column: 3; }
.mission-hud { grid-area: 2 / 1 / 3 / -1; justify-self: start; }
.mission-hud summary, .mission-panel, .mission-toast:not(:empty) {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 2px 10px #21384f20;
}
.mission-hud summary {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  min-height: 44px;
  padding: 0 12px;
  cursor: pointer;
  list-style: none;
  pointer-events: auto;
  touch-action: manipulation;
  font-size: 13px;
  font-weight: 800;
}
.mission-hud summary::-webkit-details-marker { display: none; }
.mission-hud :is(summary, .mission-panel):focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.mission-arrow {
  width: 7px;
  height: 7px;
  margin: -3px 2px 0;
  border: solid var(--accent-strong);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.mission-hud[open] .mission-arrow { margin-top: 3px; transform: rotate(225deg); }
.mission-panel {
  width: min(18rem, calc(100vw - 40px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  max-height: min(15rem, 40vh);
  max-height: min(15rem, 40dvh);
  margin-top: 5px;
  padding: 10px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
  touch-action: pan-y;
  font-size: 13px;
  line-height: 1.35;
}
[data-input="touch"] .mission-panel {
  /* Reserve the toolbar and joystick on short landscape screens. */
  --control-space: calc(124px + env(safe-area-inset-top) + var(--joystick-size) + var(--joystick-bottom));
  max-height: min(15rem, 40vh, max(46px, calc(100vh - var(--control-space))));
  max-height: min(15rem, 40dvh, max(46px, calc(100dvh - var(--control-space))));
}
.mission-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.mission-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.mission-count { font-variant-numeric: tabular-nums; }
.mission-list [data-complete] .mission-count { color: var(--accent-strong); font-weight: 750; }
.mission-note { margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--line); }
.mission-note h2, .mission-note p { margin: 0; font-size: inherit; }
.mission-note p { margin-top: 2px; color: var(--muted); }
.mission-toast {
  grid-area: 1 / 2;
  justify-self: center;
  width: fit-content;
  max-width: min(38ch, 100%);
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
  font-weight: 750;
  text-align: center;
  overflow-wrap: anywhere;
}
.mission-toast:not(:empty) { padding: 7px 10px; }
#game:not([data-state="playing"]) :is(.mission-hud, .mission-toast) { display: none; }

@media (max-width: 540px) {
  .mission-toast { grid-area: 2 / 1 / 3 / -1; justify-self: end; max-width: calc(100% - 148px); }
}
.world-mark {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
}
.world-mark::before {
  content: "";
  width: 14px;
  height: 18px;
  background: #e2eab9;
  border-radius: 80% 10% 75% 25%;
  transform: rotate(23deg);
}
[data-level="snow"] .world-mark::before {
  width: 14px;
  height: 14px;
  background: #d3edf3;
  border-radius: 3px;
  transform: rotate(45deg);
}
:is([data-level="wooden-house"], [data-level="arendelle-village"]) .world-mark::before {
  width: 19px;
  height: 18px;
  background: #ffdfac;
  border-radius: 0;
  transform: none;
  clip-path: polygon(50% 0, 100% 43%, 88% 43%, 88% 100%, 61% 100%, 61% 64%, 39% 64%, 39% 100%, 12% 100%, 12% 43%, 0 43%);
}
[data-level="frozen-castle"] .world-mark::before {
  width: 18px;
  height: 23px;
  background: #d9f4ff;
  border-radius: 0;
  transform: none;
  clip-path: polygon(50% 0, 88% 30%, 88% 66%, 50% 100%, 12% 66%, 12% 30%);
}
.hud-button {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 3px 12px #253e2922;
  pointer-events: auto;
  font: 23px/1 system-ui, sans-serif;
}
.hud-button:hover:not(:disabled) { background: #fff; }
.menu {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: flex;
  align-items: center;
  padding: calc(65px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right))
           calc(21px + env(safe-area-inset-bottom)) calc(clamp(18px, 6.3vw, 102px) + env(safe-area-inset-left));
  background: linear-gradient(90deg, #f1f0db57, #f1f0db00 68%);
}
[data-state="playing"] .menu, [data-state="traveling"] .guide, [data-state="error"] .guide { display: none; }
.menu-content {
  width: min(430px, 100%);
  padding: clamp(18px, 3.7vw, 42px);
  border: 1px solid #ffffffda;
  border-radius: 25px;
  background: var(--surface);
  box-shadow: 0 14px 50px #253e292f;
}
h1 {
  margin: 0 0 13px;
  font-size: clamp(42px, 6.1vw, 74px);
  font-weight: 900;
  line-height: .92;
  letter-spacing: -.075em;
}
h1 span { display: block; color: var(--accent); }
.menu-message { margin: 0; color: var(--muted); font-size: clamp(14px, 1.8vw, 16px); line-height: 1.55; }
.start-button {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
  margin-top: 22px;
  min-height: 46px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fffdf1;
  font-size: 15px;
  font-weight: 800;
  touch-action: manipulation;
}
.start-button:hover:not(:disabled) { background: var(--accent-strong); }
.start-button > :last-child { font-size: 20px; }
.notice { margin: 10px 0 0; font-size: 13px; line-height: 1.35; }
.notice:empty { display: none; }
.guide {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 10px;
  margin-top: 20px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
.guide div { display: flex; align-items: center; gap: 5px; }
kbd {
  padding: 2px 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--accent-strong);
  font: 700 10px/1.2 ui-monospace, monospace;
}
.touch-guide, [data-input="touch"] .desktop-guide { display: none; }
[data-input="touch"] .touch-guide { display: flex; }
[data-controls="two-finger"] .guide .stick-steering,
#game:not([data-controls="two-finger"]) .guide .stick-strafing { display: none; }

.fps-meter {
  position: absolute;
  z-index: 2;
  right: calc(10px + env(safe-area-inset-right));
  bottom: calc(10px + env(safe-area-inset-bottom));
  padding: 5px 8px;
  border-radius: 6px;
  color: #fff;
  background: #182521ed;
  font: 600 12px/1.25 ui-monospace, monospace;
  pointer-events: none;
}

.interaction {
  position: absolute;
  z-index: 2;
  left: var(--interaction-x, 50%);
  top: var(--interaction-y, 68%);
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
}
.interaction-circle {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border: 2px solid #fffdf3;
  border-radius: 50%;
  background: var(--accent);
  color: #fffdf3;
  box-shadow: 0 3px 12px #142f2c55;
  font-size: 20px;
  font-weight: 850;
}
#game[data-input="mouse"] .interaction-circle { font-size: 13px; }
.interaction:hover .interaction-circle, .interaction:focus-visible .interaction-circle { background: var(--accent-strong); }
.interaction-label {
  border-radius: 30px;
  padding: 4px 10px;
  background: var(--surface);
  box-shadow: 0 3px 12px #142f2c35;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.joystick {
  position: absolute;
  z-index: 1;
  left: calc(clamp(17px, 5vw, 54px) + env(safe-area-inset-left));
  bottom: var(--joystick-bottom);
  width: var(--joystick-size);
  aspect-ratio: 1;
  display: none;
  place-items: center;
  border: 2px solid #f9fae9ac;
  border-radius: 50%;
  background: #253e2950;
  touch-action: none;
}
[data-state="playing"][data-input="touch"]:not([data-seated]) .joystick,
[data-state="playing"][data-input="touch"][data-driving] .joystick { display: grid; }
.joystick-thumb {
  width: 42%;
  aspect-ratio: 1;
  border: 2px solid #fffaeac7;
  border-radius: 50%;
  background: #f4f2d3c4;
  box-shadow: 0 3px 9px #172c2140;
  pointer-events: none;
}

@media (max-height: 510px) {
  .hud { padding-top: calc(8px + env(safe-area-inset-top)); }
  .menu { padding-top: calc(58px + env(safe-area-inset-top)); padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .menu-content { width: min(400px, 83vw); padding: 14px 18px; border-radius: 17px; }
  h1 { margin-bottom: 7px; font-size: clamp(34px, 6.5vw, 53px); }
  h1 span { display: inline; }
  .menu-message { font-size: 13px; }
  .start-button { margin-top: 10px; min-height: 40px; }
  .guide { margin-top: 10px; padding-top: 7px; gap: 4px 8px; }
}

.snow-activity {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

#game:not([data-state="playing"]) .snow-activity { display: none; }
.snow-throw-key {
  position: absolute;
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(20px + env(safe-area-inset-bottom));
  margin: 0;
  padding: 6px 10px;
  border-radius: 18px;
  background: #f2faff;
  color: #27495e;
  font-size: 13px;
  font-weight: 750;
  box-shadow: 0 2px 10px #21384f20;
}

.snow-throw {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(22px + env(safe-area-inset-bottom));
  min-width: 66px;
  min-height: 50px;
  padding: 8px 14px;
  border: 2px solid #ebfaff;
  border-radius: 28px;
  background: #316381;
  color: #faffff;
  font-weight: 800;
  box-shadow: 0 3px 11px #21384f45;
  pointer-events: auto;
  touch-action: none;
}
#game[data-input="mouse"] .snow-throw,
#game[data-input="touch"] .snow-throw-key { display: none; }

.game-dialog {
  width: min(680px, calc(100% - 24px));
  max-height: calc(100% - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 20px;
  border: 1px solid #ffffffb8;
  border-radius: 20px;
  background: var(--surface);
  color: inherit;
  box-shadow: 0 16px 48px #26394a44;
}

.game-dialog::backdrop { background: #1f2e3a66; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-header h2 { margin: 0; font-size: 22px; }
.dialog-header .hud-button { box-shadow: none; }

#settings { width: min(400px, calc(100% - 24px)); }
.speed-options { display: grid; gap: 4px; margin-top: 16px; }
.speed-options label { display: flex; justify-content: space-between; align-items: baseline; font-weight: 750; }
.speed-options output { color: var(--muted); font-variant-numeric: tabular-nums; }
.speed-options input { width: 100%; height: 30px; margin: 0 0 4px; accent-color: var(--accent); }
.sound-setting, .control-options label {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff80;
}
.sound-setting { width: 100%; margin-top: 12px; font-weight: 750; }
.control-options { display: grid; gap: 8px; min-width: 0; margin: 12px 0 0; padding: 0; border: 0; }
.control-options legend { margin-bottom: 8px; padding: 0; font-weight: 750; }
.control-options label { cursor: pointer; }
.control-options label:has(:checked) { border-color: var(--accent); }
.control-options input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); }
.control-options small { display: block; color: var(--muted); }

.area-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 18px;
}

.area-card, .restart-level {
  border: 1px solid var(--accent);
  border-radius: 12px;
  color: var(--accent-strong);
  font-weight: 750;
  touch-action: manipulation;
}

.area-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  overflow: hidden;
  border-color: #38504430;
  background: #fffffff0;
  text-align: left;
}

.area-card:hover { border-color: var(--accent-strong); }
.area-card:focus-visible, .restart-level:focus-visible { outline: 3px solid var(--accent-strong); outline-offset: 2px; }
.area-card[aria-current="location"] { border-color: var(--accent-strong); box-shadow: inset 0 0 0 1px var(--accent-strong); }

.area-card img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #e3e4d5;
}

.area-card-title { padding: 8px 10px; line-height: 1.28; }

.area-card-mission-count {
  margin: 0 10px 8px;
  font-size: 12px;
  line-height: 1.25;
}

.area-card-title:has(+ .area-card-mission-count) { padding-bottom: 3px; }

.area-card-completion {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  align-self: flex-start;
  margin: auto 8px 8px;
  padding: 3px 7px;
  border-radius: 6px;
  background: #ddeee5;
  color: #225341;
  font-size: 11.5px;
  line-height: 1.27;
}

.restart-level {
  min-height: 44px;
  padding: 8px 12px;
  background: transparent;
}

@media (max-width: 620px) {
  .game-dialog { padding: 14px; }
  .area-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .area-card-title { font-size: 14px; }
}

.apartment-cinematic {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
#game:not([data-state="playing"]) .apartment-cinematic { display: none; }
.apartment-cinematic-flash {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(ellipse at center, #ffd8a5, #da7d55 75%, #bd4e36);
}
.apartment-cinematic-title {
  position: relative;
  padding: 0.09em 0.25em 0.13em;
  border: 3px solid #ffe0a9;
  border-radius: 0.21em;
  background: #302137e8;
  color: #ffecbc;
  font-size: clamp(3.5rem, 16vw, 8.5rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 0.035em #ab583e;
  box-shadow: 0 6px 24px #180f25a6;
}
.apartment-cinematic-title:empty { display: none; }
@media (prefers-reduced-motion: reduce) {
  .apartment-cinematic-flash { display: none; }
}

#game[data-view="drone"] :is(.mission-hud, .mission-toast, .joystick, .interaction, .snow-activity, .apartment-cinematic),
#game:not([data-state="playing"]) :is(.drone-panel, .drone-marker) { display: none; }
[data-view="drone"] #view { cursor: crosshair; }
.drone-panel {
  position: absolute;
  z-index: 3;
  left: calc(14px + env(safe-area-inset-left));
  bottom: calc(14px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 28px - env(safe-area-inset-left) - env(safe-area-inset-right));
  padding: 9px 11px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 3px 14px #253e2933;
  font-size: 13px;
}
.drone-panel h2 { display: inline; margin: 0 6px 0 0; font-size: 14px; }
.drone-area { display: inline; margin: 0; color: var(--muted); }
.drone-coordinates {
  display: block;
  margin-top: 6px;
  font: 12px/1.4 ui-monospace, monospace;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}
.drone-feedback { margin: 5px 0 0; color: var(--muted); }
.drone-feedback:empty { margin: 0; }
.drone-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.drone-actions button, .drone-entry {
  min-height: 44px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-strong);
  font-weight: 750;
  touch-action: manipulation;
}
#drone-exit { background: var(--accent); color: white; border-color: transparent; }
.drone-entry { min-height: 40px; margin: 4px 0 0 4px; vertical-align: middle; }
.drone-marker {
  position: absolute;
  z-index: 2;
  width: 14px;
  height: 14px;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #21384f, inset 0 0 0 1px #21384f;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#game:not([data-state="paused"]) #pause-reset { display: none; }
