/* ============================================
   Element Mage - Mobile-First Responsive CSS
   ============================================ */

/* CSS Variables */
:root {
    --color-bg: #0a0a1a;
    --color-bg-overlay: rgba(10, 10, 26, 0.9);
    --color-primary: #00ffcc;
    --color-secondary: #ff0055;
    --color-text: #ffffff;
    --color-text-dim: #888899;
    --color-danger: #ff3366;
    --color-success: #00ff88;

    --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

body {
    font-family: var(--font-main);
    background-color: var(--color-bg);
    color: var(--color-text);
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ============================================
   Screen Container
   ============================================ */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
    z-index: 10;
}

.screen.active {
    display: flex;
}

.screen.overlay {
    background-color: var(--color-bg-overlay);
    z-index: 100;
}

/* ============================================
   Loading Screen
   ============================================ */
#loading-screen {
    background: linear-gradient(135deg, #0a0a1a 0%, #1a1a3a 100%);
}

.loading-content {
    text-align: center;
    padding: 20px;
}

.game-title {
    font-size: clamp(1.8rem, 8vw, 3rem);
    font-weight: bold;
    color: var(--color-primary);
    text-shadow: 0 0 20px var(--color-primary);
    margin-bottom: 40px;
    letter-spacing: 2px;
}

.loading-spinner {
    width: 80px;
    height: 80px;
    margin: 0 auto 30px;
    border: 4px solid var(--color-primary);
    border-radius: 50%;
    position: relative;
    animation: spin 2s linear infinite, glow 1.5s ease-in-out infinite;
}

.loading-spinner::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    border: 2px solid var(--color-secondary);
    border-radius: 50%;
    animation: spin 1.5s linear reverse infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 10px var(--color-primary); }
    50% { box-shadow: 0 0 30px var(--color-primary), 0 0 50px var(--color-primary); }
}

#loading-status {
    color: var(--color-text-dim);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.progress-bar {
    width: 200px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    margin: 0 auto;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-secondary));
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ============================================
   Menu Screen
   ============================================ */
#menu-screen {
    background: linear-gradient(135deg, #0a0a1a 0%, #1a1a3a 100%);
}

.menu-content {
    text-align: center;
    padding: 20px;
    width: 100%;
    max-width: 400px;
}

.menu-stats {
    margin: 30px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.menu-stats p {
    color: var(--color-text-dim);
    font-size: 1.1rem;
}

.menu-stats span {
    color: var(--color-primary);
    font-weight: bold;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

.version-text {
    margin-top: 40px;
    color: var(--color-text-dim);
    font-size: 0.8rem;
}

.menu-footer {
    margin-top: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.menu-footer .version-text {
    margin-top: 0;
}

.btn-language {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
    padding: 8px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 60px;
}

.btn-language:hover,
.btn-language:active {
    background: var(--color-primary);
    color: var(--color-bg);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
    padding: 16px 40px;
    font-size: 1.1rem;
    font-weight: bold;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), #00cc99);
    color: var(--color-bg);
    box-shadow: 0 4px 20px rgba(0, 255, 204, 0.3);
}

.btn-primary:active {
    transform: scale(0.95);
    box-shadow: 0 2px 10px rgba(0, 255, 204, 0.5);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.95);
}

.btn-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-icon:active {
    background: rgba(255, 255, 255, 0.2);
}

.btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-skip {
    position: absolute;
    top: calc(20px + var(--safe-top));
    right: calc(20px + var(--safe-right));
    background: none;
    border: none;
    color: var(--color-text-dim);
    font-size: 1rem;
    cursor: pointer;
    padding: 10px;
}

/* ============================================
   Tutorial Screen
   ============================================ */
#tutorial-screen {
    background: linear-gradient(135deg, #0a0a1a 0%, #1a1a3a 100%);
}

.tutorial-content {
    text-align: center;
    padding: 20px;
    width: 100%;
    max-width: 400px;
    position: relative;
}

.tutorial-slides {
    position: relative;
    min-height: 350px;
}

.tutorial-slide {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tutorial-slide.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.tutorial-slide h2 {
    color: var(--color-text-dim);
    font-size: 0.9rem;
    margin-bottom: 30px;
    letter-spacing: 2px;
}

.tutorial-slide h3 {
    color: var(--color-primary);
    font-size: 1.3rem;
    margin: 20px 0 15px;
}

.tutorial-slide p {
    color: var(--color-text-dim);
    line-height: 1.6;
}

.tutorial-demo {
    width: 150px;
    height: 150px;
    margin: 0 auto;
    border: 3px solid var(--color-primary);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 20px rgba(0, 255, 204, 0.3); }
    50% { transform: scale(1.05); box-shadow: 0 0 40px rgba(0, 255, 204, 0.5); }
}

.hand-icon {
    font-size: 4rem;
}

.hand-icon.palm {
    animation: wave 1s ease-in-out infinite;
}

.hand-icon.fist {
    animation: punch 0.5s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% { transform: rotate(-10deg); }
    50% { transform: rotate(10deg); }
}

@keyframes punch {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

.target-icon {
    font-size: 4rem;
    color: var(--color-secondary);
    text-shadow: 0 0 20px var(--color-secondary);
    animation: float 2s ease-in-out infinite;
}

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

.tutorial-dots {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 30px 0;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
}

.dot.active {
    background: var(--color-primary);
    box-shadow: 0 0 10px var(--color-primary);
}

/* ============================================
   Game Screen
   ============================================ */
#game-screen {
    padding: 0;
    z-index: 1;
}

#camera-video {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    opacity: 0.2;
    z-index: 1;
}

#game-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.game-hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding: calc(15px + var(--safe-top)) calc(15px + var(--safe-right)) 15px calc(15px + var(--safe-left));
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    z-index: 50;
    pointer-events: none;
}

.game-hud > * {
    pointer-events: auto;
}

.hud-left {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.hud-right {
    display: flex;
    flex-direction: row;
    gap: 10px;
}

.score-display {
    display: flex;
    flex-direction: column;
}

.score-label {
    font-size: 0.7rem;
    color: var(--color-text-dim);
    letter-spacing: 2px;
}

.score-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--color-primary);
    text-shadow: 0 0 10px var(--color-primary);
}

.combo-display {
    background: var(--color-secondary);
    padding: 5px 15px;
    border-radius: 20px;
    animation: comboPopIn 0.3s ease;
}

.combo-display.hidden {
    display: none;
}

.combo-value {
    font-size: 1rem;
    font-weight: bold;
    color: white;
}

@keyframes comboPopIn {
    from { transform: scale(0.5); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Level Display */
.level-display {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 15px;
    background: rgba(255, 255, 255, 0.1);
    margin-top: 5px;
}

.level-display.level-1 {
    border: 2px solid #888;
}

.level-display.level-2 {
    border: 2px solid #00ff88;
    background: rgba(0, 255, 136, 0.1);
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.3);
}

.level-display.level-3 {
    border: 2px solid #ffaa00;
    background: rgba(255, 170, 0, 0.1);
    box-shadow: 0 0 15px rgba(255, 170, 0, 0.4);
    animation: levelGlow 1s ease-in-out infinite;
}

@keyframes levelGlow {
    0%, 100% { box-shadow: 0 0 10px rgba(255, 170, 0, 0.4); }
    50% { box-shadow: 0 0 20px rgba(255, 170, 0, 0.7); }
}

.level-label {
    font-size: 0.7rem;
    color: var(--color-text-dim);
}

.level-value {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--color-text);
}

/* Skill Bar */
.skill-bar {
    position: fixed;
    top: calc(90px + var(--safe-top));
    left: calc(15px + var(--safe-left));
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 50;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 12px;
    border-radius: 20px;
}

.skill-bar.hidden {
    display: none;
}

.skill-bar-label {
    font-size: 0.75rem;
    color: #ffcc00;
    font-weight: bold;
}

.skill-bar-track {
    width: 80px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

.skill-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #ffcc00, #ff6600);
    border-radius: 4px;
    transition: width 0.2s ease;
}

.skill-ready-indicator {
    font-size: 0.7rem;
    color: #ffcc00;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.skill-ready-indicator.active {
    opacity: 1;
    animation: skillPulse 0.5s ease-in-out infinite;
}

@keyframes skillPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Level Up Overlay */
.level-up-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.level-up-overlay.active {
    opacity: 1;
}

.level-up-text {
    font-size: 3rem;
    font-weight: bold;
    color: #ffcc00;
    text-shadow: 0 0 30px #ffcc00, 0 0 60px #ff6600;
    text-align: center;
    white-space: pre-line;
    animation: levelUpBounce 0.5s ease-out;
}

@keyframes levelUpBounce {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); opacity: 1; }
}

/* Chain Explosion Flash Animation */
@keyframes chainFlash {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

.gesture-hint {
    position: fixed;
    bottom: calc(30px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    padding: 10px 20px;
    border-radius: 20px;
    z-index: 50;
}

#gesture-status {
    font-size: 0.9rem;
    color: var(--color-text-dim);
}

/* ============================================
   Pause Screen
   ============================================ */
.pause-content, .result-content, .error-content {
    text-align: center;
    padding: 30px;
    background: rgba(20, 20, 40, 0.95);
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    width: 90%;
    max-width: 350px;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.pause-content h2, .result-content h2, .error-content h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--color-primary);
}

.pause-stats, .result-stats {
    margin: 20px 0;
    color: var(--color-text-dim);
}

.pause-buttons, .result-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================================
   Result Screen
   ============================================ */
#result-screen {
    background: var(--color-bg-overlay);
}

.result-score {
    margin: 20px 0;
    padding: 20px;
    background: rgba(0, 255, 204, 0.1);
    border-radius: 15px;
    border: 2px solid var(--color-primary);
}

.final-score-label {
    display: block;
    font-size: 0.8rem;
    color: var(--color-text-dim);
    letter-spacing: 2px;
    margin-bottom: 10px;
}

.final-score-value {
    display: block;
    font-size: 3rem;
    font-weight: bold;
    color: var(--color-primary);
    text-shadow: 0 0 20px var(--color-primary);
}

.new-record {
    display: block;
    margin-top: 10px;
    color: gold;
    font-size: 1rem;
    animation: pulse 1s ease-in-out infinite;
}

.new-record.hidden {
    display: none;
}

.result-stats {
    text-align: left;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row span:first-child {
    color: var(--color-text-dim);
}

.stat-row span:last-child {
    color: var(--color-text);
    font-weight: bold;
}

/* ============================================
   Error Screen
   ============================================ */
#error-screen {
    background: var(--color-bg-overlay);
}

.error-content h2 {
    color: var(--color-danger);
}

#error-message {
    color: var(--color-text-dim);
    margin-bottom: 20px;
    line-height: 1.6;
}

/* ============================================
   Utility Classes
   ============================================ */
.hidden {
    display: none !important;
}

/* ============================================
   Landscape Warning (for phones)
   ============================================ */
@media screen and (orientation: landscape) and (max-height: 500px) {
    body::after {
        content: var(--landscape-warning, '📱 Please rotate your device to portrait mode');
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: var(--color-bg);
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 1.2rem;
        color: var(--color-text);
        z-index: 9999;
        text-align: center;
        padding: 20px;
    }
}

/* ============================================
   Desktop Adjustments
   ============================================ */
@media screen and (min-width: 768px) {
    .btn {
        padding: 18px 50px;
        font-size: 1.2rem;
    }

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

    .score-value {
        font-size: 2.5rem;
    }
}
