:root {
    --bg-color: #f7f9fc;
    --card-bg: #ffffff;
    --primary: #4a90e2;
    --text: #2c3e50;
    --highlight: #ffeaa7;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
}

body {
    font-family: 'Quicksand', sans-serif;
    background-color: var(--bg-color);
    color: var(--text);
    overflow: hidden; /* Prevent bouncing on iOS */
    height: 100%;
    height: 100dvh;
    width: 100vw;
}

.view {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    flex-direction: column;
    overflow: hidden;
}

#read-view {
    touch-action: pan-y;
}

.view.active {
    display: flex;
}

/* Home View */
.lite-header {
    padding: 30px 20px;
    background: linear-gradient(135deg, #4a90e2, #63a4ff);
    color: white;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    border-bottom-left-radius: 24px;
    border-bottom-right-radius: 24px;
    margin-bottom: 10px;
}

.lite-header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 25px;
    letter-spacing: -0.5px;
}

.level-filters {
    display: flex;
    justify-content: center;
    gap: 15px;
    flex-wrap: wrap;
}

.filter-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    padding: 12px 30px;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.1s ease-out;
    -webkit-tap-highlight-color: transparent;
}

.filter-btn:active {
    transform: scale(0.95);
}

.filter-btn.active {
    background: white;
    color: var(--primary);
    border-color: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.book-grid {
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 25px;
    overflow-y: auto;
    flex: 1;
    padding-bottom: 40px;
}

.book-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    text-align: center;
    cursor: pointer;
    transition: transform 0.1s ease-out;
    content-visibility: auto;
    contain-intrinsic-size: auto 250px;
}

.book-card:active {
    transform: scale(0.95);
}

.book-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 10px;
}

.book-card h3 {
    font-size: 1.2rem;
    margin-bottom: 5px;
}

.book-level {
    display: inline-block;
    padding: 4px 12px;
    background: #e1f0ff;
    color: var(--primary);
    border-radius: 20px;
    font-weight: bold;
    font-size: 0.9rem;
}

/* Reading View */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    z-index: 10;
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--primary);
    padding: 10px;
    cursor: pointer;
    transition: transform 0.1s ease-out;
}

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

.book-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.page-img-wrapper {
    position: relative;
    display: inline-block;
}

#page-img {
    max-width: 100%;
    max-height: 50vh;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    margin-bottom: 30px;
    object-fit: contain;
    -webkit-user-drag: none;
    user-drag: none;
    user-select: none;
    -webkit-user-select: none;
    transition: opacity 0.15s ease-in-out, transform 0.15s ease-in-out;
}

.tag-replace-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #ef4444;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    z-index: 10;
    padding: 0;
    line-height: 1;
}

.text-container {
    font-family: 'Comic Neue', cursive;
    font-size: 2.5rem;
    font-weight: 700;
    text-align: center;
    max-width: 800px;
    line-height: 1.4;
    transition: opacity 0.15s ease-in-out, transform 0.15s ease-in-out;
}

.page-transition-out {
    opacity: 0;
    transform: scale(0.98) translateY(4px);
}

.word {
    display: inline-block;
    margin: 0 6px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 8px;
    transition: background 0.1s ease-out;
}

.word:active {
    background: var(--highlight);
}

.word.speaking {
    background: var(--highlight);
    color: #d35400;
}

.bottom-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: white;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.nav-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 60px;
    height: 60px;
    border-radius: 30px;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(74, 144, 226, 0.3);
    transition: transform 0.1s ease-out;
}

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

.nav-btn:disabled {
    background: #ccc;
    box-shadow: none;
}

.page-indicator {
    font-size: 1.2rem;
    font-weight: bold;
    color: #7f8c8d;
}

@media (max-width: 600px) {
    .lite-header {
        padding: 15px 10px;
        margin-bottom: 5px;
    }
    
    .lite-header h1 {
        font-size: 1.4rem;
        margin-bottom: 12px;
    }
    
    .filter-btn {
        font-size: 0.95rem;
        padding: 8px 18px;
    }
    
    .book-grid {
        padding: 12px;
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 12px;
    }
    
    .book-card {
        padding: 10px;
    }
    
    .book-card h3 {
        font-size: 1rem;
    }
    
    .top-bar {
        padding: 8px 12px;
    }
    
    .top-bar h2 {
        font-size: 1.1rem;
    }
    
    .book-content {
        padding: 10px;
    }
    
    #page-img {
        max-height: 38dvh;
        margin-bottom: 15px;
        -webkit-user-drag: none;
        user-drag: none;
        user-select: none;
        -webkit-user-select: none;
    }
    
    .text-container {
        font-size: 1.6rem;
        line-height: 1.3;
    }
    
    .word {
        margin: 0 4px;
        padding: 1px 4px;
    }
    
    .bottom-bar {
        padding: 10px 15px;
    }
    
    .nav-btn {
        width: 48px;
        height: 48px;
        font-size: 1.2rem;
        border-radius: 24px;
    }
    
    .page-indicator {
        font-size: 1rem;
    }
}
