:root {
    --primary-color: #6366f1;
    --primary-dark: #4f46e5;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-light: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-color);
    line-height: 1.4;
    min-height: 100vh;
    padding: 1.5rem 1rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1.5rem 1.5rem;
    text-align: center;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    line-height: 1.2;
}

.subtitle {
    font-size: 0.95rem;
    opacity: 0.95;
    line-height: 1.3;
}

main {
    padding: 1.5rem;
}

section {
    background: var(--bg-color);
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
    border: 1px solid var(--border-color);
}

h2 {
    color: var(--text-color);
    font-size: 1.35rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    line-height: 1.3;
}

/* Settings Panel */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.875rem;
    margin-bottom: 1rem;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.setting-group label {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.875rem;
    line-height: 1.2;
}

.setting-group select,
.setting-group input {
    padding: 0.5rem 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
    line-height: 1.3;
}

/* Prevent zoom on iOS when focusing inputs */
@media screen and (max-width: 768px) {
    .setting-group select,
    .setting-group input {
        font-size: 16px;
    }
}

.setting-group select:focus,
.setting-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1.3;
}

.checkbox-label input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

.checkbox-label span {
    user-select: none;
}

/* Buttons */
button {
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1.3;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

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

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

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

.secondary-btn:hover {
    background: #475569;
}

.control-btn {
    background: var(--card-bg);
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 0.5rem 1rem;
}

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

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Exercise Panel */
.exercise-panel {
    background: var(--bg-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
}

.exercise-header {
    margin-bottom: 1.25rem;
}

.exercise-header h2 {
    margin-bottom: 0.75rem;
    color: var(--primary-color);
}

.playback-status {
    padding: 0.5rem 0.875rem;
    background: var(--bg-color);
    border-radius: 6px;
    margin-bottom: 0.875rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-color);
    border-left: 4px solid var(--primary-color);
    line-height: 1.3;
}

.playback-status.playing {
    background: #dbeafe;
    border-left-color: #2563eb;
    color: #1e40af;
}

/* Answer Table */
.answer-table-container {
    overflow-x: auto;
    margin-top: 1.25rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

/* Bottom controls */
.bottom-controls {
    margin-top: 1.25rem;
}

.answer-table {
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
    table-layout: fixed;
    min-width: max-content;
}

.answer-table thead {
    background: var(--primary-color);
    color: white;
}

.answer-table th,
.answer-table td {
    padding: 0.4rem 0.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    min-height: 70px;
    vertical-align: middle;
}

/* Desktop: Fixed width for columns and fixed button sizes */
@media (min-width: 769px) {
    .answer-table th:nth-child(1),
    .answer-table td:nth-child(1) {
        width: 50px;
        min-width: 50px;
        max-width: 50px;
    }

    .answer-table th:nth-child(2),
    .answer-table td:nth-child(2) {
        width: 240px;
        min-width: 240px;
        max-width: 240px;
    }

    /* Other columns (previous tries) are flexible */
    .answer-table th:nth-child(n+3),
    .answer-table td:nth-child(n+3) {
        width: 80px;
        min-width: 80px;
    }

    /* Desktop: Keep fixed button sizes */
    .interval-btn {
        min-width: 30px;
        width: 30px;
        height: 26px;
        flex: none;
    }

    .interval-btn-spacer {
        min-width: 30px;
        width: 30px;
        flex: none;
    }

    .interval-selector {
        gap: 0.125rem;
        width: auto;
    }

    .interval-row {
        gap: 0.15rem;
        width: auto;
    }
}

.answer-table th {
    font-weight: 600;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
}

.answer-table tbody tr:hover {
    background: var(--bg-color);
}

.answer-table tbody tr.current-row {
    background: #fef3c7;
}

.answer-table tbody tr.completed-row {
    background: #f3f4f6;
}

.answer-table tbody tr.correct-row {
    background: #d1fae5;
}

.answer-table tbody tr.incorrect-row {
    background: #fee2e2;
}

.answer-table select {
    padding: 0.375rem 0.5rem;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.875rem;
    min-width: 140px;
    background: white;
    line-height: 1.3;
}

.answer-table select:disabled {
    cursor: not-allowed;
}

/* Interval Button Selector */
.interval-selector {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    justify-content: center;
    align-items: center;
}

.interval-row {
    display: flex;
    gap: 0.15rem;
    justify-content: center;
}

.interval-btn {
    padding: 0.2rem 0.3rem;
    border: 2px solid transparent;
    border-radius: 3px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-width: 30px;
    width: 30px;
    height: 26px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.interval-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

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

.interval-btn.selected {
    border-color: #1e40af;
    box-shadow: 0 0 0 2px rgba(30, 64, 175, 0.2);
    transform: scale(1.05);
}

.interval-btn.correct-answer {
    background: #d1fae5 !important;
    color: #065f46 !important;
    border-color: #065f46 !important;
}

.interval-btn-spacer {
    min-width: 30px;
    width: 30px;
}

/* Compact answer badge for previous tries */
.answer-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #d1fae5;
    color: #065f46;
    border: 2px solid #065f46;
}

/* Interval color classes */
.interval-unison {
    background: #f3f4f6;
    color: #374151;
    border-color: #d1d5db;
}

.interval-minor {
    background: #dbeafe;
    color: #1e40af;
    border-color: #93c5fd;
}

.interval-major {
    background: #d1fae5;
    color: #065f46;
    border-color: #6ee7b7;
}

.interval-perfect {
    background: #e9d5ff;
    color: #6b21a8;
    border-color: #c084fc;
}

.interval-tritone {
    background: #fee2e2;
    color: #991b1b;
    border-color: #fca5a5;
}

.interval-octave {
    background: #fef3c7;
    color: #92400e;
    border-color: #fcd34d;
}


.result-info {
    padding: 1rem;
    background: var(--bg-color);
    border-radius: 6px;
    border-left: 4px solid var(--primary-color);
}

.result-info h3 {
    margin: 0 0 0.375rem 0;
    color: var(--primary-color);
    font-size: 1.1rem;
    line-height: 1.3;
}

.result-icon {
    font-size: 1.25rem;
}

.play-type-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.2;
}

.play-type-melodic {
    background: #dbeafe;
    color: #1e40af;
}

.answer-table tbody tr.playing-row {
    background: #dbeafe;
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}
.controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.875rem;
    flex-wrap: wrap;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.375rem;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 0.3s;
}

.status-text {
    color: var(--text-light);
    font-size: 0.85rem;
}

/* Piano Keyboard */
.piano-keyboard {
    display: flex;
    gap: 2px;
    justify-content: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--card-bg);
    border-radius: 8px;
    overflow-x: auto;
}

.piano-key {
    min-width: 40px;
    height: 120px;
    border: 2px solid #333;
    border-radius: 0 0 4px 4px;
    cursor: pointer;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    transition: all 0.1s;
    position: relative;
}

.piano-key.white {
    background: white;
    color: #333;
}

.piano-key.black {
    background: #333;
    color: white;
    height: 80px;
    margin: 0 -12px;
    z-index: 1;
    min-width: 28px;
}

.piano-key:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.piano-key:active {
    transform: translateY(0);
    background: var(--primary-color);
    color: white;
}

/* Answer Display */
.answer-display {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    align-items: center;
}

.user-answer {
    flex: 1;
    min-height: 60px;
    padding: 1rem;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.user-answer .placeholder {
    color: var(--text-light);
    font-style: italic;
}

.note-badge {
    background: var(--primary-color);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.note-badge .remove {
    cursor: pointer;
    font-weight: bold;
}

.answer-actions {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Results */
.results-content {
    padding: 1rem;
}

.result-correct {
    background: #d1fae5;
    color: var(--success-color);
    padding: 1.5rem;
    border-radius: 8px;
    border: 2px solid var(--success-color);
    font-size: 1.1rem;
    font-weight: 600;
}

.result-incorrect {
    background: #fee2e2;
    color: var(--error-color);
    padding: 1.5rem;
    border-radius: 8px;
    border: 2px solid var(--error-color);
}

.score-display {
    font-size: 2rem;
    font-weight: 700;
    margin: 1rem 0;
}

.answer-comparison {
    margin-top: 1rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.answer-column {
    padding: 1rem;
    background: var(--card-bg);
    border-radius: 8px;
}

.answer-column h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-light);
}

/* Notation Display */
.notation-display {
    min-height: 200px;
    background: var(--card-bg);
    border-radius: 8px;
    padding: 2rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
    align-items: center;
}

.note-visual {
    text-align: center;
}

.note-symbol {
    font-size: 3rem;
    line-height: 1;
}

.note-name {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-top: 0.5rem;
}

/* Footer */
footer {
    background: var(--bg-color);
    padding: 1rem;
    text-align: center;
    color: var(--text-light);
    border-top: 1px solid var(--border-color);
    font-size: 0.875rem;
    line-height: 1.3;
}

footer i {
    color: var(--error-color);
}

/* Results Panel */
.results-panel {
    padding: 1.25rem;
    animation: fadeIn 0.5s ease-in;
}

.results-panel h2 {
    color: var(--primary-color);
    margin-bottom: 1rem;
    text-align: center;
}

.results-summary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 1.25rem;
    border-radius: 10px;
    margin-bottom: 1.25rem;
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
}

.results-table-container {
    overflow-x: auto;
    margin-bottom: 1.25rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.results-table thead {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.results-table th,
.results-table td {
    padding: 0.625rem 0.875rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.results-table th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8125rem;
    letter-spacing: 0.05em;
    line-height: 1.2;
}

.results-table tbody tr:hover {
    background: #f8fafc;
}

.results-table tbody tr:last-child td {
    border-bottom: none;
}

.try-badge {
    display: inline-block;
    padding: 0.2rem 0.625rem;
    border-radius: 16px;
    font-weight: 600;
    font-size: 0.8125rem;
    line-height: 1.3;
}

.try-badge.first-try {
    background: #d1fae5;
    color: #065f46;
}

.try-badge.second-try {
    background: #fef3c7;
    color: #92400e;
}

.try-badge.later-try {
    background: #fee2e2;
    color: #991b1b;
}

.try-badge.not-solved {
    background: #f3f4f6;
    color: #6b7280;
}

.incorrect-count {
    display: inline-block;
    padding: 0.2rem 0.625rem;
    border-radius: 16px;
    background: #fee2e2;
    color: #991b1b;
    font-weight: 600;
    font-size: 0.8125rem;
    line-height: 1.3;
}

.incorrect-count.zero {
    background: #d1fae5;
    color: #065f46;
}

/* Insights Section */
.insights-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 0.875rem;
    margin-bottom: 1.25rem;
}

.insight-card {
    padding: 0.875rem 1rem;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    box-shadow: var(--shadow);
}

.insight-card i {
    font-size: 1.25rem;
    margin-bottom: 0.125rem;
}

.insight-card strong {
    font-size: 0.9375rem;
    display: block;
    line-height: 1.3;
}

.insight-detail {
    font-size: 0.8125rem;
    opacity: 0.9;
    line-height: 1.3;
}

.insight-card.success {
    background: linear-gradient(135deg, #d1fae5, #a7f3d0);
    color: #065f46;
}

.insight-card.challenge {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    color: #92400e;
}

.insight-card.expert {
    background: linear-gradient(135deg, #fce7f3, #fbcfe8);
    color: #831843;
}

/* Responsive Design for Mobile */
@media (max-width: 768px) {
    body {
        padding: 0.5rem;
    }

    .container {
        border-radius: 8px;
    }

    header {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    main {
        padding: 0.75rem;
    }

    section {
        padding: 0.875rem;
        margin-bottom: 0.875rem;
    }

    h2 {
        font-size: 1.15rem;
    }

    /* Settings - stack vertically */
    .settings-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    /* Make buttons touch-friendly (minimum 44x44px) */
    button {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
        min-height: 44px;
    }

    .primary-btn {
        width: 100%;
    }

    /* Exercise panel - reduce padding on mobile */
    .exercise-panel {
        padding: 0.875rem;
        padding-bottom: 0.875rem;
    }

    /* Bottom controls on mobile */
    .bottom-controls {
        margin: 0 -0.875rem 0 -0.875rem;
        padding: 1rem 0.875rem;
        background: var(--bg-color);
    }

    .exercise-header h2 {
        font-size: 1.15rem;
    }

    /* Controls */
    .controls {
        flex-direction: column;
        gap: 0.5rem;
    }

    .controls button {
        width: 100%;
    }

    /* Move table outside exercise panel padding on mobile */
    .exercise-panel {
        padding: 0.875rem;
        padding-bottom: 0;
    }

    .answer-table-container {
        margin: 0.75rem -0.875rem 0 -0.875rem;
        width: calc(100% + 1.75rem);
        overflow-x: auto;
    }

    .answer-table {
        width: 100%;
        table-layout: fixed;
    }

    .answer-table th,
    .answer-table td {
        padding: 0.5rem 0.4rem;
        font-size: 0.75rem;
    }

    /* Mobile 2-column layout: # | Current Try */
    .answer-table th:nth-child(1),
    .answer-table td:nth-child(1) {
        width: 15%;
        min-width: 40px;
    }

    .answer-table th:nth-child(2),
    .answer-table td:nth-child(2) {
        width: 85%;
    }

    /* Interval buttons - use grid for perfectly equal button sizes */
    .interval-selector {
        width: 100%;
        gap: 0.2rem;
    }

    .interval-row {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(7, 1fr);
        gap: 0.2rem;
    }

    .interval-btn {
        min-width: 0;
        width: 100%;
        height: 36px;
        font-size: 0.75rem;
        padding: 0.25rem 0.3rem;
    }

    .interval-btn-spacer {
        min-width: 0;
    }

    /* Piano keyboard */
    .piano-keyboard {
        justify-content: flex-start;
        padding: 0.75rem;
    }

    .piano-key {
        min-width: 35px;
        height: 100px;
    }

    .piano-key.black {
        height: 65px;
        min-width: 24px;
    }

    /* Answer comparison */
    .answer-comparison {
        grid-template-columns: 1fr;
    }

    /* Results panel */
    .results-panel {
        padding: 0.875rem;
    }

    .results-summary {
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
    }

    .results-table th,
    .results-table td {
        padding: 0.5rem;
        font-size: 0.8125rem;
    }

    /* Insights - stack on very small screens */
    .insights-section {
        grid-template-columns: 1fr;
    }

    .insight-card {
        padding: 0.75rem 0.875rem;
    }

    /* Playback status */
    .playback-status {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }

    /* Answer badge - larger on mobile */
    .answer-badge {
        font-size: 0.85rem;
        padding: 0.3rem 0.6rem;
    }
}

/* Extra small devices (phones in portrait) */
@media (max-width: 480px) {
    header h1 {
        font-size: 1.25rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    h2 {
        font-size: 1rem;
    }

    button {
        font-size: 0.95rem;
        padding: 0.625rem 1.25rem;
    }

    /* Adjust button height and font for very small screens */
    .interval-btn {
        height: 32px;
        font-size: 0.7rem;
    }

    .interval-row {
        gap: 0.15rem;
    }

    .interval-selector {
        gap: 0.15rem;
    }

    .answer-table th,
    .answer-table td {
        padding: 0.4rem 0.2rem;
        font-size: 0.7rem;
        min-height: 55px;
    }

    /* Mobile 2-column layout adjustments */
    .answer-table th:nth-child(1),
    .answer-table td:nth-child(1) {
        width: 12%;
        min-width: 35px;
    }

    .answer-table th:nth-child(2),
    .answer-table td:nth-child(2) {
        width: 88%;
    }

    .results-table th,
    .results-table td {
        padding: 0.4rem;
        font-size: 0.75rem;
    }
}

/* Landscape mobile devices */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 0.5rem;
    }

    header {
        padding: 0.75rem;
    }

    header h1 {
        font-size: 1.35rem;
    }

    .subtitle {
        font-size: 0.8rem;
    }

    main {
        padding: 0.75rem;
    }

    section {
        padding: 0.75rem;
    }

    /* In landscape, we can use 2 columns for settings */
    .settings-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.625rem;
    }

    /* Smaller buttons in landscape to fit more content */
    button {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
        min-height: 40px;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

section {
    animation: fadeIn 0.3s ease-out;
}
