/* Mobile cockpit. Sizes follow the game surface, including its rotated fallback,
   rather than the physical portrait browser window. Menus remain upright. */
#app {
  container-type: size;
  container-name: game-shell;
  --game-safe-top: env(safe-area-inset-top, 0px);
  --game-safe-right: env(safe-area-inset-right, 0px);
  --game-safe-bottom: env(safe-area-inset-bottom, 0px);
  --game-safe-left: env(safe-area-inset-left, 0px);
  --hud-height: 78px;
}

body.forced-landscape #app {
  position: absolute;
  width: 100dvh;
  height: 100dvw;
  left: 100%;
  top: 0;
  transform-origin: top left;
  transform: rotate(90deg);
  --game-safe-top: env(safe-area-inset-right, 0px);
  --game-safe-right: env(safe-area-inset-bottom, 0px);
  --game-safe-bottom: env(safe-area-inset-left, 0px);
  --game-safe-left: env(safe-area-inset-top, 0px);
}

/* Keep the insignia and its descriptor in document flow at every menu size. */
.title-word::after { content: none; }
.title-sub::after {
  content: 'AUTONOMOUS TACTICAL UNIT';
  display: block;
  margin-top: .6rem;
  font-family: Terminal, 'Courier New', monospace;
  font-size: clamp(.65rem, 1cqw, .85rem);
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: .24em;
  color: #a4b4aa;
}
.home-description { margin-top: 1.7rem; }

/* Touch controls do not inherit browser gestures or text selection. Panels
   retain normal vertical scrolling outside gameplay. */
body.touch-controls.in-game,
body.touch-controls.in-game #app {
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
body.touch-controls #touch {
  --control-surface: #10251fe0;
  --control-line: #b6dfbc99;
  opacity: var(--touch-opacity, .7);
}
body.touch-controls #touch button {
  min-width: 44px;
  min-height: 44px;
  touch-action: none;
  -webkit-touch-callout: none;
  border-color: var(--control-line);
  box-shadow: inset 0 0 0 2px #07130d4d, 0 2px 6px #0005;
}
body.touch-controls #touch button:active {
  background: #52705bdd;
  border-color: #e2f6d7;
  color: #f0ffe5;
}
body.touch-controls #look-zone {
  inset: 0 0 calc(var(--hud-height) + var(--game-safe-bottom)) 34%;
}
body.touch-controls #joystick {
  transform: scale(var(--touch-scale, 1));
  transform-origin: bottom left;
  left: calc(var(--game-safe-left) + 22px);
  bottom: calc(var(--hud-height) + var(--game-safe-bottom) + 22px);
  width: 132px;
  height: 132px;
  border: 1px solid #b2d8b073;
  background: radial-gradient(circle, #344d3833 48%, #0d211d66 49%, #10211d80 70%);
  box-shadow: inset 0 0 0 8px #07171340, 0 2px 10px #0003;
}
body.touch-controls #joystick::before {
  content: '+';
  font-family: 'Courier New', monospace;
  font-size: 40px;
  color: #c4dfbc3b;
}
body.touch-controls #stick {
  width: 54px;
  height: 54px;
  top: calc(50% - 27px);
  left: calc(50% - 27px);
  border: 2px solid #c1e0bb9c;
  background: #6a8a626e;
  box-shadow: inset 0 0 0 5px #182f2040, 0 2px 8px #0005;
}
body.touch-controls .touch-actions {
  right: calc(var(--game-safe-right) + 20px);
  bottom: calc(var(--hud-height) + var(--game-safe-bottom) + 20px);
  width: 252px;
  height: 178px;
  transform: scale(var(--touch-scale, 1));
  transform-origin: bottom right;
}
body.touch-controls .touch-actions button {
  width: 54px;
  height: 54px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  border-radius: 50%;
  background: var(--control-surface);
}
body.touch-controls .touch-actions .fire {
  width: 86px;
  height: 86px;
  top: 32px;
  right: 0;
  left: auto;
  border: 2px solid #edc58b;
  color: #ffd49a;
  background: radial-gradient(circle, #72573580, #1d271fc9 68%);
  box-shadow: inset 0 0 0 5px #f7bd7221, 0 2px 10px #0006;
  font-family: 'Courier New', monospace;
  font-size: 38px;
}
body.touch-controls .touch-actions [data-touch='interact'] {
  top: 0;
  left: 100px;
  right: auto;
  border-color: #93e8cf;
  color: #b0f3db;
}
body.touch-controls .touch-actions [data-touch='reload'] {
  top: auto;
  bottom: 0;
  left: 100px;
  right: auto;
}
body.touch-controls .touch-actions [data-touch='alt'] {
  top: auto;
  bottom: 36px;
  left: 32px;
  right: auto;
  font-size: 11px;
  letter-spacing: .03em;
}
body.touch-controls .touch-actions [data-touch='weapon'],
body.touch-controls .touch-actions [data-touch='weapons'] {
  width: 86px;
  height: 46px;
  top: auto;
  bottom: 0;
  right: 0;
  left: auto;
  border-radius: 6px;
  font-size: 13px;
  letter-spacing: .04em;
  color: #e9c790;
  border-color: #c4a46f9c;
}
body.touch-controls .touch-top {
  top: calc(var(--game-safe-top) + 12px);
  left: calc(var(--game-safe-left) + 16px);
  display: flex;
  gap: 8px;
}
body.touch-controls .touch-top button {
  display: grid;
  place-items: center;
  height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border-radius: 3px;
  font-size: 11px;
  line-height: 1;
  letter-spacing: .05em;
  background: #10221edb;
}
body.touch-controls .touch-top [data-touch='pause'] { font-size: 18px; }
body.touch-controls .touch-top [data-touch='fullscreen'] { font-size: 21px; padding: 0; }

/* Mirror the complete control cluster instead of changing its internal order. */
body.touch-controls.touch-left #joystick {
  transform-origin: bottom right;
  left: auto;
  right: calc(var(--game-safe-right) + 22px);
}
body.touch-controls.touch-left .touch-actions {
  left: calc(var(--game-safe-left) + 20px);
  right: auto;
  transform: scale(var(--touch-scale, 1)) scaleX(-1);
  transform-origin: bottom left;
}
body.touch-controls.touch-left .touch-actions button { transform: scaleX(-1); }
body.touch-controls.touch-left #look-zone {
  inset: 0 34% calc(var(--hud-height) + var(--game-safe-bottom)) 0;
}

/* A full-surface HUD lets the objective sit above the world while the status
   rail remains at the bottom. Pointer events still pass through it. */
body.touch-controls.in-game #hud { top: 0; bottom: 0; }
body.touch-controls.in-game .hud-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: none;
  height: calc(var(--hud-height) + var(--game-safe-bottom));
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 70px minmax(0, 1.1fr) minmax(0, .9fr);
  padding: 0 var(--game-safe-right) var(--game-safe-bottom) var(--game-safe-left);
  border: 0;
  border-top: 2px solid #8a9a83;
  background: linear-gradient(#293a31, #14221d 14%, #0c1715);
  box-shadow: 0 -3px 0 #07100e, 0 -5px 16px #0006;
}
body.touch-controls.in-game .hud-cell { padding: 7px 14px 6px; }
body.touch-controls.in-game .hud-label {
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: .04em;
  color: #a5bba8;
  white-space: nowrap;
}
body.touch-controls.in-game .hud-value {
  margin-top: 2px;
  font-size: 29px;
  line-height: 1.05;
}
body.touch-controls.in-game .hud-value small { font-size: 11px; }
body.touch-controls.in-game .hud-meter { height: 3px; margin-top: 6px; }
body.touch-controls.in-game .hud-portrait img { width: 68px; height: 72px; }
body.touch-controls.in-game .portrait-code { bottom: 2px; font-size: 8px; }
body.touch-controls.in-game .weapon-name {
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.1;
  white-space: nowrap;
}
body.touch-controls.in-game .hud-keys { gap: 5px; margin-top: 9px; }
body.touch-controls.in-game .hud-key { width: 22px; height: 10px; }
body.touch-controls.in-game .hud-modules { margin-top: 8px; font-size: 10px; line-height: 1.2; }
body.touch-controls.in-game .hud-help { display: none; }
body.touch-controls.in-game .hud-top {
  position: absolute;
  top: calc(var(--game-safe-top) + 12px);
  bottom: auto;
  left: calc(var(--game-safe-left) + 292px);
  right: calc(var(--game-safe-right) + 18px);
  padding: 0;
  align-items: start;
  gap: 16px;
  background: none;
  text-shadow: 0 2px 2px #000, 1px 0 #000;
}
body.touch-controls.in-game .hud-sector { font-size: 11px; line-height: 1.4; letter-spacing: .06em; }
body.touch-controls.in-game .hud-objective {
  max-width: none;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
  color: #d3ddce;
}
body.touch-controls.in-game .hud-time { font-size: 12px; line-height: 1.6; }
body.touch-controls.in-game #interaction {
  bottom: calc(var(--hud-height) + var(--game-safe-bottom) + 14px);
  left: 50%;
  max-width: 38%;
  padding: 7px 12px;
  border-color: #83c6a691;
  font-size: 12px;
  line-height: 1.4;
  white-space: normal;
  background: #071a15ed;
}
body.touch-controls.in-game #interaction .key { display: none; }
body.touch-controls.in-game #messages {
  top: calc(var(--game-safe-top) + 74px);
  width: min(60%, 580px);
  gap: 6px;
}
body.touch-controls.in-game .message {
  padding: 6px 12px;
  font-size: 12px;
  line-height: 1.45;
  max-width: 100%;
}
body.touch-controls.in-game .message:nth-last-child(n + 3) { display: none; }
body.minimal.touch-controls.in-game .hud-bar {
  background: #0b1713c9;
  border-top: 1px solid #8a9a8366;
  box-shadow: none;
}
body.minimal.touch-controls.in-game .hud-portrait { background: transparent; }

/* The selector exists only while playing; it is deliberately separate from
   the circular fire button so switching does not start a shot. */
body.touch-controls .weapon-picker,
body.touch-controls #weapon-picker {
  position: absolute;
  top: calc(var(--game-safe-top) + 74px);
  bottom: auto;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  z-index: 12;
  display: grid;
  grid-template-columns: repeat(4, minmax(44px, 1fr));
  gap: 6px;
  width: min(430px, 60%);
  padding: 10px;
  background: #071713f5;
  border: 1px solid #8aa48a;
  box-shadow: 0 5px 26px #0009;
  pointer-events: auto;
}
body.touch-controls .weapon-picker button,
body.touch-controls #weapon-picker button {
  min-height: 50px;
  padding: 8px;
  text-align: center;
  border-radius: 2px;
  font-size: 11px;
  background: #1b2c23;
}
body.touch-controls .weapon-picker button.selected,
body.touch-controls #weapon-picker button.selected {
  border-color: var(--amber);
  background: #4a3b26;
  color: #ffda9d;
}
body.touch-controls.touch-left .weapon-picker,
body.touch-controls.touch-left #weapon-picker {
  left: 50%;
  right: auto;
}

@container game-shell (max-height: 500px) {
  /* The variable must be set on descendants: a container cannot query itself. */
  body.touch-controls #hud,
  body.touch-controls #touch,
  body.touch-controls #interaction,
  body.touch-controls #messages,
  body.touch-controls .weapon-picker,
  body.touch-controls #weapon-picker { --hud-height: 66px; }
  body.touch-controls #joystick { width: 112px; height: 112px; }
  body.touch-controls #stick { width: 48px; height: 48px; top: calc(50% - 24px); left: calc(50% - 24px); }
  body.touch-controls .touch-actions { width: 240px; height: 164px; }
  body.touch-controls .touch-actions button { width: 52px; height: 52px; }
  body.touch-controls .touch-actions .fire { width: 80px; height: 80px; top: 30px; font-size: 36px; }
  body.touch-controls .touch-actions [data-touch='alt'] { left: 36px; bottom: 36px; width: 48px; height: 48px; font-size: 10px; }
  body.touch-controls .touch-actions [data-touch='weapon'],
  body.touch-controls .touch-actions [data-touch='weapons'] { width: 80px; height: 44px; font-size: 12px; }
  body.touch-controls.in-game .hud-bar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 62px minmax(0, 1.1fr) minmax(0, .85fr); }
  body.touch-controls.in-game .hud-cell { padding: 5px 12px 4px; }
  body.touch-controls.in-game .hud-value { font-size: 27px; }
  body.touch-controls.in-game .hud-meter { margin-top: 4px; }
  body.touch-controls.in-game .hud-portrait img { width: 60px; height: 62px; }
  body.touch-controls.in-game .weapon-name { margin-top: 3px; font-size: 11px; }
  body.touch-controls.in-game .hud-keys { margin-top: 7px; }
  body.touch-controls.in-game .hud-modules { margin-top: 6px; font-size: 9px; }
  body.touch-controls.in-game .hud-time { display: none; }
  body.touch-controls.in-game .hud-top { left: calc(var(--game-safe-left) + 276px); }
  .home-description { margin-top: .85rem; }
  .title-sub::after { margin-top: .35rem; font-size: 10px; letter-spacing: .2em; }
  .home-body { min-height: auto; }
  .home-menu button { min-height: 44px; }
  .menu-minor button { min-height: 36px; }
}

@container game-shell (max-width: 760px) {
  body.touch-controls.in-game .hud-cell { padding-right: 9px; padding-left: 9px; }
  body.touch-controls.in-game .hud-label { font-size: 10px; }
  body.touch-controls.in-game .hud-cell:nth-child(1) .hud-label,
  body.touch-controls.in-game .hud-cell:nth-child(2) .hud-label,
  body.touch-controls.in-game .hud-cell:nth-child(4) .hud-label { font-size: 0; }
  body.touch-controls.in-game .hud-cell:nth-child(1) .hud-label::after { content: 'INTEGRITA'; font-size: 11px; }
  body.touch-controls.in-game .hud-cell:nth-child(2) .hud-label::after { content: 'PANCÍŘ'; font-size: 11px; }
  body.touch-controls.in-game .hud-cell:nth-child(4) .hud-label::after { content: 'MUNICE'; font-size: 11px; }
  body.touch-controls.in-game .hud-value small { font-size: 10px; }
  body.touch-controls.in-game .hud-key { width: 17px; height: 9px; }
  body.touch-controls.in-game .hud-top { left: calc(var(--game-safe-left) + 266px); right: calc(var(--game-safe-right) + 14px); }
  body.touch-controls.in-game .hud-objective { font-size: 11px; }
  body.touch-controls.in-game #messages { width: 62%; }
  body.touch-controls.in-game #interaction { max-width: 30%; font-size: 11px; }
  body.touch-controls .touch-top { left: calc(var(--game-safe-left) + 14px); gap: 6px; }
  body.touch-controls .touch-top button { padding: 0 10px; font-size: 10px; }
}

@container game-shell (max-width: 610px) and (max-height: 500px) {
  body.touch-controls #joystick { left: calc(var(--game-safe-left) + 14px); width: 102px; height: 102px; }
  body.touch-controls.touch-left #joystick { left: auto; right: calc(var(--game-safe-right) + 14px); }
  body.touch-controls .touch-actions { right: calc(var(--game-safe-right) + 12px); }
  body.touch-controls.touch-left .touch-actions { left: calc(var(--game-safe-left) + 12px); right: auto; }
  body.touch-controls.in-game .hud-top { left: calc(var(--game-safe-left) + 238px); }
  body.touch-controls.in-game .hud-sector { font-size: 10px; }
  body.touch-controls.in-game .hud-bar { grid-template-columns: 1fr 1fr 54px 1.1fr .8fr; }
  body.touch-controls.in-game .hud-portrait img { width: 52px; }
  body.touch-controls.in-game .hud-label { letter-spacing: 0; }
  body.touch-controls.in-game .hud-modules { font-size: 8px; }
  body.touch-controls.in-game #interaction { max-width: 28%; }
  body.touch-controls .touch-top { gap: 4px; }
  body.touch-controls .touch-top button { padding: 0 7px; }
}

/* Portrait menus are deliberately unaffected by the gameplay rotation. */
@media (pointer: coarse) {
  .overlay button,
  .home-menu button,
  .menu-minor button,
  .panel-head button,
  .tabs button,
  .bind button { min-height: 44px; }
  .field input[type='range'] { min-height: 36px; }
  .field select { min-height: 44px; }
  .check-field { min-height: 44px; }
  .overlay { overscroll-behavior: contain; }
}
@media (max-width: 600px) and (min-height: 501px) {
  .title-sub::after { font-size: 10px; letter-spacing: .19em; }
  .home-description { margin-top: 1.4rem; }
  .home-body { min-height: auto; }
  .panel-head .eyebrow { font-size: 11px; letter-spacing: .12em; }
  .panel-body .field > span,
  .check-field { font-size: 14px; }
}
.weapon-grid { display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px; }
.weapon-option {display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:120px;padding:8px;gap:4px;text-align:center;}
.weapon-option img {width:86px;height:68px;object-fit:contain;image-rendering:pixelated;}
.weapon-option strong {font-size:14px;color:var(--amber);}
.weapon-option small {font-size:12px;}
.weapon-option.selected {border-color:var(--cyan);background:#19362d;}
@container game-shell (max-height:500px) { .weapon-option {min-height:92px;} .weapon-option img {height:48px;} }
@container game-shell (max-width:550px) { .weapon-grid {grid-template-columns:repeat(2,minmax(0,1fr));} }
