* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #334155;
    --shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
    position: relative;
    overflow-x: hidden;
}

/* Realistic sky background - iMessage style */
.sky {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    background: linear-gradient(to bottom, #87CEEB 0%, #87CEEB 30%, #B0E0E6 70%, #E0F6FF 100%);
    transition: background 1s ease;
}

/* Dark mode (system preference or manual toggle) */
@media (prefers-color-scheme: dark) {
    .sky {
        background: linear-gradient(to bottom, #0a0e27 0%, #1a1f3a 30%, #2a2f4a 60%, #1a1f3a 90%, #0a0e27 100%);
    }
    .cloud {
        opacity: 0;
    }
    .moon {
        opacity: 1;
    }
    .stars {
        opacity: 1;
    }
}

body.dark-mode .sky {
    background: linear-gradient(to bottom, #0a0e27 0%, #1a1f3a 30%, #2a2f4a 60%, #1a1f3a 90%, #0a0e27 100%);
}
body.dark-mode .cloud {
    opacity: 0;
}
body.dark-mode .moon {
    opacity: 1;
}
body.dark-mode .stars {
    opacity: 1;
}

/* When user chose light, override system dark */
body.force-light .sky {
    background: linear-gradient(to bottom, #87CEEB 0%, #87CEEB 30%, #B0E0E6 70%, #E0F6FF 100%);
}
body.force-light .cloud {
    opacity: 0.95;
}
body.force-light .moon {
    opacity: 0;
}
body.force-light .stars {
    opacity: 0;
}

/* Show clouds in light mode */
.cloud {
    transition: opacity 1s ease;
}

/* Realistic cloud styling */
.cloud {
    position: absolute;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 100px;
    opacity: 0.95;
    filter: blur(0.5px);
    box-shadow: 
        0 0 25px rgba(255, 255, 255, 0.5),
        inset 0 0 15px rgba(255, 255, 255, 0.6);
}

.cloud:before,
.cloud:after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 100px;
    box-shadow: 
        0 0 20px rgba(255, 255, 255, 0.4),
        inset 0 0 12px rgba(255, 255, 255, 0.5);
}

/* Cloud 1 - Large fluffy cloud */
.cloud1 {
    width: 320px;
    height: 110px;
    top: 15%;
    left: -380px;
    animation: moveCloud1 40s linear infinite;
    border-radius: 160px;
}

.cloud1:before {
    width: 160px;
    height: 160px;
    top: -80px;
    left: 40px;
    border-radius: 160px;
}

.cloud1:after {
    width: 190px;
    height: 190px;
    top: -95px;
    right: 30px;
    border-radius: 190px;
}

@keyframes moveCloud1 {
    0% {
        left: -380px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 2 - Medium cloud */
.cloud2 {
    width: 270px;
    height: 85px;
    top: 30%;
    left: -320px;
    animation: moveCloud2 35s linear infinite;
    animation-delay: -8s;
    border-radius: 135px;
}

.cloud2:before {
    width: 130px;
    height: 130px;
    top: -65px;
    left: 30px;
    border-radius: 130px;
}

.cloud2:after {
    width: 150px;
    height: 150px;
    top: -75px;
    right: 20px;
    border-radius: 150px;
}

@keyframes moveCloud2 {
    0% {
        left: -320px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(8px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 3 - Smaller cloud */
.cloud3 {
    width: 220px;
    height: 75px;
    top: 50%;
    left: -270px;
    animation: moveCloud3 30s linear infinite;
    animation-delay: -15s;
    border-radius: 110px;
}

.cloud3:before {
    width: 110px;
    height: 110px;
    top: -55px;
    left: 25px;
    border-radius: 110px;
}

.cloud3:after {
    width: 120px;
    height: 120px;
    top: -60px;
    right: 25px;
    border-radius: 120px;
}

@keyframes moveCloud3 {
    0% {
        left: -270px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 4 - Large cloud (lower) */
.cloud4 {
    width: 300px;
    height: 95px;
    top: 65%;
    left: -360px;
    animation: moveCloud4 45s linear infinite;
    animation-delay: -20s;
    border-radius: 150px;
}

.cloud4:before {
    width: 150px;
    height: 150px;
    top: -75px;
    left: 40px;
    border-radius: 150px;
}

.cloud4:after {
    width: 170px;
    height: 170px;
    top: -85px;
    right: 30px;
    border-radius: 170px;
}

@keyframes moveCloud4 {
    0% {
        left: -360px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(12px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 5 - Medium cloud (upper) */
.cloud5 {
    width: 240px;
    height: 80px;
    top: 8%;
    left: -290px;
    animation: moveCloud5 38s linear infinite;
    animation-delay: -25s;
    border-radius: 120px;
}

.cloud5:before {
    width: 120px;
    height: 120px;
    top: -60px;
    left: 30px;
    border-radius: 120px;
}

.cloud5:after {
    width: 140px;
    height: 140px;
    top: -70px;
    right: 20px;
    border-radius: 140px;
}

@keyframes moveCloud5 {
    0% {
        left: -290px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 6 - Small cloud (lower) */
.cloud6 {
    width: 200px;
    height: 65px;
    top: 75%;
    left: -240px;
    animation: moveCloud6 32s linear infinite;
    animation-delay: -12s;
    border-radius: 100px;
}

.cloud6:before {
    width: 100px;
    height: 100px;
    top: -50px;
    left: 25px;
    border-radius: 100px;
}

.cloud6:after {
    width: 110px;
    height: 110px;
    top: -55px;
    right: 20px;
    border-radius: 110px;
}

@keyframes moveCloud6 {
    0% {
        left: -240px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(6px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 7 - Small wispy cloud */
.cloud7 {
    width: 150px;
    height: 50px;
    top: 25%;
    left: -180px;
    animation: moveCloud7 28s linear infinite;
    animation-delay: -3s;
    border-radius: 75px;
    opacity: 0.85;
}

.cloud7:before {
    width: 75px;
    height: 75px;
    top: -37px;
    left: 15px;
    border-radius: 75px;
}

.cloud7:after {
    width: 85px;
    height: 85px;
    top: -42px;
    right: 15px;
    border-radius: 85px;
}

@keyframes moveCloud7 {
    0% {
        left: -180px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(-4px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 8 - Medium cloud */
.cloud8 {
    width: 260px;
    height: 85px;
    top: 45%;
    left: -310px;
    animation: moveCloud8 42s linear infinite;
    animation-delay: -18s;
    border-radius: 130px;
}

.cloud8:before {
    width: 130px;
    height: 130px;
    top: -65px;
    left: 35px;
    border-radius: 130px;
}

.cloud8:after {
    width: 145px;
    height: 145px;
    top: -72px;
    right: 25px;
    border-radius: 145px;
}

@keyframes moveCloud8 {
    0% {
        left: -310px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(10px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 9 - Small cloud */
.cloud9 {
    width: 140px;
    height: 45px;
    top: 12%;
    left: -170px;
    animation: moveCloud9 26s linear infinite;
    animation-delay: -7s;
    border-radius: 70px;
    opacity: 0.88;
}

.cloud9:before {
    width: 70px;
    height: 70px;
    top: -35px;
    left: 18px;
    border-radius: 70px;
}

.cloud9:after {
    width: 80px;
    height: 80px;
    top: -40px;
    right: 18px;
    border-radius: 80px;
}

@keyframes moveCloud9 {
    0% {
        left: -170px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(-6px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 10 - Large voluminous cloud */
.cloud10 {
    width: 340px;
    height: 115px;
    top: 55%;
    left: -400px;
    animation: moveCloud10 48s linear infinite;
    animation-delay: -22s;
    border-radius: 170px;
}

.cloud10:before {
    width: 170px;
    height: 170px;
    top: -85px;
    left: 45px;
    border-radius: 170px;
}

.cloud10:after {
    width: 195px;
    height: 195px;
    top: -97px;
    right: 35px;
    border-radius: 195px;
}

@keyframes moveCloud10 {
    0% {
        left: -400px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(8px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 11 - Thin wispy cloud */
.cloud11 {
    width: 180px;
    height: 40px;
    top: 70%;
    left: -220px;
    animation: moveCloud11 30s linear infinite;
    animation-delay: -14s;
    border-radius: 90px;
    opacity: 0.82;
}

.cloud11:before {
    width: 90px;
    height: 90px;
    top: -45px;
    left: 22px;
    border-radius: 90px;
}

.cloud11:after {
    width: 95px;
    height: 95px;
    top: -47px;
    right: 22px;
    border-radius: 95px;
}

@keyframes moveCloud11 {
    0% {
        left: -220px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(5px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 12 - Medium cloud */
.cloud12 {
    width: 230px;
    height: 75px;
    top: 38%;
    left: -280px;
    animation: moveCloud12 36s linear infinite;
    animation-delay: -11s;
    border-radius: 115px;
}

.cloud12:before {
    width: 115px;
    height: 115px;
    top: -57px;
    left: 28px;
    border-radius: 115px;
}

.cloud12:after {
    width: 135px;
    height: 135px;
    top: -67px;
    right: 22px;
    border-radius: 135px;
}

@keyframes moveCloud12 {
    0% {
        left: -280px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(-7px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 13 - Small cloud */
.cloud13 {
    width: 160px;
    height: 55px;
    top: 5%;
    left: -200px;
    animation: moveCloud13 24s linear infinite;
    animation-delay: -9s;
    border-radius: 80px;
    opacity: 0.9;
}

.cloud13:before {
    width: 80px;
    height: 80px;
    top: -40px;
    left: 20px;
    border-radius: 80px;
}

.cloud13:after {
    width: 90px;
    height: 90px;
    top: -45px;
    right: 20px;
    border-radius: 90px;
}

@keyframes moveCloud13 {
    0% {
        left: -200px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(-5px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 14 - Medium cloud */
.cloud14 {
    width: 250px;
    height: 80px;
    top: 60%;
    left: -300px;
    animation: moveCloud14 40s linear infinite;
    animation-delay: -16s;
    border-radius: 125px;
}

.cloud14:before {
    width: 125px;
    height: 125px;
    top: -62px;
    left: 32px;
    border-radius: 125px;
}

.cloud14:after {
    width: 140px;
    height: 140px;
    top: -70px;
    right: 24px;
    border-radius: 140px;
}

@keyframes moveCloud14 {
    0% {
        left: -300px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(9px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

/* Cloud 15 - Small wispy cloud */
.cloud15 {
    width: 130px;
    height: 42px;
    top: 85%;
    left: -160px;
    animation: moveCloud15 22s linear infinite;
    animation-delay: -5s;
    border-radius: 65px;
    opacity: 0.8;
}

.cloud15:before {
    width: 65px;
    height: 65px;
    top: -32px;
    left: 16px;
    border-radius: 65px;
}

.cloud15:after {
    width: 72px;
    height: 72px;
    top: -36px;
    right: 16px;
    border-radius: 72px;
}

@keyframes moveCloud15 {
    0% {
        left: -160px;
        transform: translateY(0);
    }
    50% {
        transform: translateY(4px);
    }
    100% {
        left: 100%;
        transform: translateY(0);
    }
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--bg-color);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 40px;
    border: 1px solid var(--border-color);
    position: relative;
    z-index: 1;
    backdrop-filter: blur(10px);
    background: rgba(15, 23, 42, 0.85);
}

header {
    margin-bottom: 40px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-content > div {
    text-align: center;
    flex: 1;
    min-width: 200px;
}

.dark-mode-toggle {
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.dark-mode-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.dark-mode-toggle:active {
    transform: scale(0.95);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

.text-area-container {
    margin-bottom: 30px;
}

.text-area-container label {
    display: block;
    margin-bottom: 10px;
    font-weight: 500;
    color: var(--text-secondary);
}

#text-input {
    width: 100%;
    padding: 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface-color);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.3s, box-shadow 0.3s;
}

#text-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.char-count {
    margin-top: 8px;
    text-align: right;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.text-display {
    margin-top: 15px;
    padding: 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--surface-color);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.6;
    min-height: 150px;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.text-display .word {
    padding: 2px 4px;
    border-radius: 4px;
    transition: background-color 0.2s, color 0.2s;
    display: inline-block;
    margin: 1px;
}

.text-display .word.highlighted {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.3) 0%, rgba(118, 75, 162, 0.3) 100%);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
    animation: pulse 1s ease-in-out infinite;
}

.text-display .word.spoken {
    color: var(--text-secondary);
    opacity: 0.7;
}

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

.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
    padding: 25px;
    background: var(--surface-color);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: background 0.3s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
    transition: background 0.3s;
}

input[type="range"]::-moz-range-thumb:hover {
    background: var(--primary-hover);
}

select {
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.3s;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.button-group {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 20px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:not(:disabled):hover {
    background: #475569;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:not(:disabled):hover {
    background: var(--danger-hover);
}

.btn-icon {
    font-size: 1.1rem;
}

.status {
    text-align: center;
    padding: 15px;
    border-radius: 8px;
    background: var(--surface-color);
    color: var(--text-secondary);
    font-size: 0.9rem;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

footer {
    margin-top: 40px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    .container {
        padding: 25px;
    }

    header h1 {
        font-size: 2rem;
    }

    .header-content {
        flex-direction: column;
        align-items: center;
    }

    .dark-mode-toggle {
        margin-top: 10px;
    }

    .controls {
        grid-template-columns: 1fr;
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .moon {
        font-size: 70px;
        top: 10%;
        right: 5%;
    }
}

/* Moon styling - just the 🌙 emoji */
.moon {
    position: absolute;
    top: 15%;
    right: 10%;
    font-size: 100px;
    line-height: 1;
    opacity: 0;
    transition: opacity 1s ease;
    z-index: 1;
    filter: drop-shadow(0 0 30px rgba(255, 255, 220, 0.6));
}

.emoji {
    -webkit-text-fill-color: initial;
    background: none;
    background-clip: initial;
    -webkit-background-clip: initial;
}

/* Stars */
.stars {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 1s ease;
}

.star {
    position: absolute;
    width: 2px;
    height: 2px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 0 4px white;
    animation: twinkle 3s ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% {
        opacity: 0.3;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}
