/* ==========================================================================
   Vesmírné klany – mobilní vrstva
   Načítá se jen na úzkých displejích (media="(max-width: 820px)" v header.php), vzhled na počítači se nemění.
   Styl (neonově sci-fi) zůstává; mění se rozvržení, velikosti dotykových ploch a zátěž pro grafiku telefonu.
   Hra používá hodně inline stylů, proto se zde místy cílí atributovými selektory a !important.
   ========================================================================== */

:root {
    --mobile-bar-h: 64px;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* --- Výkon: animované a pevné pozadí a rozmazání (backdrop-filter) jsou na telefonech velmi drahé --- */
body {
    animation: none !important;
    background-attachment: scroll !important;
    background-size: cover !important;
    padding-bottom: calc(var(--mobile-bar-h) + env(safe-area-inset-bottom, 0px)) !important;
}

section, .form-box, .map-sidebar-panel, .techtree-container, .game-world-card,
[style*="backdrop-filter"] {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    background: rgba(11, 14, 20, 0.9) !important;
}

section:hover {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), inset 0 0 10px rgba(102, 252, 241, 0.05) !important;
}

img, video, canvas, svg {
    max-width: 100%;
}

img {
    height: auto;
}

/* --- Obsah nesmí přetékat --- */
main {
    padding-left: 8px !important;
    padding-right: 8px !important;
    box-sizing: border-box;
    max-width: 100%;
}

/* Vnořené odsazení z počítačového rozvržení se na telefonu zmenší, ať zbyde místo na obsah */
html body #game-container {
    padding: 0 4px !important;
    margin: 12px auto !important;
    box-sizing: border-box !important;
    max-width: 100% !important;
}

main, section, .form-box {
    min-width: 0;
}

h1, h2, h3 {
    overflow-wrap: anywhere;
}

.page-header h2 {
    font-size: 1.35rem !important;
}

/* Víceslupcová rozvržení z inline stylů se na telefonu skládají pod sebe */
[style*="grid-template-columns: 1fr 1fr"],
[style*="grid-template-columns: 2fr 1fr"],
[style*="grid-template-columns: 1fr 2fr"],
[style*="grid-template-columns: 1.2fr"],
[style*="grid-template-columns: 1.5fr"],
[style*="grid-template-columns: 3fr 1fr"],
[style*="grid-template-columns: 260px 1fr"],
[style*="grid-template-columns: 2fr 1fr 1fr"] {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 16px !important;
}

/* Tři a čtyři sloupce jen na dvě (musí být až za pravidlem výše) */
[style*="grid-template-columns: 1fr 1fr 1fr"],
[style*="repeat(3, 1fr)"],
[style*="repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

[style*="repeat(auto-fit, minmax(300px"],
[style*="repeat(auto-fit, minmax(280px"] {
    grid-template-columns: minmax(0, 1fr) !important;
}

.page-header [style*="display: flex"],
nav[style*="display: flex"],
[style*="justify-content: space-between"] {
    flex-wrap: wrap;
    gap: 10px;
}

/* Řádky záložek (administrace, superadmin) se zalomí na více řádků */
div:has(> a.btn[href*="tab="]) {
    flex-wrap: wrap;
    gap: 8px !important;
}

div:has(> a.btn[href*="tab="]) > a.btn {
    padding: 8px 12px !important;
    font-size: 0.8rem !important;
}

/* Formuláře "pole + tlačítko" v jednom řádku (chat, hledání): pole se smí zúžit, ať tlačítko nevyčnívá */
form[style*="display: flex"] > input,
form[style*="display: flex"] > textarea,
form[style*="display: flex"] > select,
form[style*="display: flex"] > .form-group {
    min-width: 0;
    flex: 1 1 0;
}

form[style*="display: flex"] > button {
    flex: 0 0 auto;
}

/* Stránky s mřížkou ve stylu Bootstrapu (diplomacie): záporný okraj řádku by na telefonu vyčníval za displej */
main .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

main [class*="col-"] {
    padding-left: 0 !important;
    padding-right: 0 !important;
    max-width: 100%;
}

/* Řádky tlačítek-záložek na stránce (aliance, ...) se zalomí, ať se poslední záložka neořízne */
div:has(> button[id^="btn-tab"]) {
    flex-wrap: wrap;
    gap: 8px !important;
}

div:has(> button[id^="btn-tab"]) > button,
div:has(> button[id^="btn-tab"]) > a.btn {
    flex: 1 1 auto;
}

/* Tabulky se na telefonu posouvají do strany místo aby rozbily stránku */
main table, section table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Žebříčky a seznamy: každý řádek je karta (popisky sloupců doplní js/mobile.js do data-label) */
main table.ranking-table,
main table.table-ranking,
section table.ranking-table,
section table.table-ranking {
    display: block;
    overflow: visible;
}

.ranking-table thead,
.table-ranking thead {
    display: none;
}

.ranking-table tbody,
.table-ranking tbody {
    display: block;
}

.ranking-table tr,
.table-ranking tr {
    display: block;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin: 0 0 10px;
    padding: 8px 12px;
}

.ranking-table td,
.table-ranking td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 5px 0 !important;
    border: 0 !important;
    text-align: right !important;
    min-width: 0;
    overflow-wrap: anywhere;
}

.ranking-table td::before,
.table-ranking td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 0.72rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    text-align: left;
}

.ranking-table td[data-label=""]::before,
.table-ranking td:not([data-label])::before {
    content: none;
}

/* --- Dotykové plochy a formuláře (16 px zabrání automatickému přiblížení v iOS) --- */
.btn, button, select, input[type="text"], input[type="number"], input[type="email"], input[type="password"], input[type="search"], textarea {
    min-height: 42px;
}

input, select, textarea {
    font-size: 16px !important;
    max-width: 100%;
    box-sizing: border-box;
}

.btn {
    -webkit-tap-highlight-color: rgba(102, 252, 241, 0.2);
    touch-action: manipulation;
}

a, button {
    touch-action: manipulation;
}

/* --- Horní lišta zdrojů (HUD): přilepená nahoře, po rolování jen zdroje --- */
.hud-wrap {
    position: sticky !important;
    top: 0;
    z-index: 900;
    background: rgba(8, 10, 16, 0.96) !important;
    padding: 8px 0 !important;
}

.hud-wrap #game-container {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
    padding: 0 10px !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
}

.hud-status-panel {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px 10px;
    width: 100%;
}

.hud-status-panel .hud-status-col,
.hud-status-panel .hud-status-value {
    min-width: 0;
}

.hud-status-panel .hud-status-value a {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hud-status-panel .hud-status-divider {
    display: none !important;
}

.hud-status-panel .hud-status-col:last-child {
    grid-column: 1 / -1;
}

.hud-wrap.hud-compact .hud-status-panel {
    display: none !important;
}

.resources-bar {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 6px !important;
    padding: 6px 8px !important;
    border-radius: 12px !important;
    width: 100%;
    box-sizing: border-box;
}

.resources-bar .resource-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    font-size: 0.8rem;
    min-width: 0;
}

.resources-bar .resource-icon {
    font-size: 0.95rem;
}

.resources-bar .resource-details {
    width: 100% !important;
    min-width: 0;
}

.resources-bar .resource-production {
    display: none;
}

/* --- Spodní navigační lišta ve hře (ovládání palcem) --- */
.game-header {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto !important;
    z-index: 1000;
    height: auto !important;
    min-height: var(--mobile-bar-h);
    padding: 0 0 env(safe-area-inset-bottom, 0px) !important;
    background: rgba(8, 10, 16, 0.97) !important;
    border-top: 1px solid rgba(102, 252, 241, 0.3) !important;
    border-bottom: 0 !important;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.6) !important;
}

.game-header nav {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-around;
    align-items: stretch;
    width: 100%;
    gap: 0;
    padding: 0;
}

.game-header .nav-item,
.game-header .nav-more {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1 1 0;
    min-width: 0;
    gap: 3px;
    padding: 9px 2px 7px;
    font-size: 0.64rem;
    line-height: 1.15;
    text-align: center;
    white-space: nowrap;
    border: 0 !important;
    border-top: 2px solid transparent !important;
    background: transparent;
    color: var(--text-secondary, #c5c6c7);
    font-family: inherit;
    font-weight: 700;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    cursor: pointer;
    position: relative;
}

.game-header .nav-item i,
.game-header .nav-more i {
    font-size: 1.25rem;
}

.game-header .nav-item.active {
    color: var(--neon-blue);
    border-top-color: var(--neon-blue) !important;
    background: rgba(102, 252, 241, 0.06);
}

.game-header .nav-item .badge {
    position: absolute;
    top: 3px;
    left: calc(50% + 6px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 0.62rem;
    line-height: 16px;
    border-radius: 8px;
    box-sizing: border-box;
}

.game-header .nav-more .more-dot {
    position: absolute;
    top: 6px;
    left: calc(50% + 6px);
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #ff5252;
    box-shadow: 0 0 6px #ff5252;
    display: none;
}

.game-header .nav-more.has-badge .more-dot {
    display: block;
}

/* Ve sbalené liště jen hlavní položky; ostatní se ukážou po "Více" */
.game-header:not(.nav-open) .nav-item:not(.nav-primary),
.game-header #audio-toggle-btn {
    display: none !important;
}

.game-header.nav-open nav {
    flex-wrap: wrap;
}

.game-header.nav-open .nav-item,
.game-header.nav-open .nav-more {
    flex: 0 0 25%;
    border-top: 0 !important;
    padding: 12px 2px 10px;
}

.game-header.nav-open .nav-item:not(.nav-primary) {
    display: flex !important;
}

.game-header.nav-open #audio-toggle-btn {
    display: flex !important;
    flex: 0 0 25%;
    justify-content: center;
}

.nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.55);
    display: none;
}

.nav-backdrop.show {
    display: block;
}

/* Hlavička mimo hru (rozcestník, přihlášení): běžná horní lišta, která se zalamuje */
#main-header:not(.game-header) {
    position: static !important;
    height: auto !important;
    padding: 6px 8px !important;
}

#main-header:not(.game-header) nav {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
}

#main-header:not(.game-header) .nav-item {
    padding: 10px 10px;
    font-size: 0.72rem;
}

/* --- Úvodní stránka (hero): na telefonu na celou šířku obsahu, tlačítka pod sebou --- */
.hero {
    width: 100% !important;
    left: 0 !important;
    right: auto !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-top: 0 !important;
    height: auto !important;
    min-height: calc(100vh - 140px);
    padding: 24px 12px !important;
    border-radius: 12px;
    box-sizing: border-box;
}

.hero-content {
    width: 100%;
    max-width: 100%;
    padding: 22px 16px !important;
    box-sizing: border-box;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    background: rgba(5, 7, 12, 0.72) !important;
}

.hero-content h2 {
    font-size: clamp(1.6rem, 8vw, 2.1rem) !important;
    line-height: 1.2;
    margin-bottom: 14px !important;
}

.hero-content p {
    font-size: 0.98rem !important;
    margin-bottom: 22px !important;
}

.hero-buttons {
    flex-direction: column;
    gap: 10px !important;
    width: 100%;
}

.hero-buttons .btn {
    width: 100%;
    box-sizing: border-box;
    justify-content: center;
    text-align: center;
}

/* --- Základna: popisky budov na obrázku jsou na telefonu menší, aby se na sebe nelepily --- */
#station-view-graphic {
    margin-top: 10px;
    margin-bottom: 20px;
}

.station-hotspot {
    -webkit-tap-highlight-color: rgba(102, 252, 241, 0.25);
}

.hotspot-badge {
    padding: 2px 5px !important;
    font-size: 0.56rem !important;
    line-height: 1.15;
    border-radius: 3px !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    box-shadow: none !important;
}

.hotspot-badge .lvl-badge {
    font-size: 0.54rem !important;
}

/* --- Mapa: mapa je nahoře, ovládací panel se rozbaluje tlačítkem --- */
.map-layout {
    display: flex !important;
    flex-direction: column;
    gap: 12px !important;
}

.map-layout .map-view-container {
    order: 1;
    width: 100% !important;
    max-width: 100% !important;
    align-self: stretch;
    box-sizing: border-box;
}

.map-layout .map-grid-wrapper {
    width: 100%;
    flex: 1 1 auto;
}

.map-layout .map-sidebar-panel {
    order: 2;
}

.map-sidebar-toggle {
    order: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    background: rgba(11, 14, 20, 0.9);
    color: var(--neon-blue);
    border: 1px solid rgba(102, 252, 241, 0.35);
    border-radius: 8px;
    padding: 10px;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
}

.map-layout:not(.map-panel-open) .map-sidebar-panel {
    display: none;
}

.map-layout.map-panel-open .map-sidebar-panel {
    order: 1;
}

.map-layout.map-panel-open .map-view-container {
    order: 2;
}

/* Mapa se dá ovládat prstem: stránka se při tažení po mapě nerolují a nepřibližuje */
.map-grid-wrapper {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Plovoucí tlačítko hlášení chyb nesmí zakrývat spodní lištu */
[style*="position: fixed"][style*="bottom"]:not(.game-header):not(.nav-backdrop) {
    bottom: calc(var(--mobile-bar-h) + 12px + env(safe-area-inset-bottom, 0px)) !important;
}

.bug-fab {
    padding: 11px 13px !important;
    right: 10px !important;
    bottom: calc(var(--mobile-bar-h) + 10px + env(safe-area-inset-bottom, 0px)) !important;
    font-size: 1rem !important;
    opacity: 0.9;
}

.bug-fab .bug-fab-label {
    display: none;
}

body.nav-sheet-open .bug-fab {
    display: none !important;
}

/* Dotykové displeje nemají "najetí myší": po klepnutí by tlačítko zůstalo trvale zvýrazněné, proto se hover neutralizuje
   a odezvu dává stisk (:active) */
@media (hover: none) {
    .btn-primary:hover {
        background: rgba(102, 252, 241, 0.03);
        color: var(--neon-blue);
        box-shadow: 0 0 8px rgba(102, 252, 241, 0.05);
        transform: none;
    }
    .btn-secondary:hover {
        background: rgba(232, 67, 147, 0.03);
        color: var(--neon-magenta);
        box-shadow: 0 0 8px rgba(232, 67, 147, 0.05);
        transform: none;
    }
    .btn-success:hover {
        background: rgba(46, 204, 113, 0.03);
        color: #2ecc71;
        box-shadow: 0 0 8px rgba(46, 204, 113, 0.05);
        transform: none;
    }
    .btn-danger:hover {
        background: rgba(231, 76, 60, 0.03);
        color: #e74c3c;
        box-shadow: 0 0 8px rgba(231, 76, 60, 0.05);
        transform: none;
    }
}

.btn-primary:active { background: var(--neon-blue); color: #0b0c10; }
.btn-secondary:active { background: var(--neon-magenta); color: #fff; }
.btn-success:active { background: #2ecc71; color: #0b0c10; }
.btn-danger:active { background: #e74c3c; color: #fff; }

/* Omezení pohybu na přání uživatele */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
