/**
 * SchoolGames Mobile Controls v1.0
 * Fixed bottom panel with game-specific controls
 */

/* ============================================
   CSS Variables
   ============================================ */
:root {
    --panel-height: 70px;
    --panel-height-arcade: 120px;
    --panel-bg: rgba(255, 255, 255, 0.98);
    --panel-border: #e0e0e0;
    --btn-size: 50px;
    --btn-size-small: 44px;
    --primary: #667eea;
    --primary-dark: #5a6fd6;
    --secondary: #764ba2;
    --success: #51cf66;
    --error: #ff6b6b;
    --warning: #fcc419;
    --text-dark: #333;
    --text-muted: #666;
}

/* ============================================
   Bottom Panel Base - Always Visible
   ============================================ */
.mobile-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--panel-bg);
    border-top: 2px solid var(--panel-border);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 9999;
    padding: 10px 15px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    transition: height 0.3s ease;
}

/* Panel height based on game type */
.mobile-panel[data-type="simple"] {
    height: var(--panel-height);
}

.mobile-panel[data-type="arcade"] {
    height: var(--panel-height-arcade);
}

.mobile-panel[data-type="quiz"] {
    height: var(--panel-height);
}

/* ============================================
   Panel Sections
   ============================================ */
.panel-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-section.left {
    flex: 0 0 auto;
}

.panel-section.center {
    flex: 1;
    justify-content: center;
}

.panel-section.right {
    flex: 0 0 auto;
}

/* ============================================
   Control Buttons
   ============================================ */
.panel-btn {
    width: var(--btn-size);
    height: var(--btn-size);
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.panel-btn:active {
    transform: scale(0.92);
}

.panel-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Button variants */
.panel-btn.secondary {
    background: #6c757d;
}

.panel-btn.success {
    background: var(--success);
}

.panel-btn.danger {
    background: var(--error);
}

.panel-btn.warning {
    background: var(--warning);
    color: var(--text-dark);
}

.panel-btn.ghost {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
}

/* Small button variant */
.panel-btn.small {
    width: var(--btn-size-small);
    height: var(--btn-size-small);
    font-size: 16px;
}

/* Text button (with label) */
.panel-btn.with-label {
    width: auto;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 600;
}

/* ============================================
   D-Pad for Arcade Games
   ============================================ */
.dpad-container {
    display: grid;
    grid-template-columns: repeat(3, var(--btn-size-small));
    grid-template-rows: repeat(3, var(--btn-size-small));
    gap: 4px;
}

.dpad-btn {
    width: var(--btn-size-small);
    height: var(--btn-size-small);
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 0.1s ease;
}

.dpad-btn:active {
    transform: scale(0.9);
    background: var(--primary-dark);
}

.dpad-btn.up { grid-column: 2; grid-row: 1; }
.dpad-btn.left { grid-column: 1; grid-row: 2; }
.dpad-btn.center { grid-column: 2; grid-row: 2; background: #e0e0e0; color: #999; }
.dpad-btn.right { grid-column: 3; grid-row: 2; }
.dpad-btn.down { grid-column: 2; grid-row: 3; }

/* ============================================
   Score/Info Display in Panel
   ============================================ */
.panel-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5px 12px;
    background: #f5f5f5;
    border-radius: 10px;
    min-width: 70px;
}

.panel-info-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.panel-info-value {
    font-size: 18px;
    font-weight: bold;
    color: var(--primary);
}

.panel-info-value.success { color: var(--success); }
.panel-info-value.error { color: var(--error); }

/* ============================================
   Action Buttons Row (for quiz/puzzle games)
   ============================================ */
.panel-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.panel-actions .panel-btn {
    flex: 1;
    max-width: 100px;
}

/* ============================================
   Body Padding to Account for Panel
   ============================================ */
body.has-mobile-panel {
    padding-bottom: calc(var(--panel-height) + 20px);
}

body.has-mobile-panel.arcade-mode {
    padding-bottom: calc(var(--panel-height-arcade) + 20px);
}

/* ============================================
   Hide Panel on Desktop (optional)
   ============================================ */
@media (min-width: 769px) {
    .mobile-panel.mobile-only {
        display: none;
    }

    body.has-mobile-panel.mobile-only-panel {
        padding-bottom: 0;
    }
}

/* ============================================
   Responsive Canvas Wrapper
   ============================================ */
.canvas-wrapper {
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.canvas-wrapper canvas {
    max-width: 100%;
    height: auto;
    touch-action: none;
}

/* ============================================
   Game Container Adjustments
   ============================================ */
@media (max-width: 768px) {
    .game-container {
        border-radius: 0;
        min-height: calc(100vh - var(--panel-height) - 20px);
        margin-bottom: 0;
    }

    body.arcade-mode .game-container {
        min-height: calc(100vh - var(--panel-height-arcade) - 20px);
    }

    /* Hide inline controls on mobile when panel is active */
    .mobile-panel-active .inline-controls,
    .mobile-panel-active .controls {
        display: none !important;
    }
}

/* ============================================
   Swipe Indicator (for touch games)
   ============================================ */
.swipe-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 15px 25px;
    border-radius: 15px;
    font-size: 24px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 10000;
}

.swipe-indicator.visible {
    opacity: 1;
}

/* ============================================
   Multiplayer Info in Panel
   ============================================ */
.panel-mp-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: linear-gradient(135deg, #e0f2fe 0%, #ddd6fe 100%);
    border-radius: 10px;
    font-size: 12px;
}

.panel-mp-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 14px;
}

.panel-mp-name {
    font-weight: 600;
    color: var(--text-dark);
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel-mp-score {
    color: var(--primary);
    font-weight: bold;
}

/* ============================================
   Animations
   ============================================ */
@keyframes panelSlideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.mobile-panel {
    animation: panelSlideUp 0.3s ease forwards;
}

/* Button press feedback */
@keyframes buttonPress {
    0% { transform: scale(1); }
    50% { transform: scale(0.9); }
    100% { transform: scale(1); }
}

.panel-btn.pressed {
    animation: buttonPress 0.15s ease;
}

/* ============================================
   Landscape Mode Adjustments
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    .mobile-panel {
        height: 60px;
        padding: 5px 15px;
    }

    .mobile-panel[data-type="arcade"] {
        height: 80px;
    }

    .dpad-container {
        grid-template-columns: repeat(3, 36px);
        grid-template-rows: repeat(3, 36px);
        gap: 2px;
    }

    .dpad-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .panel-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
}

/* ============================================
   Answer Buttons Panel (Quiz games)
   ============================================ */
.answer-panel {
    position: fixed;
    bottom: 80px;
    left: 0;
    right: 0;
    display: none;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.98);
    border-top: 1px solid #e0e0e0;
    z-index: 9998;
}

.answer-panel.visible {
    display: grid;
}

.answer-panel-btn {
    padding: 14px 8px;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    background: white;
    font-size: 0.85em;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s ease;
    min-height: 52px;
    line-height: 1.2;
}

.answer-panel-btn:active {
    transform: scale(0.96);
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.answer-panel-btn.correct {
    background: #d4edda;
    border-color: #28a745;
    color: #155724;
}

.answer-panel-btn.incorrect {
    background: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
}

.answer-panel-label {
    display: block;
    font-size: 0.7em;
    color: #999;
    margin-bottom: 3px;
}

body.has-answer-panel {
    padding-bottom: 160px;
}
