:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --card-bg: rgba(30, 41, 59, 0.7);
    --primary: #8b5cf6;
    --primary-hover: #7c3aed;
    --secondary: #3b82f6;
    --success: #10b981;
    --error: #ef4444;
    --glass-border: rgba(255, 255, 255, 0.1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding-top: 5vh;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
}

.container {
    width: 100%;
    max-width: 600px;
    padding: 2rem;
    position: relative;
    z-index: 1;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.screen.active {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

h1 {
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

p {
    font-size: 1.2rem;
    color: #94a3b8;
    margin-bottom: 2rem;
}

.small-text {
    font-size: 0.9rem;
    margin-top: 1rem;
    color: #64748b;
}

button {
    font-family: 'Outfit', sans-serif;
    cursor: pointer;
    border: none;
    outline: none;
    transition: all 0.2s ease;
}

.primary-btn {
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: 50px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}

.primary-btn:active {
    transform: translateY(1px);
}

.secondary-btn {
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 12px;
    background: rgba(255,255,255,0.1);
    color: white;
    border: 1px solid var(--glass-border);
}
.secondary-btn:hover {
    background: rgba(255,255,255,0.15);
}

.header {
    width: 100%;
    margin-bottom: 2rem;
    display: flex;
    gap: 1rem;
    align-items: center;
}

.progress-container {
    flex-grow: 1;
    background: var(--card-bg);
    padding: 1rem 1.5rem;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 1rem;
}

#current-group-label {
    font-weight: 600;
    color: var(--secondary);
    min-width: 80px;
}

.progress-bar-bg {
    flex-grow: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 4px;
    transition: width 0.4s ease;
}

#progress-text {
    font-weight: 600;
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
}

.question-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 4rem 2rem;
    width: 100%;
    backdrop-filter: blur(10px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.question-card.correct {
    border-color: var(--success);
    box-shadow: 0 20px 40px rgba(16, 185, 129, 0.2);
    animation: pop 0.4s ease;
}

.question-card.incorrect {
    border-color: var(--error);
    box-shadow: 0 20px 40px rgba(239, 68, 68, 0.2);
    animation: shake 0.4s ease;
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-10px); }
    50% { transform: translateX(10px); }
    75% { transform: translateX(-10px); }
}

.question-text {
    font-size: 5rem;
    font-weight: 800;
    letter-spacing: 2px;
}

.feedback-icon {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    font-size: 2rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.question-card.correct .feedback-icon {
    opacity: 1;
    color: var(--success);
}
.question-card.incorrect .feedback-icon {
    opacity: 1;
    color: var(--error);
}

.listening-indicator {
    margin-top: 2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    border-radius: 50px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    transition: all 0.3s ease;
}

.listening-indicator.active {
    background: rgba(139, 92, 246, 0.1);
    border-color: rgba(139, 92, 246, 0.5);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.2);
}

.mic-icon {
    color: #94a3b8;
    transition: color 0.3s ease;
}

.listening-indicator.active .mic-icon {
    color: var(--primary);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.speech-status-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

#speech-status {
    font-weight: 600;
    color: #cbd5e1;
}

.interim-text {
    font-size: 0.9rem;
    color: var(--secondary);
    min-height: 1.2rem;
    font-style: italic;
    opacity: 0.8;
}

.fallback-input-container {
    margin-top: 2rem;
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

#fallback-input {
    flex-grow: 1;
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.2);
    color: white;
    font-family: 'Outfit', sans-serif;
    font-size: 1.1rem;
    outline: none;
    transition: border-color 0.2s ease;
}
#fallback-input:focus {
    border-color: var(--primary);
}

.success-text {
    background: linear-gradient(135deg, var(--success), #34d399);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Stats */
.stats-overview {
    margin-bottom: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.stat-badge {
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.2s ease;
}
.stat-badge:hover {
    background: rgba(255,255,255,0.1);
    transform: translateY(-2px);
}
.stat-badge.completed {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--success);
}
.stat-badge.completed:hover {
    background: rgba(16, 185, 129, 0.2);
}

.stat-badge.review {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(59, 130, 246, 0.25));
    border-color: var(--primary);
    color: #e2e8f0;
    font-weight: 700;
    box-shadow: 0 0 16px rgba(139, 92, 246, 0.35);
    animation: glow 2s ease-in-out infinite;
}

.stat-badge.review:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.4), rgba(59, 130, 246, 0.4));
    box-shadow: 0 0 24px rgba(139, 92, 246, 0.5);
    transform: translateY(-2px);
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 16px rgba(139, 92, 246, 0.35); }
    50% { box-shadow: 0 0 28px rgba(139, 92, 246, 0.55); }
}

.stop-btn {
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 12px;
    background: rgba(239, 68, 68, 0.1);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.stop-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    transform: translateY(-2px);
}

/* Stats Screen */
.start-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1rem;
}

.view-stats-btn {
    border-radius: 50px;
    padding: 1rem 2rem;
}

.section-title {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    color: var(--text-color);
}

.tables-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    width: 100%;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.table-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    padding: 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.table-row:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.table-name {
    font-size: 1.2rem;
    font-weight: 600;
}

.table-status {
    font-size: 0.9rem;
    color: #94a3b8;
}
.table-status.completed {
    color: var(--success);
}

.details-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    width: 100%;
}

.text-btn {
    background: none;
    color: var(--secondary);
    font-size: 1rem;
    padding: 0.5rem;
    border-radius: 8px;
}
.text-btn:hover {
    background: rgba(59, 130, 246, 0.1);
}

.table-details {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 1rem;
}

.detail-table-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.stats-graphs {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    width: 100%;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.graph-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: rgba(0,0,0,0.1);
    padding: 1rem;
    border-radius: 12px;
}

.graph-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}

.graph-label {
    font-weight: 600;
}

.graph-metrics {
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
}

.accuracy-badges {
    display: flex;
    gap: 0.5rem;
    font-size: 0.8rem;
}
.acc-badge {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    background: rgba(255,255,255,0.05);
}
.acc-badge.correct { color: var(--success); }
.acc-badge.wrong { color: var(--error); }

.bar-track {
    width: 100%;
    height: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.5s ease;
}

.bar-fill.good {
    background: linear-gradient(90deg, var(--success), #34d399);
}
.bar-fill.medium {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
}
.bar-fill.slow {
    background: linear-gradient(90deg, var(--error), #f87171);
}

.tables-list::-webkit-scrollbar, .stats-graphs::-webkit-scrollbar {
    width: 6px;
}
.tables-list::-webkit-scrollbar-thumb, .stats-graphs::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

@media (max-width: 600px) {
    body { padding-top: 2vh; }
    .container { padding: 1rem; max-width: 100%; width: 100%; }
    .question-card { padding: 2rem 1rem; }
    .question-text { font-size: 3.5rem; }
    h1 { font-size: 2.5rem; }
}

@media (max-height: 600px) {
    .question-card { padding: 1.5rem 1rem; }
    .question-text { font-size: 3rem; }
    .listening-indicator { margin-top: 1rem; padding: 0.5rem 1rem; }
    .fallback-input-container { margin-top: 1rem; }
    h1 { font-size: 2rem; }
}

/* Stats Screen Restyle */
#stats-screen.screen.active {
    align-items: stretch;
    justify-content: flex-start;
}

.stats-controls {
    display: flex;
    gap: 0.8rem;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    width: 100%;
}

.tables-dropdown {
    flex: 1;
    min-width: 160px;
    padding: 0.8rem 2.5rem 0.8rem 1.2rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    color: var(--text-color);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M4.646 5.646a.5.5 0 0 1 .708 0L8 8.293l2.646-2.647a.5.5 0 0 1 .708.708l-3 3a.5.5 0 0 1-.708 0l-3-3a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    background-size: 16px;
}
.tables-dropdown:hover {
    border-color: rgba(255,255,255,0.2);
}
.tables-dropdown:focus {
    border-color: var(--primary);
}
.tables-dropdown option {
    background: #1e293b;
    color: var(--text-color);
    padding: 0.5rem;
}

.mode-toggle {
    display: flex;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    background: rgba(255,255,255,0.05);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

.mode-btn {
    padding: 0.8rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    background: transparent;
    color: #94a3b8;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Outfit', sans-serif;
}
.mode-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}
.mode-btn:not(.active):hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-color);
}

.stats-chart-container {
    flex: 1;
    min-height: 400px;
    width: 100%;
    position: relative;
}

@media (min-height: 800px) {
    .stats-chart-container {
        min-height: 500px;
    }
}

/* User Indicator */
#user-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    border-radius: 50px;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    transition: background 0.2s ease;
}
#user-indicator:hover {
    background: rgba(255,255,255,0.1);
}
.user-indicator-emoji {
    font-size: 1.5rem;
}
.user-indicator-name {
    font-weight: 600;
    color: var(--text-color);
}
.user-indicator-hint {
    font-size: 0.8rem;
    color: #64748b;
}

/* User Setup Screen */
#setup-name-input {
    width: 100%;
    max-width: 320px;
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(0,0,0,0.2);
    color: white;
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    outline: none;
    text-align: center;
    transition: border-color 0.2s ease;
}
#setup-name-input:focus {
    border-color: var(--primary);
}
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
    max-width: 320px;
    margin: 1.5rem auto;
}
.emoji-option {
    font-size: 2rem;
    padding: 0.4rem;
    border-radius: 12px;
    background: rgba(255,255,255,0.05);
    border: 2px solid transparent;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
    text-align: center;
    line-height: 1;
}
.emoji-option:hover {
    background: rgba(255,255,255,0.1);
    transform: scale(1.1);
}
.emoji-option.selected {
    border-color: var(--primary);
    background: rgba(139,92,246,0.2);
    transform: scale(1.15);
}

/* User Switcher Screen */
#user-switcher-screen.screen.active {
    align-items: stretch;
    justify-content: flex-start;
}
.user-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    max-height: 50vh;
    overflow-y: auto;
    overflow-x: hidden;
}
.user-list-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: 12px;
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    transition: background 0.2s ease;
}
.user-list-item:hover {
    background: rgba(255,255,255,0.1);
}
.user-list-item .emoji {
    font-size: 2rem;
}
.user-list-item .name {
    font-weight: 600;
    flex-grow: 1;
    text-align: left;
}
.user-list-item .delete-btn {
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    background: rgba(239,68,68,0.1);
    color: var(--error);
    border: 1px solid rgba(239,68,68,0.3);
    font-size: 0.9rem;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
}
.user-list-item .delete-btn:hover {
    background: rgba(239,68,68,0.2);
}
.user-switcher-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

#setup-save-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}
