/* ==================================================================================================================
   Mobile / touch layout of the game UI (phones, tablets). Loaded after app.css and the component styles.
   The classes on <html> come from js/mobile.js:
     ui-touch    finger input (pointer: coarse) - bigger hit areas, folding panels, no sticky hover looks;
     ui-compact  phone-sized screen - the compact layout below (the UI is also scaled down by mobile.js);
     ui-portrait / ui-landscape - orientation of the safe area.
   All sizes inside .game-ui are design px (the whole .game-ui is scaled by --ui-scale).
   ================================================================================================================== */

/* ---- Safe area (notch, rounded corners, home indicator; index.html: viewport-fit=cover). The canvas keeps the whole
   screen, every UI panel lives in the safe box. On a monitor all insets are 0 (no change). */
:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
.game-ui {
  left: var(--safe-l); top: var(--safe-t);
  width: calc((100% - var(--safe-l) - var(--safe-r)) / var(--ui-scale, 1));
  height: calc((100% - var(--safe-t) - var(--safe-b)) / var(--ui-scale, 1));
}

/* Drag handles never start a browser pan / zoom gesture (it would cancel the drag with pointercancel). */
.drag-handle, .menu-grip { touch-action: none; }
/* Fold arrow and the attack / configuration buttons of the action bars: touch screens only (below). */
.action-bar > .bar-fold, .action-bar > .bar-action { display: none; }
/* iPhone Safari has no Fullscreen API. */
html.ui-no-fullscreen [data-game-fullscreen] { display: none; }

/* ==================================================================================================================
   ui-touch: tablets and phones
   ================================================================================================================== */
html.ui-touch .game-root { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }
/* Like a native game: no pull-to-refresh / bounce of the page, no page zoom by pinch or double tap on the interface
   (the scene zooms itself), no text selection by a long press (text boxes excepted). */
html.ui-touch, html.ui-touch body { overscroll-behavior: none; }
html.ui-touch .game-root { touch-action: pan-x pan-y; -webkit-user-select: none; user-select: none; }
html.ui-touch .game-root :is(input, textarea, [contenteditable="true"]) { -webkit-user-select: text; user-select: text; }
/* Target panel: ✕ drops the target (there is no Escape key). */
.target-clear { display: none; }
html.ui-touch .target-panel .target-name { position: relative; padding-right: 40px; }
html.ui-touch .target-clear { display: flex; align-items: center; justify-content: center; position: absolute; right: 0; top: 50%;
  transform: translateY(-50%); width: 34px; height: 30px; padding: 0; font-size: .9rem; line-height: 1; color: var(--muted);
  background: transparent; border: 1px solid var(--border); border-radius: 6px; }
html.ui-touch :is(.journal-list, .chat-messages, .window-body, .mission-tracker, .group-panel, .group-log-panel, .nerd-stats) {
  overscroll-behavior: contain; }
/* Text boxes at 16 px: iOS zooms the page into any smaller input on focus. */
html.ui-touch :is(input:not([type]), input[type=text], input[type=number], input[type=search], input[type=email],
  input[type=password], textarea, select) { font-size: 16px; }

/* Title bar (GamePanel.razor): bigger tool buttons and the move grip as its own button (a tap on the panel name folds
   the panel, mobile.js; dragging the bar still moves it). */
html.ui-touch .ow-panel > .ow-titlebar { min-height: 36px; }
html.ui-touch .ow-titlebar .ow-tool { width: 32px; height: 30px; font-size: 18px; }
html.ui-touch .ow-titlebar .ow-tool .ui-icon { width: 16px; height: 16px; }
html.ui-touch .ow-titlebar .ow-grip { display: inline-flex; }
html.ui-touch .panel-heading-name { min-height: 34px; padding-right: 6px; cursor: pointer; }
html.ui-touch .panel-heading-name::after { content: ""; width: 6px; height: 6px; margin-left: 4px; flex: none;
  border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: translateY(-2px) rotate(45deg); opacity: .8;
  transition: transform .15s; }
html.ui-touch [data-collapsed] .panel-heading-name::after { transform: rotate(-45deg); }
html.ui-touch [data-collapsed] .panel-heading-name { color: var(--text); }
/* Folded: no reset button (journal), so the header keeps one line. */
html.ui-touch [data-collapsed] > .panel-heading .panel-reset { display: none; }

/* Folded panel: only its header (the chat keeps its channel tabs while one has unread messages). */
html.ui-touch .panel[data-collapsed] { height: auto; max-height: none; min-height: 0; overflow: visible; }
html.ui-touch .panel[data-collapsed] > :not(.panel-heading) { display: none !important; }
html.ui-touch .panel[data-collapsed] > .panel-heading { margin-bottom: 0; }
html.ui-touch .panel.ow-panel[data-collapsed] { padding-bottom: 0; }
html.ui-touch .chat-window[data-collapsed] > .tabs:has(.unread) { display: flex !important; }
html.ui-touch .chat-window[data-collapsed] > .tabs:has(.unread) button:not(.unread) { display: none; }

/* Window frame: bigger header buttons and tabs. */
html.ui-touch .ow-panel > .window-header { min-height: 44px; }
html.ui-touch .ow-panel > .window-header .ow-tool { width: 40px; height: 36px; }
html.ui-touch .game-window .tabs button { min-height: 34px; }
html.ui-touch .game-window button.small, html.ui-touch .panel button.small { min-height: 30px; }

/* Chat: bigger tabs, input and send button. */
html.ui-touch .chat-window .tabs button { min-height: 30px; padding: 3px 12px; }
html.ui-touch .chat-input :is(input, button) { min-height: 36px; }
html.ui-touch .chat-line .sender { padding: 2px 0; }
/* The software keyboard must not cover the chat input (mobile.js: --kb-inset). Monitor layout on a touch screen: the
   chat is at the bottom; the compact layout keeps it in the panel corner at the top. */
html.ui-touch:not(.ui-compact) .chat-window:focus-within:not([data-moved]) {
  bottom: max(12px, calc(var(--kb-inset, 0px) / var(--ui-scale, 1) + 8px)); }

/* Minimap header zoom buttons / checkbox, ship + pilot value toggles. */
html.ui-touch .minimap .zoom-toggle { min-height: 30px; }
html.ui-touch .minimap .zoom-toggle input { width: 18px; height: 18px; }
html.ui-touch .minimap .zoom-buttons button { width: 34px; height: 30px; }
html.ui-touch button.stat-value { min-height: 26px; }

/* System buttons in the top right corner. */
html.ui-touch .game-brand button { width: 40px; height: 40px; }
html.ui-touch .game-brand .ui-icon { width: 22px; height: 22px; }
/* Their fold arrow (Game.razor, data-fold-id="SystemButtons"), the same as the one of the action bars: folded = only the
   arrow is left (a dot on it = unread mail). In the row of the monitor layout the buttons fold towards the screen edge,
   in the column of the compact layout upwards (below). */
html.ui-touch .game-brand-actions > button.sys-fold { display: flex; align-items: center; justify-content: center; position: relative;
  width: 26px; height: 40px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--muted); }
html.ui-touch .game-brand-actions > button.sys-fold:hover { background: var(--panel); }
html.ui-touch .game-brand-actions > .sys-fold .bar-fold-arrow { transform: translateX(-2px) rotate(-45deg); }
html.ui-touch .game-brand-actions[data-collapsed] > .sys-fold .bar-fold-arrow { transform: translateX(2px) rotate(135deg); }
html.ui-touch .game-brand-actions[data-collapsed] > :not(.sys-fold) { display: none; }
.sys-fold-dot { display: none; }
html.ui-touch .game-brand-actions[data-collapsed] .sys-fold-dot { display: block; position: absolute; right: 3px; top: 3px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }

/* Toolbar: a bigger grip; folded, the whole toolbar (panels + windows) is one menu button (a tap opens it,
   mobile.js). */
html.ui-touch .menu-dock > .menu-grip { min-height: 30px; display: flex; align-items: center; justify-content: center; }
html.ui-touch .menu-dock[data-collapsed] > .menu-groups { display: none; }
html.ui-touch .menu-dock[data-collapsed] > .menu-grip { position: relative; width: 46px; height: 46px; padding: 0;
  color: var(--text); background: var(--panel-fill); border: 1px solid var(--panel-edge); border-radius: 6px;
  box-shadow: 0 0 10px var(--panel-glow), inset 0 0 18px var(--panel-inner-glow); }
html.ui-touch .menu-dock[data-collapsed] > .menu-grip .ui-icon { display: none; }
html.ui-touch .menu-dock[data-collapsed] > .menu-grip::before { content: ""; width: 22px; height: 18px; }
/* The toolbar menu button = "menu" (three lines). */
html.ui-touch .menu-dock.menu-toolbar[data-collapsed] > .menu-grip::before {
  background: linear-gradient(currentColor 0 0) 0 0 / 100% 2px no-repeat, linear-gradient(currentColor 0 0) 0 8px / 100% 2px no-repeat,
    linear-gradient(currentColor 0 0) 0 16px / 100% 2px no-repeat; }
html.ui-touch .menu-dock.menu-toolbar[data-collapsed]:has(.menu-badge) > .menu-grip::after { content: ""; position: absolute; right: 4px; top: 4px;
  width: 9px; height: 9px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }

/* A tapped button keeps :hover on touch screens until the next tap elsewhere - the slot / button looked selected.
   Hover looks are reset to the plain look (selected / attacking / reloading keep theirs). */
html.ui-touch .action-bar .slot:hover:not(.active, .attacking, .bar-action) { background: var(--slot-fill); border-color: var(--slot-edge); }
html.ui-touch button.sq-btn:hover:not(.active, .admin-toggle, .quick-buy) { color: var(--sq-icon); border-color: var(--sq-edge);
  background: linear-gradient(180deg, var(--sq-top), var(--sq-bottom)); }
html.ui-touch button.sq-btn.bar-menu-item:hover:not(.active, .quick-buy) { background: var(--slot-fill); border-color: var(--slot-edge); }
html.ui-touch .bar-menu-toggle:hover:not(.open) { color: var(--sq-icon); border-color: var(--sq-edge);
  background: linear-gradient(180deg, var(--sq-top), var(--sq-bottom)); }

/* Action bars (ActionBar.razor): the arrow on the left folds a bar (mobile.js, data-collapsed; bar 2 starts folded in
   the compact layout). Folded = the first slots as quick access (2..5, Settings → Interface; the others carry
   .fold-extra). Every bar ends with a button that is always
   shown on touch screens: bar 1 = laser attack (Attack key: start / stop with the ammunition selected on the bars;
   the reload of the next shot sweeps over it), bar 2 = switch the configuration (SwitchConfig key; the active
   configuration, the sweep and the seconds until the next switch). Bar 2 above bar 1, both aligned left (the fold
   arrows in one column); the compact layout moves them to the corner of the attack hand (below). */
html.ui-touch .bottom-bars .bars { align-items: flex-start; }
html.ui-touch .bottom-bars .action-bar { display: flex; align-items: center; gap: 3px; }
html.ui-touch .action-bar > .bar-fold { display: flex; align-items: center; justify-content: center; flex: none;
  width: 26px; height: 40px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--muted); }
html.ui-touch .action-bar > .bar-fold:hover { background: var(--panel); }
html.ui-touch .bar-fold-arrow { width: 8px; height: 8px; border: solid currentColor; border-width: 0 2px 2px 0;
  transform: translateX(2px) rotate(135deg); }
html.ui-touch .action-bar[data-collapsed] .bar-fold-arrow { transform: translateX(-2px) rotate(-45deg); }
html.ui-touch .action-bar[data-collapsed] > .slots > .slot.fold-extra { display: none; }
/* The item menu starts at the first slot (right of the fold arrows), so its columns stay in line with the slots. */
html.ui-touch .bar-menu { left: calc(26px + var(--slot-gap)); }
html.ui-touch .action-bar > .bar-action { display: flex; flex: none; width: var(--slot); height: var(--slot); }
html.ui-touch .action-bar > .bar-action .bar-action-icon { position: relative; width: 46%; height: 46%; margin-top: -6%; }
html.ui-touch .action-bar > .bar-action .bar-action-label { position: relative; font-size: .5rem; font-weight: 700; line-height: 1;
  text-transform: uppercase; letter-spacing: .02em; max-width: 86%; text-align: center; }
/* Cooldown: a dark sweep over the square (clipped by the slot), counting down clockwise; --cd = share still to wait. */
html.ui-touch .action-bar > .bar-action .bar-cooldown { position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: conic-gradient(rgba(0, 0, 0, .62) calc(var(--cd, 0) * 360deg), transparent 0); }
html.ui-touch .action-bar > .bar-action .bar-cooldown-text { position: absolute; inset: 0; z-index: 3; display: flex;
  align-items: center; justify-content: center; font-size: 1.05rem; font-weight: 800; color: #fff; text-shadow: 0 0 4px #000, 0 0 2px #000; }
html.ui-touch .action-bar > .attack-slot { color: #ffb3ae; border-color: #c0453e; background: hsl(3 55% 16% / .85); }
html.ui-touch .action-bar > .attack-slot.attacking { color: #fff; border-color: #ff6b62;
  background: radial-gradient(circle, hsl(3 70% 30%) 0%, hsl(3 60% 18%) 70%); box-shadow: 0 0 8px rgba(255, 107, 98, .55); }
html.ui-touch .action-bar > .attack-slot.attacking .bar-action-icon { filter: drop-shadow(0 0 4px #ff6b62); animation: attack-pulse 1s ease-in-out infinite; }
html.ui-touch .action-bar > .attack-slot:hover:not(.attacking) { border-color: #c0453e; background: hsl(3 55% 16% / .85); }
@keyframes attack-pulse { 50% { transform: scale(1.12); } }
/* Configuration: violet like the configuration tag of the ship panel; the number of the active configuration over the
   arrows. Waiting for the next switch = greyed border. */
html.ui-touch .action-bar > .config-slot { color: #e4d6ff; border-color: #8f6ad8; background: hsl(265 45% 16% / .85); }
html.ui-touch .action-bar > .config-slot:hover:not(.waiting) { border-color: #8f6ad8; background: hsl(265 45% 16% / .85); }
html.ui-touch .action-bar > .config-slot.waiting { border-color: var(--muted); }
html.ui-touch .action-bar > .config-slot .config-number { position: absolute; left: 0; right: 0; top: 30%; z-index: 1;
  text-align: center; font-size: .78rem; font-weight: 800; line-height: 1; color: #fff; }
html.ui-touch .action-bar > .config-slot .bar-action-icon { opacity: .55; }
/* Touch drag & drop (js/touchInput.js): a long press picks an item up; it floats above the finger, the slot under it
   lights up. The items never start a browser pan (that would cancel the drag). */
html.ui-touch :is(.action-bar .slot, .bar-menu .bar-menu-item) { touch-action: none; }
.action-bar .slot.touch-dragging, .bar-menu .bar-menu-item.touch-dragging { opacity: .45; }
.action-bar .slot.touch-drop-over { border-color: #ffd23f; background: hsl(45 60% 22% / .85); }
.touch-drag-ghost { position: fixed; left: 0; top: 0; z-index: 100001; pointer-events: none; display: flex; flex-direction: column;
  align-items: center; gap: 2px; filter: drop-shadow(0 0 8px rgba(255, 210, 63, .8)); }
.touch-drag-ghost > :first-child { width: 48px; height: 48px; }
.touch-drag-ghost :is(svg, img) { width: 100%; height: 100%; }
.touch-drag-ghost .item-icon { border: none; background: transparent; box-shadow: none; }
.touch-drag-name { max-width: 160px; padding: 1px 6px; border-radius: 4px; background: rgba(0, 0, 0, .7); color: #fff;
  font: 600 12px/1.3 system-ui, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* A press is felt: the button shrinks a little (no hover on touch). */
html.ui-touch .action-bar .slot:active { transform: scale(.92); }
html.ui-touch .action-bar .slot { transition: transform .08s; }

/* ==================================================================================================================
   ui-compact: phones and tablets - four corners for two thumbs (js/mobile.js, section 5). Right hand (default):
     bottom left:   movement joystick + configuration switch (TouchControls.razor), a little away from the edges;
     bottom right:  the action bars (folded = their first 2..5 slots, Settings → Interface) with a big laser attack
                    button at the edge, under the right thumb; lifted above the joystick when they would overlap it;
     top right:     minimap (zoomed by default), the system buttons in a column beside it, the toolbar
                    menu button ☰ under it (folded by default);
     top left:      the HUD panels one under another, in columns (mobile.js flow: --flow-x / --flow-y = distance from
                    the corner side), the pilot and ship panels as long, low strips; the target panel at the top in
                    the middle with the action log under it.
   Left hand (html.ui-left-hand, Settings → Interface): the same mirrored. Every panel can still be dragged (the inline
   position from panels.js wins; saved per layout and hand, never shared with the monitor layout). Game windows (shop,
   hangar, settings, ...) fill the screen.
   ================================================================================================================== */
/* Panel names a little tighter: a header with a counter keeps one line in the narrow panels. */
html.ui-compact .panel-heading-name { letter-spacing: .04em; gap: 4px; }

/* ---- Panel corner (top left; top right for the left hand). */
html.ui-compact :is(.pilot-panel, .hud.panel, .mission-tracker, .reward-log, .group-panel, .group-log-panel, .pet-panel, .chat-window) {
  left: var(--flow-x, 8px); right: auto; top: var(--flow-y, 8px); bottom: auto; transform: none; }
html.ui-compact.ui-left-hand :is(.pilot-panel, .hud.panel, .mission-tracker, .reward-log, .group-panel, .group-log-panel, .pet-panel, .chat-window) {
  left: auto; right: var(--flow-x, 8px); }
/* Pilot and ship: long, low strips - the "name | value" pairs (.stat-pair) side by side, wrapped into rows; the user /
   rank captions and the rank name give way to the values (the rank icon stays, its name is the tooltip). */
html.ui-compact { --strip-w: min(440px, var(--flow-max-w, 440px)); }
html.ui-compact :is(.pilot-panel, .hud.panel) { width: var(--strip-w); --frame-pad-x: 8px; --frame-pad-b: 5px; font-size: .78rem; }
html.ui-compact :is(.pilot-panel, .hud.panel) > .panel-heading { margin-bottom: 1px; }
html.ui-compact :is(.pilot-panel, .hud.panel) .stat-grid { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; margin-top: 0; }
html.ui-compact :is(.pilot-panel, .hud.panel) .stat-pair { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
html.ui-compact :is(.pilot-panel, .hud.panel) .stat-value { justify-self: auto; text-align: left; }
html.ui-compact :is(.pilot-panel, .hud.panel) .stat-bar { width: 104px; min-width: 0; height: 8px; }
html.ui-compact .pilot-panel :is(.stat-caption, .pilot-rank-name) { display: none; }
html.ui-compact .pilot-panel .pilot-user { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html.ui-compact .hud .status-tags { margin-top: 3px; min-height: 0; }
/* The configuration is shown by the button beside the joystick (TouchControls.razor). */
html.ui-compact .hud.panel .stat-pair.stat-pair-config { display: none; }
html.ui-compact .hud .status-tags:empty { display: none; }
html.ui-compact .mission-tracker { width: 240px; max-height: 34vh; }
html.ui-compact .reward-log { width: 240px; }
html.ui-compact .journal-list { max-height: 28vh; }
/* Group: wider, bigger text and bars (the 200 px panel was hard to read on a phone). */
html.ui-compact .group-panel { width: min(290px, var(--flow-max-w, 290px)); max-height: 50vh; font-size: .86rem; gap: 5px; }
html.ui-compact .group-panel .group-member { padding: 4px 6px; }
html.ui-compact .group-panel .group-member-line { gap: 6px; }
html.ui-compact .group-panel .group-member-line :is(.map, .level) { font-size: .76rem; }
html.ui-compact .group-panel .group-member-bars { gap: 2px; }
html.ui-compact .group-panel .bar.thin { height: 6px; }
html.ui-compact .group-panel .group-target .icon { font-size: .74rem; }
html.ui-compact .group-panel .group-member-bars .bar { height: 6px; }
html.ui-compact .group-panel .group-member-line .kick { opacity: .8; } /* no hover on touch screens */
html.ui-compact .group-panel .group-actions .group-tool { height: 34px; }
html.ui-compact .group-log-panel { width: 260px; max-height: 40vh; }
html.ui-compact .pet-panel { width: 250px; }
/* Chat: folded = a small header in the panel corner (with the channel that has unread messages); open = the whole
   screen, a small panel was too small to read and write on a phone (a tap on the name in its header folds it again).
   Over the HUD, the menus and the game windows; the software keyboard never covers the input (--kb-inset). */
html.ui-compact .chat-window { width: 240px; height: 180px; }
html.ui-compact .chat-window[data-collapsed] { width: 200px; }
html.ui-compact .game-ui .chat-window.panel:not([data-collapsed]) {
  left: 6px !important; right: 6px !important; top: 6px !important;
  bottom: calc(6px + var(--kb-inset, 0px) / var(--ui-scale, 1)) !important;
  width: auto !important; height: auto !important; max-height: none; transform: none !important; z-index: 20; font-size: .92rem;
  /* Always with an almost opaque background, also with "Hide panel backgrounds" (the scene must not show through). */
  background: hsl(calc(var(--theme-h) + 9) calc(55% * var(--theme-s)) 7% / .94) !important; border-color: var(--panel-edge) !important; backdrop-filter: blur(4px) !important;
  box-shadow: 0 0 10px var(--panel-glow), inset 0 0 18px var(--panel-inner-glow) !important; text-shadow: none !important; }
html.ui-compact .game-ui .chat-window.panel:not([data-collapsed]) > .panel-heading { visibility: visible !important; opacity: 1 !important; }
html.ui-compact .game-ui .chat-window.panel:not([data-collapsed]) .ui-icon { filter: none !important; }
html.ui-compact .chat-window:not([data-collapsed]) .panel-move { display: none; }
html.ui-compact .chat-window:not([data-collapsed]) > .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; flex: none; }
html.ui-compact .chat-window:not([data-collapsed]) > .tabs button { flex: none; font-size: .82rem; }
html.ui-compact .chat-window:not([data-collapsed]) .chat-line { padding: 2px 0; line-height: 1.45; }
html.ui-compact .chat-window:not([data-collapsed]) .chat-line .time { font-size: .76rem; }

/* Target at the top in the middle, never under the panel strips (they end at --strip-w + 8; 12 px apart). */
html.ui-compact .target-panel { left: max(calc(50% - 115px), calc(var(--strip-w) + 20px)); right: auto; top: 8px; width: 230px; font-size: .8rem; }
html.ui-compact.ui-left-hand .target-panel { left: auto; right: max(calc(50% - 115px), calc(var(--strip-w) + 20px)); }
html.ui-compact .target-panel .target-name { overflow-wrap: anywhere; }
/* Action log: under the target (ui.js docks it there); without a target in the target's place (mobile.js keeps the
   panels out of that zone). */
html.ui-compact .notifications { max-width: 440px; left: calc(max(calc(50% - 115px), calc(var(--strip-w) + 20px)) + 115px); }
html.ui-compact.ui-left-hand .notifications { left: auto; right: calc(max(calc(50% - 115px), calc(var(--strip-w) + 20px)) + 115px);
  transform: translateX(50%); }
html.ui-compact .nerd-stats { left: 50%; right: auto; top: 30%; bottom: auto; transform: translateX(-50%); }

/* ---- Map corner (top right; top left for the left hand): minimap in the corner, system buttons in a column beside
   it (--mm-w = its width + gap), the toolbar menu button under it (--menu-top, --menu-x from mobile.js). */
html.ui-compact .minimap { left: auto; right: 8px; top: 8px; bottom: auto; gap: 3px; }
html.ui-compact.ui-left-hand .minimap { right: auto; left: 8px; }
html.ui-compact .minimap .minimap-view canvas { width: calc(174px * var(--mm-k, 1)); height: calc(116px * var(--mm-k, 1)); }
/* Header: icon + fold arrow only (the zoom switch needs the room). */
html.ui-compact .minimap .panel-heading-name { font-size: 0; letter-spacing: 0; }
html.ui-compact .minimap .minimap-pos { font-size: .7rem; height: 2.6em; }
/* Two lines of a fixed height: the position, the destination under it (empty, not collapsed, when not flying). */
html.ui-compact .minimap .minimap-pos > span { display: block; height: 1.3em; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: clamp(.6rem, calc(100cqi / (var(--chars, 24) * .58)), 1em); }
html.ui-compact .minimap[data-collapsed] { width: 190px; }

/* The connection status (only a problem is shown) stands beside the button column, on the side away from the minimap. */
html.ui-compact .top-right { left: auto; right: calc(8px + var(--mm-w, 0px)); top: 8px; gap: 4px; max-width: calc(100% - 16px);
  grid-template-columns: auto auto; justify-items: end; }
html.ui-compact.ui-left-hand .top-right { right: auto; left: calc(8px + var(--mm-w, 0px)); justify-items: start; }
html.ui-compact .top-right .connection-status { grid-area: 1 / 1; margin-top: 0; padding: 3px 6px; }
html.ui-compact .game-brand { grid-area: 1 / 2; }
html.ui-compact.ui-left-hand .top-right .connection-status { grid-area: 1 / 2; }
html.ui-compact.ui-left-hand .game-brand { grid-area: 1 / 1; }
html.ui-compact .top-right .tutorial-bubble { grid-column: 1 / -1; grid-row: 2; }
html.ui-compact .game-brand { min-width: 0; padding-top: 0; }
html.ui-compact .game-brand img { display: none; }
html.ui-compact .game-brand-actions { flex-direction: column; padding-inline-end: 0; gap: 6px; }
html.ui-compact .game-brand-actions > button.sys-fold { width: 40px; height: 26px; }
html.ui-compact .game-brand-actions > .sys-fold .bar-fold-arrow { transform: translateY(2px) rotate(-135deg); }
html.ui-compact .game-brand-actions[data-collapsed] > .sys-fold .bar-fold-arrow { transform: translateY(-2px) rotate(45deg); }

html.ui-compact .menu-dock.menu-toolbar { left: auto; right: var(--menu-x, 8px); top: var(--menu-top, 200px); transform: none; }
html.ui-compact.ui-left-hand .menu-dock.menu-toolbar { right: auto; left: var(--menu-x, 8px); }
/* The open toolbar is a menu over the panels (also over the last touched one, .panel-foreground = 17). */
html.ui-compact .menu-dock { z-index: 18; }
html.ui-compact .menu-dock:not([data-collapsed]) { z-index: 19; }
/* The menu button stays where it is when its menu opens or closes: the same square (highlighted while open) in the
   corner of the open menu, the toolbar opens under it. It moves only after a 1 s hold (panels.js). */
html.ui-touch.ui-compact .menu-dock:not([data-collapsed]) { align-items: flex-end; }
html.ui-touch.ui-compact.ui-left-hand .menu-dock:not([data-collapsed]) { align-items: flex-start; }
html.ui-touch.ui-compact .menu-dock:not([data-collapsed]) > .menu-grip { position: relative; flex: none; width: 46px; height: 46px;
  min-height: 46px; padding: 0; color: var(--accent); background: var(--panel-fill); border: 1px solid var(--accent);
  border-radius: 6px; box-shadow: 0 0 10px var(--panel-glow), inset 0 0 18px var(--panel-inner-glow); }
html.ui-touch.ui-compact .menu-dock:not([data-collapsed]) > .menu-grip .ui-icon { display: none; }
html.ui-touch.ui-compact .menu-dock:not([data-collapsed]) > .menu-grip::before { content: ""; width: 22px; height: 18px; }
html.ui-touch.ui-compact .menu-dock.menu-toolbar:not([data-collapsed]) > .menu-grip::before {
  background: linear-gradient(currentColor 0 0) 0 0 / 100% 2px no-repeat, linear-gradient(currentColor 0 0) 0 8px / 100% 2px no-repeat,
    linear-gradient(currentColor 0 0) 0 16px / 100% 2px no-repeat; }
html.ui-touch .menu-dock.dragging > .menu-grip { outline: 2px solid var(--accent); outline-offset: 1px; }
html.ui-compact .menu-dock:not([data-collapsed]) { background: hsl(calc(var(--theme-h) + 9) calc(55% * var(--theme-s)) 9% / .55);
  border-radius: 8px; }
/* Open toolbar in the compact layout: four columns instead of two (half as tall, it opens over the panels like a
   menu). */
/* Both groups one under the other (the windows first, the HUD panels under a thin line): one menu. */
html.ui-compact .menu-dock:not([data-collapsed]) > .menu-groups { flex-direction: column; align-items: center; gap: 8px; }
html.ui-compact .menu-dock:not([data-collapsed]) > .menu-groups > .menu-group-windows { order: -1; }
html.ui-compact .menu-dock:not([data-collapsed]) > .menu-groups > .menu-group-windows::before { left: 4px; right: 4px; top: auto;
  bottom: -5px; border-left: 0; border-top: 1px solid hsl(var(--theme-h) calc(100% * var(--theme-s)) 65% / .22); }
html.ui-compact .menu-dock:not([data-collapsed]) .menu-grid { grid-template-columns: repeat(4, var(--menu-btn)); }

/* ---- Bars corner (bottom right; bottom left for the left hand). Square slots of at most 56 design px (≈ 40 CSS px on
   a phone: a thumb); landscape: an unfolded bar fits beside the joystick, portrait: the ten slots wrap into two rows of
   five. The attack button leaves the end of bar 1: one and a half slots big, at the outer edge beside both bars (placed
   against .bars, so the slots of both bars stay in line). The configuration button of bar 2 moves to the joystick. */
html.ui-compact { --slot-w: clamp(40px, calc((var(--area-w, 1000px) - 330px) / 11.5 - 3px), 56px); --attack-w: calc(var(--slot-w) * 1.5);
  --slot: var(--slot-w); --slot-gap: 3px; }
html.ui-compact.ui-portrait { --slot-w: 54px; }
html.ui-compact.ui-portrait .action-bar > .slots { flex-wrap: wrap; max-width: calc(5 * (var(--slot-w) + 3px)); row-gap: 3px; }
html.ui-compact .bottom-bars { left: auto; right: 8px; bottom: var(--bars-b, 8px); transform: none; gap: 4px; }
html.ui-compact.ui-left-hand .bottom-bars { right: auto; left: 8px; flex-direction: row-reverse; }
html.ui-compact .bottom-bars .bars { gap: 3px; align-items: flex-end; justify-content: flex-end;
  min-height: var(--attack-w); padding-right: calc(var(--attack-w) + 6px); }
html.ui-compact.ui-left-hand .bottom-bars .bars { align-items: flex-start; padding-right: 0; padding-left: calc(var(--attack-w) + 6px); }
html.ui-compact .bottom-bars .action-bar { position: static; }
html.ui-compact .action-bar > .attack-slot { position: absolute; right: 0; bottom: 0; width: var(--attack-w); height: var(--attack-w); }
html.ui-compact.ui-left-hand .action-bar > .attack-slot { right: auto; left: 0; }
html.ui-compact .action-bar > .attack-slot .bar-action-label { font-size: .62rem; }
html.ui-compact .action-bar > .config-slot { display: none; }
html.ui-compact .action-bar .slot .slot-icon { top: calc(var(--slot-w) * .07); width: calc(var(--slot-w) * .66); height: calc(var(--slot-w) * .66); }
html.ui-compact .action-bar .slot .count { letter-spacing: -.02em; }
html.ui-compact .bars-side { justify-content: flex-end; }
/* The item menu arrow sits above the attack button (the end of bar 2 is next to it); a long item row wraps upwards. */
html.ui-compact .bars .bar-menu-toggle { left: auto; right: 0; top: auto; bottom: calc(var(--attack-w) + 6px); transform: none;
  width: var(--attack-w); height: 28px; }
html.ui-compact.ui-left-hand .bars .bar-menu-toggle { right: auto; left: 0; }
html.ui-compact .bar-menu .bar-menu-row { flex-wrap: wrap-reverse; max-width: min(640px, calc(var(--area-w, 640px) - 40px)); }

/* ---- Joystick corner (bottom left; bottom right for the left hand): TouchControls.razor, js/joystick.js. The joystick
   a little away from the edges, the configuration switch beside it on the inner side. */
.touch-controls { display: none; }
html.ui-compact .touch-controls { position: absolute; left: 32px; bottom: 26px; z-index: 7; display: flex; align-items: center; gap: 14px;
  pointer-events: none; }
html.ui-compact.ui-left-hand .touch-controls { left: auto; right: 32px; flex-direction: row-reverse; }
.joystick { position: relative; flex: none; width: 140px; height: 140px; pointer-events: auto; touch-action: none; cursor: grab;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.joystick-ring { --stick-travel: 42px; position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid hsl(var(--theme-h) calc(100% * var(--theme-s)) 65% / .45);
  background: radial-gradient(circle, hsl(var(--theme-h) calc(60% * var(--theme-s)) 22% / .28) 0%, hsl(var(--theme-h) calc(60% * var(--theme-s)) 8% / .5) 72%);
  box-shadow: 0 0 12px var(--panel-glow), inset 0 0 18px var(--panel-inner-glow); transition: border-color .15s; }
.joystick.active .joystick-ring { border-color: var(--accent); }
.joystick-knob { position: absolute; left: 50%; top: 50%; z-index: 1; width: 56px; height: 56px; border-radius: 50%;
  transform: translate(-50%, -50%); transition: transform .14s ease-out;
  background: radial-gradient(circle at 42% 36%, hsl(var(--theme-h) calc(70% * var(--theme-s)) 72%) 0%, hsl(var(--theme-h) calc(60% * var(--theme-s)) 38%) 55%, hsl(var(--theme-h) calc(60% * var(--theme-s)) 20%) 100%);
  border: 2px solid var(--accent); box-shadow: 0 2px 10px rgba(0, 0, 0, .65); }
.joystick.active .joystick-knob { transition: none; }
.joystick-arrow { position: absolute; width: 0; height: 0; border: 7px solid transparent; opacity: .55; }
.joystick-arrow.up { left: 50%; top: 7px; transform: translateX(-50%); border-top: 0; border-bottom: 9px solid var(--accent); }
.joystick-arrow.down { left: 50%; bottom: 7px; transform: translateX(-50%); border-bottom: 0; border-top: 9px solid var(--accent); }
.joystick-arrow.left { top: 50%; left: 7px; transform: translateY(-50%); border-left: 0; border-right: 9px solid var(--accent); }
.joystick-arrow.right { top: 50%; right: 7px; transform: translateY(-50%); border-right: 0; border-left: 9px solid var(--accent); }
/* Configuration switch: violet like the configuration of the ship panel; the active configuration in the middle; after a
   switch a dark sweep counts down clockwise (--cd = share still to wait) and the seconds replace the caption. */
.touch-config { position: relative; flex: none; width: 66px; height: 66px; padding: 0; border-radius: 50%; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; pointer-events: auto;
  touch-action: manipulation; color: #f0e8ff; border: 2px solid #8f6ad8;
  background: radial-gradient(circle at 50% 38%, hsl(265 45% 28%) 0%, hsl(265 45% 14%) 100%);
  box-shadow: 0 0 10px rgba(143, 106, 216, .45); transition: transform .08s, border-color .15s; }
.touch-config:hover { background: radial-gradient(circle at 50% 38%, hsl(265 45% 28%) 0%, hsl(265 45% 14%) 100%); }
.touch-config:active { transform: scale(.92); }
.touch-config.waiting { border-color: var(--muted); box-shadow: none; }
.touch-config-icon { position: absolute; left: 14%; top: 14%; width: 72%; height: 72%; opacity: .28; }
.touch-config > :is(.touch-config-number, .touch-config-label, .touch-config-seconds) { position: relative; z-index: 3; line-height: 1; }
.touch-config-number { font-size: 1.35rem; font-weight: 800; }
.touch-config-label { font-size: .5rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; opacity: .85; }
.touch-config.waiting .touch-config-label { display: none; }
.touch-config-seconds { font-size: .78rem; font-weight: 800; color: #fff; text-shadow: 0 0 4px #000, 0 0 2px #000; }
.touch-config-sweep { position: absolute; inset: 0; z-index: 2; pointer-events: none; border-radius: 50%;
  background: conic-gradient(rgba(0, 0, 0, .62) calc(var(--cd, 0) * 360deg), transparent 0); }

/* Centre banners: away from the target panel and the action log at the top. */
html.ui-compact .gate-countdown { top: 34%; }
html.ui-compact .radiation-banner { top: 36%; }
html.ui-compact .countdown-banner { top: 62%; }
html.ui-compact .countdown-banner.logout { top: 70%; }
html.ui-compact .destroyed-banner { top: 40%; }
html.ui-compact .group-invite-popup { top: 40%; }

/* Universal window frame: the shape of the screen (ui.js sets --win-w / --win-h, app.css uses them). */
/* A window fills the screen: above the HUD, the menu buttons and the system buttons, below dialogs (.modal-backdrop 20). */
html.ui-compact .game-window, html.ui-compact .game-window.panel-foreground { z-index: 19; }
html.ui-compact .game-window .window-header { gap: 8px; }
html.ui-compact .game-window .window-header .wallet { flex-wrap: wrap; gap: 2px 8px; font-size: .78rem; }

/* Galaxy panel (GalaxyWindow.razor). Landscape phone: the two rows stay (galaxy on top, three columns below with their
   own scroll bars), a bit tighter. Portrait phone: the galaxy on top, the three columns one under another and the
   whole panel scrolls; the alien list keeps its own scroll bar so the alien card below it stays within reach. */
html.ui-compact .game-window > .window-body.galaxy-body { grid-template-rows: minmax(150px, 1fr) minmax(140px, 1fr); gap: 6px; padding-top: 4px; }
html.ui-compact .galaxy-legend { gap: 6px; font-size: .62rem; padding: 2px 6px; }
html.ui-compact .galaxy-col { padding: 0 6px; }
html.ui-compact .galaxy-npc { min-height: 34px; align-items: center; }
/* Phone: the picked alien's texts stay white even with the system's dark mode / auto-darkening of the browser. */
html.ui-compact .galaxy-npc.active { color-scheme: only dark; forced-color-adjust: none; }
html.ui-compact .galaxy-npc.active, html.ui-compact .galaxy-npc.active * { color: #fff !important; -webkit-text-fill-color: #fff !important; }
html.ui-compact .galaxy-npc-card .model-preview.galaxy-npc-model { height: 110px; }
html.ui-compact.ui-portrait .game-window > .window-body.galaxy-body { display: flex; flex-direction: column; overflow: auto; }
html.ui-compact.ui-portrait .galaxy-view { flex: none; height: min(calc(var(--win-h, 640px) * .45), 360px); }
html.ui-compact.ui-portrait .galaxy-details { display: flex; flex-direction: column; gap: 10px; }
html.ui-compact.ui-portrait .galaxy-col { overflow: visible; padding: 0; }
html.ui-compact.ui-portrait .galaxy-col + .galaxy-col { border-left: 0; border-top: 1px solid var(--border); padding-top: 8px; }
html.ui-compact.ui-portrait .galaxy-map-npcs { max-height: 240px; overflow: auto; }

/* ---- Portrait phone: narrow and tall. The target in the middle of the screen (the panels flow around it), the
   joystick and the bars keep the bottom corners (the bars go above the joystick when they would overlap it). */
html.ui-compact.ui-portrait .target-panel { left: 50%; right: auto; top: 36%; transform: translateX(-50%); }
html.ui-compact.ui-portrait .notifications { left: 50%; right: auto; top: 36%; transform: translateX(-50%); max-width: calc(var(--area-w, 100vw) - 24px); }
html.ui-compact.ui-portrait .touch-controls { left: 22px; bottom: 22px; }
html.ui-compact.ui-portrait.ui-left-hand .touch-controls { left: auto; right: 22px; }

/* Minimap title bar in the map corner of the phone layout: no move grip (the corner is its place), slimmer − / +. */
html.ui-compact .minimap .ow-titlebar .ow-grip { display: none; }
html.ui-compact .minimap .ow-titlebar .ow-tool { width: 26px; }
