/* ---- Offline entry on touch devices ---- */

.lobby-page .offline-skirmish { display: none; }

@media (pointer: coarse) {
  .lobby-page .offline-skirmish {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin-top: 10px;
    padding: 7px 12px;
    color: #f0e1ba;
    background: #202a1f;
    border: 1px solid #878a64;
    border-radius: 4px;
    font-size: 13px;
  }
}

#touch-bar [hidden], #touch-bar[hidden], #touch-help[hidden] { display: none; }

.touch-layout { --touch-hud-height: 26px; --touch-rail-width: clamp(66px, 12vw, 88px); }
/* ---- Match setup and player roster ---- */

.touch-layout #setup {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto auto auto;
  align-content: start;
  overflow: auto;
  padding: 8px;
  gap: 6px 10px;
}
.touch-layout #setup h1 { font-size: 20px; }
.touch-layout #setup .setup-sub { font-size: 11px; }
.touch-layout #setup .setup-label { margin-bottom: 3px; }
.touch-layout #setup .setup-left,
.touch-layout #setup .setup-right { min-width: 0; gap: 5px; }
.touch-layout #setup .slot-table { overflow: auto; max-height: 43dvh; padding-right: 2px; }
.touch-layout .slot-row {
  flex: none;
  grid-template-columns: 16px minmax(44px, 1fr) 25px minmax(38px, 1fr) minmax(37px, .85fr) minmax(57px, 1.12fr);
  gap: 3px;
  padding: 2px 3px;
}
.touch-layout .slot-row.head { font-size: 11px; letter-spacing: normal; }
.touch-layout .slot-row button {
  min-width: 0;
  min-height: 28px;
  width: 100%;
  padding: 2px 3px;
  font-size: 11px;
}
.touch-layout .slot-row .seg { min-width: 0; }
.touch-layout .slot-row .team-btn,
.touch-layout .slot-row .faction-btn { gap: 2px; white-space: normal; }
.touch-layout .slot-row .swatch { width: 11px; height: 11px; flex: none; }
.touch-layout .slot-row .start-btn:not(:disabled) {
  white-space: normal;
  overflow-wrap: anywhere;
}
.touch-layout #setup .setup-foot {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: #24291d;
  padding: 4px;
  gap: 4px;
  border: 1px solid var(--metal-line);
  border-radius: 5px;
}
.touch-layout #setup #start-btn { min-height: 34px; padding: 3px 12px; font-size: 13px; }
.touch-layout #setup .setup-foot .small-btn { font-size: 11px; padding: 3px 5px; }
.touch-layout #setup .map-picker { gap: 3px; margin: 0; }
.touch-layout #setup .map-picker-canvas { max-height: min(38dvh, 200px); }
.touch-layout #setup .map-picker-hint { font-size: 11px; }
.touch-layout .popup-menu { max-height: min(320px, calc(100dvh - 16px)); }

@media (orientation: landscape) and (min-width: 600px) {
  .touch-layout #setup { grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); }
  .touch-layout #setup .setup-right { grid-row: 2; grid-column: 2; }
  .touch-layout #setup .setup-foot { grid-row: 3; }
}

/* ---- Match bar and production shortcuts ---- */

.touch-layout #topbar { height: var(--touch-hud-height); gap: 6px; padding-inline: 5px; }
.touch-layout .production-shortcuts-active {
  --touch-hud-height: 45px;
  --match-topbar-height: var(--touch-hud-height);
}
.touch-layout #production-shortcuts .small-btn { min-width: 44px; min-height: 44px; padding-inline: 6px; }
@media (max-width: 920px) {
  .touch-layout .production-shortcuts-active { --touch-hud-height: 71px; }
  .touch-layout .production-shortcuts-active #topbar { grid-template-rows: 26px 44px; row-gap: 0; }
}
.touch-layout #topbar-buttons { gap: 3px; }
.touch-layout #topbar-buttons .small-btn { min-height: 22px; min-width: 24px; padding: 0 4px; font-size: 11px; }
.touch-layout #hud { gap: 6px; }
.touch-layout #minimap-panel { top: calc(var(--touch-hud-height) + 6px); right: 6px; padding: 3px; }
/* ---- Production and economy panels ---- */

.touch-layout #build,
.touch-layout #resources {
  top: calc(var(--touch-hud-height) + 6px) !important;
  bottom: auto;
  left: 6px;
  right: auto;
  width: min(248px, calc(100% - var(--touch-rail-width) - 20px));
  min-width: 0;
  max-height: calc(100dvh - var(--touch-hud-height) - 12px) !important;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 8;
}
.touch-layout .touch-panel-closed { display: none; }
.touch-layout #build .build-btn { min-height: 46px; }
.touch-layout #build .sell-btn, .touch-layout #resources button { min-height: 32px; font-size: 12px; }
/* ---- Help and settings ---- */

.touch-layout #help, .touch-layout #settings, .touch-layout #primer {
  max-height: calc(100dvh - 36px);
  max-width: calc(100% - 24px);
  overflow: auto;
}
.touch-layout #help > .row { display: none; }
.touch-layout #help { width: min(420px, calc(100% - 24px)); }
#touch-help .touch-help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
#touch-help-close { min-height: 44px; padding-inline: 12px; font-size: 13px; }
#touch-help .row { padding-block: 6px; font-size: 13px; }

/* ---- Touch orders and action bar ---- */

#touch-bar {
  position: absolute;
  bottom: 6px;
  right: 6px;
  z-index: 9;
  display: grid;
  gap: 6px;
  width: var(--touch-rail-width);
  pointer-events: none;
}
#touch-bar > * {
  pointer-events: auto;
  background: #242c20;
  border: 1px solid #828665;
  border-radius: 6px;
  padding: 4px;
}
#touch-actions, #touch-orders-menu { display: grid; gap: 3px; }
#touch-orders-menu {
  position: fixed;
  top: calc(var(--touch-hud-height) + 6px);
  left: 6px;
  width: 146px;
}
#touch-bar .small-btn {
  min-width: 0;
  min-height: 25px;
  margin: 0;
  padding: 4px 3px;
  font-size: 11px;
  line-height: 1.3;
  white-space: normal;
  touch-action: manipulation;
}
#touch-bar .small-btn[aria-pressed="true"],
#touch-bar .small-btn[aria-expanded="true"] {
  background: #d4b06c;
  color: #231d12;
  border-color: #e5c589;
}
#touch-instruction {
  position: fixed;
  bottom: 6px;
  left: 6px;
  max-width: min(330px, calc(100% - var(--touch-rail-width) - 18px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
#touch-hint { padding-inline: 6px; color: #eee9d7; font-size: 12px; }
#touch-bar #touch-cancel { min-width: 62px; }
[lang="fa"] #touch-hint { direction: rtl; }
