/* Shared commands, adapted presentation. Desktop retains its existing layout. */
#mobile-dock, #mobile-map-tools, #mobile-details, #mobile-finish-order,
#mobile-menu-backdrop, .mobile-sheet-bar, .nav-label, .mobile-site-list { display: none; }
#mobile-sheet { display: contents; }
.mobile-table-scroll { max-width: 100%; overflow-x: auto; }
.mobile-table-scroll:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

@media (max-width: 900px) {
    :root { --top: calc(120px + env(safe-area-inset-top, 0px)); --bottom: calc(64px + env(safe-area-inset-bottom, 0px)); --left: 0px; --right: 0px; }
    html { -webkit-text-size-adjust: 100%; overflow: auto; }
    #app { height: 100dvh; }
    button, input, select, textarea, label input, label select { font-size: 16px; }
    .btn, .btn.small, .tab, input:not([type=checkbox]):not([type=range]), select { min-height: 44px; }
    button, a, summary { touch-action: manipulation; }
    button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; }
    #topbar { padding: calc(6px + env(safe-area-inset-top, 0px)) 12px 6px; height: calc(80px + env(safe-area-inset-top, 0px)); grid-template-columns: minmax(0,1fr) auto; grid-template-rows: 35px 1fr; background: #090b0e; }
    #topbar .brand { min-width: 0; }
    #topbar .brand-text, #topbar .logo-mark { display: none; }
    #topbar .clock { padding: 0; }
    #clock-date { font-size: 12px; letter-spacing: .02em; }
    .tick-bar { width: 55px; }
    .wallet { grid-column: 2; grid-row: 1 / 3; }
    .credits { font-size: clamp(14px, 4vw, 19px); }
    .income { font-size: 12px; }
    .title-block { grid-column: 1; grid-row: 2; text-align: left; overflow: hidden; }
    #title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .01em; }
    #subtitle { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    #viewport { top: var(--top); bottom: var(--bottom); }
    #galaxy-canvas, #system-svg { touch-action: none; }
    #page, #page.wide { inset: 0; padding: 12px 12px 76px; overflow-x: hidden; overscroll-behavior: contain; }
    #bottombar { top: calc(80px + env(safe-area-inset-top, 0px)); bottom: auto; left: 0; right: 0; height: 40px; overflow-x: auto; overflow-y: hidden; border-width: 1px 0; }
    .bb-cell { flex: 0 0 auto; padding: 0 12px; gap: 7px; }
    .bb-cell svg { width: 17px; height: 17px; }
    .bb-label { font-size: 10px; }
    .bb-value { font-size: 12px; }
    #leftbar { display: none; }
    .mobile-menu-open #leftbar { display: flex; position: fixed; top: auto; bottom: var(--bottom); left: 8px; right: 8px; width: auto; max-height: calc(100dvh - var(--top) - var(--bottom)); overflow-y: auto; z-index: 33; padding: 12px; background: #090b0e; border: 1px solid var(--line); border-radius: 16px 16px 0 0; gap: 4px; }
    #leftbar .nav-btn { width: 100%; min-height: 46px; height: auto; justify-content: flex-start; gap: 14px; padding: 10px; text-align: left; }
    .nav-label { display: inline; }
    .mobile-site-list { display: block; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
    #portal-map { touch-action: none; }
    #leftbar .badge { top: 12px; right: 12px; }
    #mobile-menu-backdrop { position: fixed; inset: 0; background: #0009; border: 0; z-index: 32; }
    .mobile-menu-open #mobile-menu-backdrop { display: block; }
    #mobile-dock { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); position: absolute; bottom: 0; left: 0; right: 0; height: var(--bottom); padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); background: #090b0e; border-top: 1px solid var(--line); z-index: 35; gap: 3px; }
    #mobile-dock button { min-width: 0; border: 1px solid transparent; background: transparent; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 13px; padding: 6px 2px; }
    #mobile-dock button.active, #mobile-dock button[aria-expanded=true] { color: var(--orange); background: #ff8c1a18; border-color: var(--orange-dim); }
    #mobile-map-tools { position: absolute; top: calc(var(--top) + 10px); right: 10px; display: flex; flex-direction: column; gap: 5px; z-index: 11; }
    #mobile-map-tools button { min-width: 44px; min-height: 44px; padding: 6px; border: 1px solid var(--orange-dim); border-radius: 9px; color: var(--orange); background: #090b0eee; font-size: 12px; }
    #mobile-map-tools button:first-child, #mobile-map-tools button:nth-child(2) { font-size: 23px; }
    #mobile-map-tools [aria-pressed=true] { background: var(--orange); color: black; }
    #app:not([data-mobile-view=galaxy]):not([data-mobile-view=system]) #mobile-map-tools { display: none; }
    #mobile-details { display: block; position: absolute; right: 12px; bottom: calc(var(--bottom) + 12px); z-index: 15; min-height: 46px; padding: 10px 16px; border: 1px solid var(--orange); border-radius: 24px; color: #000; background: var(--orange); font-weight: 700; box-shadow: 0 4px 20px #0009; }
    #mobile-details[hidden], #mobile-finish-order[hidden], #mobile-map-tools [hidden] { display: none; }
    #mobile-sheet { display: none; }
    .mobile-panel-open #mobile-sheet { display: flex; flex-direction: column; position: absolute; left: 0; right: 0; bottom: var(--bottom); max-height: calc(100dvh - var(--top) - var(--bottom) - 8px); height: min(68dvh, 640px); z-index: 25; border: 1px solid var(--line); border-radius: 18px 18px 0 0; background: #090b0e; box-shadow: 0 -12px 36px #0008; }
    .mobile-sheet-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex: none; padding: 8px 12px; border-bottom: 1px solid var(--line); color: var(--orange); font-weight: 600; }
    #mobile-sheet-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    #sidepanel { position: static; width: auto; max-height: none; min-height: 0; flex: 1; overflow-y: auto; overscroll-behavior: contain; border: 0; padding: 12px 16px 24px; }
    #mobile-finish-order { display: block; position: absolute; left: 12px; bottom: calc(var(--bottom) + 12px); min-height: 46px; z-index: 16; padding: 10px 14px; border: 1px solid var(--green); border-radius: 24px; background: #090b0e; color: var(--green); }
    #hint { left: 10px; right: 74px; bottom: calc(var(--bottom) + 72px); transform: none; font-size: 11px; letter-spacing: .02em; }
    .page-grid, .form-grid, .species-grid, .battle-columns, .portal-grid { grid-template-columns: minmax(0,1fr); }
    .box, .card, .battle-unit { min-width: 0; overflow-wrap: anywhere; }
    .page-title { font-size: 22px; }
    .btn-row { flex-wrap: wrap; gap: 8px; }
    .btn-row > .btn { flex: 1 1 auto; }
    .mobile-table-scroll { touch-action: pan-x pan-y; overscroll-behavior-x: contain; margin-bottom: 10px; }
    .data-table { width: max-content; min-width: 100%; }
    .log-entry { grid-template-columns: minmax(0,1fr); gap: 4px; }
    .kv { grid-template-columns: minmax(0,1fr) minmax(0,auto); }
    .modal-backdrop { padding: 12px; }
    .modal { width: min(100%,520px); max-height: 90dvh; overflow: auto; padding: 16px; }
    #toasts { position: fixed; top: var(--top); width: calc(100% - 24px); }
    .toast { max-width: 100%; font-size: 14px; }
    .tutorial { left: 10px; right: 10px; bottom: calc(var(--bottom) + 72px); width: auto; max-height: 38dvh; overflow-y: auto; padding: 10px 12px; }
    .mobile-panel-open .tutorial, .mobile-menu-open .tutorial { visibility: hidden; }
    .login-card, .login-card.wide { width: min(100% - 24px,520px); max-height: 95dvh; overflow-y: auto; padding: 20px; }
    .overlay { overflow-y: auto; padding: 12px 0; }
    .logo-title { font-size: 20px; }
    .portal-body { overflow: auto; height: auto; min-height: 100dvh; }
    .portal-header { padding: 12px; gap: 8px; position: static; }
    .portal-tabs { display: flex; overflow-x: auto; white-space: nowrap; }
    .portal-tabs .tab { flex: none; }
    .portal-main { padding: 12px; }
    .portal-main .data-table { display: block; overflow-x: auto; max-width: 100%; }
    .portal-map-wrap { height: min(44dvh,360px); }
    .commander-card { flex-wrap: wrap; }
}

@media (max-width: 900px) and (max-height: 500px) {
    #mobile-map-tools { flex-direction: row; top: calc(var(--top) + 4px); }
    .mobile-panel-open #mobile-sheet { height: calc(100dvh - var(--top) - var(--bottom)); }
}
