/* Virtual Candle Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #0f0f1e 50%, #1a0033 100%);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    cursor: pointer;
    overflow: hidden;
    -webkit-text-size-adjust: 100%; /* Prevent font scaling on mobile */
    touch-action: manipulation; /* Improve touch response */
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
}

.candle-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
}

.candle-wrapper {
    position: relative;
    width: 200px;
    height: 300px;
    perspective: 1000px;
}

/* Flame */
.flame {
    position: absolute;
    bottom: 180px;
    left: 50%;
    transform: translateX(-50%) scaleY(0);
    width: 40px;
    height: 80px;
    background: linear-gradient(to top, #ff6b1b, #ffa500, #ffeb3b);
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    box-shadow: 0 0 20px rgba(255, 107, 27, 0.8), 0 0 40px rgba(255, 165, 0, 0.6);
    transition: transform 0.3s ease;
    filter: drop-shadow(0 0 10px rgba(255, 200, 0, 0.9));
    visibility: hidden;
}

.flame.on {
    visibility: visible;
    transform: translateX(-50%) scaleY(1);
}

@media (prefers-reduced-motion: no-preference) {
    .flame.on {
        animation: flicker 0.3s ease-in-out infinite;
    }
}

@keyframes flicker {
    0%, 100% {
        transform: translateX(-50%) scaleY(1) scaleX(1);
    }
    25% {
        transform: translateX(-48%) scaleY(0.98) scaleX(0.98);
    }
    50% {
        transform: translateX(-52%) scaleY(1.05) scaleX(1.02);
    }
    75% {
        transform: translateX(-49%) scaleY(0.97) scaleX(0.99);
    }
}

/* Wick */
.wick {
    position: absolute;
    bottom: 185px;
    left: 50%;
    transform: translateX(-50%);
    width: 3px;
    height: 12px;
    background: #2c2416;
    border-radius: 2px;
    z-index: 1;
    transition: all 0.3s ease;
}

.wick.on {
    background: #1a1410;
}

/* Candle Body */
.candle-body {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 160px;
    background: linear-gradient(to right, #f5deb3, #ffe4b5, #f5deb3);
    border-radius: 10px 10px 15px 15px;
    box-shadow: 
        inset -5px 0 10px rgba(0, 0, 0, 0.1),
        inset 5px 0 10px rgba(255, 255, 255, 0.3),
        0 10px 30px rgba(0, 0, 0, 0.3);
    transition: all 0.5s ease;
}

.candle-body.melting {
    background: linear-gradient(to bottom, 
        #f5deb3 0%,
        #ffe4b5 30%,
        #f5deb3 60%,
        #daa520 100%);
}

/* Melted wax drips */
.drip {
    position: absolute;
    left: 50%;
    top: 160px;
    width: 8px;
    height: 40px;
    background: linear-gradient(to bottom, #f5deb3, #daa520);
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.drip.visible {
    opacity: 0.7;
}

.drip:nth-child(2) {
    transform: translateX(-30px);
}

.drip:nth-child(3) {
    transform: translateX(22px);
}

/* Base */
.base {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 130px;
    height: 20px;
    background: linear-gradient(to right, #d4a574, #daa520, #d4a574);
    border-radius: 50%;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4), inset 0 2px 5px rgba(255, 255, 255, 0.2);
}

/* Glow effect when candle is on */
.candle-glow {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(255, 165, 0, 0.3) 0%, rgba(255, 165, 0, 0.1) 40%, transparent 70%);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.5s ease;
    pointer-events: none;
    z-index: -1;
}

.candle-glow.on {
    opacity: 1;
}

.text {
    color: #e0e0e0;
    font-size: 18px;
    text-align: center;
    letter-spacing: 1px;
    font-weight: 300;
}

.status {
    font-size: 14px;
    color: #888;
    margin-top: 10px;
    transition: all 0.3s ease;
}

.status.on {
    color: #ffa500;
    font-weight: 500;
}

/* Loading state */
.mic-loading {
    font-size: 12px;
    color: #aaa;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mic-loading.visible {
    opacity: 1;
}

.mic-loading .spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid #555;
    border-top-color: #ffa500;
    border-radius: 50%;
    margin-right: 8px;
    animation: spin 0.8s linear infinite;
}

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

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    background: rgba(255, 255, 255, 0.06);
    padding: 12px 16px;
    border-radius: 12px;
    color: #ddd;
    backdrop-filter: blur(2px);
    cursor: default;
}

.controls label {
    font-size: 14px;
    color: #bbb;
}

.controls input[type="range"] {
    width: 200px;
    cursor: pointer;
}

.controls input[type="number"] {
    width: 64px;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.3);
    color: #eee;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
}

.visualizer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.visualizer-track {
    position: relative;
    width: 200px;
    height: 10px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    overflow: hidden;
}

.visualizer-fill {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0%;
    background: linear-gradient(90deg, #4caf50, #ff9800, #f44336);
    transition: width 0.08s linear;
}

.visualizer-threshold {
    position: absolute;
    top: -2px;
    bottom: -2px;
    width: 2px;
    background: #ffa500;
    opacity: 0.9;
    pointer-events: none;
}

.visualizer-meta {
    display: flex;
    justify-content: space-between;
    width: 200px;
    font-size: 12px;
    color: #aaa;
}

/* Keyboard focus styles */
.controls input[type="range"]:focus,
.controls input[type="number"]:focus {
    outline: 2px solid #ffa500;
    outline-offset: 2px;
}

/* Calibration section */
.calibration-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.calibrate-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.calibrate-btn:hover {
    background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
}

.calibrate-btn:active {
    transform: translateY(0);
}

.calibrate-btn:disabled {
    background: linear-gradient(135deg, #666 0%, #555 100%);
    cursor: not-allowed;
    box-shadow: none;
}

.calibrate-btn:focus {
    outline: 2px solid #ffa500;
    outline-offset: 2px;
}

.calibrate-icon {
    font-size: 16px;
}

/* Enable Mic Button (shown when in manual mode) */
.enable-mic-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.3);
}

.enable-mic-btn:hover {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
}

.enable-mic-btn:active {
    transform: translateY(0);
}

.enable-mic-btn:focus {
    outline: 2px solid #ffa500;
    outline-offset: 2px;
}

.calibration-progress-container {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.calibration-progress-container.active {
    opacity: 1;
}

.calibration-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    transition: width 0.1s linear;
}

.calibration-status {
    font-size: 12px;
    color: #888;
    text-align: center;
    margin: 0;
    transition: color 0.3s ease;
}

/* Responsive design - Mobile fixes */
@media (max-width: 768px) {
    body {
        padding: 10px;
        min-height: 100dvh; /* Use dynamic viewport height for mobile */
        cursor: default; /* Remove pointer cursor on mobile */
        overflow-x: hidden;
    }

    .container {
        gap: 20px;
        width: 100%;
        max-width: 100vw;
        padding: 10px 5px;
    }

    .candle-section {
        gap: 15px;
        width: 100%;
    }

    .candle-wrapper {
        width: 150px;
        height: 220px;
    }

    .flame {
        bottom: 130px;
        width: 30px;
        height: 60px;
    }

    .wick {
        bottom: 135px;
        width: 2px;
        height: 10px;
    }

    .candle-body {
        width: 80px;
        height: 130px;
        border-radius: 8px 8px 12px 12px;
    }

    .base {
        width: 100px;
        height: 15px;
    }

    /* Fix drip positioning on mobile - match mobile candle body height */
    .drip {
        top: 130px; /* Mobile candle body height */
        width: 6px;
        height: 30px;
    }

    .text {
        font-size: 14px;
        line-height: 1.4;
    }

    h1.text {
        font-size: 20px;
    }

    .status {
        font-size: 12px;
        margin-top: 5px;
    }

    /* Controls mobile fixes */
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 10px 12px;
        width: 100%;
        max-width: 320px;
    }

    .controls label {
        font-size: 13px;
        text-align: center;
    }

    .controls input[type="range"] {
        width: 100%;
        min-width: 200px;
        height: 44px; /* Larger touch target */
    }

    .controls input[type="number"] {
        width: 100%;
        height: 44px; /* Larger touch target */
        text-align: center;
        font-size: 16px;
    }

    .visualizer {
        width: 100%;
    }

    .visualizer-track,
    .visualizer-meta {
        width: 100%;
    }

    /* Calibration section mobile fixes */
    .calibration-section {
        width: 100%;
    }

    .calibrate-btn {
        font-size: 14px;
        padding: 12px 16px;
        min-height: 44px; /* Minimum touch target size */
    }

    .enable-mic-btn {
        font-size: 14px;
        padding: 12px 16px;
        min-height: 44px; /* Minimum touch target size */
    }

    .calibration-status {
        font-size: 11px;
    }

    /* Make candle wrapper larger touch target on mobile */
    .candle-wrapper {
        cursor: pointer;
        touch-action: manipulation; /* Prevent double-tap zoom */
        -webkit-tap-highlight-color: transparent;
    }

    /* Ensure proper spacing for mic loading */
    .mic-loading {
        font-size: 11px;
    }
}

/* Extra small screens (phones in portrait) */
@media (max-width: 380px) {
    .candle-wrapper {
        width: 120px;
        height: 180px;
    }

    .flame {
        bottom: 110px;
        width: 25px;
        height: 50px;
    }

    .wick {
        bottom: 115px;
        width: 2px;
        height: 8px;
    }

    .candle-body {
        width: 65px;
        height: 110px;
    }

    /* Fix drip positioning on extra small screens */
    .drip {
        top: 110px; /* Extra small candle body height */
        width: 5px;
        height: 25px;
    }

    .base {
        width: 85px;
        height: 12px;
    }

    h1.text {
        font-size: 18px;
    }

    .controls {
        padding: 8px 10px;
    }

    .controls input[type="range"] {
        min-width: 160px;
    }
}

/* Subtle background animation */
@media (prefers-reduced-motion: no-preference) {
    body.dark-mode {
        animation: backgroundShift 20s ease infinite;
        background-size: 200% 200%;
    }
}

@keyframes backgroundShift {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

/* Screen reader only text */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    width: 90%;
    max-width: 400px;
    background: linear-gradient(135deg, #1a1a2e 0%, #0f0f1e 100%);
    border-radius: 16px;
    box-shadow: 
        0 20px 60px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.1);
    padding: 24px;
    animation: modalSlideIn 0.3s ease-out;
}

.modal.active {
    display: block;
}

.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 999;
    animation: backdropFadeIn 0.3s ease-out;
}

.modal-backdrop.active {
    display: block;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

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

.modal-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.modal-icon {
    font-size: 48px;
    line-height: 1;
}

.modal-title {
    color: #fff;
    font-size: 22px;
    font-weight: 600;
    text-align: center;
    margin: 0;
    letter-spacing: 0.5px;
}

.modal-description {
    color: #aaa;
    font-size: 14px;
    text-align: center;
    line-height: 1.6;
    margin: 0 0 24px 0;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 48px;
}

.modal-btn-primary {
    background: linear-gradient(135deg, #4caf50 0%, #45a049 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.modal-btn-primary:hover {
    background: linear-gradient(135deg, #45a049 0%, #3d8b40 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}

.modal-btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #ddd;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.modal-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

.modal-btn:active {
    transform: translateY(0);
}

.modal-btn:focus {
    outline: 2px solid #ffa500;
    outline-offset: 2px;
}

/* Mobile modal adjustments */
@media (max-width: 768px) {
    .modal {
        width: 92%;
        max-width: 340px;
        padding: 20px;
    }

    .modal-title {
        font-size: 20px;
    }

    .modal-description {
        font-size: 13px;
    }

    .modal-btn {
        padding: 12px 16px;
        font-size: 14px;
        min-height: 44px;
    }
}
