* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: #0f172a; color: #e2e8f0;
    min-height: 100vh; overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
}

/* LOGIN */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-box { background: #1e293b; border-radius: 16px; padding: 40px 32px; width: 100%; max-width: 360px; text-align: center; }
.login-box h1 { font-size: 22px; margin-bottom: 24px; color: #f1f5f9; }
.login-box input[type=password] {
    width: 100%; padding: 14px 16px; font-size: 18px; border: 2px solid #334155;
    background: #0f172a; color: #e2e8f0; border-radius: 10px; margin-bottom: 16px;
    -webkit-user-select: text; user-select: text;
}
.login-box input:focus { outline: none; border-color: #3b82f6; }
.login-box button {
    width: 100%; padding: 14px; font-size: 18px; font-weight: 700;
    background: #3b82f6; color: #fff; border: none; border-radius: 10px;
    cursor: pointer; -webkit-appearance: none;
}
.login-box button:active { background: #2563eb; }

/* TOP BAR */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: #1e293b; border-bottom: 1px solid #334155;
    position: sticky; top: 0; z-index: 100;
}
.topbar h1 { font-size: 17px; font-weight: 700; }
.topbar-btns { display: flex; gap: 8px; }
.topbar-btns button {
    padding: 8px 14px; font-size: 13px; font-weight: 600; border-radius: 8px;
    border: 1px solid #475569; background: #334155; color: #cbd5e1; cursor: pointer;
}
.topbar-btns button.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }
.topbar-btns button:active { opacity: 0.8; }
.logout-btn { font-size: 12px !important; color: #94a3b8 !important; border-color: #475569 !important; }

/* PANELS */
.panel { display: none; padding: 16px; padding-bottom: 100px; }
.panel.active { display: block; }

/* CHORD INPUT */
.chord-display {
    background: #1e293b; border: 2px solid #334155; border-radius: 12px;
    padding: 16px; min-height: 56px; margin-bottom: 16px; font-size: 20px;
    font-family: 'SF Mono', 'Fira Code', monospace; color: #67e8f9;
    word-wrap: break-word; line-height: 1.6;
}
.chord-display .chord-tag {
    display: inline-block; background: #164e63; padding: 2px 10px;
    border-radius: 6px; margin: 2px; font-weight: 600;
}
.chord-display .chord-tag.minor { background: #713f12; color: #fcd34d; }
.chord-display:empty::after {
    content: 'Detected and tapped chords appear here…';
    color: #475569; font-family: inherit; font-size: 16px;
}
.chord-display-editable .chord-tag {
    cursor: pointer; position: relative; transition: opacity 0.15s, transform 0.15s;
}
.chord-display-editable .chord-tag:active {
    opacity: 0.5; transform: scale(0.9);
}
.chord-display-editable .chord-tag::after {
    content: '✕'; position: absolute; top: -6px; right: -6px;
    font-size: 10px; width: 16px; height: 16px; line-height: 16px;
    text-align: center; background: #ef4444; color: #fff;
    border-radius: 50%; font-weight: 700;
}
.edit-hint {
    font-weight: 400; font-size: 11px; color: #64748b;
    text-transform: none; letter-spacing: 0;
}

.input-controls { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.input-controls button {
    flex: 1; min-width: 70px; padding: 10px; font-size: 14px; font-weight: 700;
    border-radius: 8px; border: none; cursor: pointer;
}
.btn-match { background: #22c55e; color: #052e16; }
.btn-match:active { background: #16a34a; }
.btn-clear { background: #475569; color: #e2e8f0; }
.btn-clear:active { background: #64748b; }
.btn-undo { background: #334155; color: #cbd5e1; }
.btn-undo:active { background: #475569; }

.chord-grid {
    display: grid; grid-template-columns: repeat(7, 1fr);
    gap: 8px; margin-bottom: 8px;
}
.chord-btn {
    padding: 18px 0; font-size: 22px; font-weight: 800; text-align: center;
    border-radius: 12px; border: 2px solid #334155; background: #1e293b;
    color: #67e8f9; cursor: pointer; transition: background 0.1s;
    font-family: 'SF Mono', 'Fira Code', monospace;
}
.chord-btn:active { background: #164e63; }
.chord-btn.minor { color: #fcd34d; border-color: #854d0e; }
.chord-btn.minor:active { background: #713f12; }
.grid-label { font-size: 11px; color: #64748b; font-weight: 600; text-transform: uppercase;
    letter-spacing: 1px; padding: 8px 0 4px; }

/* RESULTS */
.results-area { margin-top: 16px; }
.result-card {
    background: #1e293b; border: 1px solid #334155; border-radius: 12px;
    padding: 16px; margin-bottom: 10px; cursor: pointer; transition: border-color 0.15s;
}
.result-card:active { border-color: #3b82f6; }
.result-card.top-match { border-color: #22c55e; }
.result-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.result-title { font-size: 17px; font-weight: 700; color: #f1f5f9; }
.result-artist { font-size: 13px; color: #94a3b8; }
.result-badge {
    padding: 3px 10px; border-radius: 20px; font-size: 13px; font-weight: 700;
    white-space: nowrap; flex-shrink: 0; margin-left: 8px;
}
.badge-green { background: #052e16; color: #4ade80; }
.badge-amber { background: #422006; color: #fbbf24; }
.badge-red { background: #450a0a; color: #f87171; }
.result-sections { font-size: 13px; color: #fbbf24; margin-bottom: 6px; }
.result-bar { height: 4px; background: #334155; border-radius: 2px; overflow: hidden; margin-bottom: 8px; }
.result-bar-fill { height: 100%; border-radius: 2px; }
.result-sections-detail { margin-top: 4px; }
.result-section-group { margin-bottom: 8px; }
.result-section-group:last-child { margin-bottom: 0; }
.result-section-label {
    font-size: 11px; font-weight: 700; color: #fbbf24;
    text-transform: uppercase; letter-spacing: 0.5px;
    margin-bottom: 3px; padding-left: 2px;
}
.result-section-chords { display: flex; flex-wrap: wrap; gap: 4px; }
.result-chord { font-size: 12px; padding: 2px 6px; border-radius: 4px; font-family: monospace; font-weight: 600; }
.rc-match { background: #052e16; color: #4ade80; border: 1px solid #166534; }
.rc-dim { background: #1e293b; color: #475569; border: 1px solid #334155; }
.no-results { text-align: center; padding: 40px; color: #475569; }

/* KEY PICKER MODAL */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7);
    z-index: 200; align-items: flex-end; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal-sheet {
    background: #1e293b; border-radius: 20px 20px 0 0; width: 100%;
    max-width: 500px; padding: 24px 16px 40px; max-height: 80vh; overflow-y: auto;
}
.modal-title { font-size: 18px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.modal-subtitle { font-size: 13px; color: #94a3b8; text-align: center; margin-bottom: 20px; }
.key-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px;
}
.key-btn {
    padding: 16px 0; font-size: 20px; font-weight: 700; text-align: center;
    border-radius: 12px; border: 2px solid #334155; background: #0f172a;
    color: #e2e8f0; cursor: pointer;
}
.key-btn:active { background: #334155; }
.key-btn.selected { border-color: #3b82f6; background: #1e3a5f; color: #60a5fa; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions button {
    flex: 1; padding: 16px; font-size: 17px; font-weight: 700; border: none;
    border-radius: 12px; cursor: pointer;
}
.btn-cancel { background: #334155; color: #e2e8f0; }
.btn-load { background: #3b82f6; color: #fff; }
.btn-load:active { background: #2563eb; }

/* CHART VIEW */
.chart-header {
    background: #1e293b; border-radius: 12px; padding: 16px; margin-bottom: 16px;
}
.chart-title { font-size: 22px; font-weight: 800; color: #f1f5f9; }
.chart-artist { font-size: 15px; color: #94a3b8; margin-top: 2px; }
.chart-meta { font-size: 13px; color: #64748b; margin-top: 8px; display: flex; flex-wrap: wrap; gap: 12px; }
.chart-meta .key-highlight { color: #67e8f9; font-weight: 700; }
.chart-body {
    background: #1e293b; border-radius: 12px; padding: 20px 16px;
    font-size: 17px; line-height: 2; font-family: 'SF Mono', 'Fira Code', monospace;
    -webkit-user-select: text; user-select: text;
}
.chart-body .section-header {
    color: #fbbf24; font-weight: 800; font-size: 14px;
    text-transform: uppercase; letter-spacing: 1px;
    margin-top: 16px; margin-bottom: 4px; padding-top: 8px;
    border-top: 1px solid #334155; font-family: system-ui, sans-serif;
}
.chart-body .section-header:first-child { border-top: none; margin-top: 0; }
.chart-body .chord { color: #67e8f9; font-weight: 800; }
.chart-body .bar-line { color: #475569; }
.chart-body .chart-line { word-wrap: break-word; }
.chart-body .chart-blank { height: 8px; }
.chart-back-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 16px; font-size: 15px; font-weight: 600;
    background: #334155; color: #cbd5e1; border: none; border-radius: 10px;
    cursor: pointer; margin-bottom: 16px;
}
.chart-back-btn:active { background: #475569; }
.chart-rekey-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 16px; font-size: 15px; font-weight: 600;
    background: #164e63; color: #67e8f9; border: none; border-radius: 10px;
    cursor: pointer; margin-bottom: 16px; margin-left: 8px;
}

/* LISTEN */
.listen-key-bar { margin-bottom: 16px; }
.listen-key-label { font-size: 12px; font-weight: 700; color: #64748b; text-transform: uppercase;
    letter-spacing: 1px; margin-bottom: 8px; }
.listen-key-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.listen-key-btn {
    padding: 12px 0; font-size: 16px; font-weight: 700; text-align: center;
    border-radius: 8px; border: 2px solid #334155; background: #1e293b;
    color: #94a3b8; cursor: pointer;
}
.listen-key-btn:active { background: #334155; }
.listen-key-btn.active { border-color: #3b82f6; background: #1e3a5f; color: #60a5fa; }
.listen-controls { display: flex; gap: 10px; margin-bottom: 16px; }
.listen-btn {
    flex: 1; padding: 18px; font-size: 18px; font-weight: 700; border: none;
    border-radius: 12px; cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 10px; transition: background 0.2s;
}
.listen-btn-off { background: #334155; color: #94a3b8; }
.listen-btn-on { background: #dc2626; color: #fff; animation: pulse-glow 1.5s ease-in-out infinite; }
.listen-btn-ready { background: #22c55e; color: #052e16; }
.listen-btn:disabled { opacity: 0.5; cursor: default; }
@keyframes pulse-glow { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.4); } 50% { box-shadow: 0 0 0 12px rgba(220,38,38,0); } }
.listen-viz { margin-bottom: 16px; border-radius: 8px; overflow: hidden; background: #1e293b;
    border: 1px solid #334155; display: none; }
.listen-viz.active { display: block; }
.listen-viz canvas { width: 100%; height: 60px; display: block; }
.listen-current {
    text-align: center; padding: 16px; background: #1e293b; border-radius: 12px;
    margin-bottom: 16px; border: 1px solid #334155; display: none;
}
.listen-current.active { display: block; }
.listen-current-label { font-size: 11px; font-weight: 700; color: #64748b;
    text-transform: uppercase; letter-spacing: 1px; }
.listen-current-chord { font-size: 48px; font-weight: 800; color: #67e8f9;
    font-family: 'SF Mono', 'Fira Code', monospace; line-height: 1.2; }
.listen-current-nashville { font-size: 20px; color: #fbbf24; font-weight: 700;
    font-family: 'SF Mono', 'Fira Code', monospace; }

/* UPLOAD */
.upload-zone { margin-bottom: 16px; }
.upload-btn {
    width: 100%; padding: 18px; font-size: 17px; font-weight: 700;
    background: #1e293b; color: #67e8f9; border: 2px dashed #334155;
    border-radius: 12px; cursor: pointer; display: flex; align-items: center;
    justify-content: center; gap: 8px; transition: border-color 0.15s;
}
.upload-btn:active { border-color: #3b82f6; background: #0f172a; }
.upload-icon { font-size: 24px; font-weight: 400; }
.upload-status { margin-top: 8px; font-size: 13px; }
.upload-msg { padding: 8px 12px; border-radius: 8px; margin-top: 6px; }
.upload-msg.success { background: #052e16; color: #4ade80; }
.upload-msg.error { background: #450a0a; color: #f87171; }
.upload-msg.info { background: #1e293b; color: #94a3b8; }

/* SONG ROW WITH DELETE */
.song-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 16px; background: #1e293b; border-radius: 10px;
    margin-bottom: 6px; cursor: pointer; border: 1px solid #334155;
}
.song-row:active { border-color: #3b82f6; }
.song-row-inner { flex: 1; min-width: 0; overflow: hidden; }
.song-name { font-weight: 700; font-size: 15px; color: #f1f5f9; }
.song-artist-sm { font-size: 12px; color: #94a3b8; }
.song-key-badge { font-size: 12px; padding: 2px 8px; background: #334155; border-radius: 6px; color: #94a3b8; }
.song-delete-btn {
    padding: 10px 14px; font-size: 13px; font-weight: 600;
    background: #450a0a; color: #f87171; border: 1px solid #7f1d1d;
    border-radius: 8px; cursor: pointer; flex-shrink: 0; margin-left: 10px;
    display: none;
}
.song-row.show-delete .song-delete-btn { display: block; }

/* DELETE MODAL */
.btn-delete-confirm {
    flex: 1; padding: 16px; font-size: 17px; font-weight: 700; border: none;
    border-radius: 12px; cursor: pointer; background: #dc2626; color: #fff;
}
.btn-delete-confirm:active { background: #b91c1c; }

/* LIBRARY SEARCH */
.library-search {
    width: 100%; padding: 14px 16px; font-size: 16px; border: 2px solid #334155;
    background: #1e293b; color: #e2e8f0; border-radius: 10px; margin-bottom: 12px;
    -webkit-user-select: text; user-select: text;
}
.library-search:focus { outline: none; border-color: #3b82f6; }

/* LOADING */
.spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid #475569;
    border-top-color: #67e8f9; border-radius: 50%; animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 600px) {
    .chord-grid { gap: 10px; }
    .chord-btn { padding: 22px 0; font-size: 26px; }
    .chart-body { font-size: 19px; padding: 24px; }
}