/* --- Reset & base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #1a1a2e;
    --bg2: #16213e;
    --bg3: #0f3460;
    --fg: #e0e0e0;
    --fg2: #a0a0b0;
    --accent: #e94560;
    --accent2: #0f3460;
    --success: #4caf50;
    --error: #f44336;
    --warning: #ff9800;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,.3);
}

html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Layout --- */
#app { max-width: 900px; margin: 0 auto; padding: 0 1rem 2rem; }

/* --- Nav --- */
.nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0;
    border-bottom: 1px solid var(--bg3);
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.nav-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
    margin-right: auto;
}
.nav a, .nav-link {
    color: var(--fg2);
    font-size: 0.9rem;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
}
.nav a:hover, .nav-link:hover { color: var(--fg); text-decoration: none; }
.nav-user {
    font-size: 0.85rem;
    color: var(--fg2);
    padding-left: 1rem;
    border-left: 1px solid var(--bg3);
}

/* --- Cards / menu --- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}
.card {
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform .15s, box-shadow .15s;
    border: 1px solid transparent;
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,.4);
    border-color: var(--accent);
}
.card h3 { margin-bottom: .5rem; font-size: 1.1rem; }
.card p { color: var(--fg2); font-size: 0.9rem; }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .5rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    transition: background .15s, transform .1s;
    color: #fff;
    background: var(--accent);
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: scale(.97); }
.btn-sm { padding: .35rem .75rem; font-size: .85rem; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
}
.btn-outline:hover { background: var(--accent); color: #fff; }
.btn-success { background: var(--success); }
.btn-ghost {
    background: transparent;
    color: var(--fg2);
    padding: .35rem .75rem;
}
.btn-ghost:hover { color: var(--fg); background: var(--bg3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Forms / inputs --- */
input, select {
    background: var(--bg);
    border: 1px solid var(--bg3);
    color: var(--fg);
    padding: .5rem .75rem;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

label {
    display: block;
    font-size: 0.85rem;
    color: var(--fg2);
    margin-bottom: .25rem;
}

/* --- Exercise layout --- */
.exercise {
    max-width: 600px;
}
.exercise-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.exercise-header h2 { font-size: 1.3rem; }

.settings-panel {
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}
.settings-panel label {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--fg);
    font-size: .9rem;
    cursor: pointer;
}
.settings-panel input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
}

.answer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: .5rem;
    margin: 1.5rem 0;
}
.answer-btn {
    padding: .75rem .5rem;
    background: var(--bg2);
    border: 1px solid var(--bg3);
    border-radius: var(--radius);
    color: var(--fg);
    font-size: 1rem;
    cursor: pointer;
    text-align: center;
    transition: all .15s;
    font-family: inherit;
}
.answer-btn:hover { border-color: var(--accent); background: var(--bg3); }
.answer-btn.correct { background: var(--success); border-color: var(--success); color: #fff; }
.answer-btn.wrong { background: var(--error); border-color: var(--error); color: #fff; }
.answer-btn:disabled { cursor: default; }

.feedback {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin: 1rem 0;
    font-weight: 500;
}
.feedback.correct { background: rgba(76,175,80,.15); color: var(--success); }
.feedback.wrong { background: rgba(244,67,54,.15); color: var(--error); }

.score-bar {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1rem;
    font-size: .9rem;
    color: var(--fg2);
}
.score-bar span { font-weight: 600; color: var(--fg); }

/* --- User picker --- */
.user-picker {
    max-width: 400px;
    margin: 4rem auto;
    text-align: center;
}
.user-picker h1 {
    font-size: 1.8rem;
    margin-bottom: .5rem;
}
.user-picker p {
    color: var(--fg2);
    margin-bottom: 2rem;
}
.user-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin-bottom: 1.5rem;
}
.user-list button {
    padding: .75rem 1rem;
    background: var(--bg2);
    border: 1px solid var(--bg3);
    border-radius: var(--radius);
    color: var(--fg);
    font-size: 1rem;
    cursor: pointer;
    text-align: left;
    transition: all .15s;
    font-family: inherit;
}
.user-list button:hover { border-color: var(--accent); }
.user-form {
    display: flex;
    gap: .5rem;
}
.user-form input { flex: 1; }

/* --- Piano roll --- */
.piano-roll-wrap {
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
}
.piano-roll-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: .75rem;
    flex-wrap: wrap;
}
.piano-roll-controls label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .85rem;
    color: var(--fg2);
    margin-bottom: 0;
}
.piano-roll-controls input[type="range"] {
    width: 100px;
    accent-color: var(--accent);
}
canvas.piano-roll {
    display: block;
    border-radius: 4px;
    cursor: crosshair;
}

/* --- Melody list --- */
.melody-list {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    margin: 1rem 0;
}
.melody-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem .75rem;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: .9rem;
}
.melody-item .name { flex: 1; }

/* --- Star rating --- */
.star-rating {
    display: flex;
    gap: .25rem;
    margin: 1rem 0;
}
.star-rating button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--bg3);
    transition: color .1s;
}
.star-rating button.active { color: var(--warning); }
.star-rating button:hover { color: var(--warning); }

/* --- Progress / charts --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}
.stat-card {
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}
.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}
.stat-card .label {
    font-size: .85rem;
    color: var(--fg2);
}
.chart-container {
    background: var(--bg2);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
}
.chart-container h3 {
    margin-bottom: .75rem;
    font-size: 1rem;
}

/* --- Responsive --- */
@media (max-width: 600px) {
    .answer-grid { grid-template-columns: repeat(3, 1fr); }
    .card-grid { grid-template-columns: 1fr; }
    .nav { gap: .5rem; }
    .piano-roll-controls { gap: .5rem; }
}
