/* Rudolf Game - Main Styles */
/* Cross-device compatible */

:root {
    --primary-color: #e74c3c;
    --secondary-color: #2ecc71;
    --background-dark: #1a1a2e;
    --background-mid: #16213e;
    --text-light: #ffffff;
    --text-muted: #b0b0b0;
    --fog-color: rgba(200, 210, 220, 0.9);
    --gold: #f1c40f;
    --danger: #e74c3c;

    /* Safe area insets */
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

html {
    /* Prevent pull-to-refresh on mobile */
    overscroll-behavior: none;
    /* Prevent text size adjustment */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background-dark);
    color: var(--text-light);
    touch-action: none;
    position: fixed;
    top: 0;
    left: 0;
}

#game-container {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    padding-top: calc(var(--sat) + 20px);
    padding-bottom: calc(var(--sab) + 20px);
    padding-left: calc(var(--sal) + 20px);
    padding-right: calc(var(--sar) + 20px);
    background: linear-gradient(180deg, var(--background-dark) 0%, var(--background-mid) 100%);
    z-index: 10;
}

.screen.active {
    display: flex;
}

/* Start Screen */
#start-screen {
    text-align: center;
}

.title-container {
    margin-bottom: 40px;
}

.game-title {
    font-size: clamp(2.5rem, 10vw, 4rem);
    font-weight: 900;
    color: var(--primary-color);
    text-shadow: 0 4px 20px rgba(231, 76, 60, 0.5);
    letter-spacing: 0.1em;
    margin-bottom: 10px;
}

.rudolf-icon {
    font-size: clamp(3rem, 12vw, 5rem);
    margin: 20px 0;
    animation: bob 2s ease-in-out infinite;
}

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

.tagline {
    font-size: clamp(0.9rem, 3vw, 1.1rem);
    color: var(--text-muted);
    margin-top: 15px;
    padding: 0 10px;
}

.motion-hint {
    position: absolute;
    bottom: calc(var(--sab) + 40px);
    font-size: 0.9rem;
    color: var(--text-muted);
    animation: pulse 2s ease-in-out infinite;
}

/* Hide motion hint on desktop */
.desktop-mode .motion-hint {
    display: none;
}

/* Desktop controls hint */
.desktop-hint {
    position: absolute;
    bottom: calc(var(--sab) + 40px);
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
    display: none;
}

.desktop-mode .desktop-hint {
    display: block;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 40px;
    font-size: clamp(1rem, 4vw, 1.3rem);
    font-weight: 700;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    margin: 10px 0;
    transition: all 0.2s ease;
    min-width: 200px;
    max-width: 90vw;
    -webkit-appearance: none;
    appearance: none;
}

.btn:focus {
    outline: none;
}

.btn:hover {
    transform: translateY(-2px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #c0392b 100%);
    color: white;
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.btn-primary:active {
    transform: scale(0.96);
    box-shadow: 0 3px 10px rgba(231, 76, 60, 0.4);
}

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

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

.btn-icon {
    font-size: 1.2rem;
}

/* Permission Screen */
.permission-content,
.calibration-content {
    text-align: center;
    max-width: 300px;
    padding: 0 15px;
}

.permission-icon,
.calibration-icon {
    font-size: clamp(3rem, 10vw, 4rem);
    margin-bottom: 20px;
}

.permission-content h2,
.calibration-content h2 {
    font-size: clamp(1.4rem, 5vw, 1.8rem);
    margin-bottom: 15px;
}

.permission-content p,
.calibration-content p {
    color: var(--text-muted);
    margin-bottom: 20px;
    font-size: clamp(0.9rem, 3vw, 1rem);
}

.permission-note {
    font-size: 0.85rem;
    margin-top: 20px;
}

/* Calibration */
.calibration-progress {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin: 20px 0;
}

.calibration-bar {
    height: 100%;
    width: 0%;
    background: var(--secondary-color);
    border-radius: 4px;
    transition: width 0.1s linear;
}

/* Game Screen */
#game-screen {
    padding: 0;
    background: transparent;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 15px 20px;
    padding-top: calc(var(--sat) + 15px);
    padding-left: calc(var(--sal) + 15px);
    padding-right: calc(var(--sar) + 15px);
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    z-index: 100;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 12px;
    border-radius: 12px;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

.hud-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.hud-item.score #score-value {
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    font-weight: 700;
    color: var(--gold);
}

.hud-item.timer #timer-value {
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    font-weight: 700;
}

.hud-item.timer.warning #timer-value {
    color: var(--danger);
    animation: blink 0.5s infinite;
}

@keyframes blink {
    50% { opacity: 0.5; }
}

.hud-item.chimneys {
    flex-direction: row;
    gap: 5px;
    font-size: clamp(1rem, 3.5vw, 1.2rem);
    font-weight: 600;
}

.hud-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.boost-charges {
    display: flex;
    gap: 6px;
}

.boost-dot {
    font-size: clamp(1rem, 3vw, 1.2rem);
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

.boost-dot.active {
    opacity: 1;
}

.level-indicator {
    background: rgba(0, 0, 0, 0.5);
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 0.8rem;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

/* Pause Overlay */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.overlay.hidden {
    display: none;
}

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

.overlay-content h2 {
    font-size: clamp(2rem, 8vw, 2.5rem);
    margin-bottom: 30px;
}

/* Result Screens */
.result-content {
    text-align: center;
    max-width: 350px;
    padding: 0 15px;
}

.result-title {
    font-size: clamp(1.4rem, 5vw, 1.8rem);
    margin-bottom: 15px;
    line-height: 1.3;
}

.result-title.success {
    color: var(--secondary-color);
}

.result-title.failure {
    color: var(--text-muted);
}

.result-subtitle {
    font-size: clamp(0.95rem, 3.5vw, 1.1rem);
    color: var(--text-muted);
    margin-bottom: 30px;
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 80px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 5px;
}

.stat-value {
    font-size: clamp(1.2rem, 4vw, 1.5rem);
    font-weight: 700;
}

.result-hint {
    margin-top: 25px;
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
}

/* Settings Screen */
.settings-content {
    width: 100%;
    max-width: 320px;
    padding: 0 15px;
}

.settings-content h2 {
    text-align: center;
    font-size: clamp(1.6rem, 6vw, 2rem);
    margin-bottom: 30px;
}

.setting-group {
    margin-bottom: 25px;
}

.setting-label {
    display: flex;
    align-items: center;
    font-size: 0.95rem;
    margin-bottom: 10px;
    color: var(--text-light);
}

input[type="range"] {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 28px;
    height: 28px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.5);
}

input[type="range"]::-moz-range-thumb {
    width: 28px;
    height: 28px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(231, 76, 60, 0.5);
}

.setting-hints {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 5px;
}

input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin-right: 12px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

/* Mobile-first touch targets (min 48px per WCAG) */
.btn {
    min-height: 48px;
    min-width: 48px;
}

/* Mobile pause button (always visible on mobile) */
.mobile-pause-btn {
    position: fixed;
    top: calc(var(--sat) + 12px);
    right: calc(var(--sar) + 12px);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    font-size: 1.4rem;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 160;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    cursor: pointer;
    -webkit-appearance: none;
    pointer-events: auto;
}

.mobile-pause-btn:active {
    transform: scale(0.9);
    background: rgba(0, 0, 0, 0.8);
}

/* Show mobile pause on touch devices, hide on desktop */
.touch-device .mobile-pause-btn {
    display: flex;
}
.desktop-mode .mobile-pause-btn {
    display: none;
}

/* Mobile boost button - always visible on mobile during gameplay */
.mobile-boost-btn {
    position: fixed;
    bottom: calc(var(--sab) + 24px);
    right: calc(var(--sar) + 20px);
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, #c0392b 100%);
    border: 3px solid rgba(255, 255, 255, 0.3);
    font-size: 1.8rem;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(231, 76, 60, 0.5);
    z-index: 160;
    display: none;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease;
    -webkit-appearance: none;
    pointer-events: auto;
}

.mobile-boost-btn:active {
    transform: scale(0.85);
}

.mobile-boost-btn.cooldown {
    opacity: 0.4;
    background: linear-gradient(135deg, #666 0%, #444 100%);
}

.touch-device .mobile-boost-btn {
    display: flex;
}
.desktop-mode .mobile-boost-btn {
    display: none;
}

/* Mobile radar button */
.mobile-radar-btn {
    position: fixed;
    bottom: calc(var(--sab) + 24px);
    left: calc(var(--sal) + 20px);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(241, 196, 15, 0.5);
    font-size: 1.4rem;
    color: var(--gold);
    cursor: pointer;
    z-index: 160;
    display: none;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
    pointer-events: auto;
}

.mobile-radar-btn:active {
    transform: scale(0.9);
}

.mobile-radar-btn.cooldown {
    opacity: 0.3;
}

.touch-device .mobile-radar-btn {
    display: flex;
}
.desktop-mode .mobile-radar-btn {
    display: none;
}

/* Orientation lock overlay */
.orientation-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background-dark);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    text-align: center;
    padding: 40px;
}

.orientation-overlay .rotate-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: rotatePhone 1.5s ease-in-out infinite;
}

.orientation-overlay p {
    font-size: 1.2rem;
    color: var(--text-muted);
}

@keyframes rotatePhone {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-30deg); }
    75% { transform: rotate(30deg); }
}

@media (orientation: landscape) and (max-height: 500px) {
    .orientation-overlay {
        display: flex;
    }
    #game-container {
        display: none;
    }
}

/* Responsive - Small screens */
@media (max-height: 600px) {
    .title-container {
        margin-bottom: 20px;
    }

    .rudolf-icon {
        margin: 10px 0;
    }

    .btn {
        padding: 12px 35px;
    }

    .result-stats {
        gap: 15px;
    }
}

/* Responsive - Large screens / Desktop */
@media (min-width: 768px) {
    .screen {
        padding: 40px;
    }

    .btn:hover {
        transform: translateY(-3px);
        box-shadow: 0 8px 25px rgba(231, 76, 60, 0.5);
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .screen {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        align-content: center;
        gap: 20px;
    }

    .title-container {
        width: 45%;
        margin-bottom: 0;
    }

    #start-screen .btn {
        width: auto;
    }

    .motion-hint,
    .desktop-hint {
        display: none;
    }
}

/* Loading animation */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Boost effect indicator */
.boost-active {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    border: 8px solid var(--primary-color);
    box-shadow: inset 0 0 80px rgba(231, 76, 60, 0.4);
    z-index: 50;
    animation: boost-glow 0.3s ease-out;
}

@keyframes boost-glow {
    from {
        border-width: 20px;
        opacity: 1;
    }
    to {
        border-width: 8px;
        opacity: 0.7;
    }
}

/* Direction indicators */
.direction-arrow {
    position: fixed;
    font-size: 2rem;
    color: var(--gold);
    animation: point 0.5s ease-in-out infinite alternate;
    z-index: 100;
    pointer-events: none;
}

@keyframes point {
    from { opacity: 0.5; transform: scale(1); }
    to { opacity: 1; transform: scale(1.2); }
}

/* Control mode indicators */
.control-mode-badge {
    position: fixed;
    bottom: calc(var(--sab) + 10px);
    right: calc(var(--sar) + 10px);
    background: rgba(0, 0, 0, 0.6);
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    z-index: 150;
    pointer-events: none;
}

/* Boost button for desktop/fallback (hidden on mobile - use mobile-boost-btn instead) */
.boost-button {
    position: fixed;
    bottom: calc(var(--sab) + 80px);
    right: calc(var(--sar) + 20px);
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, #c0392b 100%);
    border: none;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.5);
    z-index: 150;
    display: none;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    -webkit-appearance: none;
}

.boost-button:active {
    transform: scale(0.9);
}

.desktop-mode .boost-button,
.fallback-mode .boost-button {
    display: flex;
}

/* Hide desktop boost button when mobile buttons visible */
.touch-device .boost-button {
    display: none !important;
}

/* Keyboard hints for desktop */
.keyboard-hints {
    position: fixed;
    bottom: calc(var(--sab) + 20px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.8rem;
    color: var(--text-muted);
    z-index: 150;
    display: none;
    gap: 15px;
}

.desktop-mode .keyboard-hints {
    display: flex;
}

.key-hint {
    display: flex;
    align-items: center;
    gap: 5px;
}

.key {
    background: rgba(255, 255, 255, 0.15);
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
    font-weight: bold;
}

/* Print styles - hide everything */
@media print {
    body {
        display: none;
    }
}
