/* 
 * Maestro - Music Practice Tutor
 * Main Stylesheet
 */

/* ============ CSS Variables ============ */
:root {
    /* Colors - Vibrant, fun palette */
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;
    --secondary: #f59e0b;
    --secondary-light: #fbbf24;
    --accent: #10b981;
    --accent-light: #34d399;

    /* Background gradients */
    --bg-gradient: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%);
    --card-bg: rgba(255, 255, 255, 0.08);
    --card-bg-hover: rgba(255, 255, 255, 0.12);

    /* Text colors */
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;

    /* Chat colors */
    --user-bubble: linear-gradient(135deg, #6366f1, #8b5cf6);
    --maestro-bubble: linear-gradient(135deg, #1e293b, #334155);

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --glow-primary: 0 0 20px rgba(99, 102, 241, 0.5);
    --glow-accent: 0 0 20px rgba(16, 185, 129, 0.5);

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Typography */
    --font-family: 'Nunito', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-size-sm: 14px;
    --font-size-md: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;
    --font-size-xxl: 32px;

    /* Border radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    /* Layout */
    --header-height: 60px;
    --timer-height: 50px;
    --input-height: 180px;
}

/* ============ Reset & Base ============ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-md);
    color: var(--text-primary);
    background: var(--bg-gradient);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 100%;
    margin: 0 auto;
}

/* ============ Header ============ */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--header-height);
    padding: 0 var(--spacing-md);
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo {
    font-size: 28px;
    animation: bounce 2s infinite;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-5px);
    }
}

.app-header h1 {
    font-size: var(--font-size-xl);
    font-weight: 800;
    background: linear-gradient(135deg, var(--secondary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right {
    display: flex;
    align-items: center;
}

.stats-mini {
    display: flex;
    gap: var(--spacing-md);
    font-weight: 700;
    font-size: var(--font-size-sm);
}

.stats-mini .streak {
    color: #fb923c;
}

.stats-mini .points {
    color: var(--secondary-light);
}

.stats-mini .level {
    color: var(--accent-light);
    background: rgba(16, 185, 129, 0.2);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

/* ============ Timer Bar ============ */
.timer-bar {
    position: relative;
    height: var(--timer-height);
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--spacing-md);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.timer-progress {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    opacity: 0.3;
    transition: width 0.5s ease;
}

.timer-text {
    display: flex;
    align-items: baseline;
    gap: var(--spacing-xs);
    font-weight: 700;
    font-size: var(--font-size-lg);
    z-index: 1;
}

#timer-display {
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.timer-goal {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.timer-instruments {
    display: flex;
    gap: var(--spacing-md);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    z-index: 1;
}

/* ============ Chat Container ============ */
.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--spacing-md);
    scroll-behavior: smooth;
}

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    max-width: 800px;
    margin: 0 auto;
}

/* ============ Chat Messages ============ */
.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
}

.message.maestro {
    align-self: flex-start;
}

.message-bubble {
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    line-height: 1.5;
}

.message.user .message-bubble {
    background: var(--user-bubble);
    border-bottom-right-radius: var(--spacing-xs);
}

.message.maestro .message-bubble {
    background: var(--maestro-bubble);
    border-bottom-left-radius: var(--spacing-xs);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.message-sender {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin-bottom: var(--spacing-xs);
    padding: 0 var(--spacing-sm);
}

.message.maestro .message-sender {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.message.maestro .message-sender::before {
    content: '🎼';
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: var(--spacing-md);
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-8px);
    }
}

/* ============ Input Area ============ */
.input-area {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

/* Action Buttons */
.action-buttons {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 120px;
}

.action-btn:hover,
.action-btn:active {
    background: var(--card-bg-hover);
    transform: scale(1.02);
}

.action-btn.recording {
    border-color: rgba(239, 68, 68, 0.5);
}

.action-btn.recording:hover {
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.3);
}

.btn-icon {
    font-size: 28px;
}

.btn-label {
    font-weight: 600;
}

/* Voice Input */
.voice-input-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
}

.voice-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    width: 100%;
    max-width: 300px;
    padding: var(--spacing-md) var(--spacing-lg);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: var(--radius-full);
    color: white;
    font-family: inherit;
    font-size: var(--font-size-lg);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--glow-primary);
}

.voice-btn:hover,
.voice-btn:active {
    transform: scale(1.02);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.6);
}

.voice-btn.listening {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 20px rgba(239, 68, 68, 0.5);
    }

    50% {
        box-shadow: 0 0 40px rgba(239, 68, 68, 0.8);
    }
}

.voice-icon {
    font-size: 24px;
}

.voice-status {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    min-height: 20px;
}

/* Text Input (fallback) */
.text-input-area {
    display: flex;
    gap: var(--spacing-sm);
}

#text-input {
    flex: 1;
    padding: var(--spacing-md);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--font-size-md);
    outline: none;
    transition: all 0.2s ease;
}

#text-input:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.15);
}

#text-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 50px;
    height: 50px;
    background: var(--primary);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.send-btn:hover {
    background: var(--primary-light);
    transform: scale(1.05);
}

/* ============ Modals ============ */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-lg);
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-lg);
    padding: var(--spacing-xl);
    text-align: center;
    max-width: 400px;
    width: 100%;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Recording Modal */
.recording-animation {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.recording-circle {
    width: 20px;
    height: 20px;
    background: #ef4444;
    border-radius: 50%;
    animation: recordingPulse 1s infinite;
}

.recording-circle:nth-child(2) {
    animation-delay: 0.2s;
}

.recording-circle:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes recordingPulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.3);
        opacity: 0.7;
    }
}

.recording-text {
    font-size: var(--font-size-lg);
    margin-bottom: var(--spacing-sm);
}

.recording-time {
    font-size: var(--font-size-xxl);
    font-weight: 800;
    color: var(--secondary);
    margin-bottom: var(--spacing-lg);
}

.recording-buttons {
    display: flex;
    gap: var(--spacing-md);
    justify-content: center;
}

/* Level Up Modal */
.levelup-animation {
    font-size: 64px;
    animation: celebrate 0.5s ease infinite;
}

@keyframes celebrate {

    0%,
    100% {
        transform: scale(1) rotate(0deg);
    }

    25% {
        transform: scale(1.1) rotate(-5deg);
    }

    75% {
        transform: scale(1.1) rotate(5deg);
    }
}

.levelup-modal-content h2 {
    font-size: var(--font-size-xxl);
    color: var(--secondary);
    margin: var(--spacing-md) 0;
}

.levelup-text {
    font-size: var(--font-size-lg);
    margin-bottom: var(--spacing-sm);
}

.levelup-title {
    font-size: var(--font-size-xl);
    font-weight: 800;
    color: var(--accent-light);
    margin-bottom: var(--spacing-lg);
}

/* Badge Modal */
.badge-animation {
    font-size: 72px;
    animation: badgeReveal 0.5s ease;
}

@keyframes badgeReveal {
    from {
        transform: scale(0) rotate(-180deg);
    }

    to {
        transform: scale(1) rotate(0deg);
    }
}

.badge-modal-content h2 {
    font-size: var(--font-size-xl);
    color: var(--secondary);
    margin: var(--spacing-md) 0;
}

.badge-name {
    font-size: var(--font-size-lg);
    font-weight: 700;
    margin-bottom: var(--spacing-sm);
}

.badge-description {
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

/* Modal Buttons */
.modal-btn {
    padding: var(--spacing-md) var(--spacing-xl);
    border: none;
    border-radius: var(--radius-full);
    font-family: inherit;
    font-size: var(--font-size-md);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
}

.modal-btn.primary:hover {
    transform: scale(1.05);
    box-shadow: var(--glow-primary);
}

.modal-btn.cancel {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
}

.modal-btn.cancel:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ============ Responsive Adjustments ============ */
@media (max-width: 600px) {
    .action-btn {
        min-width: 100px;
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .btn-icon {
        font-size: 24px;
    }

    .stats-mini {
        font-size: 12px;
        gap: var(--spacing-sm);
    }
}

/* iPad specific */
@media (min-width: 768px) {
    .chat-messages {
        max-width: 700px;
    }

    .action-buttons {
        gap: var(--spacing-lg);
    }

    .action-btn {
        min-width: 150px;
        padding: var(--spacing-md) var(--spacing-xl);
    }

    .voice-btn {
        max-width: 350px;
    }
}

/* Landscape mode */
@media (orientation: landscape) and (max-height: 500px) {
    .input-area {
        flex-direction: row;
        flex-wrap: wrap;
        padding: var(--spacing-sm);
    }

    .action-buttons {
        flex: 0;
    }

    .voice-input-area {
        flex: 1;
    }

    .text-input-area {
        width: 100%;
    }
}

/* ============ Utility Classes ============ */
.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Sheet Music Modal */
.sheet-music-modal-content {
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.sheet-music-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 20px 0;
    overflow-y: auto;
    justify-content: center;
    min-height: 150px;
}

.sheet-music-thumbnail {
    position: relative;
    width: 100px;
    height: 140px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.sheet-music-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-page-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
}

.sheet-music-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
}

.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
}

.modal-btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Start Session Overlay */
.start-session-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.start-content {
    animation: float 3s ease-in-out infinite;
    padding: 20px;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.start-icon {
    font-size: 80px;
    margin-bottom: 20px;
    display: block;
}

.start-content h1 {
    font-size: 32px;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--secondary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.start-content p {
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-size: 18px;
}

.start-btn {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    padding: 15px 40px;
    border-radius: 30px;
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    transition: transform 0.2s;
}

.start-btn:active {
    transform: scale(0.95);
}