:root {
  color-scheme: dark;
  --ink: #1d2a23;
  --ink-soft: #33473a;
  --paper: #f5f1e4;
  --paper-soft: rgba(245, 241, 228, 0.88);
  --map: #d8c58f;
  --map-shadow: #b79b64;
  --nest: #b86b4f;
  --ant: #241e1d;
  --trail-weak: #a88958;
  --trail-strong: #735136;
  --teal: #8ed3bd;
  --pink: #ee6b9a;
  --line: rgba(238, 229, 193, 0.26);
  --muted: #c5c4b3;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: #eef3ef;
}

body {
  color: var(--paper);
  overscroll-behavior-x: none;
}

button,
select {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:focus-visible,
select:focus-visible,
#ant-map:focus-visible {
  outline: 2px solid #ffe3a4;
  outline-offset: 3px;
}

.page-shell {
  width: 100%;
  overflow-x: hidden;
  background: #eef3ef;
}

.site-header,
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 52px;
  padding: 12px max(20px, calc((100vw - 1180px) / 2));
  color: #edf5f0;
  background: #0a110f;
}

.site-logo,
.site-nav a,
.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-logo {
  color: #8de8d8;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 800;
}

.site-nav,
.site-footer {
  display: flex;
  flex-wrap: wrap;
}

.site-nav {
  justify-content: flex-end;
  gap: 8px 18px;
  font-size: 0.78rem;
}

.site-nav a:hover,
.site-footer a:hover {
  color: #e4b96d;
}

.site-footer {
  justify-content: center;
  font-size: 0.75rem;
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  min-height: 38px;
  padding: 9px max(20px, calc((100vw - 1180px) / 2));
  color: #a7bab1;
  background: #111b18;
  font-size: 0.7rem;
}

.breadcrumb a {
  color: #8de8d8;
}

.app-shell {
  position: relative;
  width: 100%;
  height: max(620px, 100dvh);
  min-height: 620px;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 48%, rgba(92, 123, 82, 0.28), transparent 39%),
    linear-gradient(145deg, #17221c, #27372a 62%, #17221c);
}

#ant-map {
  position: absolute;
  z-index: 0;
  top: 50%;
  left: 50%;
  display: block;
  width: min(80vw, 78dvh, 512px);
  height: min(80vw, 78dvh, 512px);
  border: 2px solid rgba(254, 229, 164, 0.54);
  border-radius: 4px;
  background: var(--map);
  box-shadow:
    0 0 0 8px rgba(14, 22, 17, 0.25),
    0 26px 80px rgba(0, 0, 0, 0.42);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  transform: translate(-50%, -50%);
  touch-action: none;
}

.pixel-vignette {
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, transparent 32%, rgba(8, 15, 11, 0.2) 100%);
}

.site-head {
  position: absolute;
  z-index: 3;
  top: max(20px, env(safe-area-inset-top));
  left: max(24px, env(safe-area-inset-left));
  width: min(440px, calc(100vw - 48px));
  pointer-events: none;
  text-shadow: 0 3px 20px rgba(0, 0, 0, 0.45);
}

.eyebrow,
.panel-kicker,
.usage-kicker {
  margin: 0 0 8px;
  color: #f4d994;
  font-size: 0.67rem;
  font-weight: 760;
  letter-spacing: 0.16em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  line-height: 1.08;
  letter-spacing: 0.035em;
}

.lead {
  max-width: 390px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(0.78rem, 1.3vw, 0.94rem);
  line-height: 1.65;
}

.game-hud {
  position: absolute;
  z-index: 3;
  top: max(22px, env(safe-area-inset-top));
  right: max(24px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: repeat(3, minmax(78px, auto));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(17, 27, 21, 0.76);
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(16px);
}

.metric {
  display: grid;
  gap: 3px;
  min-width: 86px;
  padding: 9px 12px;
  border-left: 1px solid var(--line);
}

.metric:first-child {
  border-left: 0;
}

.metric > span,
.metric small {
  color: var(--muted);
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.metric strong {
  color: var(--paper);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.metric-food strong {
  color: #ffe0a1;
}

.metric-delivered strong {
  color: var(--teal);
}

.metric-time strong {
  color: #e6c2a2;
}

.level-panel,
.status-panel,
.view-panel {
  position: absolute;
  z-index: 3;
  left: max(24px, env(safe-area-inset-left));
  width: min(280px, calc(100vw - 48px));
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(17, 27, 21, 0.7);
  box-shadow: 0 16px 45px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(14px);
}

.level-panel {
  top: 142px;
  padding: 11px 13px;
}

.level-panel label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.65rem;
}

#level-select {
  width: 100%;
  min-height: 46px;
  padding: 6px 9px;
  border: 1px solid rgba(238, 229, 193, 0.27);
  border-radius: 9px;
  color: var(--paper);
  background: rgba(255, 255, 255, 0.08);
}

#level-description {
  min-height: 2.7em;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.67rem;
  line-height: 1.45;
}

.status-panel {
  top: 290px;
  padding: 10px 13px;
}

.view-panel {
  top: 368px;
  padding: 10px 13px;
}

.view-panel.is-modal-accessible {
  top: calc(50% + 135px);
  z-index: 9;
}

.status-line {
  min-height: 1.4em;
  margin: 0;
  color: #f2dda8;
  font-size: 0.72rem;
  line-height: 1.45;
}

.status-details {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.61rem;
}

.view-controls {
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.view-control-label {
  display: block;
  color: var(--muted);
  font-size: 0.62rem;
}

.view-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.view-button {
  min-width: 0;
  min-height: 46px;
  padding: 7px 6px;
  border: 1px solid rgba(238, 229, 193, 0.2);
  border-radius: 9px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  font-size: 0.68rem;
  line-height: 1.25;
  transition: border-color 140ms ease, background 140ms ease, color 140ms ease, transform 140ms ease;
}

.view-button:hover:not(:disabled) {
  border-color: rgba(255, 225, 159, 0.72);
  background: rgba(255, 225, 159, 0.12);
}

.view-button:active:not(:disabled) {
  transform: translateY(1px);
}

.view-button[aria-pressed="true"] {
  color: #1c281d;
  border-color: rgba(142, 211, 189, 0.82);
  background: linear-gradient(135deg, #b8ead2, #72b8a4);
}

.scent-legend {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.58rem;
  line-height: 1.35;
}

.scent-legend[hidden] {
  display: none;
}

.legend-swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 5px;
  border-radius: 2px;
  vertical-align: -1px;
}

.legend-swatch-exploration {
  background: #f9da6f;
  box-shadow: 0 0 7px rgba(249, 218, 111, 0.62);
}

.legend-swatch-strong {
  background: #ff71a6;
  box-shadow: 0 0 7px rgba(255, 113, 166, 0.62);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.control-panel {
  position: absolute;
  z-index: 4;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(375px, calc(100vw - 48px));
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(17, 27, 21, 0.86);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(18px);
}

.speed-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.speed-control-label {
  color: var(--muted);
  font-size: 0.62rem;
  white-space: nowrap;
}

.speed-toggle {
  display: grid;
  grid-template-columns: repeat(4, minmax(44px, 1fr));
  gap: 6px;
  min-width: 0;
}

.speed-button {
  min-width: 44px;
  min-height: 46px;
  padding: 8px 5px;
  border: 1px solid rgba(238, 229, 193, 0.2);
  border-radius: 10px;
  color: var(--paper);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.speed-button:hover:not(:disabled) {
  border-color: rgba(255, 225, 159, 0.72);
  background: rgba(255, 225, 159, 0.12);
}

.speed-button:active:not(:disabled) {
  transform: translateY(1px);
}

.speed-button[aria-pressed="true"] {
  color: #1c281d;
  border-color: rgba(142, 211, 189, 0.82);
  background: linear-gradient(135deg, #b8ead2, #72b8a4);
}

.action-row {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 7px;
}

.button {
  min-height: 46px;
  padding: 8px 10px;
  border: 1px solid rgba(238, 229, 193, 0.2);
  border-radius: 10px;
  color: var(--paper);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.button:hover:not(:disabled) {
  border-color: rgba(255, 225, 159, 0.72);
  background: rgba(255, 225, 159, 0.12);
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button-primary {
  color: #1c281d;
  border-color: rgba(255, 221, 145, 0.72);
  background: linear-gradient(135deg, #ffe0a0, #d8a969);
  box-shadow: 0 10px 28px rgba(216, 169, 105, 0.18);
}

.button-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #ffedbb, #e4bc7d);
}

.button-quiet {
  color: var(--muted);
}

.key-help {
  margin: 9px 1px 0;
  color: rgba(197, 196, 179, 0.75);
  font-size: 0.62rem;
  line-height: 1.45;
}

.joystick {
  position: absolute;
  z-index: 5;
  bottom: max(26px, env(safe-area-inset-bottom));
  left: max(24px, env(safe-area-inset-left));
  width: 112px;
  height: 112px;
  border: 1px solid rgba(255, 225, 159, 0.36);
  border-radius: 50%;
  background: rgba(16, 25, 19, 0.5);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.26);
  touch-action: none;
  user-select: none;
}

.joystick-ring {
  position: absolute;
  inset: 18px;
  border: 1px dashed rgba(255, 225, 159, 0.35);
  border-radius: 50%;
}

.joystick-knob {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255, 232, 172, 0.9);
  border-radius: 50%;
  background: rgba(184, 107, 79, 0.9);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
  transform: translate(-50%, -50%);
  transition: transform 80ms ease;
}

.joystick.is-active .joystick-knob {
  background: rgba(238, 107, 154, 0.92);
  transition: none;
}

.overlay-panel {
  position: absolute;
  z-index: 8;
  top: 50%;
  left: 50%;
  width: min(410px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid rgba(238, 229, 193, 0.34);
  border-radius: 18px;
  color: var(--paper);
  background: rgba(18, 29, 21, 0.95);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.52);
  transform: translate(-50%, -50%);
  backdrop-filter: blur(24px);
}

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

.overlay-panel h2 {
  margin: 0 0 13px;
  font-size: 1.35rem;
}

.overlay-panel p:not(.panel-kicker) {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.65;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 18px;
}

.result-grid div {
  display: grid;
  gap: 5px;
  min-height: 68px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.05);
}

.result-grid dt {
  color: var(--muted);
  font-size: 0.62rem;
}

.result-grid dd {
  margin: 0;
  color: #ffe0a1;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.overlay-panel .button {
  width: 100%;
}

.usage-section,
.info-section,
.game-comment-section {
  width: min(1040px, calc(100% - 32px));
  margin-inline: auto;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
}

.usage-section {
  padding: 54px 0 30px;
}

.info-section {
  padding: 24px 0 36px;
}

.game-comment-section {
  margin-bottom: 48px;
  padding: 24px;
  border: 1px solid #d5e0d8;
  border-radius: 14px;
  background: #fff;
}

.usage-section .usage-kicker,
.info-section .usage-kicker {
  color: #347e78;
}

.usage-section h2,
.info-section h2 {
  margin: 0 0 24px;
  color: var(--ink);
  font-size: clamp(1.35rem, 2.4vw, 1.8rem);
}

.usage-grid,
.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 28px;
}

.usage-grid article,
.info-grid article {
  min-width: 0;
  padding-top: 14px;
  border-top: 1px solid #9db1aa;
}

.usage-grid h3,
.info-grid h3 {
  margin: 0 0 7px;
  color: var(--ink);
  font-size: 1.03rem;
}

.usage-grid p,
.info-grid p {
  margin: 0;
  color: #465a54;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

.game-comment-note {
  margin: 0 0 18px;
  color: #465a54;
  line-height: 1.8;
}

.app-comments {
  color: var(--ink);
}

.app-comments h2 {
  margin: 0 0 12px;
  color: var(--ink);
  font-size: clamp(1.2rem, 2.2vw, 1.5rem);
}

.app-comments-empty {
  margin: 0;
  color: #465a54;
  line-height: 1.8;
}

@media (max-width: 900px) {
  .site-head {
    max-width: min(48vw, 360px);
  }

  .game-hud {
    top: 100px;
    right: 16px;
    left: 16px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metric {
    min-width: 0;
    padding: 8px 9px;
  }

  .level-panel {
    top: 178px;
    right: 16px;
    left: 16px;
    width: auto;
  }

  .status-panel {
    top: 306px;
    right: 16px;
    left: 16px;
    width: auto;
  }

  .view-panel {
    top: 405px;
    right: 16px;
    left: 16px;
    width: auto;
  }

  .control-panel {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(142px, 31vw);
    width: auto;
    padding: 11px;
  }

  .joystick {
    bottom: max(15px, env(safe-area-inset-bottom));
    left: max(14px, env(safe-area-inset-left));
    width: 104px;
    height: 104px;
  }
}

@media (max-width: 580px) {
  .site-header {
    align-items: flex-start;
    padding: 10px 14px;
  }

  .site-nav {
    gap: 6px 12px;
    font-size: 0.68rem;
  }

  .breadcrumb {
    padding-inline: 14px;
  }

  .app-shell {
    height: max(620px, 100dvh);
    min-height: 620px;
  }

  .site-head {
    top: max(13px, env(safe-area-inset-top));
    left: max(16px, env(safe-area-inset-left));
    width: calc(100vw - 32px);
    max-width: none;
  }

  .eyebrow {
    margin-bottom: 5px;
    font-size: 0.56rem;
  }

  h1 {
    margin-bottom: 5px;
    font-size: 1.34rem;
  }

  .lead {
    max-width: 320px;
    font-size: 0.7rem;
  }

  .game-hud {
    top: 91px;
    right: 10px;
    left: 10px;
  }

  .metric {
    padding: 7px 5px;
  }

  .metric > span,
  .metric small {
    font-size: 0.52rem;
  }

  .metric strong {
    font-size: 0.78rem;
  }

  .level-panel {
    top: 147px;
    right: 10px;
    left: 10px;
    padding: 8px 9px;
  }

  .level-panel label {
    display: inline-block;
    width: 44px;
    margin: 0 5px 0 0;
  }

  #level-select {
    width: calc(100% - 53px);
    min-height: 46px;
  }

  #level-description {
    min-height: 1.45em;
    margin-top: 5px;
    font-size: 0.61rem;
  }

  .status-panel {
    top: 230px;
    right: 10px;
    left: 10px;
    padding: 8px 10px;
  }

  .view-panel {
    top: 305px;
    right: 10px;
    left: 10px;
    padding: 8px 9px;
  }

  .status-line {
    font-size: 0.65rem;
  }

  .view-controls {
    margin-top: 7px;
    padding-top: 7px;
  }

  .view-toggle {
    gap: 5px;
    margin-top: 5px;
  }

  .view-button {
    min-height: 46px;
    padding: 6px 4px;
    font-size: 0.64rem;
  }

  .scent-legend {
    gap: 3px;
    margin-top: 6px;
    font-size: 0.55rem;
  }

  .control-panel {
    right: 9px;
    bottom: max(9px, env(safe-area-inset-bottom));
    left: 9px;
    padding: 9px;
  }

  .speed-controls {
    grid-template-columns: 1fr;
    gap: 5px;
    margin-bottom: 7px;
  }

  .speed-control-label {
    font-size: 0.6rem;
  }

  .speed-toggle {
    gap: 5px;
  }

  .speed-button {
    padding: 7px 4px;
    font-size: 0.7rem;
  }

  .action-row {
    gap: 6px;
  }

  .button {
    min-height: 46px;
    padding: 7px 6px;
    font-size: 0.7rem;
  }

  .key-help {
    display: none;
  }

  .joystick {
    bottom: max(133px, calc(env(safe-area-inset-bottom) + 132px));
    left: 14px;
    width: 92px;
    height: 92px;
  }

  .joystick-ring {
    inset: 15px;
  }

  .joystick-knob {
    width: 34px;
    height: 34px;
  }

  .result-grid {
    gap: 6px;
  }

  .result-grid div {
    padding: 7px;
  }

  .result-grid dt {
    font-size: 0.57rem;
  }

  .result-grid dd {
    font-size: 0.82rem;
  }

  .usage-section,
  .info-section {
    width: calc(100% - 28px);
  }

  .usage-section {
    padding-top: 38px;
  }

  .usage-grid,
  .info-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .game-comment-section {
    width: calc(100% - 28px);
    padding: 18px;
  }

  .site-footer {
    gap: 8px 14px;
    padding-inline: 14px;
  }
}

@media (max-width: 340px) {
  .action-row {
    grid-template-columns: 1fr 1fr;
  }

  #pause-button {
    display: none;
  }

  .joystick {
    bottom: max(126px, calc(env(safe-area-inset-bottom) + 126px));
  }
}

@media (max-height: 480px) and (min-width: 700px) {
  .app-shell {
    height: 100dvh;
    min-height: 0;
  }

  #ant-map {
    width: min(62vh, 44vw);
    height: min(62vh, 44vw);
  }

  .site-head {
    top: 10px;
    left: 16px;
    width: min(330px, 35vw);
  }

  .eyebrow {
    margin-bottom: 4px;
    font-size: 0.56rem;
  }

  h1 {
    margin-bottom: 4px;
    font-size: 1.22rem;
  }

  .lead {
    max-width: 310px;
    font-size: 0.64rem;
    line-height: 1.4;
  }

  .game-hud {
    top: 10px;
    right: 16px;
    left: auto;
    width: min(312px, 38vw);
  }

  .level-panel {
    top: 92px;
    left: 16px;
    width: 220px;
    padding: 8px 10px;
  }

  .status-panel {
    top: 194px;
    left: 16px;
    width: 220px;
  }

  .view-panel {
    top: 270px;
    left: 16px;
    width: 220px;
    padding: 8px 10px;
  }

  .view-panel.is-modal-accessible {
    top: 285px;
    left: 10px;
    width: 200px;
  }

  .view-controls {
    margin-top: 7px;
    padding-top: 6px;
  }

  .view-button {
    min-height: 46px;
    padding: 5px 4px;
    font-size: 0.6rem;
  }

  .scent-legend {
    gap: 3px;
    margin-top: 6px;
    font-size: 0.54rem;
  }

  .control-panel {
    right: 16px;
    bottom: 10px;
    left: auto;
    width: min(320px, 38vw);
    padding: 8px;
  }

  .speed-controls {
    display: block;
    margin-bottom: 3px;
  }

  .speed-control-label {
    display: none;
  }

  .speed-toggle {
    grid-template-columns: repeat(2, minmax(44px, 1fr));
    gap: 3px;
  }

  .speed-button {
    min-height: 46px;
    padding: 4px 1px;
    font-size: 0.56rem;
  }

  .button {
    min-height: 46px;
    padding: 6px 7px;
    font-size: 0.67rem;
  }

  .joystick {
    bottom: 12px;
    left: 16px;
    width: 84px;
    height: 84px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .button,
  .joystick-knob {
    transition: none;
  }
}

/* Keep the map and the surrounding controls in separate regions at each
   supported viewport. The game surface remains absolute so the canvas stays
   stable while the UI panels use fixed, non-overlapping slots. */
@media (min-width: 901px) and (min-height: 481px) {
  #ant-map {
    top: 56%;
    left: 45%;
  }
}

@media (min-width: 1400px) and (min-height: 481px) {
  #ant-map {
    left: 51%;
  }
}

@media (max-width: 580px) and (min-height: 481px) {
  .game-hud {
    top: 99px;
  }

  .level-panel {
    top: 163px;
  }

  .status-panel {
    top: 275px;
  }

  .view-panel {
    top: 337px;
  }

  #ant-map {
    top: 472px;
    left: 50%;
    width: min(72vw, 270px);
    height: min(72vw, 270px);
    transform: translateX(-50%);
  }

  .control-panel {
    right: 9px;
    bottom: max(9px, env(safe-area-inset-bottom));
    left: 118px;
    width: auto;
  }

  .joystick {
    right: auto;
    bottom: max(9px, env(safe-area-inset-bottom));
    left: 14px;
  }
}

@media (max-height: 480px) and (min-width: 700px) {
  #ant-map {
    top: 84px;
    left: 16px;
    width: min(58vh, 27vw);
    height: min(58vh, 27vw);
    transform: none;
  }

  .level-panel {
    top: 84px;
    right: 178px;
    left: auto;
    width: 150px;
    padding: 8px;
  }

  .status-panel {
    top: 84px;
    right: 16px;
    left: auto;
    width: 150px;
    padding: 8px;
  }

  .view-panel {
    top: 230px;
    right: 178px;
    left: auto;
    width: 150px;
    padding: 8px;
  }

  .view-controls {
    margin-top: 4px;
    padding-top: 5px;
  }

  .view-toggle {
    gap: 4px;
    margin-top: 4px;
  }

  .view-button {
    min-height: 46px;
    padding: 5px 2px;
    font-size: 0.56rem;
  }

  .scent-legend {
    gap: 2px;
    margin-top: 5px;
    font-size: 0.5rem;
  }

  .control-panel {
    top: 230px;
    right: 16px;
    bottom: auto;
    left: auto;
    width: 160px;
    padding: 6px;
  }

  .key-help {
    display: none;
  }

  .action-row {
    grid-template-columns: 48px 44px 44px;
    gap: 4px;
  }

  .button {
    min-width: 44px;
    min-height: 46px;
    padding: 6px 1px;
    font-size: 0.56rem;
  }

  .joystick {
    top: auto;
    right: auto;
    bottom: 6px;
    left: calc(50% - 42px);
    width: 84px;
    height: 84px;
  }
}

/* Reserve the narrow middle-width map slot below the view panel. */
@media (min-width: 581px) and (max-width: 900px) and (min-height: 901px) {
  .game-hud {
    right: 16px;
    left: calc(24px + min(48vw, 360px) + 12px);
  }

  #ant-map {
    top: calc(100% - 232px);
    left: 50%;
    width: min(42vw, 240px);
    height: min(42vw, 240px);
  }
}

@media (min-width: 581px) and (max-width: 900px) and (min-height: 901px) {
  .control-panel {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    column-gap: 8px;
    padding: 7px 11px;
    align-items: start;
  }

  .speed-controls {
    display: flex;
    grid-column: 1;
    gap: 6px;
    align-items: center;
    margin-bottom: 0;
  }

  .speed-toggle {
    gap: 4px;
  }

  .action-row {
    grid-column: 2;
  }

  .key-help {
    grid-column: 1 / -1;
  }
}

@media (max-width: 480px) and (min-height: 481px) {
  #ant-map {
    width: min(58vw, 240px);
    height: min(58vw, 240px);
  }
}
