/* Theme Variables */
:root {
    /* Blue Theme */
    --primary-color: #4361ee;
    --secondary-color: #3f37c9;
    --accent-color: #4895ef;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --background-gradient: linear-gradient(135deg, #f5f7fa, #c3cfe2);
    --card-bg: #ffffff;
    --text-color: #212529;
    --word-display-gradient: linear-gradient(120deg, #4361ee, #3a0ca3);
    --word-text-color: white;
}

/* Dark Theme */
[data-theme="dark"] {
    --primary-color: #5e60ce;
    --secondary-color: #6930c3;
    --accent-color: #7400b8;
    --light-color: #2a2b2d;
    --dark-color: #f8f9fa;
    --background-gradient: linear-gradient(135deg, #232526, #414345);
    --card-bg: #2d3436;
    --text-color: #f8f9fa;
    --word-display-gradient: linear-gradient(120deg, #5e60ce, #121212);
    --word-text-color: #f8f9fa;
}

/* Green Theme */
[data-theme="green"] {
    --primary-color: #2a9d8f;
    --secondary-color: #287271;
    --accent-color: #52b788;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --background-gradient: linear-gradient(135deg, #e6f2ef, #b7e4c7);
    --card-bg: #ffffff;
    --text-color: #212529;
    --word-display-gradient: linear-gradient(120deg, #2a9d8f, #264653);
    --word-text-color: white;
}

/* Purple Theme */
[data-theme="purple"] {
    --primary-color: #9d4edd;
    --secondary-color: #7b2cbf;
    --accent-color: #c77dff;
    --light-color: #f8f9fa;
    --dark-color: #212529;
    --background-gradient: linear-gradient(135deg, #f5f0ff, #e0c3fc);
    --card-bg: #ffffff;
    --text-color: #212529;
    --word-display-gradient: linear-gradient(120deg, #7b2cbf, #5a189a);
    --word-text-color: white;
}

/* High Contrast Theme */
[data-theme="high-contrast"] {
    --primary-color: #ffbe0b;
    --secondary-color: #fb5607;
    --accent-color: #ff006e;
    --light-color: #ffffff;
    --dark-color: #000000;
    --background-gradient: #ffffff;
    --card-bg: #ffffff;
    --text-color: #000000;
    --word-display-gradient: #000000;
    --word-text-color: #ffbe0b;
}

/* Base Styles */
body {
    background: var(--background-gradient);
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text-color);
}

/* Card Styles */
.card {
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    border: none;
    transition: transform 0.3s;
    background-color: var(--card-bg);
}

.card:hover {
    transform: translateY(-5px);
}

/* Button Styles */
.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    padding: 10px 25px;
    border-radius: 30px;
    font-weight: 600;
    transition: all 0.3s;
}

.btn-primary:hover {
    background-color: var(--secondary-color);
    transform: scale(1.05);
}

.btn-outline-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-outline-primary:hover {
    background-color: var(--primary-color);
    color: var(--word-text-color);
}

/* Word Display Component */
.word-display {
    background: var(--word-display-gradient);
    color: var(--word-text-color);
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    position: relative;
    overflow: hidden;
    max-width: 900px;
    margin: 0 auto;
}

.word-display::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%);
    transform: rotate(30deg);
    pointer-events: none;
}

.word-text {
    font-size: 4.5rem;
    font-weight: 800;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}

/* Hide word styles */
.word-text.hidden {
    filter: blur(10px);
    user-select: none;
    position: relative;
}

.word-text.hidden:hover {
    filter: none;
    transition: filter 0.3s ease;
}

.phonetic {
    font-size: 1.8rem;
    opacity: 0.85;
    margin-bottom: 20px;
}

.meaning {
    font-size: 2rem;
    margin-top: 20px;
    background: rgba(255,255,255,0.15);
    padding: 15px 25px;
    border-radius: 12px;
    display: inline-block;
    backdrop-filter: blur(5px);
}

/* Hide meaning styles */
.meaning.hidden {
    filter: blur(10px);
    user-select: none;
}

.meaning.hidden:hover {
    filter: none;
    transition: filter 0.3s ease;
}

.example {
    font-size: 1.3rem;
    margin-top: 25px;
    padding: 15px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    border-left: 4px solid white;
    transition: all 0.2s ease;
}

.example[title] {
    cursor: pointer;
}

.example[title]:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.example .fa-volume-up {
    opacity: 0.7;
}

.example:hover .fa-volume-up {
    opacity: 1;
    transform: scale(1.1);
}

/* Example sentence language styles */
.example-en {
    display: block;
    margin-bottom: 8px;
}

.example-zh {
    display: block;
    font-size: 0.9em;
    opacity: 0.85;
    color: rgba(255, 255, 255, 0.95);
}

.auto-fullscreen-active .example-zh {
    font-size: 0.85em;
    margin-top: 10px;
}

/* Controls Styles */
.controls {
    margin-top: 30px;
    display: flex;
    justify-content: center;
    gap: 15px;
}

.control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    transition: all 0.2s;
}

.control-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

.auto-play-toggle {
    padding: 10px 20px;
    border-radius: 30px;
    font-weight: 600;
}

.progress-container {
    margin-top: 25px;
    padding: 0 20px;
}

.progress {
    height: 8px;
    border-radius: 4px;
}

.progress-bar {
    background-color: var(--accent-color);
}

/* Button state feedback */
.control-btn.active {
    transform: scale(0.9);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    opacity: 0.8;
}

/* Page Layout */
.page-title {
    color: var(--primary-color);
    text-align: center;
    margin: 25px 0;
    font-weight: 700;
    font-size: 2.2rem;
}

.textbook-icon {
    font-size: 4rem;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.unit-badge {
    position: absolute;
    top: 15px;
    right: 15px;
    background: var(--accent-color);
    color: white;
    border-radius: 20px;
    padding: 5px 15px;
    font-weight: 600;
}

/* Logo */
.logo {
    font-weight: 800;
    color: var(--primary-color);
    font-size: 1.8rem;
    margin-bottom: 30px;
}

.logo span {
    color: var(--secondary-color);
}

/* Fullscreen Mode */
.fullscreen-active {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    background: var(--word-display-gradient);
    padding: 5vh 5vw;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    max-width: none; /* Reset max-width from word-display */
    margin: 0; /* Reset margin from word-display */
}

.floating-info {
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(5px);
    border-radius: 10px;
    padding: 8px 15px;
    font-size: 0.9rem;
}

.fullscreen-active .floating-info {
    top: 20px;
    left: 20px;
    font-size: 1.2rem;
}

.fullscreen-active .word-text {
    font-size: 7rem;
}

.fullscreen-active .phonetic {
    font-size: 2.5rem;
}

.fullscreen-active .meaning {
    font-size: 3rem;
}

.fullscreen-active .example {
    font-size: 1.8rem;
    max-width: 80%;
}

.fullscreen-active .example-zh {
    font-size: 1.5rem;
}

.fullscreen-active .controls {
    margin-top: 50px;
}

.fullscreen-active .control-btn {
    width: 70px;
    height: 70px;
    font-size: 1.8rem;
}

/* Auto Fullscreen Mode */
.auto-fullscreen-active {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    background: var(--word-display-gradient);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 5vh 5vw;
    max-width: none; /* Reset max-width from word-display */
    margin: 0; /* Reset margin from word-display */
}

.auto-fullscreen-active .controls {
    display: none !important;
}

.auto-fullscreen-active .floating-info {
    top: 20px;
    left: 20px;
    font-size: 1.5rem;
    padding: 10px 20px;
    background: rgba(255,255,255,0.25);
}

.auto-fullscreen-active .word-text {
    font-size: 11rem;
    line-height: 1.2;
    margin-bottom: 15px;
    max-width: 90vw;
    text-align: center;
    transition: all 0.3s ease;
}

.auto-fullscreen-active .phonetic {
    font-size: 4.5rem; /* Increased from 3.5rem */
    margin-bottom: 20px;
    max-width: 90vw;
}

.auto-fullscreen-active .meaning {
    font-size: 4.5rem;
    max-width: 95vw;
    padding: 20px 30px;
    margin-top: 25px;
}

.auto-fullscreen-active .example {
    font-size: 4.4rem;
    max-width: 90vw;
    padding: 20px;
    margin-top: 35px;
}

.auto-fullscreen-active .example-en {
    margin-bottom: 15px;
}

.auto-fullscreen-active .example-zh {
    font-size: 3.6rem;
}

.auto-fullscreen-active .mt-3 {
    display: none !important;
}

/* Theme Switcher */
.theme-switcher {
    position: fixed;
    right: 20px;
    top: 20px;
    z-index: 9999;
    background-color: var(--card-bg);
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    min-width: 140px;
    border: 1px solid rgba(0,0,0,0.1);
}

.theme-option {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    cursor: pointer;
    padding: 5px;
    border-radius: 5px;
    transition: all 0.2s;
}

.theme-option:last-child {
    margin-bottom: 0;
}

.theme-option:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .theme-option:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.theme-label {
    margin-left: 10px;
    font-size: 14px;
    color: var(--text-color);
}

.theme-button {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
    display: inline-block;
    flex-shrink: 0;
}

.theme-button:hover {
    transform: scale(1.1);
}

.theme-button.active {
    border-color: var(--primary-color);
    transform: scale(1.1);
    box-shadow: 0 0 0 2px rgba(0,0,0,0.1);
}

.theme-button.blue {
    background: linear-gradient(120deg, #4361ee, #3a0ca3);
}

.theme-button.dark {
    background: linear-gradient(120deg, #5e60ce, #121212);
}

.theme-button.green {
    background: linear-gradient(120deg, #2a9d8f, #264653);
}

.theme-button.purple {
    background: linear-gradient(120deg, #7b2cbf, #5a189a);
}

.theme-button.high-contrast {
    background: #000000;
    border: 2px dashed #ffbe0b;
}

.theme-toggle-btn {
    position: fixed;
    right: 20px;
    top: 20px;
    z-index: 9999;
    background-color: var(--card-bg);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    color: var(--primary-color);
}

.theme-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* Additional device-specific classes */
.mobile-device .word-display {
    /* Touch-specific adjustments for mobile devices */
    touch-action: manipulation;
}

.small-screen .floating-info {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* Landscape orientation on small screens */
.compact-landscape .word-text {
    margin-bottom: 0;
}

.compact-landscape .phonetic {
    margin-bottom: 5px;
}

.compact-landscape .meaning {
    padding: 8px 15px;
    margin-top: 5px;
}

.compact-landscape .example {
    margin-top: 5px;
}

.compact-landscape .controls {
    margin-top: 10px;
}

/* Extra compact mode for very small heights */
.extra-compact {
    padding: 10px !important;
}

.extra-compact .floating-info {
    padding: 2px 8px;
    font-size: 0.75rem;
}

.extra-compact .progress-container {
    margin-top: 5px;
}

/* Responsive Styles */
@media (max-height: 800px) {
    .auto-fullscreen-active .word-text {
        font-size: 10rem; /* Increased from 8rem */
    }
    
    .auto-fullscreen-active .phonetic {
        font-size: 3.8rem; /* Increased from 3rem */
    }
    
    .auto-fullscreen-active .meaning {
        font-size: 4.2rem; /* Increased from 3.5rem */
    }
}

@media (max-height: 600px) {
    .auto-fullscreen-active .word-text {
        font-size: 8rem; /* Increased from 6rem */
    }
    
    .auto-fullscreen-active .phonetic {
        font-size: 3.2rem; /* Increased from 2.5rem */
    }
    
    .auto-fullscreen-active .meaning {
        font-size: 3.8rem; /* Increased from 3rem */
    }

    .auto-fullscreen-active .example {
        font-size: 3.2rem; /* Increased from 2.5rem */
    }
    
    .auto-fullscreen-active .example-zh {
        font-size: 2.5rem; /* Increased from 2rem */
    }
}

/* Enhanced responsive styles for different device sizes */
/* Small phones (portrait) */
@media (max-width: 576px) {
    /* Homepage adjustments */
    .logo {
        font-size: 1.5rem;
        margin-bottom: 15px;
    }
    
    .page-title {
        font-size: 1.8rem;
        margin: 15px 0;
    }
    
    .lead {
        font-size: 1rem;
    }
    
    .textbook-icon {
        font-size: 3rem;
    }
    
    /* Word display adjustments */
    .word-text {
        font-size: 2.8rem;
    }
    
    .phonetic {
        font-size: 1.2rem;
    }
    
    .meaning {
        font-size: 1.6rem;
        padding: 10px 15px;
    }
    
    .example {
        font-size: 1rem;
        padding: 10px;
    }
    
    /* Controls adjustments */
    .controls {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .control-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }
    
    .auto-play-toggle {
        width: 100%;
        margin-top: 10px;
        order: 3; /* Move to bottom */
    }
    
    /* Header adjustments */
    #wordPage .d-flex.justify-content-between {
        flex-direction: column;
        gap: 15px;
    }
    
    #wordPage .d-flex.justify-content-between h4 {
        order: -1; /* Move to top */
    }
    
    #wordPage .d-flex.justify-content-between .d-flex.align-items-center {
        width: 100%;
        justify-content: space-between;
    }
    
    /* Theme switcher positioning */
    .theme-toggle-btn {
        top: 10px;
        right: 10px;
    }
    
    .theme-switcher {
        top: 10px;
        right: 10px;
        min-width: 120px;
    }
    
    /* Additional control button layout */
    .mt-3 {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }
    
    .mt-3 button {
        padding: 6px 10px;
        font-size: 0.9rem;
    }
    
    /* Make sure buttons are always visible */
    .btn {
        white-space: nowrap;
    }
}

/* Medium phones and small tablets */
@media (min-width: 577px) and (max-width: 767px) {
    .word-text {
        font-size: 3.5rem;
    }
    
    .phonetic {
        font-size: 1.5rem;
    }
    
    .meaning {
        font-size: 1.8rem;
    }
    
    .example {
        font-size: 1.2rem;
    }
    
    /* Header adjustments */
    #wordPage .d-flex.justify-content-between {
        flex-wrap: wrap;
        gap: 15px;
    }
    
    #wordPage .d-flex.justify-content-between h4 {
        order: -1; /* Move to top */
        width: 100%;
        text-align: center;
    }
    
    #toggleAutoFullscreen, #toggleFullscreen {
        padding: 6px 10px;
        font-size: 0.9rem;
    }
}

/* Tablets and small laptops */
@media (min-width: 768px) and (max-width: 991px) {
    .word-text {
        font-size: 4rem;
    }
    
    .example {
        max-width: 95%;
    }
    
    /* Adjust the button sizes */
    #toggleAutoFullscreen, #toggleFullscreen {
        padding: 8px 12px;
    }
}

/* Landscape orientation specific adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    /* Make the word display more compact in landscape on small devices */
    .word-display {
        padding: 15px;
    }
    
    .word-text {
        font-size: 3rem;
        margin-bottom: 5px;
    }
    
    .phonetic {
        font-size: 1.3rem;
        margin-bottom: 10px;
    }
    
    .meaning {
        font-size: 1.5rem;
        padding: 8px 15px;
        margin-top: 10px;
    }
    
    .example {
        margin-top: 10px;
        padding: 8px;
    }
    
    .progress-container {
        margin-top: 10px;
    }
    
    .controls {
        margin-top: 15px;
    }
    
    /* Compact control buttons */
    .control-btn {
        width: 45px;
        height: 45px;
    }
    
    /* Layout adjustments for word page header */
    #wordPage .d-flex.justify-content-between {
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }
    
    #backToHome {
        order: 2;
    }
    
    #wordPage .d-flex.justify-content-between h4 {
        order: 1;
    }
    
    #wordPage .d-flex.justify-content-between .d-flex.align-items-center {
        order: 3;
        width: 100%;
        justify-content: center;
    }
}

/* Ensure proper spacing in the unit selection area */
@media (max-width: 768px) {
    .diagnostic-panel {
        width: 95vw !important;
        right: 2.5vw !important;
        left: 2.5vw !important;
        max-height: 70vh !important;
    }
    
    .diagnostic-toggle {
        top: 10px !important;
        right: 10px !important;
    }
    
    /* Improve unit selection UI on mobile */
    .card p-3 {
        padding: 10px !important;
    }
    
    .form-check {
        margin-bottom: 8px;
    }
    
    .form-check-label {
        font-size: 1rem;
    }
    
    /* Make sure select boxes are finger-friendly */
    .form-select {
        height: 48px;
    }
    
    /* Home page layout */
    .col-md-8.col-lg-6 {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* Apply styles for touchscreen devices */
@media (hover: none) and (pointer: coarse) {
    /* Increase button sizes for touchscreens */
    .control-btn {
        min-width: 55px;
        min-height: 55px;
    }
    
    .btn {
        padding-top: 10px;
        padding-bottom: 10px;
    }
    
    /* Improve tap target size */
    .theme-option {
        padding: 8px 5px;
        margin-bottom: 12px;
    }
    
    .theme-button {
        width: 24px;
        height: 24px;
    }
    
    /* Make sure hidden elements reveal on touch for mobile */
    .word-text.hidden:active,
    .meaning.hidden:active {
        filter: none;
    }
    
    /* Improve selection of units */
    .form-check {
        padding: 10px 30px 10px 40px;
    }
    
    .form-check-input {
        width: 20px;
        height: 20px;
    }
} 

/* Orientation-specific styles */
.orientation-landscape .theme-toggle-btn {
    top: 10px;
    right: 10px;
}

/* For notched phones (like iPhone) */
@supports (padding-top: env(safe-area-inset-top)) {
    .auto-fullscreen-active {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .fullscreen-active {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Improve accessibility for touch interaction */
@media (hover: none) and (pointer: coarse) {
    /* Hide word/meaning on touch rather than hover */
    .word-text.hidden:active,
    .meaning.hidden:active {
        filter: none !important;
    }

    /* Double-tap protection - make sure hover states don't interfere with touch */
    .theme-option:hover,
    .theme-button:hover,
    .btn:hover,
    .control-btn:hover {
        transform: none;
    }
    
    /* Increase tap area */
    .control-btn {
        min-height: 56px;
        min-width: 56px;
    }
}

/* Small devices fixes */
@media (max-width: 320px) {
    /* For iPhone SE and other very small devices */
    .word-text {
        font-size: 2.5rem !important;
    }
    
    .phonetic {
        font-size: 1rem !important;
    }
    
    .meaning {
        font-size: 1.3rem !important;
    }
    
    /* Adjust header elements */
    #wordPage .d-flex.justify-content-between {
        gap: 5px;
    }
    
    /* Button text */
    .btn {
        padding: 0.25rem 0.5rem;
    }
    
    /* Controls */
    .controls {
        gap: 5px;
    }
    
    .control-btn {
        width: 40px;
        height: 40px;
    }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 991px) and (orientation: portrait) {
    .word-display {
        padding: 25px;
    }
    
    .controls {
        margin-top: 25px;
    }
}

/* Layout fixes for specific screen sizes and orientations */
@media (min-width: 992px) and (max-height: 768px) and (orientation: landscape) {
    /* For laptops with smaller height screens */
    .word-display {
        padding: 20px;
    }
    
    .word-text {
        font-size: 4rem;
        margin-bottom: 5px;
    }
    
    .phonetic {
        font-size: 1.6rem;
        margin-bottom: 10px;
    }
    
    .meaning {
        font-size: 2rem;
    }
} 