/* Add Lexend font */
@font-face {
    font-family: 'Lexend';
    src: url('Lexend-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

body {
    font-family: 'Lexend', Arial, sans-serif;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    /* Gradient background from old app */
    background: linear-gradient(to bottom, #2589fb 0%, #83a4ec 100%);
    overflow-x: hidden;
    color: #333;
    /* Disable text selection */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

#mountain-bg-container {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 40vh;
    pointer-events: none;
    z-index: 0;
}

#mountain-bg {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100vw;
    height: 100%;
    object-fit: cover;
    z-index: 0;
    pointer-events: none;
    opacity: 0.8;
    filter: blur(2.5px) brightness(0.93);
}

#clouds-container {
    position: absolute;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.cloud {
    position: absolute;
    pointer-events: none;
    will-change: transform;
    opacity: 0.9;
    z-index: 2;
    transition: opacity 0.5s;
}

/* Music toggle icon in top left */
#music-toggle-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 200;
    cursor: pointer;
}

#music-toggle-icon {
    font-size: 24px;
    color: rgba(255, 255, 255, 0.7);
    transition: all 0.3s ease;
    padding: 10px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#music-toggle-icon:hover {
    color: rgba(255, 255, 255, 0.9);
    background-color: rgba(0, 0, 0, 0.3);
    transform: scale(1.1);
}

#music-toggle-icon.playing {
    color: #4361ee;
    background-color: rgba(255, 255, 255, 0.9);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Bottom controls area */
#bottom-controls {
    position: fixed;
    bottom: 20px;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 100%;
    z-index: 100;
    padding: 0 20px;
    box-sizing: border-box;
}

#text-switcher-btn {
    padding: 12px 24px;
    border-radius: 30px;
    border: none;
    background-color: #4361ee;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.2s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    font-size: 1rem;
    min-width: 150px;
    margin: 0 auto;
    position: relative;
    z-index: 10;
}

#text-switcher-btn:hover {
    background-color: #3a56d4;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

#text-switcher-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#text-switcher-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.3), 0 4px 8px rgba(0, 0, 0, 0.2);
}

#word-scroller-app {
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

#word-scroller-viewport {
    width: 100%;
    height: calc(6 * 3em); /* 6 visible lines * line height */
    overflow: hidden;
    border: none;
    background-color: transparent;
    position: relative;
    border-radius: 8px;
    /* Ensure clean cutoff for words */
    mask-image: linear-gradient(to bottom, 
        rgba(0,0,0,1) 0%, 
        rgba(0,0,0,1) 95%, 
        rgba(0,0,0,0) 100%);
    -webkit-mask-image: linear-gradient(to bottom, 
        rgba(0,0,0,1) 0%, 
        rgba(0,0,0,1) 95%, 
        rgba(0,0,0,0) 100%);
}

#word-scroller-container {
    position: relative;
    top: calc(-1 * 3em); /* Offset by 1 slot height to hide the top buffer */
    transition: transform 0.65s cubic-bezier(0.25, 0.1, 0.25, 1);
    will-change: transform;
    backface-visibility: hidden;
    /* Add slight padding to better hide partial words */
    padding-bottom: 0.5em;
}

.word-line {
    height: 3em;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5em;
    box-sizing: border-box;
    padding: 0 20px;
    opacity: 1;
    transition: opacity 0.4s ease-in-out;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-weight: 600;
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 100%;
    color: #FFB347; /* Golden orange */
    text-shadow: 0 3px 6px rgba(0, 0, 0, 0.6), 0 0 15px rgba(255, 166, 0, 0.5), 0 0 5px rgba(255, 215, 0, 0.3);
}

.word-line[data-slot-id="7"].newest-visible {
    text-decoration: underline;
    text-underline-offset: 0.15em;
    color: #FFD700; /* Brighter gold for emphasis */
    text-shadow: 0 0 10px rgba(255, 166, 0, 0.9), 0 0 20px rgba(255, 215, 0, 0.7);
    font-weight: 700;
    /* Add glow effect */
    position: relative;
}

/* Create the glow effect with a pseudo-element */
.word-line[data-slot-id="7"].newest-visible::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% + 30px);
    height: calc(100% + 10px);
    border-radius: 15px;
    background: radial-gradient(ellipse at center, rgba(255, 215, 0, 0.4) 0%, rgba(255, 215, 0, 0) 70%);
    z-index: -1;
    animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* For users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    #word-scroller-container {
        transition: none;
    }
    
    .word-line {
        transition: opacity 0.1s ease-out;
    }
}

/* Device indicator */
#device-indicator {
    width: 40px;
    height: 40px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    position: absolute;
    left: 15px;
    bottom: 0;
}

#desktop-icon, #mobile-icon {
    font-size: 1.5rem;
    color: white;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

#mobile-icon {
    display: none;
}

/* Text Switcher Container */
#text-switcher-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* Speed Control Styles */
#speed-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    align-items: center;
}

.speed-icon {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.speed-icon i {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.7);
    transition: color 0.3s ease;
}

.speed-icon:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.speed-icon:hover i {
    color: rgba(255, 255, 255, 0.9);
}

.speed-icon.active {
    background-color: rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.speed-icon.active i {
    color: rgba(255, 255, 255, 1);
}

/* Meditation Timer Styles */
#meditation-timer-icon {
    position: absolute;
    right: 15px;
    bottom: 0;
    width: 40px;
    height: 40px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Invisible overlay button for reliable clicking */
#timer-click-overlay {
    position: absolute;
    top: -5px;
    left: -5px;
    width: 50px;
    height: 50px;
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 101;
    outline: none;
}

#meditation-timer-icon:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.clock-face {
    width: 28px;
    height: 28px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hour-hand, .minute-hand {
    position: absolute;
    background-color: #333;
    transform-origin: bottom center;
    border-radius: 2px;
    pointer-events: none; /* Allow clicks to pass through to parent */
}

.hour-hand {
    width: 2px;
    height: 8px;
    top: 6px;
}

.minute-hand {
    width: 1.5px;
    height: 10px;
    top: 4px;
}

/* Clock animation classes */
.clock-rotating .hour-hand {
    animation: rotate-hour 7200s linear infinite; /* 2 hours rotation */
}

.clock-rotating .minute-hand {
    animation: rotate-minute 600s linear infinite; /* 10 minutes rotation */
}

/* Alarm clock animation when timer finishes */
.clock-alarm {
    animation: alarm-shake 0.8s ease-in-out infinite;
}

@keyframes alarm-shake {
    0%, 100% { 
        transform: rotate(0deg) scale(1); 
    }
    10% { 
        transform: rotate(-5deg) scale(1.05); 
    }
    20% { 
        transform: rotate(5deg) scale(1.05); 
    }
    30% { 
        transform: rotate(-3deg) scale(1.02); 
    }
    40% { 
        transform: rotate(3deg) scale(1.02); 
    }
    50% { 
        transform: rotate(-2deg) scale(1.01); 
    }
    60% { 
        transform: rotate(2deg) scale(1.01); 
    }
    70% { 
        transform: rotate(-1deg) scale(1); 
    }
    80% { 
        transform: rotate(1deg) scale(1); 
    }
    90% { 
        transform: rotate(0deg) scale(1); 
    }
}

.clock-complete {
    animation: clock-complete-animation 1s ease-in-out infinite alternate;
}

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

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

@keyframes clock-complete-animation {
    0% { transform: scale(1) rotate(-5deg); }
    100% { transform: scale(1.2) rotate(5deg); }
}

/* Timer Control Window */
#timer-control-window {
    position: absolute;
    right: 60px;
    bottom: 50px;
    width: 250px;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    padding: 15px;
    z-index: 99;
    display: none;
    flex-direction: column;
    gap: 15px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transform-origin: bottom right;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

#timer-control-window.visible {
    display: flex;
    animation: popup-animation 0.3s ease-out forwards;
}

@keyframes popup-animation {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.timer-header {
    display: flex;
    justify-content: center;
    align-items: center;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.timer-display-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

#timer-display {
    font-size: 24px;
    font-weight: bold;
    color: #333;
}

.show-timer-container {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: #666;
}

.timer-settings {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.time-inputs {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.time-input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
}

.time-input-group label {
    font-size: 12px;
    color: #666;
}

.time-input-group input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 100%;
    box-sizing: border-box;
}

.timer-buttons {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.timer-buttons button {
    flex: 1;
    padding: 8px 0;
    border: none;
    border-radius: 4px;
    background-color: #4361ee;
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.timer-buttons button:hover:not(:disabled) {
    background-color: #3a56d4;
}

.timer-buttons button:disabled {
    background-color: #a0a0a0;
    cursor: not-allowed;
}

.timer-stats {
    padding-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.stat-item {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 8px;
}

.stat-item:last-child {
    margin-bottom: 0;
}

.stat-label-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-label {
    color: #666;
}

.show-stat-container {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: #888;
}

#lines-read-count,
#focused-time-count {
    font-weight: bold;
    color: #333;
}

/* Make app responsive */
/* Tutorial popup styles */
#tutorial-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 180px;
    height: 280px;
    background-color: rgba(255, 255, 255, 0.75);
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#tutorial-popup.visible {
    opacity: 1;
    visibility: visible;
}

#tutorial-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

#tutorial-icons {
    position: relative;
    width: 100%;
    height: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
}

#tutorial-fingertip {
    width: 50px;
    height: auto;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    animation: hover-animation 1.5s ease-in-out infinite;
}

#tutorial-device-desktop,
#tutorial-device-mobile {
    width: 80px;
    height: auto;
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
}

#tutorial-device-mobile {
    display: none;
}

@keyframes hover-animation {
    0% {
        transform: translateX(-50%) translateY(0);
    }
    50% {
        transform: translateX(-50%) translateY(-15px);
    }
    100% {
        transform: translateX(-50%) translateY(0);
    }
}

.finger-press {
    animation: press-animation 0.3s ease-in-out forwards !important;
}

@keyframes press-animation {
    0% {
        transform: translateX(-50%) translateY(-15px);
    }
    100% {
        transform: translateX(-50%) translateY(15px);
    }
}

@keyframes fade-out {
    0% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        visibility: hidden;
    }
}

@media (max-width: 520px) {
    #text-input-area,
    #word-scroller-app {
        width: 90%;
    }
    
    .word-line {
        font-size: 1.1em;
        padding: 0 10px;
    }
    
    #text-switcher-btn {
        padding: 12px 20px;
        font-size: 1rem;
        min-width: 120px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        z-index: 1000; /* Ensure button is in foreground */
        position: relative; /* Required for z-index to work */
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3); /* Enhanced shadow for better visibility */
    }
    
    #desktop-icon {
        display: none;
    }
    
    #mobile-icon {
        display: block;
    }
    
    #tutorial-device-desktop {
        display: none;
    }
    
    #tutorial-device-mobile {
        display: block;
    }
    
    /* Ensure clean cutoff for words on mobile */
    #word-scroller-viewport {
        height: calc(6 * 3em - 15px); /* Even shorter to prevent seeing next word */
        mask-image: linear-gradient(to bottom, 
            rgba(0,0,0,1) 0%, 
            rgba(0,0,0,1) 92%, 
            rgba(0,0,0,0) 100%);
        -webkit-mask-image: linear-gradient(to bottom, 
            rgba(0,0,0,1) 0%, 
            rgba(0,0,0,1) 92%, 
            rgba(0,0,0,0) 100%);
        overflow: hidden;
    }
    
    #bottom-controls {
        bottom: 30px; /* Move button even lower on mobile */
        z-index: 999; /* High z-index for the controls container */
    }
}
