/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #1a1a2e;
    --bg-card: #16213e;
    --bg-card-hover: #1a2744;
    --bg-input: #0f1a30;
    --accent: #e94560;
    --accent-glow: rgba(233, 69, 96, 0.3);
    --accent2: #0f9b8e;
    --text: #eaeaea;
    --text-dim: #8892a4;
    --text-muted: #5a6578;
    --border: #2a3a5c;
    --positive: #4ade80;
    --negative: #f87171;
    --radius: 10px;
    --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

html { font-size: 15px; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* === HEADER === */
header {
    background: linear-gradient(135deg, #16213e 0%, #1a1a2e 100%);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.logo {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    white-space: nowrap;
}
.logo span { color: var(--accent); }

/* === CONTROLS === */
.controls {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-wrap: wrap;
    flex: 1;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.control-group label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

select, button {
    font-family: inherit;
    font-size: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text);
    padding: 0.45rem 0.7rem;
    cursor: pointer;
    transition: all 0.15s;
}

select:hover, select:focus { border-color: var(--accent); outline: none; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
    padding: 0.45rem 1.2rem;
}
.btn-primary:hover { background: #d13a52; box-shadow: 0 0 12px var(--accent-glow); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-stop {
    background: transparent;
    border-color: var(--accent);
    color: var(--accent);
}
.btn-stop:hover { background: rgba(233,69,96,0.15); }

/* === MAIN LAYOUT === */
main {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 1rem;
    padding: 1rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 65px);
}

@media (max-width: 900px) {
    main { grid-template-columns: 1fr; }
    header { padding: 0.8rem 1rem; }
    main { padding: 0.8rem 1rem; }
}

/* === LEFT PANEL === */
.panel-left {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Description card */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem 1.5rem;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 1.2rem;
    margin-bottom: 0.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card .period {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card .description {
    margin-top: 0.8rem;
    font-size: 0.9rem;
    color: var(--text-dim);
    line-height: 1.7;
}
.card .description strong { color: var(--text); }
.card .description em { color: var(--accent); font-style: normal; }

/* === COMPARISON TABLE === */
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.comparison-table th {
    padding: 0.5rem 0.4rem;
    text-align: center;
    color: var(--text-dim);
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.comparison-table td {
    padding: 0.35rem 0.4rem;
    text-align: center;
    border-bottom: 1px solid rgba(42,58,92,0.5);
    white-space: nowrap;
}

.comparison-table tr:hover td { background: rgba(233,69,96,0.05); }

.comparison-table .note-name {
    font-weight: 700;
    color: var(--text);
    text-align: left;
    padding-left: 0.8rem;
}

.comparison-table .active-col {
    background: rgba(233,69,96,0.08);
    color: var(--text);
    font-weight: 600;
}

.cents-positive { color: var(--positive); }
.cents-negative { color: var(--negative); }
.cents-zero { color: var(--text-muted); }

/* === RIGHT PANEL === */
.panel-right {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Examples */
.examples-grid {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.example-btn {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
    text-align: left;
    padding: 0.7rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}

.example-btn:hover {
    border-color: var(--accent);
    background: var(--bg-card-hover);
    transform: translateX(3px);
}

.example-btn.playing {
    border-color: var(--accent);
    background: rgba(233,69,96,0.1);
    box-shadow: 0 0 15px var(--accent-glow);
}

.example-btn .icon {
    font-size: 1.4rem;
    width: 2rem;
    text-align: center;
    flex-shrink: 0;
}

.example-btn .info { flex: 1; min-width: 0; }

.example-btn .info .name {
    font-weight: 600;
    font-size: 0.85rem;
}

.example-btn .info .desc {
    font-size: 0.72rem;
    color: var(--text-dim);
    line-height: 1.4;
    margin-top: 2px;
}

/* === KEYBOARD VISUALIZATION === */
.keyboard-container {
    padding: 0.8rem 0;
}

.keyboard {
    display: flex;
    position: relative;
    height: 100px;
    margin: 0 auto;
    max-width: 100%;
}

.key {
    position: relative;
    border: 1px solid #333;
    border-radius: 0 0 4px 4px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding-bottom: 6px;
    user-select: none;
}

.key.white {
    background: linear-gradient(180deg, #f5f5f5 0%, #e8e8e8 100%);
    width: calc(100% / 7);
    height: 100%;
    z-index: 1;
}

.key.black {
    background: linear-gradient(180deg, #333 0%, #1a1a1a 100%);
    width: calc(100% / 12);
    height: 62%;
    position: absolute;
    z-index: 2;
    border-radius: 0 0 3px 3px;
}

.key.white:hover { background: linear-gradient(180deg, #fff 0%, #f0f0f0 100%); }
.key.black:hover { background: linear-gradient(180deg, #444 0%, #2a2a2a 100%); }
.key.white:active, .key.white.active { background: linear-gradient(180deg, #ffe0e6 0%, #ffd0d8 100%); }
.key.black:active, .key.black.active { background: linear-gradient(180deg, #e94560 0%, #c73a52 100%); }

.key .cents-label {
    font-size: 0.55rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}
.key.white .cents-label { color: #666; }
.key.black .cents-label { color: #aaa; }

.key .note-label {
    font-size: 0.6rem;
    font-weight: 700;
    pointer-events: none;
    margin-top: 2px;
}
.key.white .note-label { color: #444; }
.key.black .note-label { color: #ccc; }

/* === TABS === */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 0;
}

.tab {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-dim);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { display: none; padding-top: 1rem; }
.tab-content.active { display: block; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === LOADING ANIMATION === */
@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}
.playing .icon { animation: pulse 0.8s ease-in-out infinite; }

/* === LIBRARY === */
.library-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.35rem 0.6rem;
    margin-bottom: 2px;
    font-size: 0.78rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 5px;
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.12s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.library-item:hover {
    background: var(--bg-card-hover);
    color: var(--text);
    border-color: var(--border);
}

.library-item.active {
    background: rgba(233,69,96,0.12);
    border-color: var(--accent);
    color: var(--text);
    font-weight: 600;
}

/* === TEMPO SLIDER === */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

/* === SCORE CONTAINER === */
#score-container svg {
    max-width: 100%;
}

/* Engraved score (Verovio): black-on-cream paper look */
.engraved-score {
    background: #faf7ee;
    border-radius: 6px;
    padding: 0.5rem 0.8rem;
    overflow-x: auto;
}
.engraved-score svg {
    display: block;
    width: 100%;
    height: auto;
}

/* Upload button */
.upload-btn {
    display: inline-block;
    font-size: 0.8rem;
    background: var(--bg-input);
    color: var(--text);
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.8rem;
    cursor: pointer;
    width: 100%;
    text-align: center;
    transition: border-color 0.15s, background 0.15s;
}
.upload-btn:hover {
    border-color: var(--accent2);
    background: var(--bg-card-hover);
}

/* User library item delete button */
.library-item-del {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 0.5rem;
    font-size: 1rem;
    cursor: pointer;
}
.library-item-del:hover {
    color: var(--negative);
    border-color: var(--negative);
}

/* Secondary button (save to library) */
.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
}
.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent2);
}

/* === FOOTER === */
footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    border-top: 1px solid var(--border);
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }
