:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background: #d8d0b8;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

html,
body,
#game-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  overscroll-behavior: none;
  touch-action: none;
}

#game-shell {
  position: fixed;
  inset: 0;
  background: #d8d0b8;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  /* Keep the 3D terrain and lighting smooth; pixel-art sprites retain their
     crisp edges through nearest-neighbour texture filtering in the loader. */
  image-rendering: auto;
  touch-action: none;
}

#game-ui {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  color: #fff7e7;
  font-size: 12px;
  letter-spacing: 0.09em;
  text-shadow: 0 1px 3px #172038;
  touch-action: none;
  user-select: none;
}

.touch-device {
  display: block;
}

.move-pad,
.view-button,
.look-pad {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
}

.move-pad {
  left: max(22px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: clamp(100px, 19vw, 148px);
  aspect-ratio: 1;
  border: 2px solid rgb(255 245 225 / 45%);
  border-radius: 50%;
  background: rgb(52 74 61 / 30%);
  box-shadow: inset 0 0 0 12px rgb(255 245 225 / 5%);
}

.move-thumb {
  position: absolute;
  width: 38%;
  aspect-ratio: 1;
  top: 50%;
  left: 50%;
  border: 1px solid rgb(255 255 255 / 68%);
  border-radius: 50%;
  background: rgb(244 219 181 / 62%);
  transform: translate(0, 0);
  margin: -19% 0 0 -19%;
}

.look-pad {
  right: 0;
  top: 0;
  width: 55%;
  height: 100%;
}

.view-button {
  right: max(24px, env(safe-area-inset-right));
  bottom: max(30px, env(safe-area-inset-bottom));
  min-width: 74px;
  height: 58px;
  border: 1px solid rgb(255 244 214 / 72%);
  border-radius: 18px;
  background: rgb(51 74 62 / 78%);
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  pointer-events: auto;
  touch-action: manipulation;
}

.view-button:active {
  background: rgb(88 94 151 / 85%);
}

.rotate-prompt {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgb(49 67 58 / 88%);
  color: #fff7e7;
  font-size: 16px;
  letter-spacing: 0.03em;
  text-shadow: none;
  pointer-events: auto;
}

.rotate-prompt.visible {
  display: flex;
}

.desktop-hint {
  position: absolute;
  left: 24px;
  top: max(20px, env(safe-area-inset-top));
  padding: 10px 14px;
  border: 1px solid rgb(255 245 225 / 22%);
  border-radius: 999px;
  background: rgb(54 72 59 / 58%);
  color: #fff4d7;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 3px #172038;
  pointer-events: none;
  transition: opacity 1.2s ease;
}

.desktop-hint.hidden {
  opacity: 0;
}

.game-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(420px, calc(100vw - 32px));
  max-height: min(78vh, 620px);
  overflow: auto;
  padding: 22px;
  border: 1px solid rgb(103 91 64 / 48%);
  border-radius: 18px;
  background: rgb(238 229 204 / 97%);
  box-shadow: 0 18px 60px rgb(4 8 20 / 54%);
  color: #3e4438;
  pointer-events: auto;
  transform: translate(-50%, -50%);
}

.game-panel[hidden] {
  display: none;
}

.game-panel h2 {
  margin: 0 0 14px;
  font-size: 22px;
}

.energy-hud {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  top: max(18px, env(safe-area-inset-top));
  padding: 9px 13px;
  border: 1px solid rgb(103 91 64 / 48%);
  border-radius: 999px;
  background: rgb(62 83 68 / 78%);
  color: #3e4438;
  font-size: 13px;
  pointer-events: none;
}

.game-toast {
  position: absolute;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  max-width: min(500px, calc(100vw - 32px));
  padding: 10px 16px;
  border: 1px solid rgb(103 91 64 / 38%);
  border-radius: 999px;
  background: rgb(62 83 68 / 91%);
  color: #3e4438;
  text-align: center;
  pointer-events: none;
  transform: translateX(-50%);
}

.action-prompt {
  position: absolute;
  left: 50%;
  bottom: max(74px, calc(env(safe-area-inset-bottom) + 62px));
  padding: 9px 14px;
  border: 1px solid rgb(103 91 64 / 38%);
  border-radius: 999px;
  background: rgb(62 83 68 / 88%);
  color: #3e4438;
  font-size: 13px;
  pointer-events: none;
  transform: translateX(-50%);
}

.action-prompt[hidden] {
  display: none;
}

.game-toast[hidden] {
  display: none;
}

.inventory-details {
  margin-bottom: 12px;
  color: #74654b;
}

.inventory-items,
.inventory-row {
  display: grid;
  gap: 8px;
}

.inventory-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 9px 0;
  border-top: 1px solid rgb(103 91 64 / 22%);
  font-size: 14px;
}

.game-button,
.panel-close {
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid rgb(103 91 64 / 42%);
  border-radius: 10px;
  background: #66816a;
  color: #3e4438;
  font: inherit;
  pointer-events: auto;
  cursor: pointer;
}

.game-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.panel-close {
  margin-top: 12px;
  background: #8a6b4d;
}

.panel-status {
  min-height: 1.3em;
  margin: 12px 0 0;
  color: #8b5c3c;
}

.trade-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-top: 1px solid rgb(103 91 64 / 22%);
}

.action-button {
  position: absolute;
  right: max(112px, calc(env(safe-area-inset-right) + 100px));
  bottom: max(30px, env(safe-area-inset-bottom));
  min-width: 88px;
  min-height: 58px;
  border: 1px solid rgb(255 244 214 / 72%);
  border-radius: 18px;
  background: rgb(133 83 58 / 91%);
  color: #fff7e7;
  pointer-events: auto;
  touch-action: manipulation;
}

.inventory-touch-button {
  position: absolute;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(100px, calc(env(safe-area-inset-bottom) + 82px));
  min-width: 74px;
  min-height: 46px;
  border: 1px solid rgb(255 244 214 / 72%);
  border-radius: 15px;
  background: rgb(31 37 73 / 74%);
  color: #fff7e7;
  pointer-events: auto;
  touch-action: manipulation;
}

@media (pointer: coarse) {
  .desktop-hint {
    display: none;
  }

  .action-prompt {
    display: none;
  }
}


.sound-toggle {
  position: absolute;
  left: 24px;
  top: max(62px, calc(env(safe-area-inset-top) + 56px));
  padding: 9px 13px;
  border: 1px solid rgb(255 244 214 / 52%);
  border-radius: 999px;
  background: rgb(62 83 68 / 82%);
  color: #fff4d7;
  font: inherit;
  font-size: 12px;
  pointer-events: auto;
  touch-action: manipulation;
}

.sound-toggle:focus-visible {
  outline: 2px solid #fff4d7;
  outline-offset: 3px;
}

/* Art-direction contrast pass: parchment panels, readable ivory HUD. */
.touch-controls,
.desktop-hint,
.energy-hud,
.game-toast,
.action-prompt,
.view-button,
.action-button,
.inventory-touch-button,
.sound-toggle,
.game-button,
.panel-close {
  color: #fff3d8;
}

.desktop-hint,
.energy-hud,
.game-toast,
.action-prompt,
.sound-toggle,
.inventory-touch-button,
.view-button {
  border-color: rgb(244 226 185 / 48%);
}

.game-panel {
  background: rgb(241 232 210 / 97%);
  color: #3e4438;
  border-color: rgb(117 101 71 / 55%);
}

.game-panel h2 {
  color: #365a4b;
}

.game-button {
  background: #52745d;
}

.panel-close {
  background: #8a6247;
}
.camera-distance-control {
  position: absolute;
  left: 24px;
  top: max(108px, calc(env(safe-area-inset-top) + 102px));
  display: grid;
  gap: 6px;
  width: 190px;
  padding: 10px 12px;
  border: 1px solid rgb(244 226 185 / 48%);
  border-radius: 14px;
  background: rgb(54 72 59 / 82%);
  color: #fff3d8;
  font-size: 12px;
  pointer-events: auto;
  text-shadow: 0 1px 3px #172038;
}

.camera-distance-control input {
  width: 100%;
  margin: 0;
  accent-color: #e4c48c;
  cursor: pointer;
  touch-action: pan-x;
}

.time-control {
  position: absolute;
  z-index: 4;
  left: 24px;
  top: max(192px, calc(env(safe-area-inset-top) + 186px));
  display: grid;
  gap: 7px;
  width: 190px;
  padding: 10px 12px;
  border: 1px solid rgb(244 226 185 / 48%);
  border-radius: 14px;
  background: rgb(35 43 67 / 88%);
  color: #fff3d8;
  font-size: 12px;
  text-shadow: 0 1px 3px #172038;
  pointer-events: auto;
}

.time-control select {
  width: 100%;
  min-height: 32px;
  padding: 5px 8px;
  border: 1px solid rgb(244 226 185 / 55%);
  border-radius: 8px;
  background: #e9e3d2;
  color: #33463a;
  font: inherit;
  text-shadow: none;
}

.time-status {
  line-height: 1.4;
  font-weight: 600;
}

/* Top-right live compass and destination map. */
.navigation-widget {
  position: absolute;
  z-index: 5;
  top: max(64px, calc(env(safe-area-inset-top) + 58px));
  right: max(14px, env(safe-area-inset-right));
  width: min(278px, calc(100vw - 24px));
  color: #fff3d8;
  pointer-events: auto;
  font-size: 12px;
  line-height: 1.35;
  text-shadow: 0 1px 2px rgb(10 22 18 / 60%);
}

.navigation-toggle {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 54px;
  padding: 7px 10px;
  border: 1px solid rgb(244 226 185 / 55%);
  border-radius: 15px;
  background: rgb(40 59 47 / 91%);
  box-shadow: 0 5px 16px rgb(18 26 19 / 22%);
  color: #fff3d8;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.navigation-toggle:focus-visible,
.navigation-destination-button:focus-visible,
.navigation-map-marker:focus-visible {
  outline: 2px solid #f2d397;
  outline-offset: 2px;
}

.navigation-compass {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid rgb(237 213 166 / 56%);
  border-radius: 50%;
  background: #31483b;
}

.navigation-compass-ring {
  position: relative;
  display: block;
  width: 27px;
  height: 27px;
  border: 1px solid rgb(237 213 166 / 54%);
  border-radius: 50%;
  background: linear-gradient(135deg, rgb(255 250 226 / 9%), rgb(2 15 12 / 30%));
}

.navigation-needle {
  position: absolute;
  left: 8px;
  top: 2px;
  display: block;
  width: 10px;
  height: 21px;
  transform-origin: 50% 11.5px;
  transition: transform 100ms linear;
}

.navigation-needle::before {
  content: "";
  position: absolute;
  z-index: 1;
  top: 0;
  left: 1px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 11px solid #f2d397;
  filter: drop-shadow(0 0 1px #26372b);
}

.navigation-needle::after {
  content: "";
  position: absolute;
  top: 8px;
  left: 4px;
  width: 2px;
  height: 10px;
  border-radius: 2px;
  background: #f2d397;
  box-shadow: 0 0 1px #26372b;
}

.navigation-summary {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.navigation-summary-title {
  overflow: hidden;
  color: #fff3d8;
  font-weight: 750;
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.navigation-summary-details {
  color: #d3dfc9;
  font-size: 11px;
}

.navigation-toggle-glyph {
  align-self: center;
  color: #f2d397;
  font-size: 18px;
  padding: 0 3px;
}

.navigation-panel {
  display: grid;
  gap: 8px;
  margin-top: 7px;
  max-height: min(72vh, 580px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px;
  border: 1px solid rgb(244 226 185 / 50%);
  border-radius: 16px;
  background: rgb(32 48 39 / 96%);
  box-shadow: 0 12px 34px rgb(12 20 15 / 42%);
  backdrop-filter: blur(10px);
  scrollbar-width: thin;
  scrollbar-color: #9baf8c #2a3d31;
}

.navigation-panel[hidden] {
  display: none;
}

.navigation-panel-heading {
  display: grid;
  gap: 2px;
}

.navigation-panel-title {
  color: #f2d397;
  font-weight: 800;
  font-size: 14px;
}

.navigation-panel-subtitle {
  color: #d2ddcc;
  font-size: 11px;
}

.navigation-map {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  border: 1px solid rgb(216 225 202 / 23%);
  border-radius: 10px;
  background: #344b3d;
  touch-action: manipulation;
}

.navigation-map-ground {
  fill: #415a47;
}

.navigation-map-route {
  fill: none;
  stroke: #c3d0ab;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.44;
  stroke-dasharray: 2 2.5;
}

.navigation-map-route.is-route-active {
  opacity: 0.76;
  stroke: #e9d5a1;
  stroke-width: 2.1;
}

.navigation-map-route-active {
  fill: none;
  stroke: #f1cf83;
  stroke-width: 2.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 1px #3a4334);
  pointer-events: none;
}

.navigation-map-bearing-line {
  stroke: #fff1b9;
  stroke-width: 1.3;
  stroke-dasharray: 2 2;
  opacity: 0.95;
  pointer-events: none;
}

.navigation-map-player-marker {
  pointer-events: none;
  filter: drop-shadow(0 0 2px #0e2018);
}

.navigation-map-player-marker > circle:first-child {
  fill: #f3f1d5;
  stroke: #263d58;
  stroke-width: 2.2;
}

.navigation-map-player-core {
  fill: #8ed7ef;
}

.navigation-map-marker {
  cursor: pointer;
  outline: none;
}

.navigation-marker-hitbox {
  fill: transparent;
  stroke: transparent;
  stroke-width: 1.3;
}

.navigation-map-marker:hover .navigation-marker-hitbox,
.navigation-map-marker:focus-visible .navigation-marker-hitbox,
.navigation-map-marker.is-target .navigation-marker-hitbox {
  fill: rgb(255 244 210 / 14%);
  stroke: #fff0bb;
}

.navigation-map-marker-core {
  fill: #f0d7a0;
  stroke: #293e31;
  stroke-width: 1.3;
}

.navigation-map-marker--village .navigation-map-village-star {
  fill: #ffe7a1;
  stroke: #4b3826;
  stroke-width: 0.9;
}

.navigation-map-marker--bamboo .navigation-map-marker-core {
  fill: #91ce8b;
}

.navigation-map-marker--wetland .navigation-map-marker-core {
  fill: #7ccdd3;
}

.navigation-map-marker--snow .navigation-map-marker-core {
  fill: #f5f4e5;
}

.navigation-map-marker--ruins .navigation-map-marker-core {
  fill: #b7aa91;
}

.navigation-map-marker--desert .navigation-map-marker-core {
  fill: #e4b36e;
}

.navigation-map-marker--volcano .navigation-map-marker-core {
  fill: #ff855e;
}

.navigation-map-marker--cave .navigation-map-marker-core {
  fill: #a8a3f0;
}

.navigation-map-label {
  fill: #f3f2d9;
  font-size: 7.7px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #2a3f32;
  stroke-width: 2.2px;
  stroke-linejoin: round;
  pointer-events: none;
}

.navigation-map-label--village {
  fill: #ffe7a1;
}

.navigation-map-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  color: #d2ddcc;
  font-size: 10px;
}

.navigation-map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.navigation-legend-dot {
  display: inline-grid;
  place-items: center;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #8ed7ef;
  color: #ffe7a1;
  font-size: 11px;
  font-style: normal;
  text-shadow: none;
}

.navigation-legend-dot--village {
  background: transparent;
  border-radius: 0;
}

.navigation-village-callout {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  border: 1px solid rgb(243 215 156 / 35%);
  border-radius: 9px;
  background: rgb(242 211 151 / 9%);
  color: #f6e4b9;
  font-size: 10px;
}

.navigation-village-callout-pin {
  color: #ffe7a1;
  font-size: 15px;
}

.navigation-destination-heading {
  margin-top: 2px;
  color: #f2d397;
  font-size: 11px;
  font-weight: 800;
}

.navigation-destination-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

.navigation-destination-button {
  min-width: 0;
  min-height: 31px;
  overflow: hidden;
  padding: 5px 7px;
  border: 1px solid rgb(217 228 205 / 24%);
  border-radius: 8px;
  background: rgb(230 237 212 / 7%);
  color: #e5ebd8;
  font: inherit;
  font-size: 10px;
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  touch-action: manipulation;
}

.navigation-destination-button:hover {
  background: rgb(230 237 212 / 14%);
}

.navigation-destination-button.is-selected {
  border-color: #e9c77d;
  background: rgb(233 199 125 / 18%);
  color: #ffe7ae;
  font-weight: 800;
}

.navigation-selected-coordinates {
  color: #b8c8b2;
  font-size: 10px;
}

@media (max-width: 700px) {
  .navigation-widget {
    top: max(62px, calc(env(safe-area-inset-top) + 54px));
    right: max(8px, env(safe-area-inset-right));
    width: min(248px, calc(100vw - 16px));
  }

  .navigation-toggle {
    min-height: 49px;
    padding: 6px 8px;
    gap: 7px;
  }

  .navigation-compass {
    width: 32px;
    height: 32px;
    flex-basis: 32px;
  }

  .navigation-compass-ring {
    width: 25px;
    height: 25px;
  }

  .navigation-needle {
    left: 7px;
  }

  .navigation-panel {
    padding: 9px;
    gap: 7px;
    max-height: min(66vh, 510px);
  }
}

@media (max-height: 500px) {
  .navigation-widget {
    top: max(54px, calc(env(safe-area-inset-top) + 46px));
  }

  .navigation-panel {
    max-height: calc(100vh - 145px);
    padding: 8px 9px;
    gap: 6px;
  }

  .navigation-map {
    max-height: 145px;
  }
}

/* Landscape touch devices: keep environment controls clear of the left joystick
   and the right-side action buttons, while preserving the compact HUD. */
@media (pointer: coarse) and (max-height: 500px) {
  .time-control {
    left: auto;
    right: max(14px, env(safe-area-inset-right));
    width: 164px;
    padding: 8px 10px;
    gap: 5px;
    font-size: 10px;
  }

  .time-control {
    top: max(176px, calc(env(safe-area-inset-top) + 172px));
  }

  .time-control select {
    min-height: 28px;
    padding: 4px 7px;
  }

  .time-status {
    line-height: 1.2;
  }
}


/* Cinematic HUD layout: move controls to the lower edge so opaque UI panels
   visually mask part of the near-field lens blur and soften the focus transition. */
.desktop-hint {
    top: auto;
    bottom: max(18px, env(safe-area-inset-bottom));
  }

.sound-toggle {
  top: auto;
  bottom: max(64px, calc(env(safe-area-inset-bottom) + 46px));
}

.camera-distance-control {
  top: auto;
  bottom: max(112px, calc(env(safe-area-inset-bottom) + 94px));
}

.time-control {
  top: auto;
  bottom: max(296px, calc(env(safe-area-inset-bottom) + 278px));
}

.energy-hud {
  top: auto;
  bottom: max(18px, env(safe-area-inset-bottom));
}

.navigation-widget {
  top: auto;
  bottom: max(68px, calc(env(safe-area-inset-bottom) + 50px));
}

.navigation-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 7px);
  margin-top: 0;
}

/* Touch screens keep controls above the movement pad, but still lower than the
   old top-heavy layout. Keep the joystick/action zones free of control cards. */
@media (pointer: coarse) and (min-height: 501px) {
  .camera-distance-control,
  .time-control {
    left: max(14px, env(safe-area-inset-left));
    right: auto;
    width: min(178px, calc(50vw - 24px));
  }

  .camera-distance-control {
    top: auto;
    bottom: max(188px, calc(env(safe-area-inset-bottom) + 168px));
  }

  .time-control {
    top: auto;
    bottom: max(368px, calc(env(safe-area-inset-bottom) + 348px));
  }

  .navigation-widget {
    top: auto;
    bottom: max(104px, calc(env(safe-area-inset-bottom) + 86px));
  }

  .navigation-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 7px);
    margin-top: 0;
  }
}


/* Portrait-first responsive layout: keep all play actions accessible without an
   orientation-blocking overlay. Preserve room for the world view above controls. */
@media (orientation: portrait) and (max-width: 700px) {
  .touch-controls {
    font-size: 10px;
    letter-spacing: 0.06em;
  }

  .look-pad {
    top: 0;
    right: 0;
    width: 56%;
    height: calc(100% - max(142px, env(safe-area-inset-bottom) + 122px));
  }

  .move-pad {
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: clamp(100px, 29vw, 124px);
  }

  .view-button {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
    min-width: 68px;
    min-height: 48px;
    height: 48px;
    border-radius: 14px;
    font-size: 10px;
  }

  .action-button {
    right: max(92px, calc(env(safe-area-inset-right) + 82px));
    bottom: max(14px, env(safe-area-inset-bottom));
    min-width: 76px;
    min-height: 48px;
    border-radius: 14px;
    font-size: 10px;
  }

  .inventory-touch-button {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(72px, calc(env(safe-area-inset-bottom) + 62px));
    min-width: 68px;
    min-height: 40px;
    border-radius: 12px;
    font-size: 9px;
  }

  .camera-distance-control,
  .time-control {
    left: max(10px, env(safe-area-inset-left));
    right: auto;
    width: min(164px, calc(50vw - 18px));
    padding: 7px 9px;
    gap: 5px;
    font-size: 10px;
    border-radius: 11px;
  }

  .camera-distance-control {
    top: auto;
    bottom: max(156px, calc(env(safe-area-inset-bottom) + 142px));
  }

  .time-control {
    top: auto;
    bottom: max(238px, calc(env(safe-area-inset-bottom) + 224px));
  }

  .time-control select {
    min-height: 28px;
    padding: 4px 6px;
    font-size: 10px;
  }

  .time-status {
    line-height: 1.2;
  }

  .sound-toggle {
    left: max(10px, env(safe-area-inset-left));
    top: max(10px, env(safe-area-inset-top));
    bottom: auto;
    padding: 7px 9px;
    font-size: 10px;
  }

  .energy-hud {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    bottom: auto;
    padding: 6px 9px;
    font-size: 10px;
  }

  .navigation-widget {
    top: max(48px, calc(env(safe-area-inset-top) + 42px));
    right: max(10px, env(safe-area-inset-right));
    bottom: auto;
    width: min(220px, calc(100vw - 20px));
    font-size: 10px;
  }

  .navigation-toggle {
    min-height: 42px;
    padding: 5px 7px;
    gap: 6px;
    border-radius: 12px;
  }

  .navigation-compass {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
  }

  .navigation-compass-ring {
    width: 23px;
    height: 23px;
  }

  .navigation-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    bottom: auto;
    margin-top: 0;
    max-height: min(46vh, 360px);
    overflow: auto;
    padding: 8px;
    gap: 6px;
  }

  .navigation-map {
    max-height: 120px;
  }

  .game-panel {
    width: calc(100vw - 24px);
    max-height: 72dvh;
    padding: 16px;
    border-radius: 14px;
  }

  .game-panel h2 {
    font-size: 19px;
    margin-bottom: 10px;
  }

  .game-toast {
    bottom: max(132px, calc(env(safe-area-inset-bottom) + 120px));
    max-width: calc(100vw - 24px);
    padding: 8px 11px;
    font-size: 11px;
  }

  .action-prompt {
    bottom: max(128px, calc(env(safe-area-inset-bottom) + 116px));
    max-width: calc(100vw - 28px);
    font-size: 11px;
  }
}

@media (orientation: portrait) and (max-width: 380px) {
  .camera-distance-control,
  .time-control {
    width: min(146px, calc(48vw - 14px));
  }

  .navigation-widget {
    width: min(196px, calc(100vw - 20px));
  }

  .navigation-toggle {
    min-height: 38px;
  }

  .navigation-compass {
    flex-basis: 26px;
    width: 26px;
    height: 26px;
  }

  .navigation-compass-ring {
    width: 20px;
    height: 20px;
  }
}

/* Final compact landscape touch layout: separate the control columns so HUD
   cards never cover the joystick, action buttons or one another. */
@media (pointer: coarse) and (max-height: 500px) {
  .camera-distance-control {
    left: max(14px, env(safe-area-inset-left));
    top: max(14px, env(safe-area-inset-top));
    bottom: auto;
    width: 190px;
  }

  .sound-toggle {
    left: max(14px, env(safe-area-inset-left));
    top: max(88px, calc(env(safe-area-inset-top) + 78px));
    bottom: auto;
  }

  .time-control {
    left: auto;
    right: max(14px, env(safe-area-inset-right));
    width: 164px;
    padding: 8px 10px;
    gap: 5px;
    font-size: 10px;
  }

  .time-control {
    top: max(88px, calc(env(safe-area-inset-top) + 78px));
    bottom: auto;
  }

  .time-control select {
    min-height: 28px;
    padding: 4px 7px;
  }

  .time-status {
    line-height: 1.2;
  }

  .navigation-widget {
    top: auto;
    bottom: max(158px, calc(env(safe-area-inset-bottom) + 144px));
    right: max(14px, env(safe-area-inset-right));
    width: min(278px, calc(100vw - 300px));
  }

  .energy-hud {
    top: max(14px, env(safe-area-inset-top));
    bottom: auto;
    right: max(200px, calc(env(safe-area-inset-right) + 186px));
    padding: 7px 10px;
    font-size: 11px;
  }
}
