:root {
  color-scheme: light;
  --ink: #302943;
  --accent: #37685e;
  --panel: #fff7e6f5;
  --line: #a48eaa70;
  --paper: #fff8e9;
  --lavender: #e7dbf1;
  --body-text: #564860;
  --shadow: #46325548;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

html, body { overscroll-behavior: none; }
body { background: #80c9cc; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button {
  background: #fff9ea;
  color: var(--ink);
  border: 1px solid #a58eab;
  border-radius: 9px;
  box-shadow: 0 2px #9678a03d;
}
button:hover, button:active { background: #f3e5ff; border-color: #886596; }
button:focus-visible { outline-color: #7e5697; }
.top {
  background: linear-gradient(#4632506b, transparent);
  align-items: flex-start;
}
.brand {
  padding: 7px 14px 7px 8px;
  border: 1px solid #aa8da5;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 3px 0 #7c59754a, 0 5px 14px var(--shadow);
}
.brand-icon {
  border: 2px solid #d9918c;
  border-radius: 12px;
  background: #ffdb9c;
  color: #904766;
  font: 700 30px/1 Georgia, serif;
  box-shadow: inset 0 0 0 2px #fff5df;
}
h1, .dialog-top h2 { font-family: Georgia, "Times New Roman", serif; }
h1 { color: #423052; letter-spacing: -.035em; }
#district, .clock { color: #634f72; }
.clock, .cash {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .28rem .56rem;
  box-shadow: 0 2px 0 #70566938;
}
.cash { color: #245d51; }
.objective, .loadout, .mini, .speed, .notice, .prompt, .flight-hint {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid #aa8da5;
  border-radius: 13px;
  box-shadow: 0 3px 0 #78547c45, 0 8px 17px var(--shadow);
}
.objective { border-left: 4px solid #bd7d9d; }
.objective p, .mini span, .speed div span, .condition, .legend, .map-footer { color: var(--body-text); }
.speed strong { color: #4e365e; }
.wanted { color: #a43e5d; }
#armor-readout { color: #335c90; }
#escape-readout { color: #6c4168; }
progress { accent-color: #70a892; }
#armor { accent-color: #628dcc; }
.speed #vehicle-health { accent-color: #cb7e67; }
.mini canvas { background: #9ad5cf; border-radius: 8px; }
.mini span { font-weight: 700; }
.keys-hint { background: #fff8eadf; color: var(--ink); border: 1px solid #ab8eab60; border-radius: 9px; }
kbd { background: #e7dcf0; color: #47375c; border: 1px solid #a389a7; }
dialog {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid #b593a8;
  border-radius: 17px;
  box-shadow: 0 0 0 3px #e7c7d5b5, 0 16px 60px #42304d72;
}
dialog::backdrop { background: #45335785; }
.dialog-top { padding: 2px 0 9px; border-bottom: 1px solid #e5d2dd; }
.dialog-top h2 { color: #573861; font-weight: 700; }
#bigMap { background: #b5ddd6; border: 1px solid #a687b161; border-radius: 9px; }
.shop-item { background: linear-gradient(120deg, #fffaf1, #f8edf5); border-color: #e1cadb; border-radius: 11px; }
.shop-item span, #shop-message, .job-board-row p, .contact-brief, #helpDialog p { color: var(--body-text); }
.primary, .touch-actions #touchAction { background: #d9efcc; color: #25493c; border-color: #81a88c; }
.legend i { box-shadow: 0 0 0 1px #68487590; }
.legend .contact-dot { background: #f7c898; }
.legend .bike-dot { background: #85dbca; }
.legend .fleet-dot { background: #bca0ea; }
.touch button { background: #fff6e7e8; color: var(--ink); border-color: #9d7aa4; }
.touch button[aria-pressed="true"] { background: #ead7f5; }
.joystick {
  --thumb-x: 0px;
  --thumb-y: 0px;
  width: 108px;
  height: 108px;
  flex: 0 0 auto;
  align-self: end;
  display: none;
  place-items: center;
  position: relative;
  border: 2px solid #9d7aa4;
  border-radius: 50%;
  background: #fff6e7d9;
  box-shadow: inset 0 0 0 5px #e8d7ec8c, 0 3px 12px var(--shadow);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.joystick::before {
  position: absolute;
  inset: 12px;
  border: 1px solid #a98ca66e;
  border-radius: 50%;
  content: "";
  pointer-events: none;
}
.joystick-thumb {
  width: 43%;
  aspect-ratio: 1;
  border: 1px solid #a888aa;
  border-radius: 50%;
  background: linear-gradient(#fdf4f8, #e2ccea);
  box-shadow: 0 2px 6px #50395443;
  transform: translate(var(--thumb-x), var(--thumb-y));
  pointer-events: none;
}
.joystick[data-active] .joystick-thumb { background: linear-gradient(#f5e8ff, #cbaee1); }
.drive-controls,
.vehicle-readout {
  display: grid;
  justify-items: end;
  align-content: end;
  gap: 8px;
}
#game {
  position: fixed;
  inset: var(--game-top, 0px) auto auto var(--game-left, 0px);
  width: var(--game-width, 100%);
  height: 100vh;
  height: var(--game-height, 100dvh);
  transform: var(--game-fit, none);
  transform-origin: top left;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}
dialog { touch-action: pan-y pinch-zoom; }
@media (orientation: landscape) and (max-height: 520px) {
  .top {
    padding: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 9px)
      15px calc(var(--safe-left) + 9px);
  }
  .top-actions { gap: 5px; }
  .top-actions button { padding: .25rem .55rem; }
  .brand { padding: 4px 8px; gap: 6px; }
  .brand-icon { width: 27px; height: 27px; font-size: 21px; }
  .brand h1 { font-size: 1.15rem; }
  .objective {
    top: calc(var(--safe-top) + 53px);
    left: calc(var(--safe-left) + 9px);
    width: min(235px, 39vw);
    padding: 5px 8px;
  }
  .objective h2 { font-size: .94rem; }
  .objective p { font-size: .76rem; }
  .loadout {
    top: calc(var(--safe-top) + 53px);
    right: calc(var(--safe-right) + 9px);
    min-width: 92px;
    padding: 5px 7px;
  }
  dialog { max-height: calc(100% - var(--safe-top) - var(--safe-bottom) - 14px); }
  #bigMap { max-height: 54dvh; }
}
@media (orientation: landscape) and (max-height: 520px) and (any-pointer: coarse),
       (orientation: landscape) and (max-height: 520px) and (max-width: 720px) {
  .touch {
    justify-content: space-between;
    inset: auto calc(var(--safe-right) + 9px) calc(var(--safe-bottom) + 8px)
      calc(var(--safe-left) + 9px);
  }
  .joystick { display: grid; width: clamp(72px, 23vh, 96px); height: clamp(72px, 23vh, 96px); }
  .drive-controls { grid-auto-flow: column; align-items: end; }
  .touch-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(60px, 1fr));
    gap: 4px;
  }
  .touch button { min-height: 38px; padding: 3px 7px; font-size: .79rem; pointer-events: auto; }
  .mini {
    left: calc(var(--safe-left) + 9px);
    bottom: calc(var(--safe-bottom) + clamp(83px, calc(23vh + 12px), 108px));
  }
  .mini canvas { width: 68px; height: 53px; }
  .mini span { display: none; }
  .speed {
    padding: 5px 7px;
    width: 85px;
  }
  .speed strong { font-size: 1.35rem; }
  .flight-hint { max-width: min(160px, 29vw); }
  .prompt { bottom: calc(var(--safe-bottom) + 10px); max-width: 30vw; white-space: normal; }
  .prompt kbd { display: none; }
}
@media (pointer: coarse), (max-width: 720px) {
  .joystick { display: grid; }
  .brand { padding: 6px 7px; }
  .cash { padding: .2rem .32rem; }
}

button.prompt { pointer-events: auto; touch-action: none; cursor: pointer; }
button.prompt kbd { display: inline-block; }
.flight-hint { pointer-events: auto; }
#flight-guide { display: block; margin-bottom: .35rem; }
#flightTouch { min-height: 44px; width: 100%; background: #d9efcc; }

.legend .arcade-dot { background: #e8a6f6; }
.legend .landmark-dot { background: #80cfbc; }
#bullDialog { width: min(940px, calc(100% - 16px)); padding: 8px; }
#bullFrame {
  display: block;
  width: 100%;
  height: clamp(180px, calc(92dvh - 58px), 740px);
  border: 0;
  border-radius: 8px;
  background: #0d171c;
}
.map-destination { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.map-destination select {
  flex: 1 1 12rem;
  min-width: 0;
  border: 1px solid #a58eab;
  border-radius: 9px;
  background: #fff9ea;
  color: var(--ink);
  padding: .45rem .55rem;
  font: inherit;
}
#arcadeDialog { width: min(570px, calc(100% - 20px)); padding: 12px; }
.arcade-layout {
  display: grid;
  justify-items: center;
  align-items: center;
  gap: 8px;
}
#arcadeScreen {
  display: block;
  width: min(100%, 360px);
  height: auto;
  border: 2px solid #9776ad;
  border-radius: 8px;
  background: #151a31;
}
.arcade-controls {
  display: grid;
  gap: 6px;
  width: min(100%, 360px);
  font-size: .86rem;
}
.arcade-scores, .arcade-buttons { display: flex; justify-content: space-between; gap: 6px; }
.arcade-scores { color: #614570; font-variant-numeric: tabular-nums; }
#arcadeMessage:empty { display: none; }
#arcadeMessage { font-weight: 700; }
#arcadeStart { background: #d9efcc; }
.arcade-buttons button { flex: 1; min-height: 44px; padding: 4px; }
.arcade-buttons button,
#arcadeDialog:is([data-cabinet="maze"], [data-cabinet="bricks"]) #arcadeScreen {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
#arcadeDialog[data-cabinet="bricks"] #arcadeScreen { cursor: ew-resize; }
#arcadeDialog[data-cabinet="maze"] .arcade-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(44px, 1fr));
  grid-template-areas: ". up ." "left down right";
}
[data-arcade-direction="left"] { grid-area: left; }
[data-arcade-direction="right"] { grid-area: right; }
[data-arcade-direction="up"] { grid-area: up; }
[data-arcade-direction="down"] { grid-area: down; }
#arcadeDialog[data-horizontal="true"] :is([data-arcade-direction="up"],[data-arcade-direction="down"]) {
  display: none;
}
#tankRange, #rangeLaunch { background: #d9efcc; min-height: 44px; pointer-events: auto; }
#rangeControls:not([hidden]) { display: grid; gap: 5px; }
#rangeControls label { display: flex; align-items: center; gap: 6px; font-weight: 700; }
#rangeControls input { width: 100%; min-height: 32px; accent-color: #587c70; }
#rangeTurn { font-weight: 700; }
#arcadeDialog[data-cabinet="range"] .arcade-buttons { display: none; }
#arcadeDialog[data-cabinet="range"] {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  background: #253359;
}
#arcadeDialog[data-cabinet="range"] .arcade-layout { display: contents; }
#arcadeDialog[data-cabinet="range"] .dialog-top {
  position: absolute;
  z-index: 1;
  inset: calc(var(--safe-top) + 6px) calc(var(--safe-right) + 8px) auto calc(var(--safe-left) + 8px);
  margin: 0;
  pointer-events: none;
}
#arcadeDialog[data-cabinet="range"] .dialog-top h2 {
  padding: 4px 9px;
  background: #fff8e9ef;
  border-radius: 9px;
  font-size: clamp(1.05rem, 3vw, 1.45rem);
}
#arcadeDialog[data-cabinet="range"] .dialog-top button {
  min-width: 44px;
  min-height: 44px;
  pointer-events: auto;
}
#arcadeDialog[data-cabinet="range"] .arcade-controls {
  position: absolute;
  z-index: 1;
  bottom: calc(var(--safe-bottom) + 6px);
  left: max(8px, var(--safe-left), calc(50% - 390px));
  right: max(8px, var(--safe-right), calc(50% - 390px));
  width: auto;
  gap: 5px;
  padding: 6px 9px;
  border: 1px solid #a58eab;
  border-radius: 10px;
  background: #fff8e9f5;
}
#arcadeDialog[data-cabinet="range"] #arcadeScreen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: crosshair;
}
#arcadeDialog[data-cabinet="range"] #arcadeHelp { font-size: .78rem; }
#arcadeDialog[data-cabinet="range"][data-range-playing] #arcadeHelp { display: none; }
#arcadeDialog[data-cabinet="range"]:not([data-range-playing]) #rangeControls > :is(label, button, #rangeTurn) {
  display: none;
}
#arcadeDialog[data-cabinet="range"] #arcadeStart { min-height: 44px; }
#arcadeDialog[data-cabinet="range"] #rangeControls {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
}
#rangeControls :is(#rangeArena, #rangeTurn) { grid-column: 1 / -1; }
#rangeControls input { min-width: 0; }
#rangeArena { color: #614570; font-weight: 750; }
#rangeControls select {
  font: inherit; min-height: 44px; flex: 1; min-width: 0; color: var(--ink);
  border: 1px solid #a58eab; border-radius: 7px; background: #fff9ea;
}
@media (orientation: landscape) and (max-height: 520px) {
  .arcade-layout { grid-template-columns: minmax(0, 2fr) minmax(130px, 1fr); }
  #arcadeScreen { width: min(100%, 360px, calc((100dvh - 76px) * 1.40625)); }
  .arcade-controls { font-size: .79rem; }
  #arcadeDialog[data-cabinet="range"] #rangeControls { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #rangeControls #rangeArena { grid-column: 1 / 4; }
  #rangeControls #rangeTurn { grid-column: 4; text-align: right; }
  #arcadeDialog[data-cabinet="range"] .arcade-controls { bottom: calc(var(--safe-bottom) + 3px); }
}
