@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 680px),
  (orientation: landscape) and (max-height: 680px) and (max-width: 1180px) {
  html,
  body {
    overscroll-behavior: none;
    touch-action: none;
  }

  body {
    padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .app {
    grid-template-rows: 56px minmax(0, 1fr);
    gap: 4px;
  }

  .topbar {
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 18px 30px;
    gap: 4px;
    padding: 3px 6px;
    overflow: hidden;
  }

  .brand {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .brand p {
    display: none;
  }

  .brand h1 {
    overflow: hidden;
    font-size: 14px;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .stats {
    width: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    align-self: stretch;
    overflow: hidden;
    border: 1px solid rgba(86, 246, 255, 0.16);
    background: rgba(2, 7, 18, 0.46);
  }

  .stats .stat-card,
  .stats div {
    height: 28px;
    min-width: 0;
    grid-template-columns: 14px minmax(0, 1fr);
    grid-template-rows: 1fr;
    align-items: center;
    gap: 0 4px;
    padding: 0 7px;
    border: 0;
    border-right: 1px solid rgba(86, 246, 255, 0.12);
    background: transparent;
    box-shadow: none;
  }

  .stats .stat-card:last-child,
  .stats div:last-child {
    border-right: 0;
  }

  .stats span {
    width: 14px;
    height: 14px;
    font-size: 9px;
  }

  .stats small {
    display: none;
    font-size: 9px;
    line-height: 1;
  }

  .stats strong {
    font-size: 12px;
    line-height: 1;
  }

  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  .dock {
    display: none;
  }

  .arena {
    min-height: 0;
    border-width: 1px;
  }

  canvas {
    touch-action: none;
  }

  .actions {
    left: 8px;
    top: 8px;
    gap: 3px;
    padding: 2px;
    background: rgba(3, 8, 20, 0.36);
    backdrop-filter: blur(2px);
  }

  .actions button {
    width: 28px;
    min-width: 28px;
    height: 28px;
    padding: 0;
    gap: 0;
    opacity: 0.84;
    box-shadow: none;
  }

  .actions em {
    display: none;
  }

  .actions i {
    font-size: 13px;
  }

  .touch-controls {
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    pointer-events: none;
  }

  .touch-controls button {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-color: rgba(86, 246, 255, 0.28);
    background: rgba(3, 8, 20, 0.56);
    backdrop-filter: blur(3px);
    box-shadow: 0 0 12px rgba(86, 246, 255, 0.08);
  }

  .touch-joystick {
    position: absolute;
    left: 12px;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: 116px;
    height: 116px;
    border: 1px solid rgba(86, 246, 255, 0.22);
    border-radius: 50%;
    background:
      radial-gradient(circle, rgba(86,246,255,0.13) 0 28%, transparent 29%),
      radial-gradient(circle, rgba(3,8,20,0.74), rgba(3,8,20,0.34));
    box-shadow: inset 0 0 22px rgba(86, 246, 255, 0.08), 0 0 18px rgba(0, 0, 0, 0.28);
    pointer-events: auto;
    touch-action: none;
  }

  .touch-joystick-base {
    position: absolute;
    inset: 18px;
    border: 1px solid rgba(86, 246, 255, 0.28);
    border-radius: 50%;
    background:
      linear-gradient(90deg, transparent 48%, rgba(86,246,255,0.18) 49% 51%, transparent 52%),
      linear-gradient(180deg, transparent 48%, rgba(86,246,255,0.18) 49% 51%, transparent 52%);
  }

  .touch-joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 46px;
    height: 46px;
    border: 2px solid rgba(236, 251, 255, 0.42);
    border-radius: 50%;
    background: rgba(86, 246, 255, 0.22);
    box-shadow: 0 0 16px rgba(86, 246, 255, 0.28), inset 0 0 12px rgba(255, 255, 255, 0.06);
    transform: translate(-50%, -50%);
    transition: transform 0.08s ease;
  }

  .touch-joystick.active .touch-joystick-knob {
    transition: none;
  }

  .touch-actions {
    position: absolute;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    grid-template-columns: repeat(2, 48px);
    gap: 6px;
  }

  .touch-actions button {
    width: 48px;
    min-width: 48px;
    border-radius: 50%;
    opacity: 0.76;
    background: rgba(3, 8, 20, 0.38);
    color: rgba(236, 251, 255, 0.78);
    font-size: 13px;
    box-shadow: 0 0 10px rgba(86, 246, 255, 0.06);
  }

  .touch-actions button:active,
  .touch-controls button.active {
    opacity: 1;
    border-color: rgba(86, 246, 255, 0.48);
    background: rgba(86, 246, 255, 0.14);
  }

  .arena:has(.brief:not(.hidden)) .touch-controls {
    display: none;
  }

  .app:has(.modal-layer:not(.hidden)) .touch-controls {
    display: none;
  }

  .arena-buffs {
    right: 8px;
    bottom: 64px;
    max-width: 230px;
    gap: 4px;
  }

  .buff {
    height: 24px;
    padding: 3px 6px;
    font-size: 10px;
  }

  .toast,
  .arena .toast {
    top: 44px;
    min-width: 180px;
    max-width: 54%;
    padding: 7px 10px;
    font-size: 12px;
  }

  .brief {
    width: min(600px, calc(100% - 20px));
    max-height: calc(100% - 18px);
    padding: 10px 12px;
    overflow: auto;
  }

  .brief h2 {
    margin-bottom: 5px;
    font-size: 20px;
  }

  .brief p {
    margin-bottom: 8px;
    font-size: 11px;
    line-height: 1.35;
  }

  .brief-actions {
    gap: 6px;
  }

  .brief-actions button {
    height: 34px;
  }

  .ship-select {
    max-height: 190px;
    gap: 6px;
    margin-bottom: 8px;
  }

  .ship-select.loading {
    display: grid;
    grid-template-columns: 1fr;
    min-height: 76px;
    place-items: center;
    border: 1px dashed rgba(86, 246, 255, 0.28);
    color: var(--muted);
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
  }

  .ship-select-page {
    gap: 6px;
  }

  .ship-page-btn {
    min-height: 76px;
  }

  .ship-card {
    min-height: 78px;
    grid-template-columns: 36px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    justify-items: start;
    gap: 2px 6px;
    padding: 5px;
    text-align: left;
  }

  .ship-card .pix {
    grid-row: 1 / 4;
    width: 32px;
    height: 32px;
    padding: 2px;
  }

  .ship-card strong {
    font-size: 12px;
  }

  .ship-card small,
  .ship-card span {
    font-size: 10px;
    line-height: 1.2;
  }

  .modal-layer {
    padding: 8px;
    place-items: stretch;
  }

  .modal {
    width: 100%;
    height: calc(100vh - 16px);
    min-height: 0;
  }

  .modal.codex,
  .modal.info {
    place-self: center;
    width: min(760px, calc(100vw - 16px));
    height: min(520px, calc(100vh - 16px));
  }

  .modal.info {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .modal header {
    min-height: 48px;
    padding: 8px 12px;
  }

  .modal header p {
    margin-bottom: 2px;
    font-size: 9px;
  }

  .modal h2 {
    font-size: 20px;
  }

  .modal header strong {
    top: 9px;
    right: 12px;
    padding: 5px 8px;
  }

  .tabs {
    gap: 5px;
    padding: 7px 8px;
  }

  .tabs button {
    min-width: 70px;
    height: 30px;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    padding: 8px;
  }

  .modal.codex .tabs {
    overflow-x: auto;
  }

  .modal.codex .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mobile-info-grid {
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-auto-rows: max-content;
    align-content: start;
    gap: 8px;
    padding: 8px;
    overflow: auto;
  }

  .mobile-info-card {
    min-height: 0;
    display: grid;
    gap: 6px;
    padding: 8px;
    border: 1px solid rgba(86, 246, 255, 0.20);
    background: rgba(3, 8, 20, 0.68);
  }

  .mobile-info-card h2,
  .mobile-info-card h3,
  .mobile-info-card p {
    margin: 0;
  }

  .mobile-info-card h2 {
    color: var(--cyan);
    font-size: 11px;
  }

  .mobile-info-card h3 {
    color: var(--text);
    font-size: 13px;
    line-height: 1.15;
  }

  .mobile-info-card p,
  .mobile-info-card small {
    color: var(--muted);
    font-size: 10px;
    line-height: 1.35;
  }

  .mobile-info-card .card-head {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .mobile-info-card .card-head span {
    overflow: hidden;
    color: var(--yellow);
    font-size: 10px;
    font-weight: 900;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-info-row {
    min-width: 0;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    gap: 7px;
  }

  .mobile-info-icon .pix {
    width: 38px;
    height: 38px;
    padding: 3px;
  }

  .mobile-info-stat-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
    grid-column: 1 / -1;
  }

  .mobile-info-stat-grid div {
    min-width: 0;
    padding: 5px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.035);
    text-align: center;
  }

  .mobile-info-stat-grid span {
    display: block;
    overflow: hidden;
    color: var(--muted);
    font-size: 9px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-info-stat-grid strong {
    display: block;
    margin-top: 2px;
    color: var(--text);
    font-size: 12px;
  }

  .mobile-info-help {
    grid-column: 1 / -1;
  }

  .mobile-info-card .ministats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mobile-info-readonly .weapon-focus {
    grid-template-columns: 38px minmax(0, 1fr);
  }

  .mobile-info-grid .help {
    grid-column: 1 / -1;
  }

  .item {
    min-height: 104px;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 5px 7px;
    padding: 7px;
  }

  .item .pix {
    width: 36px;
    height: 36px;
    padding: 2px;
  }

  .item h3 {
    font-size: 13px;
  }

  .item p {
    font-size: 11px;
    line-height: 1.32;
  }

  .modal footer {
    padding: 7px 8px;
  }

  #shopModal {
    width: 100%;
    grid-template-columns: 112px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  #shopModal > .tabs {
    grid-column: 1;
    grid-row: 2;
    flex-direction: column;
    padding: 8px;
    overflow-y: auto;
  }

  #shopModal > .grid,
  #shopModal > .armory-grid {
    grid-column: 2;
    grid-row: 2;
  }

  .armory-subnav {
    padding: 7px 8px;
  }

  .armory-route-tab {
    min-width: 94px;
    height: 30px;
  }

  .armory-content {
    padding: 8px;
  }

  .armory-tree {
    min-width: 680px;
    min-height: 300px;
    max-height: calc(100vh - 170px);
    padding: 8px;
    overflow-x: auto;
    overflow-y: auto;
  }

  .armory-tree-canvas {
    min-width: 680px;
    min-height: 640px;
    margin: 0 72px 92px;
    transform: scale(var(--armory-zoom, 1));
    transform-origin: 0 0;
  }

  .armory-tree-node {
    width: clamp(154px, 20%, 204px);
    min-height: 86px;
  }
}

@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 430px),
  (orientation: landscape) and (max-height: 430px) and (max-width: 920px) {
  .modal.codex .grid,
  .mobile-info-grid {
    grid-template-columns: 1fr;
  }

  .touch-joystick {
    width: 104px;
    height: 104px;
  }
}
