/* ========================================
   PVP GAMING - RESPONSIVE GLOBAL OVERHAUL
   Loaded AFTER main.css to override where needed
   ======================================== */

/* ========================================
   BASE: Prevent any element from causing overflow
   ======================================== */
/* Nur Media-Elemente begrenzen, NICHT alle Elemente (bricht Fixed/Absolute-Positionierung) */
img, video, svg, iframe {
    max-width: 100%;
    height: auto;
}
/* Tables: horizontal scroll instead of overflow */
table:not(.games-table):not(.admin-table) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}
thead, tbody, tfoot, tr, th, td {
    max-width: none; /* undo the global max-width for table cells */
}
/* Prevent long words/URLs from breaking layout */
body {
    word-wrap: break-word;
    overflow-wrap: break-word;
}
pre, code {
    white-space: pre-wrap;
    word-break: break-all;
}

/* ========================================
   FLUID TYPOGRAPHY — scales with viewport
   ======================================== */
:root {
    --font-4xl: clamp(1.8rem, 5vw, 4rem);
    --font-3xl: clamp(1.5rem, 4vw, 3rem);
    --font-2xl: clamp(1.25rem, 3vw, 2rem);
    --font-xl:  clamp(1.1rem, 2.5vw, 1.5rem);
    --font-lg:  clamp(1rem, 2vw, 1.25rem);
}

/* ========================================
   HEADER — Always fits, never overflows
   ======================================== */
.header {
    padding: var(--space-sm, 0.5rem) var(--space-md, 1rem);
    flex-wrap: wrap;
    gap: 0.5rem;
}
.logo {
    font-size: clamp(1rem, 3vw, 1.5rem);
    flex-shrink: 0;
    white-space: nowrap;
}
.nav {
    gap: clamp(0.5rem, 2vw, 2rem);
}
.nav-link {
    font-size: clamp(0.75rem, 1.5vw, 1rem);
    white-space: nowrap;
}
.header-actions {
    flex-wrap: wrap;
    gap: 0.4rem;
}
.balance-display {
    font-size: clamp(0.7rem, 1.5vw, 0.875rem);
    padding: 0.3rem 0.6rem;
    white-space: nowrap;
}

/* ========================================
   HERO SECTION — Fluid
   ======================================== */
.hero {
    padding: clamp(5rem, 12vw, 8rem) clamp(1rem, 4vw, 2rem) clamp(1.5rem, 5vw, 4rem);
}
.hero h1 {
    font-size: var(--font-4xl);
    letter-spacing: clamp(1px, 0.3vw, 5px);
}
.hero p {
    font-size: clamp(0.9rem, 2vw, 1.25rem);
    max-width: min(600px, 90vw);
}
.hero-buttons {
    flex-wrap: wrap;
}

/* ========================================
   SECTIONS — Fluid padding
   ======================================== */
.section {
    padding: clamp(1.5rem, 4vw, 4rem) clamp(0.75rem, 3vw, 2rem);
    max-width: min(1400px, 100%);
}
.section-title {
    font-size: var(--font-2xl);
    letter-spacing: clamp(1px, 0.3vw, 5px);
}

/* ========================================
   GAME CARDS — Responsive grid
   ======================================== */
.games-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
    gap: clamp(0.75rem, 2vw, 1.5rem);
}
.game-image {
    height: clamp(120px, 15vw, 180px);
    font-size: clamp(2.5rem, 5vw, 4rem);
}
.game-title {
    font-size: clamp(0.85rem, 2vw, 1.25rem);
}
.game-price {
    font-size: clamp(0.85rem, 2vw, 1.5rem);
}

/* ========================================
   CARDS — Fluid
   ======================================== */
.card-body {
    padding: clamp(0.75rem, 2vw, 1.5rem);
}
.card-header {
    padding: clamp(0.75rem, 2vw, 1.5rem);
}
.card-title {
    font-size: clamp(0.85rem, 2vw, 1.25rem);
}

/* ========================================
   AUTH PAGES (Login, Register)
   ======================================== */
.auth-container {
    padding: clamp(1rem, 3vw, 2rem);
    padding-top: clamp(80px, 12vw, 100px);
}
.auth-box {
    max-width: min(450px, 95vw);
    margin: 0 auto;
}
.auth-header {
    padding: clamp(1rem, 3vw, 3rem);
}
.auth-header .logo {
    font-size: clamp(1.2rem, 3vw, 2rem);
}
.auth-title {
    font-size: clamp(1rem, 3vw, 1.5rem);
}
.auth-body {
    padding: clamp(1rem, 3vw, 3rem);
}

/* ========================================
   WALLET PAGE
   ======================================== */
.wallet-container {
    padding-top: clamp(70px, 10vw, 100px);
}
.wallet-balance {
    font-size: clamp(1.5rem, 5vw, 4rem);
}
.wallet-actions {
    flex-wrap: wrap;
}
.wallet-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(350px, 100%), 1fr));
    gap: clamp(1rem, 2vw, 2rem);
    padding: clamp(1rem, 3vw, 3rem);
    max-width: min(1200px, 100%);
}

/* ========================================
   MESSAGES PAGE
   ======================================== */
.messages-container {
    padding-top: clamp(70px, 10vw, 100px);
}

/* ========================================
   ADMIN PANEL
   ======================================== */
.admin-container {
    padding-top: clamp(50px, 8vw, 70px);
}
.admin-stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
    gap: clamp(0.5rem, 1.5vw, 1rem);
}

/* ========================================
   TABLES — Always scrollable on small screens
   ======================================== */
.table-container {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table th,
.table td {
    padding: clamp(0.5rem, 1.5vw, 1rem);
    font-size: clamp(0.75rem, 1.5vw, 1rem);
    white-space: nowrap;
}

/* ========================================
   MODALS — Always fit on screen
   ======================================== */
.modal {
    max-width: min(500px, 95vw);
    max-height: 90vh;
    overflow-y: auto;
    margin: 1rem;
}
.modal-header,
.modal-body,
.modal-footer {
    padding: clamp(0.75rem, 2vw, 1.5rem);
}

/* ========================================
   FOOTER — Fluid
   ======================================== */
.footer {
    padding: clamp(1rem, 3vw, 3rem);
}
.footer-links {
    flex-wrap: wrap;
    gap: clamp(0.5rem, 2vw, 2rem);
}
.footer-links a {
    font-size: clamp(0.75rem, 1.5vw, 0.875rem);
}

/* ========================================
   MARQUEE — Fluid
   ======================================== */
/* Marquee: Abstand muss exakt der Header-Hoehe entsprechen (fixed header = 70px) */
.marquee {
    margin-top: 70px;
}
.marquee-content span {
    font-size: clamp(0.65rem, 1.5vw, 0.875rem);
    padding: 0 clamp(0.5rem, 2vw, 3rem);
    letter-spacing: clamp(1px, 0.2vw, 3px);
}

/* ========================================
   BUTTONS — Fluid
   ======================================== */
.btn {
    font-size: clamp(0.75rem, 1.5vw, 1rem);
    padding: clamp(0.3rem, 1vw, 0.5rem) clamp(0.75rem, 2vw, 2rem);
    white-space: nowrap;
}
.btn-lg {
    font-size: clamp(0.85rem, 2vw, 1.25rem);
    padding: clamp(0.5rem, 1.5vw, 1rem) clamp(1rem, 3vw, 3rem);
}

/* ========================================
   STAKE SELECTION (Arena)
   ======================================== */
.stakes-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)) !important;
    gap: clamp(0.5rem, 1.5vw, 1rem);
}
.stake-amount {
    font-size: clamp(1.2rem, 3vw, 1.8rem);
}
.stake-card {
    padding: clamp(0.75rem, 2vw, 1.5rem);
}

/* ========================================
   ARENA — 5-column game grid responsive
   ======================================== */
.games-grid-5 {
    grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)) !important;
    gap: clamp(0.75rem, 2vw, 1.5rem);
}
.selected-game-title {
    font-size: clamp(1.2rem, 3vw, 2rem);
}

/* ========================================
   ACCOUNT PAGE — Responsive stats
   ======================================== */
.account-stats {
    display: flex;
    flex-wrap: wrap;
    gap: clamp(0.5rem, 1.5vw, 1.25rem);
}
.stat-card {
    min-width: min(150px, 45%);
    flex: 1 1 auto;
    padding: clamp(0.75rem, 2vw, 1.25rem);
}
.stat-value {
    font-size: clamp(1.2rem, 3vw, 1.5rem);
}
.welcome-title {
    font-size: clamp(1.5rem, 4vw, 2.25rem);
}
.reports-stats {
    flex-wrap: wrap;
}
.report-stat {
    min-width: min(120px, 30%);
    flex: 1 1 auto;
}

/* ========================================
   LEGAL PAGES (AGB, Datenschutz, Impressum)
   ======================================== */
.legal-content,
.legal-container,
article {
    max-width: min(900px, 95vw);
    margin: 0 auto;
    padding: clamp(1rem, 3vw, 3rem);
}

/* ========================================
   TOURNAMENT PAGES
   ======================================== */
.tournament-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: clamp(0.75rem, 2vw, 1.5rem);
}

/* ========================================
   GAME CANVASES — Never overflow their container
   ======================================== */
/* Canvas: begrenzen aber display nicht aendern (manche Canvases sind inline) */

/* ========================================
   MOBILE SIDEBAR — Auf grossen Screens komplett verstecken
   main.js erstellt die Sidebar dynamisch, aber main.css
   definiert ihre Styles nur in @media (max-width: 992px).
   Ohne diese Regel ist sie auf grossen Screens ein normales
   sichtbares Element am Seitenende.
   ======================================== */
.mobile-sidebar {
    display: none !important;
}
.mobile-sidebar-overlay {
    display: none !important;
}
/* Innerhalb der Media Query wird display von main.css gesetzt */
@media (max-width: 992px) {
    .mobile-sidebar {
        display: flex !important;
        position: fixed;
        right: -280px;
        visibility: visible;
    }
    .mobile-sidebar.open {
        right: 0;
    }
    .mobile-sidebar-overlay {
        display: none !important;
    }
    .mobile-sidebar-overlay.open {
        display: block !important;
    }
}

/* ========================================
   SPECIFIC BREAKPOINTS — Fine-tuning
   ======================================== */

/* Large tablets and small desktops */
@media (max-width: 1200px) {
    .main-content {
        padding: clamp(1rem, 3vw, 2.5rem);
    }
}

/* Tablets */
@media (max-width: 992px) {
    /* Messages: show sidebar as full-width list */
    .messages-container {
        grid-template-columns: 1fr;
    }
    .messages-sidebar {
        display: block;
        border-right: none;
        border-bottom: 1px solid var(--border, rgba(0,255,255,0.2));
        max-height: 40vh;
        overflow-y: auto;
    }
    /* Admin: full-width */
    .admin-container {
        grid-template-columns: 1fr;
    }
    .admin-sidebar {
        display: none;
    }
}

/* Mobile phones */
@media (max-width: 768px) {
    /* Wallet grid always 1 column */
    .wallet-grid {
        grid-template-columns: 1fr;
    }
    /* Reduce general padding */
    .section {
        padding: 1.5rem 0.75rem;
    }
    /* Auth pages tighter */
    .auth-body {
        padding: 1rem;
    }
    .auth-header {
        padding: 1.25rem 1rem;
    }
    /* Footer links wrap */
    .footer-links {
        gap: 0.75rem;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    .hero {
        padding: 4.5rem 0.75rem 1.5rem;
    }
    .hero h1 {
        font-size: 1.6rem;
    }
    .btn {
        font-size: 0.8rem;
        padding: 0.4rem 0.75rem;
    }
    .btn-lg {
        font-size: 0.9rem;
        padding: 0.5rem 1.25rem;
    }
    .game-card {
        margin: 0;
    }
    .stake-card {
        padding: 0.75rem;
    }
    /* Code inputs smaller */
    .code-input {
        width: 36px;
        height: 44px;
        font-size: 1.1rem;
    }
}

/* ========================================
   PRINT — Clean output
   ======================================== */
@media print {
    .header, .footer, .bg-animation, .grid-overlay,
    .marquee, .mobile-menu-btn, .mobile-sidebar,
    .mobile-sidebar-overlay {
        display: none !important;
    }
    body {
        background: #fff;
        color: #000;
    }
}
