/**
 * QUANTUM BRAIN STRATEGY v1.8.0 - Enhanced 3D Styles
 * Ultra-compact UI with enhanced 3D rotation controls
 */

/* === CSS CUSTOM PROPERTIES (NO MAGIC NUMBERS) === */
:root {
    /* Layout Dimensions */
    --ui-height-main: 50px;
    --ui-height-mobile: 45px;
    --ui-height-expanded: 200px;
    --ui-padding-main: 15px;
    --ui-padding-mobile: 10px;
    --ui-gap-main: 15px;
    --ui-gap-mobile: 8px;
    --ui-gap-small: 12px;
    --ui-gap-tiny: 5px;
    --ui-gap-micro: 3px;
    
    /* 3D Perspective Values */
    --perspective-body: 1200px;
    --perspective-container: 1500px;
    --perspective-mobile: 800px;
    --perspective-container-mobile: 1000px;
    
    /* 3D Transform Values */
    --cube-depth: 15px;
    --cube-hover-translate: 5px;
    --cube-hover-scale: 1.02;
    --unit-hover-translate: 10px;
    --unit-hover-scale: 1.1;
    --float-translate: 8px;
    
    /* Border Radius */
    --radius-small: 3px;
    --radius-medium: 4px;
    --radius-large: 6px;
    --radius-xlarge: 8px;
    --radius-round: 10px;
    
    /* Font Sizes */
    --font-size-tiny: 9px;
    --font-size-small: 10px;
    --font-size-medium: 11px;
    --font-size-large: 12px;
    
    /* Opacity Values */
    --opacity-low: 0.1;
    --opacity-medium: 0.2;
    --opacity-high: 0.3;
    --opacity-background: 0.98;
    --opacity-expanded: 0.95;
    --opacity-text: 0.9;
    --opacity-text-secondary: 0.8;
    
    /* Animation Durations */
    --duration-fast: 0.1s;
    --duration-normal: 0.2s;
    --duration-slow: 0.3s;
    --duration-effect: 0.4s;
    --duration-win: 0.6s;
    
    /* Z-Index Layers */
    --z-controls: 100;
    --z-ui: 100;
    
    /* Shadow Values */
    --shadow-light: 0 5px 15px rgba(0,0,0,0.2);
    --shadow-medium: 0 5px 15px rgba(0,0,0,0.3);
    --shadow-heavy: 0 8px 20px rgba(0,0,0,0.3);
    --shadow-ui: 0 -3px 15px rgba(0, 0, 0, 0.4);
    
    /* Color Palette */
    --color-ui-bg: rgba(20, 20, 35, var(--opacity-background));
    --color-ui-expanded: rgba(15, 15, 25, var(--opacity-expanded));
    --color-control-bg: rgba(255, 255, 255, var(--opacity-low));
    --color-control-border: rgba(255, 255, 255, var(--opacity-medium));
    --color-control-hover: rgba(255, 255, 255, var(--opacity-medium));
    --color-control-hover-bg: rgba(255, 255, 255, var(--opacity-high));
    --color-text-primary: rgba(255, 255, 255, var(--opacity-text));
    --color-text-secondary: rgba(255, 255, 255, var(--opacity-text-secondary));
    --color-border-light: rgba(255, 255, 255, 0.15);
    --color-border-medium: rgba(255, 255, 255, var(--opacity-low));
    --color-turn-indicator: rgba(76, 175, 80, 0.8);
    
    /* Special Effect Colors */
    --color-advantage-glow: rgba(255, 215, 0, 0.6);
    --color-disadvantage-glow: rgba(255, 0, 0, 0.6);
    --color-educational-glow: rgba(0, 123, 255, 0.6);
    
    /* Gradient Definitions with Semi-Transparent Shading */
    --gradient-cube-top: linear-gradient(135deg, #f0f8ff 0%, #e6f3ff 50%, rgba(217, 237, 255, 0.9) 100%);
    --gradient-cube-front: linear-gradient(180deg, rgba(217, 237, 255, 0.85) 0%, rgba(179, 217, 255, 0.8) 50%, rgba(140, 200, 255, 0.75) 100%);
    --gradient-cube-right: linear-gradient(90deg, rgba(140, 200, 255, 0.7) 0%, rgba(102, 179, 255, 0.65) 50%, rgba(77, 166, 255, 0.6) 100%);
    --gradient-cube-back: linear-gradient(180deg, rgba(77, 166, 255, 0.55) 0%, rgba(51, 153, 255, 0.5) 50%, rgba(26, 140, 255, 0.45) 100%);
    --gradient-cube-left: linear-gradient(270deg, rgba(26, 140, 255, 0.4) 0%, rgba(0, 128, 255, 0.35) 50%, rgba(0, 115, 230, 0.3) 100%);
    --gradient-cube-bottom: linear-gradient(135deg, rgba(0, 115, 230, 0.25) 0%, rgba(0, 102, 204, 0.2) 50%, rgba(0, 89, 179, 0.15) 100%);
    
    /* Layout Calculations - Account for bottom UI bar */
    --game-height-desktop: calc(100vh - 130px);
    --game-height-mobile: calc(100vh - 125px);
    --game-height-mobile-override: calc(100vh - 300px);
}

/* === 3D PERSPECTIVE === */
body {
    perspective: var(--perspective-body);
    /* Enhanced smoothness optimizations */
    transform-style: preserve-3d;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* === 3D GAME LAYOUT === */
.game-container {
    perspective: var(--perspective-container);
    height: var(--game-height-desktop);
    position: relative;
    /* Hardware acceleration hints */
    will-change: transform;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

#gameCanvas {
    transform-style: preserve-3d;
    transition: transform var(--duration-fast) cubic-bezier(0.4, 0.0, 0.2, 1);
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    /* Enhanced smoothness optimizations */
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    image-rendering: optimizeQuality;
    image-rendering: -webkit-optimize-contrast;
    /* Anti-aliasing for smoother edges */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Mouse movement disabled - no hover effects on canvas */
#gameCanvas:hover {
    /* No transform effects - board rotation controlled only by buttons */
}

/* === Q*BERT STYLE ISOMETRIC CUBES === */
.hex-3d {
    position: absolute;
    transform-style: preserve-3d;
    transition: all var(--duration-slow) ease;
}

.hex-cube {
    position: absolute;
    transform-style: preserve-3d;
    width: 100%;
    height: 100%;
}

.cube-face {
    position: absolute;
    border: 2px solid #333;
    transform-origin: center;
    border-width: 1px;
    border-color: rgba(0,0,0,0.4);
}

/* Q*bert style isometric cube faces */
.cube-top {
    background: var(--gradient-cube-top);
    transform: rotateX(90deg) translateZ(var(--cube-depth));
    box-shadow: inset 0 0 var(--radius-large) rgba(0,0,0,0.1);
}

.cube-front {
    background: var(--gradient-cube-front);
    transform: translateZ(var(--cube-depth));
    box-shadow: inset -5px 0 var(--radius-large) rgba(0,0,0,0.2);
}

.cube-right {
    background: var(--gradient-cube-right);
    transform: rotateY(90deg) translateZ(var(--cube-depth));
    box-shadow: inset -5px 0 var(--radius-large) rgba(0,0,0,var(--opacity-high));
}

.cube-back {
    background: var(--gradient-cube-back);
    transform: rotateY(180deg) translateZ(var(--cube-depth));
}

.cube-left {
    background: var(--gradient-cube-left);
    transform: rotateY(-90deg) translateZ(var(--cube-depth));
}

.cube-bottom {
    background: var(--gradient-cube-bottom);
    transform: rotateX(-90deg) translateZ(calc(-1 * var(--cube-depth)));
}

/* Q*bert style isometric perspective */
.qbert-isometric {
    transform: rotateX(30deg) rotateY(-45deg);
}

/* Enhanced cube depth and shadows */
.hex-cube:hover {
    transform: translateZ(var(--cube-hover-translate)) scale(var(--cube-hover-scale));
}

/* === 3D UNIT STYLES === */
.unit-3d {
    position: absolute;
    transform-style: preserve-3d;
    transition: all var(--duration-effect) ease;
    cursor: pointer;
}

.unit-3d:hover {
    transform: translateZ(var(--unit-hover-translate)) scale(var(--unit-hover-scale));
}

.unit-sphere {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.8), transparent 50%);
    box-shadow: 
        0 5px var(--cube-depth) rgba(0,0,0,var(--opacity-high)),
        inset 0 -5px var(--radius-large) rgba(0,0,0,0.2),
        inset 0 5px var(--radius-large) rgba(255,255,255,var(--opacity-high));
    position: relative;
}

.unit-sphere::before {
    content: '';
    position: absolute;
    top: 10%;
    left: 20%;
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: rgba(255,255,255,0.6);
    filter: blur(2px);
}

/* === SPECIAL 3D HEXAGON EFFECTS === */
.special-hex-3d {
    animation: float3d 3s ease-in-out infinite;
}

@keyframes float3d {
    0%, 100% { 
        transform: translateZ(0px) rotateY(0deg); 
    }
    50% { 
        transform: translateZ(var(--float-translate)) rotateY(180deg); 
    }
}

.advantage-hex-3d {
    box-shadow: 
        0 0 20px var(--color-advantage-glow),
        0 5px var(--cube-depth) rgba(0,0,0,var(--opacity-high));
}

.disadvantage-hex-3d {
    box-shadow: 
        0 0 20px var(--color-disadvantage-glow),
        0 5px var(--cube-depth) rgba(0,0,0,var(--opacity-high));
}

.educational-hex-3d {
    box-shadow: 
        0 0 20px var(--color-educational-glow),
        0 5px var(--cube-depth) rgba(0,0,0,var(--opacity-high));
}

/* === SIMPLE 3D TOGGLE === */
.simple-3d-toggle {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: var(--z-controls);
}

.toggle-3d-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 12px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    min-width: 120px;
    text-align: center;
}

.toggle-3d-btn:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

.toggle-3d-btn:active {
    transform: translateY(0px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* === ENHANCED 3D EFFECTS === */
.status-item {
    transform: translateZ(2px);
    transition: transform var(--duration-slow) ease;
}

.status-item:hover {
    transform: translateZ(var(--ui-gap-tiny));
    box-shadow: var(--shadow-light);
}

button:hover {
    transform: translateZ(var(--ui-gap-micro));
    box-shadow: var(--shadow-medium);
}

.player-turn:hover, .ai-turn:hover {
    transform: translateZ(var(--ui-gap-tiny)) translateY(-1px);
    box-shadow: var(--shadow-heavy);
}

/* === 3D WIN ANIMATION === */
@keyframes winPop {
    0% { 
        transform: scale(0.5) rotateY(-180deg);
        opacity: 0;
    }
    50% {
        transform: scale(var(--unit-hover-scale)) rotateY(-90deg);
    }
    100% { 
        transform: scale(1) rotateY(0deg);
        opacity: 1;
    }
}

.win-message {
    animation: winPop var(--duration-win) ease-out;
}

/* === COMPACT BOTTOM UI === */
.compact-ui {
    position: fixed;
    bottom: 10px; /* Raised above Windows taskbar */
    left: 0;
    right: 0;
    background: var(--color-ui-bg);
    backdrop-filter: blur(var(--cube-depth));
    border-top: 1px solid var(--color-border-light);
    border-radius: var(--radius-large) var(--radius-large) 0 0; /* Rounded top corners */
    z-index: var(--z-ui);
    transition: all var(--duration-slow) ease;
    box-shadow: var(--shadow-ui);
}

.ui-main-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--radius-xlarge) var(--ui-padding-main);
    height: var(--ui-height-main);
    gap: var(--ui-gap-main);
}

.ui-left, .ui-center, .ui-right {
    display: flex;
    align-items: center;
    gap: var(--ui-gap-small);
}

.ui-center {
    flex: 1;
    justify-content: center;
}

.compact-control {
    background: var(--color-control-bg);
    border: 1px solid var(--color-control-border);
    color: white;
    padding: var(--radius-medium) var(--radius-xlarge);
    border-radius: var(--radius-medium);
    font-size: var(--font-size-medium);
    cursor: pointer;
    transition: all var(--duration-normal);
    white-space: nowrap;
}

.compact-control:hover {
    background: var(--color-control-hover);
    transform: translateY(-1px);
}

.compact-select {
    background: var(--color-control-bg);
    border: 1px solid var(--color-control-border);
    color: white;
    padding: var(--ui-gap-micro) var(--radius-large);
    border-radius: var(--radius-small);
    font-size: var(--font-size-small);
    cursor: pointer;
}

.status-compact {
    font-size: var(--font-size-medium);
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: var(--ui-gap-tiny);
}

.turn-indicator {
    background: var(--color-turn-indicator);
    padding: 2px var(--radius-large);
    border-radius: var(--radius-round);
    font-size: var(--font-size-small);
    font-weight: bold;
}

.expand-toggle {
    background: var(--color-control-bg);
    border: 1px solid var(--color-control-border);
    color: white;
    padding: var(--radius-medium) var(--radius-xlarge);
    border-radius: var(--radius-medium);
    font-size: var(--font-size-small);
    cursor: pointer;
    transition: all var(--duration-normal);
}

.expand-toggle:hover {
    background: var(--color-control-hover);
}

/* Expanded Panel */
.ui-expanded {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--duration-slow) ease;
    background: var(--color-ui-expanded);
    border-top: 1px solid var(--color-border-medium);
}

.ui-expanded.open {
    max-height: var(--ui-height-expanded);
    overflow-y: auto;
}

.expanded-content {
    padding: var(--ui-padding-main);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.expanded-section {
    background: rgba(255, 255, 255, 0.05);
    padding: var(--radius-large);
    border-radius: var(--radius-large);
    border: 1px solid var(--color-border-medium);
}

.expanded-section h4 {
    margin: 0 0 var(--radius-xlarge) 0;
    font-size: var(--font-size-large);
    color: var(--color-text-primary);
    border-bottom: 1px solid var(--color-border-medium);
    padding-bottom: var(--radius-medium);
}

.expanded-section .content {
    font-size: var(--font-size-small);
    line-height: 1.4;
    color: var(--color-text-secondary);
}

/* Hide the original ui-panel */
.ui-panel {
    display: none;
}

/* === MOBILE RESPONSIVE === */
@media (max-width: 768px) {
    :root {
        /* Mobile-specific adjustments */
        --ui-height-mobile: 40px;
        --ui-padding-mobile: 8px;
        --ui-gap-mobile: 6px;
        --font-size-tiny: 8px;
        --font-size-small: 9px;
        --game-height-mobile: calc(100vh - 110px);
        --game-height-mobile-override: calc(100vh - 250px);
    }
    
    body {
        padding: 5px;
        perspective: var(--perspective-mobile);
        /* Prevent zoom on double tap */
        touch-action: manipulation;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    h1 {
        font-size: clamp(1rem, 4vw, 1.5rem);
        margin: 5px 0;
        line-height: 1.2;
    }
    
    .game-container {
        height: var(--game-height-mobile);
        perspective: var(--perspective-container-mobile);
        padding: 0;
        margin: 0;
    }
    
    #gameCanvas {
        /* Optimize for mobile touch */
        touch-action: manipulation;
        -webkit-touch-callout: none;
        max-width: 100vw;
        max-height: 100%;
        /* Prevent text selection on canvas */
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    .ui-main-bar {
        padding: var(--radius-large) var(--ui-padding-mobile);
        height: var(--ui-height-mobile);
        gap: var(--ui-gap-mobile);
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .ui-left, .ui-center, .ui-right {
        gap: var(--ui-gap-mobile);
        flex-shrink: 0;
    }
    
    .ui-center {
        min-width: 0; /* Allow text truncation */
    }
    
    .compact-control, .compact-select {
        font-size: var(--font-size-tiny);
        padding: var(--ui-gap-micro) var(--ui-gap-tiny);
        white-space: nowrap;
        min-width: 0;
        /* Improve touch targets */
        min-height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .status-compact {
        font-size: var(--font-size-tiny);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .turn-indicator {
        font-size: var(--font-size-tiny);
        padding: 1px var(--ui-gap-tiny);
    }
    
    .expanded-content {
        grid-template-columns: 1fr;
        gap: var(--radius-large);
        padding: var(--radius-large);
        max-height: 150px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .expanded-section {
        padding: var(--ui-gap-tiny);
    }
    
    .expanded-section h4 {
        font-size: var(--font-size-small);
        margin-bottom: var(--ui-gap-tiny);
    }
    
    .expanded-section .content {
        font-size: var(--font-size-tiny);
        line-height: 1.3;
    }
}

/* === MOBILE 3D CONTROLS === */
@media (max-width: 768px) {
    .board-controls {
        top: var(--ui-gap-tiny);
        right: var(--ui-gap-tiny);
        padding: var(--ui-gap-tiny);
        background: rgba(20, 20, 35, 0.95);
        border-radius: var(--radius-medium);
        /* Make controls more touch-friendly */
        min-width: 120px;
    }
    
    .controls-title {
        font-size: var(--font-size-small);
        margin-bottom: var(--ui-gap-micro);
    }
    
    .control-button {
        padding: var(--ui-gap-tiny) var(--ui-gap-small);
        margin: 1px;
        font-size: var(--font-size-small);
        /* Improve touch targets */
        min-width: 32px;
        min-height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        /* Prevent text selection */
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        /* Improve touch response */
        touch-action: manipulation;
    }
    
    .controls-grid {
        gap: 1px;
    }
    
    .controls-toggle-section {
        margin-bottom: var(--ui-gap-tiny);
    }
}

/* === SMALL MOBILE DEVICES === */
@media (max-width: 480px) {
    :root {
        --ui-height-mobile: 35px;
        --ui-padding-mobile: 6px;
        --ui-gap-mobile: 4px;
        --font-size-tiny: 7px;
        --font-size-small: 8px;
        --game-height-mobile: calc(100vh - 100px);
        --game-height-mobile-override: calc(100vh - 200px);
    }
    
    body {
        padding: 2px;
    }
    
    h1 {
        font-size: clamp(0.9rem, 5vw, 1.2rem);
        margin: 3px 0;
    }
    
    .ui-main-bar {
        padding: var(--ui-gap-tiny) var(--ui-gap-tiny);
        height: var(--ui-height-mobile);
        gap: var(--ui-gap-tiny);
    }
    
    .ui-left, .ui-center, .ui-right {
        gap: var(--ui-gap-tiny);
    }
    
    .compact-control, .compact-select {
        font-size: var(--font-size-tiny);
        padding: 1px var(--ui-gap-micro);
        min-height: 28px;
    }
    
    .status-compact {
        font-size: var(--font-size-tiny);
    }
    
    .board-controls {
        top: 2px;
        right: 2px;
        padding: var(--ui-gap-micro);
        min-width: 100px;
    }
    
    .control-button {
        min-width: 28px;
        min-height: 28px;
        font-size: var(--font-size-tiny);
        padding: 2px;
    }
    
    .controls-title {
        font-size: var(--font-size-tiny);
    }
}

/* === LANDSCAPE MOBILE === */
@media (max-width: 768px) and (orientation: landscape) {
    :root {
        --game-height-mobile: calc(100vh - 90px);
        --game-height-mobile-override: calc(100vh - 180px);
    }
    
    .board-controls {
        top: var(--ui-gap-micro);
        right: var(--ui-gap-micro);
        transform: scale(0.9);
        transform-origin: top right;
    }
    
    .ui-main-bar {
        height: calc(var(--ui-height-mobile) * 0.9);
    }
    
    .compact-control, .compact-select {
        min-height: 28px;
    }
}

/* === TOUCH OPTIMIZATIONS === */
@media (hover: none) and (pointer: coarse) {
    /* Touch device specific optimizations */
    .control-button:hover {
        /* Remove hover effects on touch devices */
        background: var(--color-control-hover);
        transform: none;
    }
    
    .compact-control:hover {
        background: var(--color-control-hover);
        transform: none;
    }
    
    /* Add active states for better touch feedback */
    .control-button:active {
        background: var(--color-control-hover-bg);
        transform: scale(0.95);
    }
    
    .compact-control:active {
        background: var(--color-control-hover-bg);
        transform: scale(0.95);
    }
    
    /* Improve button spacing for fat fingers */
    .control-button {
        margin: 2px;
    }
}

/* === HIGH DPI DISPLAYS === */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    #gameCanvas {
        /* Optimize for retina displays */
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* === RESPONSIVE 3D === */
@media (max-width: 768px) {
    #gameCanvas:hover {
        /* No transform effects on mobile - button-only control */
    }
    
    /* Optimize 3D performance on mobile */
    .hex-3d, .unit-3d {
        will-change: auto; /* Reduce GPU usage on mobile */
    }
    
    /* Simplify animations on mobile for better performance */
    .special-hex-3d {
        animation-duration: 4s; /* Slower animation for better performance */
    }
}
