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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f0f;
    color: #e0e0e0;
    min-height: 100vh;
}

/* ---- Common ---- */

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

a { text-decoration: none; }

.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary {
    background: #4f46e5;
    color: #fff;
}
.btn-primary:hover { background: #4338ca; }

.btn-secondary {
    background: #2a2a2a;
    color: #e0e0e0;
}
.btn-secondary:hover { background: #3a3a3a; }

.btn-start {
    background: #059669;
    color: #fff;
}
.btn-start:hover { background: #047857; }

.btn-danger {
    background: #dc2626;
    color: #fff;
}
.btn-danger:hover { background: #b91c1c; }

/* ---- Script List ---- */

#scripts-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.loading {
    text-align: center;
    color: #666;
    padding: 2rem;
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: #666;
}
.empty-state p { margin-bottom: 1rem; }

.script-card {
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    padding: 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.script-info h3 {
    font-size: 1.1rem;
    margin-bottom: 0.3rem;
}

.script-preview {
    color: #888;
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
}

.word-count {
    color: #666;
    font-size: 0.8rem;
}

.script-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* ---- New Script Form ---- */

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: #aaa;
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.8rem;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 6px;
    color: #e0e0e0;
    font-size: 1rem;
    font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #4f46e5;
}

.form-group textarea {
    resize: vertical;
    min-height: 200px;
}

.form-actions {
    text-align: right;
}

/* ---- Teleprompter ---- */

.teleprompter-body {
    overflow: hidden;
    height: 100vh;
    background: #000;
    user-select: none;
}

#teleprompter {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 2rem;
    position: relative;
}

#progress-container {
    width: 100%;
    margin-bottom: 0.5rem;
}

#progress-bar {
    width: 100%;
    height: 4px;
    background: #222;
    border-radius: 2px;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: #4f46e5;
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

#word-counter {
    text-align: center;
    color: #555;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

#display-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
    cursor: pointer;
    transition: opacity 0.3s, background 0.2s;
}
#display-area:active {
    background: rgba(255, 255, 255, 0.03);
}
#display-area.hidden {
    opacity: 0;
    pointer-events: none;
}

#display-area {
    flex: 1;
    overflow: hidden;
    position: relative;
    padding: 0;
    display: block; /* Change from flex to block for scrolling */
}

#scroll-content {
    padding: 10vh 0 40vh 0; /* Reduced top padding, kept bottom for final word centering */
    text-align: center;
    transition: transform 0.5s cubic-bezier(0.2, 0, 0.2, 1);
    width: 100%;
}

.word {
    display: inline-block;
    font-size: 3rem;
    font-weight: 500;
    color: #222;
    margin: 0.8rem 1.2rem;
    transition: all 0.4s ease;
    cursor: pointer;
    line-height: 1.4;
}

.word.active {
    color: #fff;
    font-size: 6rem;
    font-weight: 800;
    text-shadow: 0 0 40px rgba(79, 70, 229, 0.7);
    transform: scale(1.05);
}

.word.past {
    color: #1a1a1a;
    opacity: 0.2;
}

@media (max-width: 1024px) {
    .word {
        font-size: 2.5rem;
    }
    .word.active {
        font-size: 4.5rem;
    }
}

@media (max-width: 768px) {
    .word {
        font-size: 1.8rem;
    }
    .word.active {
        font-size: 3.5rem;
    }
    #scroll-content {
        padding: 30vh 0;
    }
}

#current-word.animate-in {
    animation: fadeInUp 0.25s ease-out;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#heard-text {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.2rem;
    background: rgba(0, 0, 0, 0.8);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    z-index: 10;
    pointer-events: none;
}
#heard-text.interim {
    color: #555;
    font-style: italic;
}
#heard-text.matched {
    color: #22c55e;
}
#heard-text.no-match {
    color: #ef4444;
}

#next-words {
    display: none;
}
#prev-words {
    display: none;
}

#controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1.5rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}
#controls.hidden {
    display: none;
}

#status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: #666;
}

#status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
#status-indicator.listening {
    background: #22c55e;
    animation: pulse 1.5s infinite;
}
#status-indicator.error {
    background: #ef4444;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

#key-hints {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    color: #444;
}

#key-hints kbd {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-family: inherit;
    font-size: 0.75rem;
    color: #888;
}

/* ---- Mobile Controls ---- */

.mobile-controls {
    display: none;
    justify-content: center;
    gap: 1rem;
    padding-bottom: 2rem;
}

@media (max-width: 1024px) {
    #key-hints {
        display: none;
    }
    .mobile-controls {
        display: flex;
    }
    #teleprompter {
        padding: 1rem;
    }
}

/* Phones */
@media (max-width: 768px) {
    .word {
        font-size: 1.8rem;
    }
    .word.active {
        font-size: 3.5rem;
    }
    #scroll-content {
        padding: 30vh 0;
    }
}

/* Tablets */
@media (min-width: 769px) and (max-width: 1024px) {
    .word {
        font-size: 2.2rem;
    }
    .word.active {
        font-size: 4.5rem;
    }
    #scroll-content {
        padding: 35vh 0;
    }
}

.btn-toggle {
    background: #1a1a1a;
    border: 1px solid #333;
    color: #888;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-toggle.on {
    border-color: #22c55e;
    color: #22c55e;
    background: rgba(34, 197, 94, 0.05);
}

.btn-toggle.off {
    border-color: #ef4444;
    color: #ef4444;
    background: rgba(239, 68, 68, 0.05);
}

/* ---- End Screen ---- */

#end-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    background: #000;
}

#end-screen.hidden {
    display: none;
}

#end-screen h2 {
    font-size: 3rem;
    color: #22c55e;
}
