/* ============================================
   FarmBrawl — Responsive (Mobile-First + Fluid System)
   ============================================ */

/* ─── Global overflow & viewport shell (enhanced fluid) ─── */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    touch-action: pan-y;
    overflow-x: hidden;
    overflow-y: auto;
    width: 100%;
    max-width: 100vw;
}

body {
    touch-action: pan-y;
    -webkit-tap-highlight-color: rgba(16, 185, 129, 0.18);
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
    overflow-x: hidden;
    overflow-y: auto;
    width: 100%;
    max-width: 100vw;
    height: auto;
    min-height: 100vh;
    margin: 0;
    box-sizing: border-box;
    font-size: var(--fs-base, 0.92rem);
    padding: 0;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* ─── Mobile rendering optimizations ─── */
@media (max-width: 768px) {
    /* Reduce expensive blur/glass effects on low-end mobile GPUs */
    .landing-nav,
    .landing-nav--scrolled,
    .landing-nav-links,
    .landing-nav-toggle,
    .landing-device-card,
    .landing-feature-card,
    .landing-pillar-card,
    .landing-plant-card,
    .landing-sticky-cta,
    .landing-social-proof-item,
    .landing-faq-item,
    .transparency-modal__panel,
    .plant-modal-panel,
    .purchase-confirm-panel,
    .welcome-chest-panel {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    /* Solidify nav background on mobile so hero overlay doesn't show through */
    .landing-nav:not(.landing-nav--scrolled) {
        background: rgba(15, 23, 42, 0.92);
    }

    /* Keep blur only on hero glass elements that are above-the-fold */
    .landing-hero,
    .landing-hero-tagline {
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }

    /* Reduce motion-related GPU load */
    .landing-device-mockup img,
    .dashboard-preview img,
    .landing-plant-img {
        animation: none !important;
    }

    /* Prevent unnecessary repaints on animated counters */
    .ecosystem-status .stat-value {
        will-change: auto;
    }
}

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

button,
a[role="button"],
input,
select,
textarea,
[role="button"],
.nav-tab,
.game-tool-btn,
.vip-btn,
.shop-buy-btn,
.withdraw-action-btn,
.game-topbar-wallet-btn,
.game-nav-toggle,
.shine-btn,
.hud-deposit,
.phantom-btn,
.icon-btn,
.hud-nav-link,
.landing-btn,
.iris-btn {
  min-height: var(--touch-min, 44px);
  min-width: var(--touch-min, 44px);
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: rgba(52, 211, 153, 0.2) !important;
}

/* Ensure smooth touch scrolling on modal overlays */
.modal-overlay,
.transparency-modal,
.plant-modal,
.purchase-confirm-modal {
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* ─── SAFE-AREA VERTICAL (Portrait) ───
   Aplica insets a fixed-top, fixed-bottom y shells scrollables.
   Requiere viewport-fit=cover (P0-1 completado).
────────────────────────────────────────────────────────────── */

/* Fixed-top: topbar + HUD balance tray */
.game-topbar,
.hud-balance-tray {
    padding-top: max(var(--space-2), env(safe-area-inset-top, 0));
}

/* Fixed-bottom: bottom navbar + HUD chips/botones inferiores */
.game-navbar,
.hud-chip:last-child,
.game-tool-btn:last-of-type,
.withdraw-action-btn:last-of-type {
    padding-bottom: max(var(--space-2), env(safe-area-inset-bottom, 0));
}

/* Shells scrollables: evitan que contenido quede bajo barra home-indicator */
.game-main-shell,
.game-main-shell--wide,
.withdraw-shell,
.shop-shell,
.exchange-shell,
.attack-shell,
.farm-tab-shell,
.bazaar-shell,
.lab-shell,
.plots-grid-scroll {
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom, 0));
    min-height: 100dvh;
}

/* ─── SAFE-AREA HORIZONTAL (Landscape) ───
   Aplica insets left/right a shells full-bleed y topbars en landscape.
────────────────────────────────────────────────────────────── */

/* Shells full-bleed: evitan notch lateral en landscape */
.game-main-shell,
.game-main-shell--wide,
.withdraw-shell,
.shop-shell,
.exchange-shell,
.attack-shell,
.farm-tab-shell,
.bazaar-shell,
.lab-shell {
    padding-left: max(var(--space-4), env(safe-area-inset-left, 0));
    padding-right: max(var(--space-4), env(safe-area-inset-right, 0));
}

/* Topbars HUD: safe-area horizontal en landscape */
.game-topbar,
.hud-balance-tray {
    padding-left: max(var(--space-2), env(safe-area-inset-left, 0));
    padding-right: max(var(--space-2), env(safe-area-inset-right, 0));
}

/* Legacy iOS WebView fallback horizontal (constant() deprecated) */
@supports not (padding: env(safe-area-inset-left)) {
    .game-main-shell,
    .game-main-shell--wide,
    .withdraw-shell,
    .shop-shell,
    .exchange-shell,
    .attack-shell,
    .farm-tab-shell,
    .bazaar-shell,
    .lab-shell {
        padding-left: max(var(--space-4), constant(safe-area-inset-left));
        padding-right: max(var(--space-4), constant(safe-area-inset-right));
    }
    .game-topbar,
    .hud-balance-tray {
        padding-left: max(var(--space-2), constant(safe-area-inset-left));
        padding-right: max(var(--space-2), constant(safe-area-inset-right));
    }
}

/* Legacy iOS WebView fallback (constant() deprecated) */
@supports not (padding: env(safe-area-inset-top)) {
    .game-topbar,
    .hud-balance-tray {
        padding-top: max(var(--space-2), constant(safe-area-inset-top));
    }
    .game-navbar,
    .hud-chip:last-child,
    .game-tool-btn:last-of-type,
    .withdraw-action-btn:last-of-type {
        padding-bottom: max(var(--space-2), constant(safe-area-inset-bottom));
    }
    .game-main-shell,
    .game-main-shell--wide,
    .withdraw-shell,
    .shop-shell,
    .exchange-shell,
    .attack-shell,
    .farm-tab-shell,
    .bazaar-shell,
    .lab-shell,
    .plots-grid-scroll {
        padding-bottom: max(var(--space-4), constant(safe-area-inset-bottom));
    }
}

/* ─── MOBILE (< 640px / base) ───
   Everything is fluid via clamp + mobile-first rules above.
   Use min-width queries to add desktop enhancements.
────────────────────────────────────────────────────────────── */
@media (max-width: 639px) {
    html, body {
        min-height: 100dvh;
        min-height: -webkit-fill-available;
    }

    body {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
    }

    body > * {
        width: 100%;
        max-width: 100%;
        flex-shrink: 0;
    }

    /* Force full-bleed shells on tiny screens */
    .game-topbar,
    .game-main-shell,
    .game-main-shell--wide,
    .withdraw-shell,
    .shop-shell,
    .exchange-shell,
    .attack-shell,
    .farm-tab-shell,
    .bazaar-shell,
    .lab-shell {
        width: 100% !important;
        max-width: 100% !important;
        margin-left: auto;
        margin-right: auto;
        padding-inline: var(--space-2) !important;
    }

    [id^="content-"] {
        width: 100%;
        max-width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    [id^="content-"] > * {
        width: 100%;
        max-width: 100%;
    }



    .plant-modal-backdrop,
    .purchase-confirm-backdrop,
    .welcome-chest-backdrop,
    .fixed.inset-0 {
        display: flex !important;
        align-items: center;
        justify-content: center;
        padding: max(var(--space-2), env(safe-area-inset-top, 0)) var(--space-2) max(var(--space-2), env(safe-area-inset-bottom, 0));
    }
}

/* ─── TABLET (640px+) ─── */
@media (min-width: 640px) {
    .game-main-shell,
    .shop-shell,
    .exchange-shell {
        padding-inline: var(--space-4);
    }
}

/* ─── Touch & interaction baseline ─── */

button,
a,
[role="button"],
.plot-btn,
.nav-tab,
.hud-chip,
.game-tool-btn,
.shine-btn,
.shop-buy-btn,
.withdraw-action-btn,
.game-topbar-wallet-btn,
.game-nav-toggle {
    touch-action: manipulation;
    min-height: 44px;
}

@media (hover: none) and (pointer: coarse) {
    .plot-card:hover,
    .berry-card:hover,
    .farm-stat-card:hover {
        transform: none;
    }

    .plot-card.is-touch-active,
    .plot-btn.is-touch-active,
    button.is-touch-active,
    .nav-tab.is-touch-active {
        transform: scale(0.97);
        opacity: 0.92;
        transition: transform 0.08s ease, opacity 0.08s ease;
    }
}

/* Min tap targets (WCAG / iOS HIG) */
.plot-btn,
.plot-btn-water,
.game-topbar-wallet-btn,
.game-nav-toggle,
.nav-tab,
.game-tool-btn {
    min-height: 44px;
}

/* ─── Farm plots — Responsive Grid en móviles ─── */
.plots-grid-scroll {
    position: relative;
    width: 100%;
}

@media (max-width: 767px) {
    #plots-grid {
        width: 100%;
    }

    #plots-grid > .plot-card,
    #plots-grid > div {
        width: 100%;
        min-height: 240px;
    }

    .plot-card-footer .plot-btn {
        min-height: 44px; /* Touch target estándar */
        font-size: 0.7rem;
        padding: 0.4rem 0.2rem;
    }

    .plot-card-footer .plot-btn-water {
        flex: 0 0 44px;
        width: 44px;
        height: 44px;
        min-height: 44px;
    }

    .plot-actions {
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .plot-actions__group {
        gap: 0.35rem;
    }
}

/* ─── DESKTOP TABLET (768-1023) */
@media (min-width: 768px) and (max-width: 1023px) {
    #plots-grid {
        width: 100%;
    }

    .grid-fluid,
    .shop-grid,
    .market-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

/* ─── LARGE DESKTOP */
@media (min-width: 1024px) {
    .grid-fluid-3,
    .grid-fluid-4 {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
}

/* ─── Sidebar mobile overrides ─── */
@media (max-width: 969px) {
    .game-topbar { margin-left: 0 !important; }
    .game-main-shell { margin-left: 0 !important; }
}

/* ─── Landing nav — mobile drawer ─── */
.landing-nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 0.75rem;
    background: rgba(15, 23, 42, 0.35);
    color: #fff;
    font-size: 1.15rem;
    cursor: pointer;
    backdrop-filter: blur(8px);
    touch-action: manipulation;
}

.landing-nav--scrolled .landing-nav-toggle {
    border-color: #cbd5e1;
    background: #f1f5f9;
    color: #334155;
}

@media (max-width: 767px) {
    .landing-nav-toggle {
        display: inline-flex;
    }

    .landing-nav .nav-zone-right {
        display: none !important;
    }

    .landing-nav-inner {
        flex-wrap: wrap;
        gap: 0.65rem;
        justify-content: space-between;
    }

    .landing-nav-links {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        width: 100%;
        order: 10;
        padding: 0.5rem 0;
        border-radius: 1rem;
        background: rgba(15, 23, 42, 0.92);
        backdrop-filter: blur(12px);
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .landing-nav-links.is-open {
        display: flex;
    }

    /* Mobile: dropdown button styling */
    .nav-dd { width: 100%; }
    .nav-dd-btn {
        width: 100%;
        padding: 0.7rem 1rem !important;
        font-size: 0.95rem !important;
        border-bottom: 1px solid rgba(255,255,255,0.06);
        color: #e2e8f0 !important;
    }
    .landing-nav--scrolled .nav-dd-btn {
        color: #ffffff !important;
        font-weight: 700 !important;
        border-bottom-color: rgba(255,255,255,0.1);
        text-shadow: 0 1px 6px rgba(0,0,0,0.3);
    }

    /* Mobile: dropdown menu links */
    .nav-dd-menu {
        padding: 0 0 0.3rem 0.75rem !important;
        background: transparent !important;
        backdrop-filter: none !important;
        border: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }
    .nav-dd-menu a {
        padding: 0.55rem 0.85rem !important;
        border-bottom: 1px solid rgba(255,255,255,0.04);
        color: #94a3b8 !important;
        text-shadow: none !important;
    }
    .landing-nav--scrolled .nav-dd-menu a {
        color: #cbd5e1 !important;
        border-bottom-color: rgba(255,255,255,0.06);
    }

    .landing-nav--scrolled .landing-nav-links {
        background: rgba(15, 23, 42, 0.95);
        border: 1px solid rgba(255,255,255,0.08);
    }

    .landing-nav--scrolled .landing-nav-links a {
        color: #f1f5f9 !important;
        border-bottom-color: rgba(255,255,255,0.06);
    }

    .landing-nav--scrolled .nav-dd-btn {
        color: #ffffff !important;
        font-weight: 600 !important;
        text-shadow: 0 1px 6px rgba(0,0,0,0.3);
    }

    .landing-btn-play {
        margin-left: auto;
    }
}

/* ─── Panels — single column on small screens ─── */
@media (max-width: 768px) {
    body {
        background-attachment: scroll;
    }

    .bazaar-inv-panel,
    .market-exchange-panel,
    .exchange-rates-panel,
    .withdraw-action-panel,
    .withdraw-stress-panel,
    .attack-footer-grid {
        grid-template-columns: 1fr !important;
    }
    .farm-stats-panel {
        grid-template-columns: 1fr 1fr !important;
    }

    .bazaar-panel,
    .forge-panel-wrap,
    .lab-panel-wrap {
        flex-direction: column;
    }

    .farmer-panel {
        width: min(100vw - 1.25rem, 100%) !important;
        max-width: 100%;
        max-height: calc(100dvh - 2rem);
        overflow-y: auto;
        margin-left: auto;
        margin-right: auto;
    }

    #toast-container {
        left: 0.75rem;
        right: 0.75rem;
        bottom: calc(0.75rem + env(safe-area-inset-bottom, 0));
    }

    .plant-modal-panel,
    .purchase-confirm-panel,
    .welcome-chest-panel,
    .raid-modal-panel,
    .stress-modal-panel {
        width: min(calc(100vw - 1.5rem), 100%) !important;
        max-width: 100% !important;
        margin-left: auto;
        margin-right: auto;
        max-height: calc(100dvh - 2rem - env(safe-area-inset-top, 0));
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .stress-modal-overlay {
        padding: max(0.75rem, env(safe-area-inset-top, 0)) 0.75rem max(0.75rem, env(safe-area-inset-bottom, 0));
        align-items: flex-start;
    }

    .stress-modal-body {
        max-height: min(60dvh, calc(100dvh - 12rem));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .game-main-shell {
        padding-bottom: calc(2rem + env(safe-area-inset-bottom, 0)) !important;
    }

    .hud-balance-row {
        gap: 0.25rem;
        flex-wrap: wrap;
        width: 100%;
    }

    .hud-balance-tray {
        width: fit-content;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
        padding: 0.3rem 0.35rem;
    }

    .hud-chip {
        min-width: auto;
        flex: 1 1 calc(33.33% - 0.25rem);
        padding: 0.35rem 0.45rem 0.35rem 0.4rem;
        gap: 0.35rem;
    }

    .hud-chip-label {
        font-size: 0.72rem;
    }

    .hud-chip-val {
        font-size: 0.98rem;
    }

    .game-topbar .oracle-widget--hud {
        max-width: 100%;
        flex: 1 1 100%;
        min-width: 0;
        width: 100%;
    }

    .game-topbar .oracle-widget--hud .oracle-widget-title {
        font-size: 0.76rem;
        white-space: nowrap;
        max-width: none;
        overflow: visible;
        text-overflow: unset;
    }

    .game-topbar .oracle-widget--hud .oracle-widget-sub {
        font-size: 0.7rem;
        white-space: nowrap;
        max-width: none;
        overflow: visible;
        text-overflow: unset;
    }

    .game-main-shell,
    .game-main-shell--wide,
    .game-topbar-inner,
    .withdraw-shell,
    .shop-shell,
    .exchange-shell,
    .attack-shell {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    .game-topbar-inner {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 0.4rem;
        padding: 0.35rem 0.5rem;
        overflow-x: hidden;
    }

    .game-topbar .fb-brand {
        flex: 1 1 auto;
    }

    .hud-balance-tray {
        order: 3;
        width: fit-content;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }

    .game-topbar-controls {
        flex: 1 1 auto;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        gap: 0.4rem;
        order: 2;
    }

    .game-topbar-wallet-btn,
    .game-topbar-wallet-connected,
    .game-topbar-inicio,
    .hud-nav-link {
        width: auto;
        padding: 0.6rem 0.85rem;
        font-size: 0.8rem;
    }
} /* ── END @media (max-width: 768px) ── */

/* ─── SMALL DESKTOP / LARGE TABLET enhancements ─── */
@media (min-width: 769px) {
    /* Grids become more generous */
    .grid-fluid,
    .shop-grid,
    .market-grid,
    .inventory-grid {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
}

/* ─── EXTRA SMALL (phones < 480px) — tighter fluid adjustments */
@media (max-width: 480px) {
    .game-topbar .fb-brand__wordmark {
        font-size: var(--fs-sm);
    }

    .game-topbar .fb-brand__mark {
        width: 36px;
        height: 36px;
    }

    .hud-chip {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 0;
        padding: 0.3rem 0.4rem;
    }

    .hud-chip-ico {
        width: 1.5rem;
        height: 1.5rem;
        font-size: 0.85rem;
    }

    .hud-chip-label {
        font-size: 0.65rem;
    }

    .hud-chip-val {
        font-size: 0.88rem;
    }



    /* Farm plots: 2 columnas incluso en 320px */
    #plots-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.5rem !important;
    }

    #plots-grid > .plot-card,
    #plots-grid > div {
        min-height: 210px;
    }

    #content-missions .flex.items-center.justify-between,
    #content-rewards .flex.items-center.justify-between {
        flex-direction: column;
        align-items: flex-start !important;
        gap: var(--space-2);
    }

    .shine-btn,
    .welcome-chest-btn,
    .plot-btn,
    .game-tool-btn,
    .withdraw-action-btn {
        padding: var(--space-2) var(--space-3);
        min-height: var(--touch-min);
    }

    /* Tools row: 2 columnas compactas */
    .game-tools-row {
        gap: 0.3rem;
    }

    .game-tools-row .game-tool-btn,
    .game-tools-row .vip-btn {
        min-width: 0;
        flex: 1 1 calc(50% - 0.3rem);
        padding: 0.45rem 0.65rem !important;
        font-size: 0.72rem !important;
        justify-content: center;
    }
}

/* ====================================================
   LANDSCAPE MOBILE OVERRIDES (responsive.css)
   ==================================================== */
@media screen and (max-width: 950px) and (orientation: landscape) {
    .game-topbar-inner {
        grid-template-columns: auto 1fr auto !important;
        gap: 0.2rem !important;
    }
    .hud-balance-tray {
        min-width: 0 !important;
    }
    .attack-mode-tabs {
        grid-template-columns: 1fr 1fr !important;
    }
    #mochila-container .inv-section {
        grid-column: 1 / -1 !important;
    }
}

/* ====================================================
   TOPBAR OVERFLOW FIXES (juego normal)
   ==================================================== */
#topbar {
    box-sizing: border-box;
    min-width: 0;
    overflow: hidden;
}

#topbar-center {
    box-sizing: border-box;
    min-width: 0;
}

#topbar-right {
    box-sizing: border-box;
    min-width: 0;
    flex-shrink: 1;
}

.hud-card {
    box-sizing: border-box;
    flex: 0 1 auto;
    min-width: 28px;
}

.hud-card .hc-top {
    overflow: hidden;
}

.hud-card .hc-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hud-card .hc-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hud-deposit {
    box-sizing: border-box;
    flex-shrink: 1;
    min-width: 0;
}

#lang-select {
    box-sizing: border-box;
    flex-shrink: 1;
    min-width: 0;
}

#btn-wallet {
    box-sizing: border-box;
    flex-shrink: 1;
    min-width: 0;
}

#btn-settings {
    box-sizing: border-box;
    flex-shrink: 1;
    min-width: 0;
}

.phantom-btn {
    box-sizing: border-box;
    flex-shrink: 1;
    min-width: 0;
}

#account-header-chip {
    box-sizing: border-box;
    flex-shrink: 1;
    min-width: 0;
}

/* ====================================================
   HEADER COMPACTO (juego normal)
   ==================================================== */
#topbar {
    height: 48px;
    min-height: 48px;
    padding: 0 12px;
    gap: 8px;
}

#logo {
    font-size: 10px;
}

.hud-card {
    padding: 5px 10px;
    min-width: 80px;
}

.hud-card .hc-label {
    font-size: 11px;
}

.hud-card .hc-value {
    font-size: 16px;
}

.hc-ic, .hc-ic-img {
    width: 14px;
    height: 14px;
}

.hc-fa {
    font-size: 11px;
}

.hud-deposit {
    padding: 4px 10px;
    gap: 6px;
}

.hud-deposit .hd-ic {
    width: 16px;
    height: 16px;
    font-size: 10px;
}

.hud-deposit .hd-top {
    font-size: 7px;
}

.hud-deposit .hd-bottom {
    font-size: 8px;
}

#topbar-center {
    gap: 10px;
}

#topbar-right {
    gap: 8px;
}

#lang-select {
    padding: 3px 6px;
    font-size: 12px;
}

.phantom-btn {
    padding: 4px 10px;
    font-size: 7px;
}

#account-header-chip {
    padding: 5px 10px;
}

.profile-avatar {
    width: 28px;
    height: 28px;
}

.profile-name {
    font-size: 8px;
}

.profile-wallet {
    font-size: 6px;
}

#btn-settings {
    width: 28px;
    height: 28px;
    font-size: 12px;
}

/* ====================================================
   BARRA DE MISIONES → ABAJO
   ==================================================== */
#mission-bar {
    position: fixed;
    top: auto;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    width: auto;
    max-width: min(400px, calc(100% - 32px));
    padding: 3px 10px;
    font-size: 10px;
    border-radius: 999px;
    z-index: 50;
}
