/* Main Application Styles */

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
}

/* ==============================================================
   DUAL MODE LAYOUT:
   - Landing Page  => allows vertical scroll (overflow-y: auto)
   - Gameplay      => fixed 100vh, no scroll, everything fits screen
   ============================================================== */

/* GAMEPLAY LAYOUT — see game-ui.css for grid shell; landing scroll below */
.game-layout {
    /* Base gameplay shell defined in game-ui.css */
}

.landing-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 100vh;
    height: 100%;
    overflow-y: auto;
    /* Scrolls here, not on body */
    overflow-x: hidden;
    position: relative;
    padding: 0 1rem 1.25rem;
    z-index: 10;
    box-sizing: border-box;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 1.25rem;
    flex-wrap: wrap;
    gap: 0.75rem;
    flex-shrink: 0;
}

.game-header-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    min-width: 0;
}

.game-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.game-header-actions--wide {
    gap: 1rem;
    justify-content: flex-end;
}

.game-title {
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
}

.game-subtitle {
    font-size: 0.85rem;
    color: #94A3B8;
}

/* HUD wrapper — compact, never grows */
.hud-wrapper {
    flex-shrink: 0;
}

/* game-main — grid area; full rules in game-ui.css */
.game-main {
    min-height: 0;
}

/* ==============================================================
   BATTLE SCREEN — fills game-main, action buttons always visible
   ============================================================== */

.battle-screen-wrapper {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Modal Z-Index & Layering Fixes */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999 !important;
    padding: 1rem;
}

.modal-content-card {
    width: 100%;
    max-width: 540px;
    padding: 2.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    text-align: center;
    border: 1px solid var(--border-glow);
    background: rgba(30, 41, 59, 0.96);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(56, 189, 248, 0.2);
    z-index: 100000 !important;
    position: relative;
    border-radius: 16px;
}

.input-fantasy {
    width: 100%;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 0.85rem 1.25rem;
    color: var(--text-main);
    font-size: 1.1rem;
    outline: none;
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.input-fantasy:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px var(--accent-glow);
}

/* Signature Link & Hover Effects */
.signature-link {
    color: var(--accent-primary);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
    padding: 0.4rem 0.95rem;
    border-radius: 20px;
    border: 1px solid rgba(56, 189, 248, 0.4);
    background: rgba(56, 189, 248, 0.1);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    position: relative;
    overflow: hidden;
    backdrop-filter: blur(6px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.signature-link::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transition: left 0.6s ease;
}

.signature-link:hover::before {
    left: 100%;
}

.signature-link:hover {
    color: #FFFFFF;
    background: linear-gradient(135deg, #38BDF8 0%, #0284C7 100%);
    border-color: #7DD3FC;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.6), 0 0 35px rgba(56, 189, 248, 0.3);
    transform: translateY(-2px) scale(1.05);
}

/* Responsive Grid for Choices & Battle actions */
.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.85rem;
    flex-shrink: 0;
    /* Prevent buttons from being pushed off screen */
}

/* Unified AAA Fantasy Button Design System */
.btn-fantasy,
button {
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.9) 0%, rgba(15, 23, 42, 0.95) 100%);
    border: 1px solid var(--border-glow);
    border-radius: 12px;
    color: var(--text-main);
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4), inset 0 1px 1px rgba(255, 255, 255, 0.1);
    outline: none;
    user-select: none;
    letter-spacing: 0.04em;
}

.btn-fantasy:hover,
button:hover {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.25) 0%, rgba(2, 132, 199, 0.4) 100%);
    border-color: #38BDF8;
    color: #FFFFFF;
    box-shadow: 0 0 25px rgba(56, 189, 248, 0.5), 0 6px 20px rgba(0, 0, 0, 0.6);
    transform: translateY(-2px) scale(1.02);
}

.btn-fantasy:active,
button:active {
    transform: translateY(0) scale(0.98);
}

.btn-success {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2) 0%, rgba(21, 128, 61, 0.4) 100%) !important;
    border-color: rgba(34, 197, 94, 0.6) !important;
    color: #4ADE80 !important;
}

.btn-success:hover {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.4) 0%, rgba(21, 128, 61, 0.6) 100%) !important;
    border-color: #22C55E !important;
    color: #FFFFFF !important;
    box-shadow: 0 0 25px rgba(34, 197, 94, 0.5) !important;
}

.btn-danger {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(185, 28, 28, 0.4) 100%) !important;
    border-color: rgba(239, 68, 68, 0.6) !important;
    color: #F87171 !important;
}

.btn-danger:hover {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.4) 0%, rgba(185, 28, 28, 0.6) 100%) !important;
    border-color: #EF4444 !important;
    color: #FFFFFF !important;
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.5) !important;
}

.btn-warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(180, 83, 9, 0.4) 100%) !important;
    border-color: rgba(245, 158, 11, 0.6) !important;
    color: #FBBF24 !important;
}

.btn-warning:hover {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.4) 0%, rgba(180, 83, 9, 0.6) 100%) !important;
    border-color: #F59E0B !important;
    color: #FFFFFF !important;
    box-shadow: 0 0 25px rgba(245, 158, 11, 0.5) !important;
}

/* Dialogue Box styling */
.dialogue-box {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 2rem;
    min-height: 220px;
    background: rgba(30, 41, 59, 0.92);
}

.dialogue-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.speaker-avatar {
    font-size: 1.8rem;
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: rgba(51, 65, 85, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-light);
}

.speaker-name {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    color: var(--accent-primary);
    font-weight: 700;
}

.dialogue-text {
    font-size: 1.2rem;
    line-height: 1.7;
    color: var(--text-main);
}

.dialogue-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: auto;
}

/* HUD Components */
.hud-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    padding: 0.85rem 1.25rem;
    background: rgba(30, 41, 59, 0.92);
}

.hud-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.hud-label {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
}

.hud-value {
    font-size: 1.1rem;
    font-weight: 700;
}

/* Battle Arena — compact for fixed layout */
.battle-arena {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1rem;
    align-items: center;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .battle-arena {
        grid-template-columns: 1fr;
    }
}

.fighter-card {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 1rem 1.25rem;
    position: relative;
    background: rgba(51, 65, 85, 0.9);
}

.fighter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.fighter-name {
    font-size: 1.15rem;
    font-weight: 700;
}

/* Battle logs — FIXED HEIGHT SCROLLABLE, never pushes buttons */
.battle-logs-container {
    height: 90px;
    max-height: 90px;
    min-height: 90px;
    overflow-y: auto;
    flex-shrink: 0;
    padding: 0.6rem 0.85rem;
    background: rgba(15, 23, 42, 0.8);
    border-radius: 8px;
    border: 1px solid var(--border-light);
    font-size: 0.88rem;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.battle-log-entry {
    color: var(--text-muted);
}

.battle-log-entry.latest {
    color: var(--accent-primary);
    font-weight: 600;
}

/* Progress Bars */
.progress-bar-container {
    width: 100%;
    height: 6px;
    background: rgba(15, 23, 42, 0.8);
    border-radius: 8px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 8px;
    transition: width 0.4s ease;
}

.fill-health {
    background: linear-gradient(90deg, #EF4444, #F87171);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.fill-shield {
    background: linear-gradient(90deg, #38BDF8, #7DD3FC);
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.5);
}

.fill-enemy {
    background: linear-gradient(90deg, #B91C1C, #EF4444);
    box-shadow: 0 0 8px rgba(185, 28, 28, 0.5);
}

/* Hide on mobile */
@media (max-width: 640px) {
    .hide-mobile {
        display: none;
    }
}

/* Additional mobile UX tweaks */
@media (max-width: 480px) {
    .modal-content-card {
        max-width: 94% !important;
        padding: 1rem !important;
        border-radius: 12px;
    }

    .btn-fantasy {
        padding: 0.9rem 1rem !important;
        font-size: 1.05rem !important;
        min-height: 44px;
    }

    .modal-backdrop {
        padding: 0.5rem !important;
    }

    .font-heading {
        font-size: 1.1rem !important;
    }

    .game-header {
        padding: 0.55rem 0.75rem;
    }

    .game-title {
        font-size: 1.15rem;
    }

    .hud-container {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding: 0.65rem 0.85rem;
        gap: 0.55rem;
    }
}

/* ==============================================================
   TABLET BREAKPOINT (641px – 1024px)
   ============================================================== */
@media (max-width: 1024px) {
    .game-layout {
        padding: 0.65rem 0.85rem 1rem;
        gap: 0.6rem;
    }

    .landing-layout {
        padding: 0 0.85rem 1rem;
    }

    .actions-grid {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }

    .dialogue-box {
        padding: 1.25rem;
        min-height: 180px;
    }

    .dialogue-text {
        font-size: 1.05rem;
    }
}

/* ==============================================================
   LEADERBOARD / PLAYER DASHBOARD
   ============================================================== */
.leaderboard-backdrop {
    overflow-x: hidden;
}

.leaderboard-modal {
    max-width: 720px;
    width: 95%;
    max-height: 90vh;
    overflow: hidden;
    padding: 1.25rem 1.5rem !important;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.leaderboard-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.65rem;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 0.85rem;
    flex-shrink: 0;
}

.leaderboard-title {
    color: var(--color-warning);
    font-size: clamp(1.1rem, 3vw, 1.6rem);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.leaderboard-header-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.btn-leaderboard-refresh {
    font-size: 0.8rem;
    padding: 0.4rem 0.85rem;
    min-height: 40px;
}

.leaderboard-config-warning {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid var(--color-warning);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    color: var(--color-warning);
    flex-shrink: 0;
}

.leaderboard-loading {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.player-dashboard-card {
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid var(--border-glow);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    flex-shrink: 0;
}

.player-dashboard-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.35rem 0.75rem;
    margin-bottom: 0.65rem;
}

.player-dashboard-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.player-dashboard-name {
    font-family: var(--font-heading);
    font-weight: 700;
    color: var(--accent-primary);
    font-size: 1rem;
}

.player-dashboard-name--guest {
    color: var(--text-muted);
}

.player-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.65rem;
}

.player-stats-grid--compact {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}


.player-stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    text-align: center;
    padding: 0.45rem 0.35rem;
    background: rgba(30, 41, 59, 0.55);
    border-radius: 8px;
    border: 1px solid var(--border-light);
}

.player-stat-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.player-stat-value {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
}

.player-stat-value--score {
    color: var(--color-warning);
    font-size: 1.15rem;
}

.player-dashboard-hint {
    margin: 0.65rem 0 0;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.leaderboard-empty {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
}

.leaderboard-empty-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.leaderboard-table-wrap {
    overflow-x: auto;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.leaderboard-table thead tr {
    border-bottom: 2px solid var(--color-warning);
}

.leaderboard-table th {
    padding: 0.6rem 0.5rem;
    color: var(--color-warning);
    font-family: var(--font-heading);
    letter-spacing: 0.06em;
    text-align: left;
    white-space: nowrap;
}

.leaderboard-table th:first-child,
.leaderboard-table td:first-child {
    text-align: center;
}

.leaderboard-table th:nth-child(4),
.leaderboard-table th:nth-child(5),
.leaderboard-table th:nth-child(6),
.leaderboard-table th:nth-child(7),
.leaderboard-table td:nth-child(4),
.leaderboard-table td:nth-child(5),
.leaderboard-table td:nth-child(6),
.leaderboard-table td:nth-child(7) {
    text-align: center;
}

.leaderboard-row {
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    transition: background 0.2s;
}

.leaderboard-row.rank-gold {
    background: rgba(250, 204, 21, 0.08);
}

.leaderboard-row.rank-silver {
    background: rgba(148, 163, 184, 0.06);
}

.leaderboard-row.rank-bronze {
    background: rgba(180, 83, 9, 0.07);
}

.leaderboard-row--you {
    outline: 1px solid rgba(56, 189, 248, 0.45);
}

.leaderboard-rank {
    padding: 0.75rem 0.35rem;
    font-size: 1.05rem;
    font-weight: 700;
}

.leaderboard-player-name {
    font-weight: 700;
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.leaderboard-you-badge {
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    padding: 0.12rem 0.4rem;
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.18);
    color: var(--accent-primary);
    border: 1px solid var(--border-glow);
}

.leaderboard-hero {
    padding: 0.75rem 0.5rem;
    color: var(--accent-primary);
    font-size: 0.82rem;
}

.leaderboard-score {
    padding: 0.75rem 0.5rem;
    font-weight: 700;
    color: var(--color-warning);
    font-family: var(--font-heading);
}

.leaderboard-time,
.leaderboard-ach {
    padding: 0.75rem 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.result-badge {
    border-radius: 12px;
    padding: 0.2rem 0.55rem;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.result-badge--victory {
    background: rgba(34, 197, 94, 0.15);
    color: var(--color-success);
    border: 1px solid var(--color-success);
}

.result-badge--defeat {
    background: rgba(239, 68, 68, 0.12);
    color: var(--color-danger);
    border: 1px solid var(--color-danger);
}

.leaderboard-footer-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 0;
    text-align: center;
    flex-shrink: 0;
}

/* Mobile leaderboard cards */
.leaderboard-cards {
    display: none;
    flex-direction: column;
    gap: 0.65rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.leaderboard-card {
    background: rgba(30, 41, 59, 0.55);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 0.75rem;
}

.leaderboard-card.rank-gold {
    border-color: rgba(250, 204, 21, 0.35);
}

.leaderboard-card.rank-silver {
    border-color: rgba(148, 163, 184, 0.35);
}

.leaderboard-card.rank-bronze {
    border-color: rgba(180, 83, 9, 0.35);
}

.leaderboard-card--you {
    border-color: var(--border-glow);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.15);
}

.leaderboard-card-top {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.leaderboard-card-player {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}

.leaderboard-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem 0.75rem;
    margin-top: 0.45rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    align-items: center;
}

.show-mobile-table {
    display: none;
}

@media (max-width: 768px) {
    .hide-mobile-table {
        display: none !important;
    }

    .show-mobile-table {
        display: flex;
    }

    .player-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .leaderboard-modal {
        width: 100%;
        max-height: 92vh;
        padding: 1rem !important;
    }

    .leaderboard-header {
        flex-direction: column;
        align-items: stretch;
    }

    .leaderboard-header-actions {
        justify-content: space-between;
    }
}

/* Quick menu responsive */
@media (max-width: 900px) {
    .quick-menu-bar {
        flex-wrap: wrap;
        justify-content: center;
        max-width: 100%;
    }

    .btn-quick-icon {
        min-height: 44px;
        min-width: 44px;
        padding: 0.45rem 0.65rem;
        font-size: 0.78rem;
    }
}

@media (max-width: 640px) {
    .game-header {
        flex-direction: row;
        align-items: center;
    }

    .game-header > div {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .signature-link {
        font-size: 0.82rem;
        padding: 0.45rem 0.75rem;
        min-height: 40px;
    }

    .input-fantasy,
    .glass-input {
        min-height: 44px;
        font-size: 1rem;
    }
}

/* Prevent horizontal scroll globally on small screens */
@media (max-width: 768px) {
    html,
    body {
        overflow-x: hidden;
    }

    .game-layout,
    .landing-layout {
        overflow-x: hidden;
    }
}