/*
 * OGameX responsive stylesheet (WCAG 2.2 SC 1.4.10 Reflow).
 * Provides fluid reflow for tablet (<= 1023px) and mobile (<= 767px) viewports
 * down to 320px CSS width without horizontal page scrolling.
 * Desktop layout (>= 1024px) remains 100% untouched.
 */

/* =============================================================================
   1. TABLET & NARROW SCREENS (max-width: 1023px)
   ============================================================================= */
@media (max-width: 1023px) {

    /* ---- 1.1 Page Shell & Layout Containers -------------------------------
     * Transition from fixed ~1000px desktop layout to fluid vertical flow.
     * Order: top header -> left navigation menu -> main content -> planet list.
     */
    #pageContent {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        padding: 0 8px !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
    }

    #top {
        order: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        box-sizing: border-box !important;
    }

    #left {
        order: 2 !important;
        width: 100% !important;
        max-width: 100% !important;
        top: 0 !important;
        float: none !important;
        margin: 8px 0 !important;
        box-sizing: border-box !important;
    }

    #middle {
        order: 3 !important;
        width: auto !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
    }

    #right {
        order: 4 !important;
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        margin: 12px 0 24px 0 !important;
        box-sizing: border-box !important;
    }

    #bannerSkyscrapercomponent,
    #banner_skyscraper {
        display: none !important;
    }

    #box {
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        margin: 0 auto !important;
        position: relative !important;
        box-sizing: border-box !important;
    }

    #scrollcontainer {
        width: 100% !important;
        max-width: 100% !important;
        position: static !important;
        left: auto !important;
        top: auto !important;
        overflow: visible !important;
    }

    /* Remove fixed decorative corner graphics that force overflow */
    .c-left,
    .c-right,
    div.c-left,
    div.c-right {
        display: none !important;
    }

    /* ---- 1.2 Top Bar, Clock, Resources & Commander ------------------------
     * Header bar links wrap onto several lines; resource tiles wrap cleanly;
     * officers and commander tools flow inline instead of absolute offsets.
     */
    #headerbarcomponent,
    #bar {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        box-sizing: border-box !important;
    }

    #bar ul {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 4px 10px !important;
        padding: 6px 4px !important;
        margin: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #bar ul li {
        float: none !important;
        display: inline-flex !important;
        align-items: center !important;
        height: auto !important;
        min-height: 24px !important;
        line-height: 22px !important;
        margin: 0 !important;
    }

    #bar ul li a {
        display: inline-flex !important;
        align-items: center !important;
        min-height: 24px !important;
        padding: 2px 4px !important;
        box-sizing: border-box !important;
    }

    #bar ul li#playerName,
    #bar ul li.OGameClock {
        float: none !important;
        text-align: center !important;
    }

    #pageReloader {
        position: relative !important;
        display: block !important;
        order: -1 !important;
        width: 190px !important;
        height: 70px !important;
        margin: 4px auto 0 !important;
        background: url('/img/icons/0d9cdd8b2ddfd7664a3e29c86a1436.png') no-repeat 0 -30px !important;
        cursor: pointer !important;
    }

    #resourcesbarcomponent {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 6px auto !important;
        box-sizing: border-box !important;
    }

    #resources,
    div#resources,
    ul#resources {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 6px 12px !important;
        width: 100% !important;
        height: auto !important;
        position: static !important;
        padding: 4px 0 !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
    }

    #resources .resource_tile,
    #info ul#resources li,
    #info div#resources div.resource {
        position: static !important;
        float: none !important;
        left: auto !important;
        top: auto !important;
        width: auto !important;
        min-width: 68px !important;
        height: auto !important;
        text-align: center !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        box-sizing: border-box !important;
        margin: 2px 4px !important;
    }

    #resources .resource_tile .resource {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        width: 100% !important;
        min-height: 48px !important;
    }

    #resources .resource_tile .value {
        display: block !important;
        width: 100% !important;
        text-align: center !important;
    }

    #commandercomponent {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 8px 16px !important;
        width: 100% !important;
        height: auto !important;
        margin: 8px auto !important;
        position: static !important;
        box-sizing: border-box !important;
    }

    #commandercomponent #characterclass {
        float: none !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    #commandercomponent #officers,
    #officers {
        position: static !important;
        float: none !important;
        left: auto !important;
        top: auto !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 6px !important;
        height: auto !important;
        width: auto !important;
        margin: 0 !important;
    }

    #officers a {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        min-width: 32px !important;
        min-height: 32px !important;
        height: 32px !important;
        width: 32px !important;
        box-sizing: border-box !important;
    }

    #notificationbarcomponent {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 6px auto !important;
        box-sizing: border-box !important;
    }

    #message-wrapper {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 8px 12px !important;
        width: 100% !important;
        height: auto !important;
        position: static !important;
        box-sizing: border-box !important;
    }

    #messages_collapsed {
        position: static !important;
        float: none !important;
        margin: 0 4px !important;
    }

    #attack_alert {
        position: static !important;
        float: none !important;
        margin: 0 !important;
    }

    /* ---- 1.3 Left Navigation Menu ------------------------------------------
     * Left menu expands to full width as a wrapping button grid.
     * Keeps touch targets >= 24x24px (WCAG 2.5.8) with minimum min-width ~140px.
     */
    #toolbarcomponent,
    #links {
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
    }

    #links .leftmenu,
    #menuTable.leftmenu {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: stretch !important;
        gap: 6px !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
    }

    #links .leftmenu li {
        float: none !important;
        width: calc(50% - 6px) !important;
        min-width: 140px !important;
        max-width: 220px !important;
        height: auto !important;
        min-height: 32px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    #links .leftmenu a.menubutton {
        flex: 1 1 auto !important;
        width: auto !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 30px !important;
        line-height: 28px !important;
        padding: 0 6px !important;
        margin: 0 !important;
        text-align: center !important;
        box-sizing: border-box !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background-size: 100% 100% !important;
    }

    #links .leftmenu li span.menu_icon {
        flex: 0 0 32px !important;
        width: 32px !important;
        height: 30px !important;
        float: none !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        box-sizing: border-box !important;
    }

    #toolLinksWrapper {
        width: 100% !important;
    }

    /* ---- 1.4 Planet List (Rechts / Planet Bar) -----------------------------
     * Positioned full-width underneath main content.
     * Uses a smoothly scrollable horizontal row on narrower viewports.
     */
    #planetbarcomponent,
    #rechts {
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        margin: 16px auto !important;
        position: static !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }

    #rechts #norm,
    #rechts #cutty,
    #rechts #myPlanets,
    #rechts #myWorlds {
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        box-sizing: border-box !important;
    }

    #countColonies {
        width: 100% !important;
        text-align: center !important;
        margin: 0 0 8px 0 !important;
    }

    #planetList {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 8px !important;
        padding: 6px 4px !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        scrollbar-width: thin !important;
    }

    #rechts .smallplanet,
    #rechts #myPlanets .smallplanet,
    #rechts #cutty .smallplanet,
    #rechts #norm .smallplanet {
        flex: 0 0 auto !important;
        width: 140px !important;
        min-width: 130px !important;
        height: 58px !important;
        margin: 0 !important;
        float: none !important;
        position: relative !important;
        background: rgba(14, 21, 28, 0.7) !important;
        border: 1px solid #202b35 !important;
        border-radius: 4px !important;
        box-sizing: border-box !important;
        text-align: left !important;
    }

    #rechts .smallplanet a.planetlink {
        display: block !important;
        width: 100% !important;
        height: 100% !important;
        min-height: 48px !important;
        box-sizing: border-box !important;
        padding: 6px 6px 6px 42px !important;
    }

    #rechts .smallplanet .planetPic {
        position: absolute !important;
        left: 6px !important;
        top: 8px !important;
    }

    #rechts .smallplanet span.planet-name {
        display: block !important;
        max-width: 86px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        font-size: 11px !important;
        line-height: 14px !important;
        position: static !important;
    }

    #rechts .smallplanet span.planet-koords {
        display: block !important;
        font-size: 10px !important;
        line-height: 13px !important;
        position: static !important;
        margin-top: 2px !important;
    }

    /* ---- 1.5 Main Content & Common Box Wrappers ---------------------------
     * Neutralize fixed 670px/654px desktop widths on content boxes.
     */
    #contentWrapper,
    #box #inhalt,
    #inhalt,
    .maincontent,
    .contentbox {
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
    }

    #buttonz {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 auto 10px auto !important;
        box-sizing: border-box !important;
    }

    #buttonz .content,
    #buttonz .footer,
    .contentbox .content,
    .contentbox .footer {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ---- 1.6 Site Footer, Chat Bar & Utilities ----------------------------
     * Reorganize bottom elements into clean wrapping columns.
     */
    #siteFooter {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 12px 8px !important;
        margin-top: 20px !important;
    }

    #siteFooter .content {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #siteFooter .fleft,
    #siteFooter .fright {
        float: none !important;
        text-align: center !important;
        width: 100% !important;
    }

    #chatBar {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #chatBarPlayerList {
        max-width: 100% !important;
    }

    .scroll_to_top {
        min-height: 32px !important;
        min-width: 32px !important;
    }

    /* ---- 1.7 Fixes measured live at 375px (ogamex.app, overview) ---------
     * These containers are absolutely/fixed positioned with desktop offsets
     * (left: 195px, 170px, ...) and pushed the layout viewport to ~710px.
     */
    #headerbarcomponent,
    #resourcesbarcomponent,
    #notificationbarcomponent {
        position: relative !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        width: 100% !important;
    }

    #resourcesbarcomponent,
    #notificationbarcomponent {
        margin: 6px 0 !important;
    }

    #resources .resource_tile > div[id$="_box"] {
        position: relative !important;
        left: auto !important;
        top: auto !important;
        width: auto !important;
    }

    #resources .resource_tile span.value {
        width: auto !important;
    }

    #middle {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    #chatBar {
        left: auto !important;
        right: 0 !important;
        max-width: 100vw !important;
    }

    #siteFooter {
        position: static !important;
        width: auto !important;
    }

    #siteFooter .fleft,
    #siteFooter .fright {
        width: auto !important;
        max-width: 100% !important;
        white-space: normal !important;
    }

    #detailWrapper,
    #buffBar {
        position: relative !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #techDetailLoading {
        width: auto !important;
        max-width: 100% !important;
        left: auto !important;
    }

    #buffBar {
        overflow-x: auto !important;
        overflow-y: hidden !important;
    }

    #buffBar .anythingSlider {
        left: auto !important;
        margin-left: 0 !important;
        max-width: none !important;
    }

    /* ---- 1.8 Header stacking -------------------------------------------
     * Ensure #top expands to fit dynamic children and header blocks stack
     * vertically in normal flow without overlapping. Neutralize legacy offsets
     * on commander, officers, notification bar, message wrapper, and #left.
     */
    #top {
        height: auto !important;
        min-height: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        position: relative !important;
    }

    #headerbarcomponent,
    #resourcesbarcomponent,
    #commandercomponent,
    #notificationbarcomponent {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        float: none !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 4px 0 !important;
        box-sizing: border-box !important;
    }

    #commandercomponent #characterclass,
    #characterclass {
        position: static !important;
        float: none !important;
        top: auto !important;
        left: auto !important;
        margin: 0 !important;
    }

    #commandercomponent #officers,
    #officers {
        position: static !important;
        float: none !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        width: auto !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 0 !important;
    }

    #notificationbarcomponent #message-wrapper,
    #message-wrapper {
        position: static !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        float: none !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        height: auto !important;
        box-sizing: border-box !important;
    }

    #messages_collapsed {
        position: static !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        float: none !important;
        width: auto !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 4px 0 !important;
        box-sizing: border-box !important;
    }

    #eventboxBlank,
    #eventboxLoading,
    #eventboxFilled {
        position: static !important;
        width: auto !important;
        max-width: 100% !important;
        height: auto !important;
        box-sizing: border-box !important;
    }

    #attack_alert {
        position: static !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        float: none !important;
        width: auto !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 4px auto !important;
        box-sizing: border-box !important;
    }

    #left {
        position: relative !important;
        top: 0 !important;
        left: auto !important;
        right: auto !important;
        margin-top: 8px !important;
        margin-bottom: 8px !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #middle {
        position: relative !important;
        top: 0 !important;
        left: auto !important;
        right: auto !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: auto !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #empire #siteFooter .content,
    #siteFooter .content,
    #siteFooter div.content {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ---- 1.9 Phone test fixes ----------------------------------------------
     * Targeted fixes from live device and 375px viewport audit.
     */

    /* Fix 1: Black band below viewport - full height document flow and repeated background */
    html,
    body {
        height: auto !important;
        min-height: 100% !important;
        overflow-y: visible !important;
    }

    body {
        background-repeat: repeat-y !important;
        background-size: 100% auto !important;
        background-attachment: scroll !important;
    }

    /* Fix 2: Header logo separation and non-overlapping header components */
    #top {
        background-image: none !important;
    }

    #headerbarcomponent {
        position: relative !important;
        top: auto !important;
        order: 0 !important;
    }

    #bar ul li.OGameClock {
        position: static !important;
        float: none !important;
        text-align: center !important;
    }

    /* Fix 3: Resource labels visible on mobile screens */
    .resource_label {
        display: block !important;
        font-size: 11px !important;
        color: #9ab !important;
        text-align: center !important;
        white-space: nowrap !important;
        line-height: 13px !important;
        margin-top: 2px !important;
    }

    /* Fix 4: Notification bar flex layout preventing fleet movement text overlap */
    #message-wrapper {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        justify-content: center !important;
        align-items: center !important;
        position: static !important;
        width: 100% !important;
        height: auto !important;
    }

    #message-wrapper a.comm_menu {
        position: static !important;
        display: inline-flex !important;
        min-width: 32px !important;
        min-height: 32px !important;
        float: none !important;
        margin: 0 !important;
    }

    #message-wrapper #messages_collapsed {
        flex-basis: 100% !important;
        position: static !important;
        float: none !important;
        text-align: center !important;
        margin: 0 !important;
        width: 100% !important;
        height: auto !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
    }

    #message-wrapper #messages_collapsed #eventboxFilled,
    #message-wrapper #messages_collapsed #eventboxLoading,
    #message-wrapper #messages_collapsed #eventboxBlank {
        position: static !important;
        width: auto !important;
        max-width: 100% !important;
        height: auto !important;
        text-align: center !important;
        margin: 0 auto !important;
        float: none !important;
        left: auto !important;
        top: auto !important;
    }

    /* Fix 5: Natural height for detailWrapper and planet header to prevent overflow */
    #detailWrapper {
        height: auto !important;
        min-height: 0 !important;
    }

    #planet {
        height: auto !important;
    }

    #planetdata {
        position: static !important;
        height: auto !important;
        margin-top: 6px !important;
        float: none !important;
    }

    /* Fix 7: Planet count bar background removal to eliminate stray sprite icons */
    #countColonies {
        background: none !important;
        border-bottom: 1px solid #202b35 !important;
        padding: 4px 0 !important;
        color: #9ab !important;
    }


    /* ---- 1.10 Post-deploy check ---------------------------------------------
     * Resource amounts are absolutely positioned (top:3px; left:-15px) on
     * desktop and landed on top of the icons; unread counters were positioned
     * against a far ancestor because their links were static.
     */
    #resources .resource_tile span.value > span {
        position: static !important;
        left: auto !important;
        top: auto !important;
        display: block !important;
        width: auto !important;
        text-align: center !important;
        font-size: 11px !important;
        line-height: 13px !important;
    }

    #message-wrapper a.comm_menu {
        position: relative !important;
    }

    #message-wrapper a.comm_menu .new_msg_count {
        left: auto !important;
        right: -6px !important;
        top: -6px !important;
    }

    #chatBarPlayerList {
        right: 0 !important;
        left: auto !important;
    }

    #pageReloader {
        margin-bottom: 6px !important;
        top: 0 !important;
        left: auto !important;
    }

    /* ---- 1.11 Real-device differences --------------------------------------
     * Android Chrome "font boosting" and iOS text inflation enlarge text on
     * pages that used to be fixed-width, which emulators do not reproduce.
     * Pinch zoom stays enabled (no user-scalable=no in the viewport meta).
     */
    html {
        -webkit-text-size-adjust: 100% !important;
        text-size-adjust: 100% !important;
    }
}

/* =============================================================================
   2. PHONE SCREENS & NARROW MOBILE (max-width: 767px down to 320px)
   ============================================================================= */
@media (max-width: 767px) {

    /* ---- 2.1 Viewport, Body Background & Base Reflow ----------------------
     * Prevent root horizontal document scrollbar down to 320px CSS width.
     */
    html,
    body {
        max-width: 100vw !important;
    }

    body {
        background-attachment: scroll !important;
        background-position: center top !important;
    }

    #pageContent {
        padding: 0 4px !important;
    }

    img,
    video,
    canvas,
    svg {
        max-width: 100% !important;
        height: auto !important;
    }

    /* ---- 2.2 Overview Header, Planet Display & Production Boxes -----------
     * Reflow overview planet display, header details, and production queues.
     */
    #planet {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 180px !important;
        background-size: cover !important;
        background-position: center !important;
        position: relative !important;
        margin: 0 auto 8px auto !important;
        box-sizing: border-box !important;
        padding: 8px !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
    }

    #planet.shortHeader {
        height: auto !important;
        min-height: 48px !important;
        padding: 6px 8px !important;
    }

    #header_text {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #header_text h2,
    #chat #planet h2 {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        font-size: 14px !important;
        line-height: 20px !important;
        height: auto !important;
        text-align: left !important;
        white-space: normal !important;
        overflow: visible !important;
        padding-top: 0 !important;
    }

    #planet h2 a {
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 4px !important;
    }

    #planetNameHeader {
        max-width: 100% !important;
        width: auto !important;
        float: none !important;
        white-space: nowrap !important;
        text-overflow: ellipsis !important;
        overflow: hidden !important;
    }

    #planetdata {
        float: none !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 10px 0 0 0 !important;
        position: static !important;
        box-sizing: border-box !important;
        background: rgba(20, 30, 38, 0.88) !important;
        border-radius: 6px !important;
        padding: 6px 8px !important;
    }

    #planetdata .overlay {
        display: none !important;
    }

    #planetDetails {
        height: auto !important;
        width: 100% !important;
    }

    div#planetDetails table {
        position: static !important;
        width: 100% !important;
    }

    #planetOptions {
        position: static !important;
        height: auto !important;
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: space-between !important;
        align-items: center !important;
        gap: 6px !important;
        margin-top: 8px !important;
        padding-top: 4px !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    }

    #planet-rewards {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-height: 160px !important;
        background-size: cover !important;
    }

    #overview #planet #moon,
    #overview #planet #planet_as_moon {
        position: static !important;
        text-align: center !important;
        margin-bottom: 6px !important;
    }

    #overview #planet #moon img,
    #overview #planet #planet_as_moon img {
        max-width: 72px !important;
        height: auto !important;
    }

    #productionboxBottom {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 8px !important;
        margin: 8px auto !important;
    }

    #productionboxBottom .boxColumn,
    .productionboxbuilding,
    .productionboxresearch,
    .productionboxshipyard,
    .productionboxlfbuilding,
    .productionboxlfresearch {
        width: 100% !important;
        max-width: 100% !important;
        display: block !important;
        margin: 0 0 8px 0 !important;
        box-sizing: border-box !important;
    }

    .content-box-s {
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        box-sizing: border-box !important;
        margin: 0 0 6px 0 !important;
    }

    div.content-box-s .header h3 {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ---- 2.3 Technology / Building / Ship / Defense Grids -------------------
     * Technology icons wrap into responsive grids (2 columns on 320px).
     */
    #technologies,
    #buttonz ul#building,
    #buttonz ul#storage,
    #buttonz ul#den {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 8px auto !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    #technologies li,
    #buttonz ul#building li,
    #buttonz ul#storage li,
    #buttonz ul#den li {
        float: none !important;
        margin: 0 !important;
        flex: 0 0 auto !important;
        list-style-type: none !important;
    }

    /* Fix 6: Technologies list transformed into single-column table rows */
    #technologies ul.icons {
        display: flex !important;
        flex-direction: column !important;
        gap: 6px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 8px auto !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    #technologies ul.icons li {
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        width: 100% !important;
        height: auto !important;
        min-height: 64px !important;
        float: none !important;
        position: relative !important;
        left: auto !important;
        top: auto !important;
        padding: 4px 8px !important;
        box-sizing: border-box !important;
        background: rgba(13, 20, 27, 0.85) !important;
        border: 1px solid #202b35 !important;
        border-radius: 4px !important;
        margin: 0 !important;
        flex: 0 0 auto !important;
        list-style-type: none !important;
    }

    #technologies ul.icons li > span.icon {
        flex: 0 0 auto !important;
    }

    #technologies ul.icons li::after {
        content: attr(aria-label) !important;
        flex: 1 1 auto !important;
        color: #fff !important;
        font-size: 13px !important;
        line-height: 16px !important;
        text-align: left !important;
    }

    #technologies ul.icons li button.upgrade {
        min-width: 24px !important;
        min-height: 24px !important;
    }

    /* ---- 2.4 Technology Detail Screen -------------------------------------
     * Detail panel spans full width with readable wrapped costs & inputs.
     */
    div.detail_screen,
    #detail.detail_screen {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        position: static !important;
        background-size: cover !important;
        box-sizing: border-box !important;
        padding: 8px !important;
        margin: 8px 0 !important;
    }

    div.detail_screen.small {
        height: auto !important;
    }

    .detail_screen #content {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        float: none !important;
        box-sizing: border-box !important;
    }

    .detail_screen #wrapper {
        margin-top: 8px !important;
        padding-left: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .production_info,
    .production_info.narrow {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        padding: 6px 0 !important;
        box-sizing: border-box !important;
    }

    .enter {
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        margin: 8px 0 !important;
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 6px !important;
    }

    .maxlink_wrap {
        width: 100% !important;
        max-width: 240px !important;
        box-sizing: border-box !important;
    }

    .costs_wrap {
        float: none !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 8px 0 !important;
        box-sizing: border-box !important;
    }

    .build-it_wrap,
    a.build-it,
    a.build-it_disabled,
    a.deactivate-it,
    a.deactivate-it_disabled {
        float: none !important;
        margin: 8px auto !important;
        max-width: 100% !important;
    }

    /* ---- 2.5 Wide Data Tables & Grids (Self-Contained Horizontal Scroll) ---
     * Wrapper-free overflow fix allowing tables to scroll inside their boxes
     * without causing page-level horizontal overflow (WCAG Reflow SC 1.4.10).
     */
    #galaxyContent,
    #galaxytable,
    .galaxyTable,
    #highscoreContent table,
    #highscoreContent,
    .highscore_table,
    #eventHeader,
    #eventContent,
    #movement table,
    #fleet1 table,
    #fleet2 table,
    #fleet3 table,
    #sendfleet table,
    .ship_selection_table,
    #fleetTemplates,
    #mail,
    table.list,
    table.fleetinfo,
    .content_table,
    .prefstable,
    .searchresults,
    .tabs_wrap,
    #messagecontainercomponent,
    #messages {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        box-sizing: border-box !important;
    }

    table.list,
    table.fleetinfo,
    .content_table,
    .prefstable,
    .ship_selection_table,
    #galaxyContent table {
        min-width: 100% !important;
        border-collapse: collapse !important;
    }

    .tabs_btn,
    ul.tabs_btn {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 4px !important;
        height: auto !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .tabs_btn li {
        float: none !important;
        margin: 0 !important;
        flex: 0 0 auto !important;
    }

    /* ---- 2.6 jQuery UI Dialogs, Overlays & Notification Boxes -------------
     * Constrain modals to viewport bounds and maintain touchable dialog targets.
     */
    .ui-dialog {
        max-width: calc(100vw - 16px) !important;
        left: 8px !important;
        box-sizing: border-box !important;
    }

    .ui-dialog .ui-dialog-content {
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: auto !important;
    }

    #decisionTB .errorBox,
    #notifyTB .errorBox {
        width: calc(100vw - 32px) !important;
        max-width: 380px !important;
        margin: 0 auto !important;
        left: 0 !important;
        right: 0 !important;
        box-sizing: border-box !important;
    }

    #decisionTB .response div {
        width: 50% !important;
        box-sizing: border-box !important;
    }

    #fadeBox {
        max-width: calc(100vw - 32px) !important;
        left: 16px !important;
        box-sizing: border-box !important;
    }

    #fancybox-wrap,
    #fancybox-outer,
    #fancybox-content {
        max-width: calc(100vw - 16px) !important;
        left: 8px !important;
        box-sizing: border-box !important;
    }

    /* ---- 2.7 Outgame (Login, Registration & Public Pages) ------------------
     * Reflow outgame splash into full-width stacked view down to 320px.
     */
    #start {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        background-size: cover !important;
        background-position: center top !important;
        box-sizing: border-box !important;
    }

    #header {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        padding: 12px 8px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        box-sizing: border-box !important;
        position: static !important;
    }

    #header h1,
    h1 {
        float: none !important;
        margin: 10px auto !important;
        text-align: center !important;
    }

    a#loginBtn {
        float: none !important;
        margin: 10px auto !important;
    }

    #login {
        position: static !important;
        width: 100% !important;
        max-width: 280px !important;
        height: auto !important;
        margin: 12px auto !important;
        box-sizing: border-box !important;
        right: auto !important;
        top: auto !important;
    }

    #loginForm,
    #subscribeForm {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        box-sizing: border-box !important;
        padding: 12px 10px !important;
        float: none !important;
    }

    .black-border {
        width: 100% !important;
        max-width: 240px !important;
        box-sizing: border-box !important;
    }

    .black-border input,
    input#usernameLogin,
    input#passwordLogin {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    select#serverLogin,
    select#server {
        width: 100% !important;
        max-width: 240px !important;
        box-sizing: border-box !important;
    }

    input#loginSubmit,
    input#regSubmit {
        width: 100% !important;
        max-width: 240px !important;
        box-sizing: border-box !important;
    }

    #content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        box-sizing: border-box !important;
        padding: 0 8px !important;
    }

    #subscribe {
        float: none !important;
        width: 100% !important;
        max-width: 320px !important;
        margin: 16px auto !important;
        box-sizing: border-box !important;
    }

    #contentWrap {
        float: none !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 16px auto !important;
        box-sizing: border-box !important;
    }

    #menu,
    #tabs,
    .tabContent,
    #contentFooter {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #tabs {
        display: flex !important;
        height: auto !important;
        margin: 0 !important;
        float: none !important;
    }

    #tabs li {
        flex: 1 1 auto !important;
        width: auto !important;
        float: none !important;
    }

    #footerContent,
    #footer {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        box-sizing: border-box !important;
        padding: 16px 8px !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
    }

    #footerLinks {
        float: none !important;
        text-align: center !important;
        margin-top: 10px !important;
    }

    #gfLogo,
    #usk,
    #safeplay {
        float: none !important;
        margin: 8px auto !important;
    }

    /* ---- 2.8 Page-specific overflow -----------------------------------
     * Prevent horizontal overflow caused by fixed-width elements on fleet,
     * buddies, shop, shipyard, defense, and overview pages down to 320px width.
     */
    #planet h2,
    #header_text h2,
    #fleetdispatchcomponent #planet h2,
    #buddies #planet h2,
    #fleet1 #planet h2,
    #fleet2 #planet h2,
    #fleet3 #planet h2,
    .header h2,
    #buttonz h2,
    #sendfleet h2,
    #middle h2 {
        width: auto !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
    }

    #planet h2 a,
    #header_text h2 a {
        width: auto !important;
        max-width: 100% !important;
        float: none !important;
        box-sizing: border-box !important;
    }

    div.fleetStatus,
    .fleetStatus,
    #statusBarFleet {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        height: auto !important;
        min-height: 28px !important;
        position: relative !important;
    }

    .fleetStatus ul {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        padding: 0 4px !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 4px 8px !important;
    }

    .fleetStatus ul li {
        display: inline-block !important;
        margin: 0 !important;
        max-width: 100% !important;
    }

    #warning,
    #fleetdispatchcomponent #warning,
    #fleet2 #warning,
    #movement #warning,
    div#warning {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        box-sizing: border-box !important;
        background-size: cover !important;
        padding: 12px 8px !important;
    }

    #itemBox,
    div#itemBox {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
    }

    #itemBox .aside,
    #itemBox .shop_slider {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        float: none !important;
    }

    #itemBox ul.listfilter {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #technologydetails_wrapper,
    #technologydetails_content,
    div.detail_screen,
    #detail.detail_screen,
    #techDetailLoading,
    #shipyard div.detail_screen,
    #defense div.detail_screen {
        width: 100% !important;
        max-width: 100% !important;
        left: auto !important;
        right: auto !important;
        box-sizing: border-box !important;
    }

    #technologydetails_wrapper {
        position: relative !important;
        left: 0 !important;
    }

    #technologydetails_content {
        left: 0 !important;
    }

    #technologies,
    #technologies_battle,
    #technologies_civil,
    #shipyard #technologies,
    #defense #technologies,
    #facilities #technologies {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #facilities #technologies::before,
    #facilities #technologies::after,
    #facilities header::after {
        display: none !important;
    }

    #facilities #technologies .icons::after {
        display: none !important;
        width: 0 !important;
    }

    #buttonz,
    #buttonz .content,
    #buttonz ul#building {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #buttonz .footer {
        display: none !important;
    }


    /* ---- 2.9 Fixes measured live at 375px (second pass) ------------------
     * Decorative pseudo-elements and page headers kept their 650-670px
     * desktop widths; options, premium and shop had fixed widths/offsets.
     */
    #planet::after,
    #technologies::before,
    #technologies::after {
        left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #middle header {
        width: auto !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #preferences .sectioncontent,
    #preferences #tabs-pref {
        width: auto !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-sizing: border-box !important;
    }

    #buttonz ul#building li.allOfficers {
        flex: 1 1 100% !important;
        width: auto !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #itemBox {
        flex-wrap: wrap !important;
    }

    #js_shopSliderBox {
        margin-left: 0 !important;
        width: auto !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ---- 2.10 Third pass: options tabs, header decorations, shop slider -- */
    #middle header::before,
    #middle header::after {
        left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    #preferences #preferencesTabs,
    #preferences #preferencesTabs .tabwrapper,
    #preferences #preferencesTabs ul,
    #preferences #prefs {
        width: auto !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* The item slider adds arrow buttons outside its 335px window;
       let it scroll inside its own box instead of widening the page. */
    #js_shopSliderBox {
        overflow-x: auto !important;
    }

    #preferences .fieldwrapper,
    #preferences .group,
    #preferences .fieldwrapper .thefield,
    #preferences .fieldwrapper label.styled {
        width: auto !important;
        max-width: 100% !important;
        float: none !important;
        box-sizing: border-box !important;
    }

    #itemBox button.to_shop,
    #itemBox button.to_inventory {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* ---- 2.11 Visual check on the live site --------------------------------
     * Resource values collapsed to 0px width (one digit per line), and the
     * header background (with the logo) repeated as #top grew taller.
     */
    #resources .resource_tile span.value {
        width: auto !important;
        min-width: 100% !important;
        white-space: nowrap !important;
        text-align: center !important;
        position: static !important;
    }

    /* ---- 2.12 Character Class Selection Page Responsive Reflow --------------
     * Fix 8: Reflow character class boxes into a single column without horizontal overflow.
     */
    div.boxWrapper,
    div.boxWrapper > .header,
    div.boxWrapper > .content,
    div.boxWrapper > .footer {
        width: auto !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    div.boxWrapper > .header,
    div.boxWrapper > .footer {
        background-size: 100% 100% !important;
    }

    .characterclass.boxes {
        flex-direction: column !important;
        width: auto !important;
        height: auto !important;
        gap: 10px !important;
    }

    .characterclass.box {
        width: 100% !important;
        height: auto !important;
        box-sizing: border-box !important;
        margin: 0 !important;
    }

    /* ---- 2.12 Post-deploy check: building rows ------------------------------
     * Game CSS sets `order` per technology class (.metalStorage, .resbuggy...)
     * and that class is on both the <li> and its span.icon, so in rows the
     * icon jumped to the right and some rows were reordered. Use DOM order.
     */
    #technologies li,
    #technologies li > span.icon {
        order: 0 !important;
    }

    /* ---- 2.13 Login page (audited without a session at 375/320px) --------
     * The trailer iframe is 425px wide; inputs were 16px tall (WCAG 2.5.8).
     */
    #flashTrailer,
    #flashTrailer iframe {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        aspect-ratio: 425 / 270;
        box-sizing: border-box !important;
    }

    #loginForm input[type="text"],
    #loginForm input[type="password"],
    #loginForm input[type="email"],
    #subscribeForm input[type="text"],
    #subscribeForm input[type="password"],
    #subscribeForm input[type="email"],
    #loginForm select,
    #subscribeForm select {
        min-height: 32px !important;
        font-size: 16px !important;
    }
}

/* =============================================================================
   3. DESKTOP OVERRIDES
   Hide mobile-only elements on desktop displays.
   ============================================================================= */
@media (min-width: 1024px) {
    .resource_label {
        display: none !important;
    }
}
