/* Core Typography & Variables */
:root {
    --bg-dark: #070714;
    --card-bg: rgba(20, 20, 45, 0.85);
    --glass-border: rgba(255, 255, 255, 0.08);
    
    /* Harmonious gradients */
    --blue-gradient: linear-gradient(135deg, #3b82f6, #1d4ed8);
    --red-gradient: linear-gradient(135deg, #ef4444, #b91c1c);
    --gold-gradient: linear-gradient(135deg, #fbbf24, #d97706);
    --purple-gradient: linear-gradient(135deg, #8b5cf6, #5b21b6);
    
    --text-primary: #ffffff;
    --text-muted: #94a3b8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', 'Segoe UI', system-ui, sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Wrapper Layout */
#game-wrapper {
    height: calc(100dvh - 60px); /* Fit within viewport minus bottom ad */
    max-height: 780px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    position: relative;
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 10px 15px;
    overflow: hidden; /* Prevent scrolling inside the game wrapper */
}

/* Overlays / Screen Transitions */
.hidden {
    display: none !important;
}

.mode-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
}

.mode-box {
    background: var(--card-bg);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    width: 100%;
    max-width: 420px;
    padding: 40px 30px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    animation: zoomIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.game-icon-banner {
    font-size: 4rem;
    margin-bottom: 15px;
    filter: drop-shadow(0 4px 10px rgba(251, 191, 36, 0.5));
    animation: float 3s ease-in-out infinite;
}

.mode-box h1 {
    font-size: 2.2rem;
    font-weight: 900;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    background: linear-gradient(to right, #fbbf24, #f59e0b, #ef4444);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.mode-sub {
    color: var(--text-muted);
    font-size: 1.05rem;
    margin-bottom: 35px;
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 20px;
    width: 100%;
    padding: 16px 20px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(255, 255, 255, 0.04);
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.25s ease;
}

.mode-btn-primary {
    background: var(--blue-gradient);
    border: none;
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
}

.mode-icon {
    font-size: 1.8rem;
}

.mode-btn span {
    display: flex;
    flex-direction: column;
}

.mode-btn strong {
    font-weight: 700;
}

.mode-btn small {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 2px;
}

.mode-btn:not(.mode-btn-primary):hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.15);
}

.mode-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(59, 130, 246, 0.4);
    filter: brightness(1.1);
}

/* Gameplay Main Layout */
.game-screen {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px; /* Tighter layout */
    animation: fadeIn 0.5s ease;
}

/* HUD Panel */
.game-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 8px 15px; /* Compact padding */
    backdrop-filter: blur(10px);
}

.hud-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.hud-logo {
    font-weight: 800;
    font-size: 1.05rem;
    color: white;
}

.mode-badge {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.hud-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.turn-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: #3b82f6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-shadow: 0 0 10px rgba(59, 130, 246, 0.2);
}

.hud-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.hud-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* Players Display */
.players-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px; /* Tighter layout */
    width: 100%;
}

.player-panel {
    display: flex;
    align-items: center;
    gap: 8px; /* Compact gap */
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 6px 12px; /* Tighter padding */
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.player-panel.active {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.15);
}

.player-panel.active#player1Panel {
    box-shadow: 0 0 12px rgba(59, 130, 246, 0.25), inset 0 0 1px rgba(59, 130, 246, 0.5);
    border-color: rgba(59, 130, 246, 0.4);
}

.player-panel.active#player2Panel {
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.25), inset 0 0 1px rgba(239, 68, 68, 0.5);
    border-color: rgba(239, 68, 68, 0.4);
}

.player-avatar {
    width: 28px; /* Smaller avatars */
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.player-info {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
}

.player-pos {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 1px;
}

.player-pos strong {
    color: white;
    font-size: 0.8rem;
}

/* Board Responsive Wrapping */
.board-container {
    width: 100%;
    max-width: calc(100dvh - 270px); /* Limit width based on vertical screen space to avoid scrolling */
    background: #0d0d26;
    border-radius: 16px;
    padding: 6px; /* Reduced padding */
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), 0 0 1px rgba(255, 255, 255, 0.2);
    border: 1px solid var(--glass-border);
    margin: 0 auto;
}

.board-ratio-box {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: relative;
    border-radius: 14px;
    overflow: hidden;
}

#boardCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    display: block;
}

#tokensContainer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

/* Player Token Pins */
.token-pin {
    width: 20px;
    height: 20px;
    position: absolute;
    pointer-events: none;
    z-index: 10;
    transition: left 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), top 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    filter: drop-shadow(0 6px 4px rgba(0, 0, 0, 0.4));
}

.token-pin::before {
    content: '';
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    border: 2px solid white;
}

.token-p1::before {
    background: radial-gradient(circle at 35% 35%, #60a5fa 0%, #2563eb 100%);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
}

.token-p2::before {
    background: radial-gradient(circle at 35% 35%, #f87171 0%, #dc2626 100%);
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
}

.token-pin.bouncing {
    animation: pinBounce 0.5s infinite alternate ease-in-out;
}

@keyframes pinBounce {
    from { transform: translateY(0); }
    to { transform: translateY(-8px); }
}

/* Controls (Dice & Messaging) */
.control-bar {
    display: flex;
    align-items: center;
    gap: 15px; /* Tighter layout */
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    padding: 8px 15px; /* Compact padding */
    min-height: 76px; /* Reduced from 96px */
}

.dice-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dice-wrapper {
    width: 44px; /* Reduced from 50px */
    height: 44px; /* Reduced from 50px */
    perspective: 300px;
    cursor: pointer;
}

/* 3D Dice Cube */
.dice-cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.3, 1.1);
}

.face {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #ffffff, #e2e8f0);
    border: 2px solid #cbd5e1;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem; /* Slightly smaller text */
    font-weight: 900;
    color: #1e293b;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.08), 0 4px 8px rgba(0,0,0,0.15);
}

/* Position faces in 3D space - adjusted for 44px width (translateZ: 22px) */
.front  { transform: rotateY(0deg) translateZ(22px); }
.back   { transform: rotateY(180deg) translateZ(22px); }
.right  { transform: rotateY(90deg) translateZ(22px); }
.left   { transform: rotateY(-90deg) translateZ(22px); }
.top    { transform: rotateX(90deg) translateZ(22px); }
.bottom { transform: rotateX(-90deg) translateZ(22px); }

/* Show Specific Faces Classes */
.show-1 { transform: rotateX(0deg) rotateY(0deg); }
.show-6 { transform: rotateX(0deg) rotateY(180deg); }
.show-3 { transform: rotateX(0deg) rotateY(-90deg); }
.show-4 { transform: rotateX(0deg) rotateY(90deg); }
.show-5 { transform: rotateX(-90deg) rotateY(0deg); }
.show-2 { transform: rotateX(90deg) rotateY(0deg); }

/* Rolling keyframe animation */
@keyframes diceRolling {
    0% { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
    100% { transform: rotateX(720deg) rotateY(360deg) rotateZ(180deg); }
}

.dice-cube.rolling {
    animation: diceRolling 0.6s infinite linear;
}

.roll-btn {
    background: var(--gold-gradient);
    border: none;
    color: #1e293b;
    font-size: 1rem;
    font-weight: 800;
    padding: 12px 20px;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
    transition: all 0.2s;
    letter-spacing: 0.5px;
}

.roll-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(245, 158, 11, 0.4);
}

.roll-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.roll-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
}

.game-message {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    line-height: 1.4;
    padding-left: 10px;
    border-left: 2px solid rgba(255, 255, 255, 0.08);
}

.game-message.important {
    color: #fbbf24;
    animation: textPulse 1s infinite alternate;
}

@keyframes textPulse {
    from { opacity: 0.85; }
    to { opacity: 1; text-shadow: 0 0 8px rgba(251, 191, 36, 0.2); }
}

/* GAME OVER OVERLAY */
.game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(5, 5, 15, 0.96);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border-radius: 20px;
}

.game-over-box {
    background: rgba(25, 25, 50, 0.8);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    width: 100%;
    max-width: 440px;
    padding: 35px 25px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
    animation: zoomIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.game-over-icon {
    font-size: 4.5rem;
    margin-bottom: 15px;
    filter: drop-shadow(0 0 15px rgba(251, 191, 36, 0.4));
    animation: float 2.5s ease-in-out infinite;
}

.game-over-box h2 {
    font-size: 2.2rem;
    font-weight: 900;
    margin-bottom: 10px;
    background: linear-gradient(to right, #fbbf24, #fb7185);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.game-over-box p {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 25px;
}

.more-games-scroller-container {
    width: 100%;
    margin-bottom: 20px;
}

.play-again-btn {
    width: 100%;
    background: var(--blue-gradient);
    border: none;
    color: white;
    font-size: 1.1rem;
    font-weight: 800;
    padding: 15px 20px;
    border-radius: 14px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
    transition: all 0.25s;
}

.play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 24px rgba(59, 130, 246, 0.4);
    filter: brightness(1.1);
}

/* Info Cards for Landing page look */
.game-info {
    width: 100%;
    max-width: 900px;
    margin: 40px auto 0;
    padding: 0 15px;
}

.info-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.info-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 18px;
    padding: 25px;
}

.info-card h2 {
    font-size: 1.3rem;
    margin-bottom: 15px;
    color: #fbbf24;
}

.info-content {
    color: #94a3b8;
    font-size: 0.95rem;
    line-height: 1.6;
}

.info-content ul {
    margin-top: 10px;
    padding-left: 20px;
}

.info-content li {
    margin-bottom: 8px;
}

/* Helper Animations */
@keyframes zoomIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

/* Responsive Scaling */
@media (max-width: 767px) {
    .info-container {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

@media (max-width: 480px) {
    #game-wrapper {
        padding: 10px;
    }
    .mode-box, .game-over-box {
        padding: 30px 20px;
    }
    .control-bar {
        padding: 12px 15px;
    }
    .roll-btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
    .game-message {
        font-size: 0.85rem;
        padding-left: 8px;
    }
}

/* Landscape & Short Height Viewport Optimizations */
@media (max-height: 680px) {
    #game-wrapper {
        padding: 5px 12px;
        max-height: 100dvh;
    }
    .game-screen {
        gap: 6px;
    }
    .game-hud {
        padding: 6px 12px;
        border-radius: 10px;
    }
    .hud-logo {
        font-size: 0.95rem;
    }
    .player-panel {
        padding: 4px 10px;
        border-radius: 10px;
    }
    .player-avatar {
        width: 24px;
        height: 24px;
        font-size: 0.85rem;
        border-radius: 6px;
    }
    .player-name {
        font-size: 0.75rem;
    }
    .player-pos {
        font-size: 0.65rem;
    }
    .player-pos strong {
        font-size: 0.75rem;
    }
    .board-container {
        border-radius: 12px;
        padding: 4px;
    }
    .control-bar {
        padding: 6px 12px;
        min-height: 64px;
        border-radius: 12px;
    }
    .dice-wrapper {
        width: 38px;
        height: 38px;
    }
    .face {
        font-size: 1.3rem;
        border-radius: 5px;
    }
    .front  { transform: rotateY(0deg) translateZ(19px); }
    .back   { transform: rotateY(180deg) translateZ(19px); }
    .right  { transform: rotateY(90deg) translateZ(19px); }
    .left   { transform: rotateY(-90deg) translateZ(19px); }
    .top    { transform: rotateX(90deg) translateZ(19px); }
    .bottom { transform: rotateX(-90deg) translateZ(19px); }
    .roll-btn {
        padding: 8px 14px;
        font-size: 0.85rem;
        border-radius: 8px;
    }
    .game-message {
        font-size: 0.8rem;
        padding-left: 6px;
    }
}

/* Custom Bottom Ad Style to overlay properly */
.pmg-bottom-ad {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: black;
    z-index: 900;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}
