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

:root {
    /* Color Palette */
    --primary: hsl(260, 100%, 65%);
    --primary-light: hsl(260, 100%, 75%);
    --primary-dark: hsl(260, 100%, 55%);
    --secondary: hsl(340, 100%, 60%);
    --success: hsl(140, 70%, 50%);
    --error: hsl(0, 80%, 60%);
    --warning: hsl(45, 100%, 60%);

    --bg-gradient-start: hsl(220, 40%, 98%);
    --bg-gradient-end: hsl(260, 50%, 96%);

    --card-bg: hsla(0, 0%, 100%, 0.85);
    --card-shadow: hsla(260, 50%, 40%, 0.12);

    --text-dark: hsl(240, 30%, 20%);
    --text-light: hsl(240, 15%, 50%);

    /* Typography */
    --font-primary: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Spacing */
    --spacing-xs: 0.1rem;
    --spacing-sm: 1rem;
    --spacing-md: 1rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;

    /* Border Radius */
    --radius-sm: 0.75rem;
    --radius-md: 1.25rem;
    --radius-lg: 2rem;
    --radius-full: 100px;

    /* Shadows */
    --shadow-sm: 0 2px 8px hsla(260, 50%, 40%, 0.08);
    --shadow-md: 0 4px 16px hsla(260, 50%, 40%, 0.1);
    --shadow-lg: 0 8px 32px hsla(260, 50%, 40%, 0.15);
    --shadow-glow: 0 0 40px hsla(260, 100%, 65%, 0.3);
}

body {
    font-family: var(--font-primary);
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    color: var(--text-dark);
    position: relative;
    overflow-x: hidden;
}

/* Animated background orbs */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.3;
    pointer-events: none;
    z-index: -1;
    animation: float 20s infinite ease-in-out;
}

body::before {
    width: 400px;
    height: 400px;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    top: -100px;
    left: -100px;
}

body::after {
    width: 500px;
    height: 500px;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    bottom: -150px;
    right: -150px;
    animation-delay: -10s;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) rotate(0deg);
    }

    33% {
        transform: translate(30px, -30px) rotate(120deg);
    }

    66% {
        transform: translate(-20px, 20px) rotate(240deg);
    }
}

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

/* Header */
.app-header {
    text-align: center;
    margin-bottom: var(--spacing-xl);
    animation: fadeInDown 0.6s ease-out;
}

.title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--spacing-xs);
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 1.125rem;
    color: var(--text-light);
    font-weight: 600;
}

/* Practice Area */
.practice-area {
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid hsla(0, 0%, 100%, 0.5);
    animation: fadeInUp 0.6s ease-out 0.2s backwards;
}

/* Word Card */
.word-card {
    text-align: center;
    margin-bottom: var(--spacing-lg);
    padding: var(--spacing-xl);
    background: linear-gradient(135deg, hsla(260, 100%, 65%, 0.08), hsla(340, 100%, 60%, 0.08));
    border-radius: var(--radius-md);
    border: 2px solid hsla(260, 100%, 65%, 0.15);
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.word-card:hover {
    border-color: hsla(260, 100%, 65%, 0.3);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.word-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, hsla(0, 0%, 100%, 0.3), transparent);
    transition: left 0.5s;
}

.word-card:hover::before {
    left: 100%;
}

/* First Letter Display */
.first-letter-display {
    position: absolute;
    top: var(--spacing-md);
    left: var(--spacing-md);
    width: 140px;
    height: 100px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    font-weight: 800;
    color: white;
    box-shadow: var(--shadow-md);
    animation: letterPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    letter-spacing: 5px;
}

@keyframes letterPop {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }

    70% {
        transform: scale(1.1) rotate(5deg);
    }

    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* Image Display */
.image-display {
    font-size: clamp(10rem, 10vw, 10rem);
    margin-bottom: var(--spacing-md);
    animation: imageFloat 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 4px 8px hsla(0, 0%, 0%, 0.1));
}

@keyframes imageFloat {
    0% {
        transform: translateY(-30px);
        opacity: 0;
    }

    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.word-label {
    font-size: 1rem;
    color: var(--text-light);
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.current-word {
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.02em;
    animation: scaleIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    white-space: nowrap;
    overflow: visible;
}

/* Highlighted first letter in word */
.first-letter-highlight {
    font-weight: 900;
    font-size: 1.15em;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 2px 4px hsla(260, 100%, 65%, 0.2);
    display: inline-block;
    animation: letterPulse 2s ease-in-out infinite;
}

@keyframes letterPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.08);
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Waveform Visualization */
.waveform-container {
    margin: var(--spacing-md) 0;
    padding: var(--spacing-md);
    background: linear-gradient(135deg, hsla(260, 100%, 65%, 0.05), hsla(340, 100%, 60%, 0.05));
    border-radius: var(--radius-md);
    border: 2px solid hsla(260, 100%, 65%, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

#waveformCanvas {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}

/* Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

/* Microphone Button */
.mic-button {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: var(--spacing-md) var(--spacing-xl);
    border-radius: var(--radius-full);
    font-size: 1.25rem;
    font-weight: 700;
    font-family: var(--font-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    box-shadow: var(--shadow-md);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mic-button::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    opacity: 0;
    transition: opacity 0.3s;
}

.mic-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.mic-button:hover::before {
    opacity: 1;
}

.mic-button:active {
    transform: translateY(0);
}

.mic-button.listening {
    animation: pulse 1.5s infinite;
    background: linear-gradient(135deg, var(--error), hsl(0, 80%, 50%));
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 hsla(0, 80%, 60%, 0.7);
    }

    50% {
        box-shadow: 0 0 0 20px hsla(0, 80%, 60%, 0);
    }
}

.mic-icon {
    width: 28px;
    height: 28px;
    position: relative;
    z-index: 1;
}

.button-text {
    position: relative;
    z-index: 1;
}

/* Next Button */
.next-button {
    background: hsla(0, 0%, 100%, 0.8);
    color: var(--primary);
    border: 2px solid var(--primary);
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: var(--radius-full);
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.next-button:hover {
    background: var(--primary);
    color: white;
    transform: translateX(4px);
}

/* Manual Mode */
.manual-mode {
    width: 100%;
    margin: var(--spacing-md) 0;
}

.manual-mode-label {
    font-size: 1rem;
    color: var(--text-light);
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    text-align: center;
}

.manual-buttons {
    display: flex;
    gap: var(--spacing-md);
    width: 100%;
}

.manual-button {
    flex: 1;
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    font-size: 1.125rem;
    font-weight: 700;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    box-shadow: var(--shadow-md);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.manual-button:active {
    transform: scale(0.95);
}

.correct-btn {
    background: linear-gradient(135deg, var(--success), hsl(140, 70%, 45%));
    color: white;
}

.correct-btn:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.incorrect-btn {
    background: linear-gradient(135deg, var(--error), hsl(0, 80%, 55%));
    color: white;
}

.incorrect-btn:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

/* Status Area */
.status-area {
    min-height: 30px;
    text-align: center;
    margin-top: var(--spacing-sm);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-light);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
}

.status-message {
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-sm);
    animation: fadeIn 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.status-message.listening {
    background: hsla(260, 100%, 65%, 0.1);
    color: var(--primary);
}

.status-message.processing {
    background: hsla(45, 100%, 60%, 0.1);
    color: var(--warning);
}

.status-message.error {
    background: hsla(0, 80%, 60%, 0.1);
    color: var(--error);
}

.status-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* Feedback Area */
.feedback-area {
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--spacing-lg);
}

.feedback {
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    animation: bounceIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: var(--shadow-md);
}

.feedback.correct {
    background: linear-gradient(135deg, hsla(140, 70%, 50%, 0.15), hsla(140, 70%, 45%, 0.1));
    color: hsl(140, 70%, 35%);
    border: 2px solid var(--success);
}

.feedback.incorrect {
    background: linear-gradient(135deg, hsla(0, 80%, 60%, 0.15), hsla(0, 80%, 55%, 0.1));
    color: hsl(0, 80%, 40%);
    border: 2px solid var(--error);
}

@keyframes bounceIn {
    0% {
        transform: scale(0.3);
        opacity: 0;
    }

    50% {
        transform: scale(1.05);
    }

    70% {
        transform: scale(0.9);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Progress Info */
.progress-info {
    display: flex;
    justify-content: space-around;
    gap: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 2px solid hsla(260, 100%, 65%, 0.15);
}

.score {
    text-align: center;
}

.score .label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-light);
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.score .value {
    display: block;
    font-size: 2rem;
    font-weight: 800;
    transition: transform 0.3s ease;
}

.score .value.correct {
    color: var(--success);
}

.score .value.total {
    color: var(--primary);
}

.score .value.updating {
    animation: numberPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes numberPop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.3);
    }

    100% {
        transform: scale(1);
    }
}

/* Instructions */
.instructions {
    margin-top: var(--spacing-lg);
    text-align: center;
    animation: fadeInUp 0.6s ease-out 0.4s backwards;
}

.instructions p {
    background: hsla(0, 0%, 100%, 0.7);
    backdrop-filter: blur(10px);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    color: var(--text-light);
    font-size: 0.95rem;
    line-height: 1.6;
    border: 1px solid hsla(0, 0%, 100%, 0.5);
    box-shadow: var(--shadow-sm);
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Design */
@media (max-width: 640px) {
    .practice-area {
        padding: var(--spacing-lg);
    }

    .mic-button {
        font-size: 1.125rem;
    }

    .feedback {
        font-size: 1.25rem;
    }
}

/* Debug Panel */
.debug-panel {
    margin-top: var(--spacing-xl);
    padding: var(--spacing-lg);
    background: hsla(0, 0%, 100%, 0.7);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-md);
    border: 2px dashed var(--warning);
    box-shadow: var(--shadow-md);
    animation: fadeInUp 0.6s ease-out 0.6s backwards;
}

.debug-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-dark);
    margin-bottom: var(--spacing-md);
    text-align: center;
}

.debug-control {
    margin-bottom: var(--spacing-lg);
}

.debug-control label {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: var(--spacing-xs);
}

.debug-control span {
    color: var(--primary);
    font-weight: 700;
}

.debug-control small {
    display: block;
    font-size: 0.875rem;
    color: var(--text-light);
    margin-top: var(--spacing-xs);
    font-style: italic;
}

.debug-control input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: var(--radius-full);
    background: linear-gradient(90deg, var(--primary-light), var(--primary));
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.debug-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.3s ease;
}

.debug-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: var(--shadow-md);
}

.debug-control input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    border: none;
    transition: all 0.3s ease;
}

.debug-control input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: var(--shadow-md);
}

.debug-control input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: var(--spacing-sm);
    cursor: pointer;
    accent-color: var(--primary);
}

.debug-reset-btn {
    width: 100%;
    padding: var(--spacing-md);
    background: linear-gradient(135deg, var(--warning), hsl(45, 100%, 55%));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
}

.debug-reset-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.debug-reset-btn:active {
    transform: translateY(0);
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Footer */
.app-footer {
    text-align: center;
    margin-top: var(--spacing-xl);
    margin-bottom: var(--spacing-md);
    color: var(--text-light);
    font-size: 0.9rem;
    font-weight: 500;
}

.app-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 700;
    transition: color 0.3s ease;
}

.app-footer a:hover {
    color: var(--primary-dark);
    text-decoration: underline;
}