/* ===== LOGIN PAGE ===== */

/* Hide all game chrome on login page */
body.page-login #logo,
body.page-login #top_menu2,
body.page-login #side-menu,
body.page-login #mobile-menu-toggle,
body.page-login #mobile-overlay,
body.page-login .site-footer {
    display: none !important;
}

body.page-login #container {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0;
    padding: 0;
}

body.page-login #main_game_window {
    position: static;
    right: auto;
    top: auto;
    width: 100%;
    min-height: 100vh;
    background: transparent;
}

body.page-login #main_game_window .content {
    padding: 0;
}

.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px 15px;
}

.login-card {
    width: 100%;
    max-width: 460px;
    background: linear-gradient(165deg, #2e1d12 0%, #1a0f08 50%, #0d0704 100%);
    border: 1px solid rgba(136, 45, 0, 0.6);
    border-radius: 16px;
    padding: 40px 36px 32px;
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.5),
        0 0 80px rgba(136, 45, 0, 0.08),
        inset 0 1px 0 rgba(255, 164, 0, 0.06);
}

.login-logo {
    text-align: center;
    margin-bottom: 10px;
}

.login-logo img {
    height: 100px;
    width: auto;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,0.5));
}

.login-title {
    text-align: center;
    color: #ffa400;
    font-size: 28px;
    margin: 0 0 30px 0;
    font-weight: bold;
    letter-spacing: 1px;
}

.login-field {
    margin-bottom: 22px;
}

.login-label {
    display: block;
    color: #ddb070;
    font-size: 15px;
    margin-bottom: 8px;
    font-weight: bold;
    letter-spacing: 0.3px;
}

.login-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.login-icon {
    position: absolute;
    right: 14px;
    width: 20px;
    height: 20px;
    color: #9a7a5a;
    pointer-events: none;
    z-index: 1;
}

.login-input {
    width: 100% !important;
    padding: 14px 44px 14px 14px !important;
    font-size: 16px !important;
    background: #0a0705 !important;
    border: 1px solid #4a3020 !important;
    border-radius: 10px !important;
    box-sizing: border-box !important;
    color: #ffe0b0 !important;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.login-input::placeholder {
    color: #7a6a5a;
}

.login-input:focus {
    border-color: #c34506 !important;
    box-shadow: 0 0 0 3px rgba(195, 69, 6, 0.15);
    outline: none;
}

.login-options {
    margin-bottom: 26px;
}

.login-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: #c0a888;
    font-size: 14px;
}

.login-checkbox input[type="checkbox"] {
    width: 18px !important;
    height: 18px !important;
    accent-color: #c34506;
    cursor: pointer;
}

.login-btn {
    display: block;
    width: 100%;
    padding: 14px 20px !important;
    font-size: 16px !important;
    font-weight: bold;
    border-radius: 10px !important;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    box-sizing: border-box;
    transition: all 0.2s ease;
    font-family: inherit;
}

.login-btn-primary {
    background: linear-gradient(to bottom, #df5f04 0%, #a63500 50%, #882d00 100%) !important;
    color: #fff !important;
    border: none !important;
    box-shadow: 0 4px 12px rgba(136, 45, 0, 0.4), inset 0 1px 0 rgba(255, 200, 100, 0.2);
    margin-bottom: 14px;
    letter-spacing: 0.5px;
    font-size: 18px !important;
    padding: 15px 20px !important;
}

.login-btn-primary:hover {
    background: linear-gradient(to bottom, #f06a0a 0%, #c34506 50%, #a63500 100%) !important;
    box-shadow: 0 6px 20px rgba(136, 45, 0, 0.5), inset 0 1px 0 rgba(255, 200, 100, 0.3);
    transform: translateY(-1px);
}

.login-btn-google {
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #fff !important;
    color: #333 !important;
    border: 1px solid #ddd !important;
    font-size: 16px !important;
    padding: 13px 20px !important;
}

.login-btn-google:hover {
    background: #f5f5f5 !important;
    border-color: #bbb !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    color: #333 !important;
}

.login-btn-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.login-footer {
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid rgba(90, 58, 30, 0.3);
    text-align: center;
    font-size: 13px;
    color: #9a8a7a;
}

.login-footer a {
    color: #ddb070;
}


/* Mobile menu toggle button - hidden on desktop */
#mobile-menu-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    background: #2b190f;
    border: 2px solid #882d00;
    border-radius: 5px;
    padding: 8px 10px;
    cursor: pointer;
    width: 44px;
    height: 44px;
    box-sizing: border-box;
}

#mobile-menu-toggle span {
    display: block;
    width: 22px;
    height: 3px;
    background: #ffa400;
    margin: 3px 0;
    border-radius: 2px;
    transition: transform 0.3s, opacity 0.3s;
}

#mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}
#mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}
#mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(4px, -4px);
}

/* Side menu logo - hidden on desktop */
#side-menu-logo {
    display: none;
}

/* Rank display - works on both desktop and mobile */
.rank-display {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin: 4px 0;
    max-width: 100%;
}

.rank-item {
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(191,101,48,0.3);
    border-radius: 4px;
    padding: 3px 8px;
    flex: 1;
    justify-content: center;
    min-width: 0;
}

.rank-label {
    font-size: 11px;
    color: #c0a080;
}

.rank-number {
    font-size: 15px;
    font-weight: bold;
    color: #ffa400;
}

/* Resource bar in sidebar - works on both desktop and mobile */
#menu_update_data {
    margin-top: 8px;
    padding: 8px 4px;
    background: rgba(0,0,0,0.2);
    border-radius: 6px;
    height: auto;
    line-height: normal;
}

#menu_update_data table {
    width: 100% !important;
    border-spacing: 0;
}

#menu_update_data table td {
    padding: 2px 3px;
    text-align: center;
    font-size: 13px;
    vertical-align: middle;
}

#menu_update_data table td img {
    vertical-align: middle;
    float: none;
}

/* Sidebar overflow fix */
#side-menu-user {
    overflow: hidden;
    box-sizing: border-box;
}

#side-menu-links {
    overflow: hidden;
}

/* ===== TABLET: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* Prevent iOS text size adjust */
    body {
        -webkit-text-size-adjust: 100%;
    }

    #mobile-menu-toggle {
        display: block;
    }

    #container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0;
    }

    #logo {
        display: none !important;
    }

    /* Hide top menu on mobile - links moved to sidebar */
    #top_menu2 {
        display: none !important;
    }

    /* Sidebar becomes collapsible overlay */
    #side-menu {
        position: fixed;
        top: 0;
        right: -250px;
        width: 240px;
        height: 100vh;
        z-index: 9999;
        overflow-y: auto;
        transition: right 0.3s ease;
        border-radius: 0;
    }

    #side-menu.open {
        right: 0;
    }

    #side-menu-links {
        top: 0;
        width: 100%;
    }

    #side-menu-links a {
        float: none !important;
        display: block;
        width: 100%;
    }

    #side-nav {
        width: 100%;
    }

    #side-nav li {
        width: 100%;
        box-sizing: border-box;
        padding: 8px 0;
        font-size: 10pt;
    }

    /* Main content takes full width */
    #main_game_window {
        width: 100% !important;
        right: 0 !important;
        top: 10px;
        box-sizing: border-box;
        border-radius: 0;
    }

    #main_game_window .content {
        padding: 10px;
    }

    /* Login page: remove padding so card takes full width */
    .login-page {
        padding: 10px 4px;
    }

    /* Overlay behind sidebar */
    #mobile-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.6);
        z-index: 9998;
    }

    #mobile-overlay.active {
        display: block;
    }

    /* Side menu logo */
    #side-menu-logo {
        display: block;
        text-align: center;
        padding: 4px 0 4px;
    }

    #side-menu-logo img {
        height: 36px;
        width: auto;
    }

    /* Side menu user info section */
    #side-menu-user {
        padding: 14px 12px 10px;
        margin: 0;
        text-align: center;
        font-size: 13px;
        line-height: 1.6;
        border-bottom: 1px solid rgba(191,101,48,0.25);
    }

    #side-menu-user br:first-child {
        display: none;
    }

    /* General table overflow */
    table {
        max-width: 100%;
    }

    .ftable {
        width: 100%;
    }

    #top_links_menu {
        width: 100% !important;
    }

    #content {
        width: 100% !important;
    }

    /* ===== GLOBAL: Footer ===== */
    .site-footer {
        margin-top: 40px !important;
        font-size: 10px;
        padding: 10px;
        text-align: center;
    }

    .site-footer br:first-child {
        display: none;
    }

    .site-footer a {
        font-size: 11px !important;
    }

    /* ===== GLOBAL: Resource boxes ===== */
    .res_box {
        position: relative;
        width: calc(50% - 6px) !important;
        height: auto !important;
        min-height: 48px;
        box-sizing: border-box;
        font-size: 14px;
        padding: 8px 10px 8px 8px;
        display: inline-flex !important;
        align-items: center;
        gap: 8px;
        vertical-align: top;
        margin-bottom: 4px;
    }

    .res_box .icoo {
        position: static !important;
        width: auto !important;
        height: auto !important;
        flex-shrink: 0;
    }

    .res_box .icoo img {
        width: 32px !important;
        height: 32px !important;
    }

    .res_box .contentt {
        position: static !important;
        width: auto !important;
        height: auto !important;
        flex: 1;
        min-width: 0;
        padding-right: 0 !important;
    }

    .res_box .contentt .row {
        width: auto !important;
        height: auto !important;
        line-height: 1.3;
        font-size: 13px;
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .res_box .contentt .row:last-child {
        font-weight: bold;
        font-size: 15px;
    }

    /* Inline resource summary row (gold/iron/wood/food) */
    .content > table:first-child td,
    .content > div > table:first-child td {
        font-size: 14px;
    }

    /* ===== GLOBAL: Top links menu (turns, achievements, messages, enemies) ===== */
    #top_links_menu {
        width: 100% !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 4px;
        margin-top: 0 !important;
    }

    #top_links_menu .top-item {
        display: block !important;
        padding: 8px 10px !important;
        font-size: 13px;
        border-radius: 6px !important;
        border-left: none !important;
        text-align: center;
        box-sizing: border-box;
        width: auto !important;
    }

    #top_links_menu .top-item img {
        float: none !important;
        clear: none !important;
        display: block;
        margin: 0 auto 4px;
        width: 28px;
        height: 28px;
    }

    #top_links_menu a:first-child,
    #top_links_menu a:last-child {
        border-radius: 6px !important;
    }

    /* ===== GLOBAL: Touch targets ===== */
    .content table a,
    .content table .btn,
    .content table input[type="submit"] {
        min-height: 40px;
        line-height: 1.4;
    }

    /* ===== GLOBAL: Pagination ===== */
    .pagination ul {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
        padding: 6px 0;
    }

    .pagination li {
        list-style: none;
    }

    .pagination li a {
        display: inline-block;
        min-width: 40px;
        min-height: 40px;
        line-height: 40px;
        text-align: center;
        padding: 0 8px;
        font-size: 14px;
        box-sizing: border-box;
    }

    .pagination li.active a {
        font-weight: bold;
        color: white;
    }

    /* ===== GLOBAL: nice_text_onfire headers ===== */
    .nice_text_onfire {
        font-size: 17px;
    }

}

/* Mobile secondary links in sidebar */
#side-menu .mobile-top-links {
    display: none;
}

@media screen and (max-width: 768px) {
    #side-menu .mobile-top-links {
        display: block;
        border-top: 2px solid #4f1f0a;
        margin-top: 10px;
        padding-top: 5px;
    }

    #side-menu .mobile-top-links a {
        display: block;
        color: #c69b6d;
        text-align: center;
        padding: 8px 0;
        border-bottom: 1px solid #4f1f0a;
        font-size: 10pt;
        float: none !important;
    }

    #side-menu .mobile-top-links a:hover {
        color: white;
    }
}

/* ===== ATTACK PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* Generic table stacking for pages that still use tables */
    .content > table:not(.atk-table):not(.ftable):not(.top20-table):not(.clanslist-table):not(.hist-table),
    .content > table:not(.atk-table):not(.ftable):not(.top20-table):not(.clanslist-table):not(.hist-table) > tbody,
    .content > table:not(.atk-table):not(.ftable):not(.top20-table):not(.clanslist-table):not(.hist-table) > tbody > tr,
    .content > table:not(.atk-table):not(.ftable):not(.top20-table):not(.clanslist-table):not(.hist-table) > tbody > tr > td,
    table.stable:not(.top20-table):not(.hist-table),
    table.stable:not(.top20-table):not(.hist-table) > tbody,
    table.stable:not(.top20-table):not(.hist-table) > tbody > tr,
    table.stable:not(.top20-table):not(.hist-table) > tbody > tr > td {
        display: block !important;
        width: 100% !important;
    }

    .content > table:not(.atk-table):not(.ftable) > tbody > tr > td:empty {
        display: none !important;
    }

    /* Players list table */
    table.atk-table {
        display: table;
        width: 100%;
    }

    table.atk-table td,
    table.atk-table th {
        padding: 8px 4px;
        font-size: 12px;
    }

    table.atk-table .atk-player-link {
        font-weight: bold;
        font-size: 14px;
    }

    table.atk-table .atk-rank-cell {
        gap: 2px;
    }

    /* Search bar - full width on mobile */
    .atk-search-wrap {
        float: none;
        padding: 6px 8px;
        width: 100%;
        box-sizing: border-box;
    }

    .atk-search-form {
        width: 100%;
    }

    .atk-search-form.open input[type="text"] {
        width: auto;
        flex: 1;
        padding: 8px 10px;
        font-size: 14px;
    }

    .atk-search-wrap + .pagination {
        text-align: center;
    }
}

/* ===== BASE PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* Tabs - wrap into scrollable row */
    #top_menu {
        display: flex;
        flex-wrap: wrap;
        gap: 2px;
    }

    #top_menu .tabs_title {
        flex: 1 1 calc(50% - 2px);
        box-sizing: border-box;
        padding: 8px 6px;
        font-size: 12px;
        text-align: center;
        margin-left: 0;
        border-radius: 4px;
    }

    #all_tabs {
        border-radius: 7px !important;
    }

    /* Power stat boxes - full width */
    .base_power_set {
        position: relative;
        width: 100% !important;
        height: auto !important;
        min-height: 0;
        box-sizing: border-box;
        margin-bottom: 8px;
        display: flex !important;
        align-items: flex-start;
        padding: 10px 12px;
        gap: 10px;
    }

    .base_power_set .icoo {
        position: static !important;
        width: auto !important;
        height: auto !important;
        flex-shrink: 0;
    }

    .base_power_set .icoo img {
        width: 44px !important;
        height: 44px !important;
    }

    .base_power_set .contentt {
        position: static !important;
        width: auto !important;
        height: auto !important;
        flex: 1;
        min-width: 0;
    }

    .base_power_set .row {
        width: 100% !important;
        height: auto !important;
        line-height: 1.5;
        font-size: 13px;
    }

    .base_power_set .row:first-child {
        font-size: 15px;
        font-weight: bold;
    }

    .base_power_set .row .num {
        float: left;
        padding-left: 5px;
    }

    /* Tab2 - stack population and production columns */
    #tab2 > table,
    #tab2 > table > tbody,
    #tab2 > table > tbody > tr,
    #tab2 > table > tbody > tr > td {
        display: block !important;
        width: 100% !important;
    }

    /* Tab3 - stack weapon columns */
    #tab3 table.stable > tbody > tr > td {
        width: 100% !important;
    }

    /* Clan requests dropdown */
    .requests_window {
        top: 0 !important;
    }

    .base-drop-down {
        width: 90vw !important;
        max-width: 300px;
    }

    /* Challenge box */
    .challenge-box-3wizards {
        flex-direction: column;
        gap: 8px;
        padding: 10px;
    }

    /* ===== Tab4: Diamonds & VIP ===== */

    /* Both tables in tab4 → block, no default stacking */
    #tab4 > table.stable,
    #tab4 > table.stable > tbody {
        display: block !important;
        width: 100% !important;
    }

    #tab4 > table.stable > tbody > tr {
        display: block !important;
        width: 100% !important;
        border-bottom: none !important;
    }

    #tab4 > table.stable > tbody > tr > td {
        display: block !important;
        width: 100% !important;
        padding: 8px 0 !important;
        box-sizing: border-box;
    }

    /* First table: diamond conversion — section title */
    #tab4 > table.stable:first-of-type > tbody > tr:first-child > td {
        font-size: 17px;
        font-weight: bold;
        color: #f0c040;
        text-align: center;
        padding-bottom: 4px !important;
        border-bottom: 1px solid rgba(191,101,48,0.3);
    }

    /* Diamond count row */
    #tab4 > table.stable:first-of-type > tbody > tr:nth-child(2) > td {
        text-align: center;
        padding: 12px 0 !important;
    }

    #tab4 > table.stable:first-of-type > tbody > tr:nth-child(2) > td h2 {
        font-size: 20px !important;
        display: block !important;
        margin: 0 0 6px;
    }

    /* Diamond conversion form row */
    #tab4 > table.stable:first-of-type > tbody > tr:nth-child(3) > td {
        padding: 6px 0 !important;
    }

    #tab4 > table.stable:first-of-type form {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-wrap: wrap;
        justify-content: center;
    }

    #tab4 > table.stable:first-of-type form input[type="text"] {
        width: 80px;
        padding: 10px 8px;
        font-size: 16px;
        border: 1px solid #5a3520;
        background: #1a0c04;
        color: #e0b88a;
        border-radius: 6px;
        text-align: center;
        box-sizing: border-box;
    }

    #tab4 > table.stable:first-of-type form input[type="submit"] {
        padding: 10px 24px;
        font-size: 15px;
        border-radius: 6px;
        cursor: pointer;
    }

    /* Hint text row */
    #tab4 > table.stable:first-of-type > tbody > tr:nth-child(4) > td {
        text-align: center;
        padding: 4px 0 12px !important;
    }

    /* Second table: VIP benefits */
    #tab4 > table.stable:nth-of-type(2) {
        margin-top: 10px;
    }

    /* VIP section title */
    #tab4 > table.stable:nth-of-type(2) > tbody > tr:first-child > td {
        font-size: 16px;
        font-weight: bold;
        color: #f0c040;
        text-align: center;
        padding-bottom: 6px !important;
        border-bottom: 1px solid rgba(191,101,48,0.3);
    }

    /* VIP benefit rows → card style */
    #tab4 > table.stable:nth-of-type(2) > tbody > tr:not(:first-child) > td {
        display: block !important;
        padding: 12px 14px !important;
        margin-bottom: 6px;
        border-radius: 8px;
        background: rgba(59,31,13,0.4);
        border: 1px solid rgba(191,101,48,0.2);
        font-size: 13px;
        line-height: 1.7;
        overflow: hidden;
    }

    /* Crown icons inside VIP benefit cards — small, inline on right */
    #tab4 > table.stable:nth-of-type(2) > tbody > tr:not(:first-child) > td img[src*="crown"] {
        float: right !important;
        padding: 0 0 6px 10px !important;
        width: 26px !important;
        height: 26px !important;
    }

    /* h3 inside VIP cards — no extra margin */
    #tab4 > table.stable:nth-of-type(2) > tbody > tr:not(:first-child) > td h3 {
        margin: 0 0 4px;
        font-size: 15px;
        color: #f0c040;
    }

    #tab4 > table.stable:nth-of-type(2) > tbody > tr:not(:first-child) > td h3 img[src*="crown"] {
        width: 22px !important;
        height: 22px !important;
        padding: 0 0 4px 8px !important;
    }
}

/* ===== TRAINING PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* Training tables - card layout instead of stacked cells */
    .content form[action*="training"] > table.stable {
        border-spacing: 0 8px;
    }

    .content form[action*="training"] > table.stable > tbody > tr {
        display: grid !important;
        grid-template-columns: 45px 1fr 1.5fr;
        gap: 4px 8px;
        padding: 12px 14px;
        margin-bottom: 6px;
        border-radius: 6px;
        background: rgba(59,31,13,0.4);
        border: 1px solid rgba(191,101,48,0.3);
        align-items: center;
    }

    .content form[action*="training"] > table.stable > tbody > tr > td {
        width: auto !important;
        display: block !important;
        padding: 2px 4px !important;
    }

    /* Header row - hide on mobile */
    .content form[action*="training"] > table.stable > tbody > tr.tile1,
    .content form[action*="training"] > table.stable > tbody > tr.tile2 {
        display: none !important;
    }

    /* Icon cell - spans 2 rows */
    .content form[action*="training"] > table.stable > tbody > tr > td:first-child {
        grid-row: 1 / 3;
        grid-column: 1;
        text-align: center;
    }

    .content form[action*="training"] > table.stable > tbody > tr > td:first-child img {
        width: 36px;
        height: 36px;
    }

    /* Name cell */
    .content form[action*="training"] > table.stable > tbody > tr > td:nth-child(2) {
        grid-row: 1;
        grid-column: 2;
        font-weight: bold;
        color: #e4e4e4;
    }

    /* Have/ability cell */
    .content form[action*="training"] > table.stable > tbody > tr > td:nth-child(3) {
        grid-row: 1;
        grid-column: 3;
        text-align: right;
        font-size: 16px;
        font-weight: bold;
        color: #f0c040;
    }

    /* Cost cell */
    .content form[action*="training"] > table.stable > tbody > tr > td:nth-child(4) {
        grid-row: 2;
        grid-column: 2;
        font-size: 12px;
        text-align: right;
    }

    /* Input/button cell */
    .content form[action*="training"] > table.stable > tbody > tr > td:nth-child(5) {
        grid-row: 2;
        grid-column: 3;
        text-align: right;
    }

    .content form[action*="training"] > table.stable > tbody > tr > td:nth-child(5) input[type="text"] {
        width: 80px;
        padding: 6px 8px;
        font-size: 14px;
    }

    .content form[action*="training"] > table.stable > tbody > tr > td:nth-child(5) input[type="submit"] {
        padding: 8px 12px;
        font-size: 12px;
        white-space: normal;
    }

    /* Submit row - only target rows with class .train-submit-row */
    .content form[action*="training"] > table.stable > tbody > tr.train-submit-row {
        display: block !important;
        text-align: center;
        background: none;
        border: none;
        padding: 5px 0;
    }

    .content form[action*="training"] > table.stable > tbody > tr.train-submit-row > td {
        display: none !important;
    }

    .content form[action*="training"] > table.stable > tbody > tr.train-submit-row > td:last-child {
        display: block !important;
    }

    .content form[action*="training"] > table.stable > tbody > tr.train-submit-row > td:last-child input[type="submit"] {
        width: 100%;
        padding: 12px;
        font-size: 15px;
    }

    /* Progress bars in advanced training */
    .content form[action*="training"] > table.stable .progress {
        margin: 4px 0 0 0;
        height: 8px;
        max-width: 100%;
    }

    /* Advanced training button alignment */
    .content form[action*="training"] > table.stable > tbody > tr > td:nth-child(5) input[type="submit"].btn_green {
        padding: 8px 12px;
        font-size: 12px;
        white-space: normal;
    }

    /* Untrained population bar at top */
    .tile_height {
        font-size: 14px;
        line-height: 1.5;
        padding: 12px 10px;
    }

    .tile_height img {
        width: 30px;
        height: 30px;
        vertical-align: middle;
    }
}

/* ===== DEVELOP PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* City image */
    .cities_view {
        height: 200px !important;
        background-size: cover !important;
        border-radius: 8px;
        overflow: hidden;
    }

    /* Develop description text - more readable */
    .content form[action*="develop"] td,
    .content form[action*="movecity"] td {
        font-size: 13px;
        line-height: 1.6;
        padding: 6px 2px;
    }

    /* Develop page upgrade button */
    .content form[action*="develop"] input[type="submit"],
    .content form[action*="movecity"] input[type="submit"] {
        width: 100%;
        padding: 10px;
        font-size: 14px;
        box-sizing: border-box;
        margin-top: 6px;
    }

    /* Resource cost images in develop */
    .content form[action*="develop"] img,
    .content form[action*="movecity"] img {
        max-width: 30px;
        max-height: 30px;
        vertical-align: middle;
    }
}

/* ===== HERO PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* Magic icons - spacing between rows */
    .content form[action*="hero"] table.stable td {
        padding: 6px 4px;
    }

    /* Bottom promo/hero images - prevent overflow */
    .content img[src*="hero"],
    .content img[src*="promo"],
    .content > center img,
    .content > img {
        max-width: 100%;
        height: auto;
    }

    /* City view on develop */
    .cities_view {
        border-radius: 8px;
        overflow: hidden;
    }
}

/* ===== SHOP PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* Shop tabs - proper flex wrapping */
    .content > #top_menu {
        display: flex;
        flex-wrap: wrap;
        gap: 3px;
    }

    .content > #top_menu .tabs_title {
        flex: 1 1 calc(50% - 3px);
        min-width: 0;
        box-sizing: border-box;
        padding: 10px 6px;
        font-size: 12px;
        text-align: center;
        border-radius: 4px;
    }

    .content > #top_menu .tabs_title .ico {
        display: block;
        margin: 0 auto 4px;
    }

    /* Shop weapon tables - card layout */
    .content form[action*="shop"] > table.stable > tbody > tr:first-child {
        display: none !important;
    }

    .content form[action*="shop"] > table.stable > tbody > tr {
        display: grid !important;
        grid-template-columns: 60px 1fr 1fr;
        gap: 4px 10px;
        padding: 10px 12px;
        margin-bottom: 6px;
        border-radius: 6px;
        background: rgba(59,31,13,0.4);
        border: 1px solid rgba(191,101,48,0.3);
        align-items: center;
        height: auto !important;
        line-height: 1.4 !important;
    }

    /* Image cell - spans 2 rows */
    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(1) {
        grid-row: 1 / 3;
        grid-column: 1;
        width: auto !important;
        text-align: center;
    }

    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(1) img {
        width: 55px;
        height: 55px;
        border-radius: 4px;
    }

    /* Name cell - spans 2 columns */
    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(2) {
        grid-row: 1;
        grid-column: 2 / 4;
        width: auto !important;
        font-weight: bold;
        font-size: 14px;
        color: #e4e4e4;
    }

    /* Cost cell */
    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(3) {
        grid-row: 2;
        grid-column: 2;
        width: auto !important;
        font-size: 12px;
    }

    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(3) img {
        width: 20px;
        height: 20px;
        vertical-align: middle;
    }

    /* Power cell */
    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(4) {
        grid-row: 2;
        grid-column: 3;
        width: auto !important;
        font-size: 12px;
    }

    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(4) img {
        width: 20px;
        height: 20px;
        vertical-align: middle;
    }

    /* Action cell - input + buy button */
    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(5) {
        grid-row: 3;
        grid-column: 1 / 4;
        width: auto !important;
        display: flex !important;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px;
        padding-top: 6px;
        border-top: 1px solid rgba(191,101,48,0.15);
    }

    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(5) input[type="text"] {
        width: 50px;
        padding: 6px 8px;
        font-size: 14px;
    }

    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(5) input[type="submit"] {
        padding: 6px 14px;
        font-size: 13px;
    }

    .content form[action*="shop"] > table.stable > tbody > tr > td:nth-child(5) span {
        width: 100%;
        font-size: 11px !important;
        line-height: 1.4 !important;
        color: #9a7a5a;
    }
}

/* ===== WORK PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* --- Work page form: prevent overflow --- */
    form[action*="manageslaves"] {
        max-width: 100%;
        overflow: hidden;
        box-sizing: border-box;
    }

    /* --- Management table (send slaves form) --- */
    form[action*="manageslaves"] > table.stable {
        display: block !important;
        width: auto !important;
        max-width: 100% !important;
        border-spacing: 0;
        box-sizing: border-box;
    }

    form[action*="manageslaves"] > table.stable > tbody {
        display: block !important;
        width: 100% !important;
    }

    /* Hide header row */
    form[action*="manageslaves"] > table.stable > tbody > tr.tile2 {
        display: none !important;
    }

    /* Resource rows → card layout */
    form[action*="manageslaves"] > table.stable > tbody > tr:not(.tile2):not(.work-submit-row) {
        display: grid !important;
        grid-template-columns: 44px minmax(0, 1fr) minmax(0, 1fr);
        grid-template-rows: auto auto;
        gap: 2px 10px;
        padding: 12px 14px;
        margin-bottom: 6px;
        border-radius: 8px;
        background: rgba(59,31,13,0.4);
        border: 1px solid rgba(191,101,48,0.25);
        align-items: center;
        overflow: hidden;
        box-sizing: border-box;
    }

    form[action*="manageslaves"] > table.stable > tbody > tr:not(.tile2):not(.work-submit-row) > td {
        width: auto !important;
        display: block !important;
        padding: 2px 0 !important;
        min-width: 0;
    }

    /* Icon cell - spans both rows */
    form[action*="manageslaves"] > table.stable > tbody > tr:not(.tile2):not(.work-submit-row) > td:nth-child(1) {
        grid-row: 1 / 3;
        grid-column: 1;
        text-align: center;
    }

    form[action*="manageslaves"] > table.stable > tbody > tr:not(.tile2):not(.work-submit-row) > td:nth-child(1) img {
        width: 36px !important;
        height: 36px !important;
    }

    /* Workplace name */
    form[action*="manageslaves"] > table.stable > tbody > tr:not(.tile2):not(.work-submit-row) > td:nth-child(2) {
        grid-row: 1;
        grid-column: 2;
        font-weight: bold;
        font-size: 14px;
        color: #e4e4e4;
    }

    /* Current totals */
    form[action*="manageslaves"] > table.stable > tbody > tr:not(.tile2):not(.work-submit-row) > td:nth-child(3) {
        grid-row: 1;
        grid-column: 3;
        text-align: right;
        font-size: 16px;
        font-weight: 600;
        color: #f0c040;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Input field */
    form[action*="manageslaves"] > table.stable > tbody > tr:not(.tile2):not(.work-submit-row) > td:nth-child(4) {
        grid-row: 2;
        grid-column: 2 / 4;
    }

    form[action*="manageslaves"] > table.stable > tbody > tr:not(.tile2):not(.work-submit-row) > td:nth-child(4) input[type="text"] {
        width: 100%;
        padding: 8px 10px;
        font-size: 14px;
        border: 1px solid #5a3520;
        background: #1a0c04;
        color: #e0b88a;
        border-radius: 6px;
        box-sizing: border-box;
    }

    /* Submit row - full-width buttons */
    form[action*="manageslaves"] > table.stable > tbody > tr.work-submit-row {
        display: flex !important;
        justify-content: center;
        gap: 10px;
        padding: 8px 0;
        background: none !important;
        border: none !important;
    }

    form[action*="manageslaves"] > table.stable > tbody > tr.work-submit-row > td {
        display: none !important;
    }

    form[action*="manageslaves"] > table.stable > tbody > tr.work-submit-row > td:last-child {
        display: flex !important;
        gap: 10px;
        width: 100% !important;
    }

    form[action*="manageslaves"] > table.stable > tbody > tr.work-submit-row > td:last-child input[type="submit"] {
        flex: 1;
        padding: 12px 10px;
        font-size: 15px;
        border-radius: 6px;
        cursor: pointer;
    }

    /* --- Info table (resource output stats) --- */
    form[action*="manageslaves"] ~ table.stable {
        display: block !important;
        width: auto !important;
        max-width: 100% !important;
        border-spacing: 0;
        box-sizing: border-box;
    }

    form[action*="manageslaves"] ~ table.stable tbody {
        display: block !important;
        width: 100% !important;
    }

    /* Hide info header row — target with and without tbody */
    form[action*="manageslaves"] ~ table.stable tr.tile2,
    form[action*="manageslaves"] ~ table.stable > tbody > tr.tile2,
    form[action*="manageslaves"] ~ table.stable .tile2 {
        display: none !important;
        height: 0 !important;
        overflow: hidden !important;
        visibility: hidden !important;
    }

    /* Info resource rows → card layout */
    form[action*="manageslaves"] ~ table.stable tr:not(.tile2) {
        display: grid !important;
        grid-template-columns: 44px minmax(0, 1fr);
        grid-template-rows: auto auto auto;
        gap: 2px 10px;
        padding: 12px 14px;
        margin-bottom: 6px;
        border-radius: 8px;
        background: rgba(59,31,13,0.4);
        border: 1px solid rgba(191,101,48,0.25);
        align-items: center;
        width: auto !important;
        max-width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }

    form[action*="manageslaves"] ~ table.stable tr:not(.tile2) > td {
        width: auto !important;
        display: block !important;
        padding: 2px 0 !important;
        min-width: 0;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    /* Info icon cell - spans all rows */
    form[action*="manageslaves"] ~ table.stable tr:not(.tile2) > td:nth-child(1) {
        grid-row: 1 / 4;
        grid-column: 1;
        text-align: center;
    }

    form[action*="manageslaves"] ~ table.stable tr:not(.tile2) > td:nth-child(1) img {
        width: 36px !important;
        height: 36px !important;
    }

    /* Info workplace name */
    form[action*="manageslaves"] ~ table.stable tr:not(.tile2) > td:nth-child(2) {
        grid-row: 1;
        grid-column: 2;
        font-weight: bold;
        font-size: 14px;
        color: #e4e4e4;
        min-width: 0;
    }

    /* Info stats */
    form[action*="manageslaves"] ~ table.stable tr:not(.tile2) > td:nth-child(3) {
        grid-row: 2;
        grid-column: 2;
        font-size: 13px;
        color: #c69b6d;
        line-height: 1.6;
        min-width: 0;
    }

    /* Info next update */
    form[action*="manageslaves"] ~ table.stable tr:not(.tile2) > td:nth-child(4) {
        grid-row: 3;
        grid-column: 2;
        font-size: 13px;
        color: #9a7a5a;
        min-width: 0;
    }

    /* Work page h2 heading */
    form[action*="manageslaves"] ~ h2 {
        font-size: 16px;
        margin: 20px 0 8px;
    }
}

/* ===== HISTORY PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    .hist-page {
        max-width: 100%;
        padding: 0;
    }

    /* History tabs - 2x2 grid */
    .hist-tabs {
        display: flex !important;
        flex-wrap: wrap;
        gap: 4px;
    }

    .hist-tab {
        flex: 1 1 calc(50% - 4px);
        box-sizing: border-box;
        padding: 10px 6px;
        font-size: 12px;
        text-align: center;
        border-radius: 4px;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .hist-tab.current_tab {
        font-weight: bold;
        background: rgba(136,45,0,0.5);
        border: 1px solid #882d00;
    }

    /* History summary cards */
    .hist-summary {
        flex-direction: column;
        gap: 6px;
    }

    .hist-summary-card {
        width: 100%;
        box-sizing: border-box;
    }

    /* History table */
    .hist-table {
        width: 100%;
        font-size: 12px;
    }

    .hist-table td,
    .hist-table th {
        padding: 8px 6px;
    }

    .hist-table .hist-player {
        font-weight: bold;
    }

    .hist-table .hist-date {
        font-size: 11px;
        color: #9a7a5a;
    }
}

/* ===== BANK PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    .bank-page {
        max-width: 100%;
        padding: 0;
    }

    /* Bank stats bar - stack on narrow */
    .bank-stats {
        flex-direction: column;
        gap: 6px;
    }

    .bank-stat-card {
        width: 100%;
        box-sizing: border-box;
        padding: 10px;
    }

    .bank-stat-value {
        font-size: 18px;
    }

    /* Bank cards */
    .bank-card {
        padding: 12px;
        margin-bottom: 10px;
    }

    /* Bank form row - input and button */
    .bank-form-row {
        flex-direction: column;
        gap: 8px;
    }

    .bank-input {
        width: 100% !important;
        box-sizing: border-box;
        padding: 10px;
        font-size: 16px;
    }

    .bank-btn {
        width: 100%;
        padding: 12px;
        font-size: 14px;
        box-sizing: border-box;
    }

    /* Interest upgrade details */
    .bank-upgrade-details {
        flex-direction: column;
        gap: 8px;
    }

    .bank-upgrade-item {
        width: 100%;
        text-align: center;
        padding: 8px;
    }

    /* Bank countdown */
    .bank-countdown {
        font-size: 13px;
        padding: 8px;
    }

    /* Bank hint text */
    .bank-hint {
        font-size: 12px;
        line-height: 1.5;
    }
}

/* ===== CLAN PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* Clan join/create forms */
    .content form input[type="text"] {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Clan search button */
    .content form input[type="submit"] {
        box-sizing: border-box;
    }
}

/* ===== TOP20 PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    /* Table + tbody = block, full width */
    .top20-table,
    .top20-table > tbody {
        display: block !important;
        width: 100% !important;
    }

    /* Hide header row */
    .top20-table > tbody > tr:first-child {
        display: none !important;
    }

    .top20-table > tbody > tr {
        display: grid !important;
        grid-template-columns: 32px 28px 1fr;
        grid-template-rows: auto auto;
        align-items: center;
        padding: 8px 10px;
        border-bottom: 1px solid rgba(191,101,48,0.18);
        gap: 0 6px;
    }

    .top20-table > tbody > tr:nth-child(odd) {
        background: rgba(59,31,13,0.22);
    }

    /* Reset all cells */
    .top20-table > tbody > tr > td {
        display: block !important;
        width: auto !important;
        padding: 0 !important;
        margin: 0;
    }

    /* Rank */
    .top20-table > tbody > tr > td:nth-child(2) {
        grid-row: 1;
        grid-column: 1;
        font-weight: 900;
        font-size: 18px;
        color: #f0c040;
        text-align: center;
        line-height: 1.1;
    }

    /* Race icon */
    .top20-table > tbody > tr > td:nth-child(1) {
        grid-row: 1;
        grid-column: 2;
        text-align: center;
        line-height: 1;
    }

    .top20-table > tbody > tr > td:nth-child(1) img {
        width: 22px;
        height: 22px;
        vertical-align: middle;
    }

    /* Username + clan */
    .top20-table > tbody > tr > td:nth-child(3) {
        grid-row: 1;
        grid-column: 3;
        font-size: 15px;
        font-weight: bold;
        color: #e4e4e4;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.3;
    }

    .top20-table > tbody > tr > td:nth-child(3) a {
        color: #e4e4e4;
    }

    /* Soldiers */
    .top20-table > tbody > tr > td:nth-child(4) {
        grid-row: 2;
        grid-column: 3;
        font-size: 11px;
        color: #9a7a5a;
        line-height: 1.4;
    }

    .top20-table > tbody > tr > td:nth-child(4)::before {
        content: "\2694\fe0e ";
    }

    /* Gold - hidden */
    .top20-table > tbody > tr > td:nth-child(5) {
        display: none !important;
    }

    /* City - hidden */
    .top20-table > tbody > tr > td:nth-child(6) {
        display: none !important;
    }
}

/* ===== CLANSLIST PAGE: 768px and below ===== */
@media screen and (max-width: 768px) {
    .clanslist-page {
        margin: 10px auto;
    }

    .clanslist-header {
        margin-bottom: 12px;
        padding: 0 8px;
    }

    .clanslist-header h2 {
        font-size: 18px;
    }

    .clanslist-table,
    .clanslist-table > tbody {
        display: block !important;
        width: 100% !important;
    }

    .clanslist-table > thead {
        display: none !important;
    }

    .clanslist-table > tbody > tr {
        display: grid !important;
        grid-template-columns: 36px 1fr auto;
        grid-template-rows: auto auto;
        align-items: center;
        padding: 10px 12px;
        border-bottom: 1px solid rgba(191,101,48,0.18);
        gap: 2px 8px;
    }

    .clanslist-table > tbody > tr:nth-child(odd) {
        background: rgba(59,31,13,0.22);
    }

    .clanslist-table > tbody > tr > td {
        display: block !important;
        width: auto !important;
        padding: 0 !important;
        margin: 0;
        border: none !important;
    }

    .clanslist-table > tbody > tr > td.clan-rank {
        grid-row: 1 / 3;
        grid-column: 1;
        font-size: 18px;
        font-weight: 900;
        text-align: center;
        line-height: 1.1;
    }

    .clanslist-table > tbody > tr > td.clan-name {
        grid-row: 1;
        grid-column: 2;
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .clanslist-table > tbody > tr > td.clan-power {
        grid-row: 1;
        grid-column: 3;
        font-size: 13px;
        text-align: left;
        white-space: nowrap;
    }

    .clanslist-table > tbody > tr > td.clan-members {
        grid-row: 2;
        grid-column: 2;
        font-size: 12px;
        color: #9a7a5a;
    }

    .clanslist-table > tbody > tr > td.clan-members .members-bar {
        width: 40px;
    }

    .clanslist-table > tbody > tr > td.clan-action {
        grid-row: 2;
        grid-column: 3;
        text-align: left;
    }

    .clanslist-table .clan-action .btn-request,
    .clanslist-table .clan-action .btn-enter {
        padding: 4px 10px;
        font-size: 11px;
    }
}

/* ===== MOBILE: 480px and below ===== */
@media screen and (max-width: 480px) {
    #main_game_window .content {
        padding: 8px;
        font-size: 11pt;
    }

    /* Stack form elements */
    input, textarea, select {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Overflow data tables on mobile */
    .content table.ftable {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .cities_view {
        height: 200px;
        background-size: cover;
    }

    #window_ach {
        width: 200px;
        right: 10px;
    }

    /* Attack page: hide gold and clan power columns on small screens */
    table.atk-table td:nth-child(5),
    table.atk-table th:nth-child(5),
    table.atk-table td:nth-child(6),
    table.atk-table th:nth-child(6) {
        display: none;
    }

    /* Attack page: smaller text */
    table.atk-table td,
    table.atk-table th {
        padding: 6px 3px;
        font-size: 11px;
    }

    /* Attack player name stays readable */
    table.atk-table .atk-player-link {
        font-size: 13px;
    }

    /* Bank stats cards - single column */
    .bank-stat-card {
        padding: 8px;
    }

    /* Login page - tighter on small screens */
    .login-page {
        padding: 10px 8px;
    }

    .login-card {
        padding: 24px 18px 20px;
        border-radius: 12px;
    }

    .login-logo img {
        height: 70px;
    }

    .login-title {
        font-size: 22px;
        margin-bottom: 18px;
    }
}
