body {
    font-family: "Atkinson Hyperlegible", sans-serif;
    padding: 0px clamp(15px, 4vw, 75px); /* Consistent responsive padding */
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    background-color: #E5EAE5;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Screen reader only content */
.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;
}

.banner {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    padding: clamp(8px, 2vw, 12px) clamp(15px, 4vw, 25px);
    background-color: #2E6F40;
    margin-top: 0;
    color: white;
    font-size: 2rem; /* Fallback for older browsers */
    font-size: clamp(1.5rem, 6vw, 2.4rem); /* Optimized scaling from mobile to desktop, respects user font preferences */
    font-weight: 700;
    font-style: normal;
    z-index: 100;
    cursor: pointer;
    box-sizing: border-box;
}

#upload-container {
    display: flex;
    width: 100%;
    min-height: auto;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;
    padding-bottom: clamp(20px, 4vw, 40px);
}

.disclaimer-box {
    margin-top: clamp(15px, 3vw, 25px);
    background-color: #E3F0E5;
    border: 1px solid #2E6F40;
    border-radius: 10px;
    padding: clamp(10px, 2vw, 18px);
    max-width: 90%;
    text-align: center;
    box-sizing: border-box;
}

.disclaimer-line-bold {
    font-size: clamp(1rem, 2.5vw, 1.4rem);
    color: black;
    font-weight: 700;
    text-align: center;
    margin: 0 0 clamp(6px, 1.5vw, 5px) 0;
    line-height: 1.3;
}

.disclaimer-line-regular {
    font-size: clamp(1rem, 2.5vw, 1.4rem);
    color: black;
    font-weight: 400;
    text-align: center;
    margin: 0;
    line-height: 1.1;
}

.drop-area {
    display: flex;
    margin-top: clamp(46px, 6vw, 80px); /* Reduced to keep content above fold with breathing room */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.3s ease;
    width: 100%;
    height: auto;
    padding: clamp(10px, 3vw, 20px);
    box-sizing: border-box;
}

/* Drop area focus indicator for keyboard accessibility */
.drop-area:focus {
    outline: 3px solid #2E6F40;
    outline-offset: 2px;
    background-color: rgba(46, 111, 64, 0.1);
}

#drop-area img {
    max-width: 100%;
    max-height: 45vh;
    height: auto;
}

#definitionModal img{
    margin: clamp(15px, 4vw, 25px);
    top: 0;
    right: 0;
    width: clamp(50px, 12vw, 70px);
    height: clamp(50px, 12vw, 70px);
    min-width: 44px;
    min-height: 44px;
    position: fixed;
    cursor: pointer;
    z-index: 1002;
}

#drop-area label {
    margin-top: 20px;
}

.labBtn {
    background-color: #95D3A6;
    border-radius: 20px;
    padding: clamp(15px, 4vw, 25px) clamp(20px, 5vw, 30px);
    font-size: clamp(1.7em, 4vw, 2.2em); /* Consistent button scaling */
    font-weight: 700;
    border: black solid 1px;
    box-shadow: 0 9px #2E6F40;
    min-height: 44px; /* Accessibility minimum */
    min-width: 120px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-sizing: border-box;
}

.labBtn:hover {
    background-color: #6bc382;
}

#text-display {
    margin-top: clamp(2rem, 6vw, 5rem);
    line-height: 1.6;
    margin-bottom: clamp(2rem, 6vw, 5rem);
    font-size: 2rem; /* Fallback for older browsers */
    font-size: clamp(1.2rem, 5vw, 3.2rem); /* Consistent text scaling across all devices */
    padding: clamp(1rem, 3vw, 2rem);
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word; /* Modern browser support for word breaking */
}

/* ===== TEXT HIERARCHY WITHIN MAIN CONTENT ===== */

/* Main heading within text content */
#text-display h1 {
    font-size: clamp(2.2rem, 8vw, 5.5rem); /* Much larger than body text */
    font-weight: 700;
    margin-top: clamp(2rem, 6vw, 4rem);
    margin-bottom: clamp(1rem, 3vw, 2rem);
    line-height: 1.2;
}

/* Section headings within text content */
#text-display h2 {
    font-size: clamp(1.8rem, 7vw, 4.5rem); /* Significantly larger than body */
    font-weight: 700;
    margin-top: clamp(1.5rem, 5vw, 3rem);
    margin-bottom: clamp(0.8rem, 2vw, 1.5rem);
    line-height: 1.3;
}

/* Subsection headings within text content */
#text-display h3 {
    font-size: clamp(1.5rem, 6vw, 3.8rem); /* Clearly larger than body */
    font-weight: 700;
    margin-top: clamp(1.2rem, 4vw, 2.5rem);
    margin-bottom: clamp(0.6rem, 2vw, 1.2rem);
    line-height: 1.3;
}

/* Emphasized text within content */
#text-display .emphasis {
    font-size: clamp(1.1rem, 4.5vw, 2.8rem); /* Slightly smaller than body */
    font-style: italic;
    margin: clamp(0.5rem, 2vw, 1rem) 0;
}

/* Small text for captions, notes, etc. */
#text-display .small-text {
    font-size: clamp(0.9rem, 3.5vw, 2.2rem); /* Noticeably smaller than body */
    margin: clamp(0.3rem, 1vw, 0.8rem) 0;
    line-height: 1.5;
}

/* Ensure all text hierarchy maintains word functionality */
#text-display h1 .word,
#text-display h2 .word,
#text-display h3 .word,
#text-display .emphasis .word,
#text-display .small-text .word {
    font-size: inherit;
    cursor: pointer;
}

.word {
    display: inline-block;
    cursor: pointer;
    font-size: inherit; /* Use parent's responsive font size */
    padding: 2px 1px; /* Small padding for better clickability */
    border-radius: 3px;
    /* Removed transition for instant highlighting changes */
    
    /* Reserve space to prevent reflow when bolded */
    letter-spacing: 0.5px; /* Slightly wider spacing to accommodate bold width */
    word-break: break-word; /* Allow long words to break when necessary */
    overflow-wrap: break-word; /* Modern browser support for word breaking */
}

.word:hover {
    background-color: rgba(149, 211, 166, 0.3); /* Light green hover effect */
    transition: background-color 0.2s ease; /* Smooth transition only on hover */
}

/* Keyboard focus indicator */
.word:focus,
.word.keyboard-focused {
    outline: 3px solid #2E6F40 !important;
    outline-offset: 2px;
}

/* When word is only focused (not speaking) */
.word.keyboard-focused:not(.current-word) {
    background-color: rgba(46, 111, 64, 0.15) !important;
}

/* When word is both focused AND currently being spoken - combine both styles */
.word.keyboard-focused.current-word,
.word:focus.current-word {
    /* Keep the speaking highlight background */
    background-color: #ffd54f !important; 
    font-weight: bold !important;
    /* Add the focus outline */
    outline: 3px solid #2E6F40 !important;
    outline-offset: 2px;
    /* Make the outline more prominent when both states are active */
    box-shadow: 0 0 0 1px white, 0 0 0 4px #2E6F40;
}

/* Modal keyboard focus styles - same behavior as main content */
.definition-word:focus,
.definition-word.modal-keyboard-focused {
    outline: 3px solid #2E6F40 !important;
    outline-offset: 2px;
}

/* When modal word is only focused (not speaking) */
.definition-word.modal-keyboard-focused:not(.definition-current-word) {
    background-color: rgba(46, 111, 64, 0.15) !important;
}

/* When modal word is both focused AND currently being spoken - combine both styles */
.definition-word.modal-keyboard-focused.definition-current-word,
.definition-word:focus.definition-current-word {
    /* Keep the speaking highlight background */
    background-color: #ffd54f !important; 
    font-weight: bold !important;
    /* Add the focus outline */
    outline: 3px solid #2E6F40 !important;
    outline-offset: 2px;
    /* Make the outline more prominent when both states are active */
    box-shadow: 0 0 0 1px white, 0 0 0 4px #2E6F40;
}

.word-line {
    display: block;
}

#status {
    font-size: 1rem;
    color: white;
    margin-top: 10px;
    opacity: 0;
    visibility: none;
}

#content-area {
    position: fixed;
    left: 0;
    bottom: 0;
    margin: 30px;
    display: inline;
}

.highlight {
    background-color: rgba(255, 255, 0, 0.5);
    border-radius: 3px;
}

.modal {
    display: none;
    position: fixed;
    left: 0px;
    top: 0;
    width: 100%;
    max-width: 100%;
    padding: clamp(15px, 4vw, 25px);
    background-color: #D8E1D9;
    height: 100%;
    font-size: 2rem; /* Fallback for older browsers */
    font-size: clamp(1.2rem, 5vw, 3.2rem); /* Match main text sizing exactly */
    line-height: 1.6; /* Match main text line-height exactly */
    z-index: 1000;
    box-sizing: border-box;
    overflow-y: auto;
}

.modal h2 {
    margin-top: clamp(20px, 5vw, 40px);
    margin-bottom: clamp(15px, 4vw, 25px);
    font-size: clamp(1.8rem, 7vw, 4rem); /* Consistent heading scaling */
}

.modal-content {
    max-width: clamp(90%, 85vw, 80%);
    margin: 0 auto;
    padding-bottom: clamp(100px, 15vw, 120px); /* Space for controls */
}

.modal-speech-controls {
    position: fixed;
    bottom: clamp(40px, 8vw, 70px);
    left: 50%;
    -webkit-transform: translateX(-50%);
    -ms-transform: translateX(-50%);
    transform: translateX(-50%);
    display: flex;
    gap: clamp(8px, 2vw, 12px);
    padding: clamp(8px, 2vw, 12px);
    box-shadow: 0 9px #2E6F40;
    background-color: #95D3A6;
    border: solid black 1px;
    border-radius: 30px;
    z-index: 1001;
}

.modal-speech-controls button {
    border: none;
    border-radius: 50%;
    width: clamp(50px, 12vw, 70px);
    height: clamp(50px, 12vw, 70px);
    min-width: 44px; /* Accessibility minimum */
    min-height: 44px;
    background-size: 100%;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
}

/* Modal play button states */
#modalPlayBtn {
    background-image: url('../static/assets/Play\ Button-unselected.png');
}

#modalPlayBtn.playing {
    background-image: url('../static/assets/Play\ Button-selected.png');
}

/* Modal pause button states */
#modalPauseBtn {
    background-image: url('../static/assets/Pause\ Button-Selected.png');
}

#modalPauseBtn.playing {
    background-image: url('../static/assets/Pause\ Button-unselected.png');
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #E5EAE5;
    display: none;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    z-index: 1000;
}

.loader2 {
    width: min(340px, 34vh);    
    height: min(340px, 34vh);    
    padding: 40px;
    margin-top: 60px;
    margin-bottom: 50px;
    aspect-ratio: 1;
    border-radius: 50%;
    background: #2E6F40;
    --_m:
        conic-gradient(#0000 10%, #000),
        linear-gradient(#000 0 0) content-box;
    -webkit-mask: var(--_m);
    mask: var(--_m);
    -webkit-mask-composite: source-out;
    mask-composite: subtract;
    /* Fallback for older browsers */
    background: #2E6F40;
    animation: l3 1s infinite linear;
}

@keyframes l3 {
    to {
        transform: rotate(1turn)
    }
}

.lab2 {
    font-size: 1em;
    color: #333;
}

#speech-controls {
    position: fixed;
    bottom: clamp(15px, 4vw, 25px);
    left: 50%;
    -webkit-transform: translateX(-50%);
    -ms-transform: translateX(-50%);
    transform: translateX(-50%);
    display: none;
    gap: clamp(8px, 2vw, 12px);
    padding: clamp(8px, 2vw, 12px);
    box-shadow: 0 9px #2E6F40;
    background-color: #95D3A6;
    border: solid black 1px;
    border-radius: 30px;
}

#speech-controls button {
    border: none;
    border-radius: 50%;
    width: clamp(50px, 12vw, 70px);
    height: clamp(50px, 12vw, 70px);
    min-width: 44px; /* Accessibility minimum */
    min-height: 44px;
    background-size: 100%;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
}

.speed-display {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50px; /* Changed from 50% to create ellipse */
    width: clamp(100px, 20vw, 140px); /* Wider to comfortably fit 1.25x */
    height: clamp(50px, 12vw, 70px);
    min-width: 90px; /* Increased min-width for ellipse shape */
    min-height: 44px;
    background-color: #45535B;
    color: #E5EAE5;
    font-size: clamp(2rem, 5vw, 3rem); /* Scales better on mobile */
    font-weight: 700; /* Bold */
    cursor: pointer;
    user-select: none;
    position: relative;
}

.speed-display.active {
    color: #FFD700; /* Yellow color when dropdown is open */
}

.speed-dropdown {
    display: none;
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background-color: #45535B;
    border-radius: 15px;
    padding: clamp(12px, 3vw, 18px);
    min-width: 120px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.speed-dropdown.show {
    display: flex;
    flex-direction: column;
    gap: clamp(8px, 2vw, 12px);
}

.speed-option {
    font-size: clamp(1.5rem, 3vw, 2rem); /* Simple responsive sizing for dropdown options */
    color: #E5EAE5;
    text-align: center;
    padding: clamp(6px, 1.5vw, 10px);
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s ease, font-weight 0.1s ease;
    font-weight: 400; /* Normal weight by default */
}

.speed-option.speed-label {
    font-weight: 700; /* "Speed" is always bolded */
    cursor: default;
    pointer-events: none;
}

.speed-option:hover:not(.speed-label) {
    font-weight: 700; /* Bold on hover */
    background-color: rgba(229, 234, 229, 0.1);
}

/* Front page controls styling */
#front-page-controls {
    margin-top: clamp(30px, 6vw, 50px);
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    display: flex;
    gap: clamp(8px, 2vw, 12px);
    padding: clamp(8px, 2vw, 12px);
    box-shadow: 0 9px #2E6F40;
    background-color: #95D3A6;
    border: solid black 1px;
    border-radius: 30px;
    justify-content: center;
}

#front-page-controls button {
    border: none;
    border-radius: 50%;
    width: clamp(50px, 12vw, 70px);
    height: clamp(50px, 12vw, 70px);
    min-width: 44px; /* Accessibility minimum */
    min-height: 44px;
    background-size: 100%;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
}

/* Front page play button states */
#frontPlayBtn {
    background-image: url('../static/assets/Play\ Button-unselected.png');
}

#frontPlayBtn.playing {
    background-image: url('../static/assets/Play\ Button-selected.png');
}

/* Front page pause button states */
#frontPauseBtn {
    background-image: url('../static/assets/Pause\ Button-Selected.png');
}

#frontPauseBtn.playing {
    background-image: url('../static/assets/Pause\ Button-unselected.png');
}

/* Play button states */
#playBtn {
    background-image: url('../static/assets/Play Button-unselected.png');
}

#playBtn.playing {
    background-image: url('../static/assets/Play Button-selected.png');
}

/* Pause button states */
#pauseBtn {
    background-image: url('../static/assets/Pause Button-Selected.png');
}

#pauseBtn.playing {
    background-image: url('../static/assets/Pause Button-unselected.png');
}

#fileInput {
    display: none;
}

.current-word {
    background-color: #ffd54f;
    font-weight: bold;
    border-radius: 3px;
    padding: 0 2px;
}

.definition-current-word {
    background-color: #ffd54f;
    font-weight: bold;
    border-radius: 3px;
    padding: 0 2px;
}

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Small phones - minimal adjustments to base responsive design */
@media screen and (max-width: 480px) {
    body {
        padding: 0px 10px; /* Tighter padding on very small screens */
    }
    
    .drop-area {
        margin-top: max(60px, 8vh); /* Ensure minimum spacing while being responsive */
    }
    
    #drop-area img {
        max-height: 35vh;
    }
    
    #text-display {
        margin-top: max(1.5rem, 5vh); /* Ensure readable spacing on small screens */
    }
}

/* Medium phones and small tablets - use base responsive design */
@media screen and (min-width: 481px) and (max-width: 768px) {
    /* Base responsive design handles this range perfectly */
}

/* Tablets - use base responsive design */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    /* Base responsive design handles this range perfectly */
}

/* Large tablets and small desktops - use base responsive design */
@media screen and (min-width: 1025px) and (max-width: 1440px) {
    /* Base responsive design handles this range perfectly */
}

/* Large screens - use base responsive design */
@media screen and (min-width: 1441px) {
    /* Base responsive design handles this range perfectly */
}

/* iPad and iPad Pro specific optimizations */
@media screen and (min-device-width: 768px) and (max-device-width: 1024px) and (-webkit-min-device-pixel-ratio: 1.5),
       screen and (min-device-width: 1024px) and (max-device-width: 1366px) and (-webkit-min-device-pixel-ratio: 1.5) {
    .banner {
        font-size: clamp(2.4rem, 5vw, 2.8rem) !important; /* Specific sizing for high-DPI iPad devices, respects user font preferences */
    }
}

/* Landscape orientation adjustments for phones and small tablets */
@media screen and (max-height: 500px) and (orientation: landscape) {
    #drop-area img {
        max-height: 25vh;
    }
}