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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
}

/* ── Navbar ─────────────────────────────────────── */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #16213e;
    border-bottom: 2px solid #0f3460;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 1.3rem;
    font-weight: 700;
    color: #e94560;
}

.nav-links {
    display: flex;
    gap: 8px;
}

.nav-btn {
    background: transparent;
    border: 1px solid #0f3460;
    color: #e0e0e0;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    min-height: 44px;
    min-width: 44px;
    transition: all 0.2s;
}

.nav-btn:hover { background: #0f3460; }
.nav-btn.active {
    background: #e94560;
    border-color: #e94560;
    color: white;
}

/* ── Main ───────────────────────────────────────── */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px;
}

/* ── Instrument Selector ────────────────────────── */
.selector-category {
    margin-bottom: 24px;
}

.selector-category h3 {
    color: #e94560;
    font-size: 1.1rem;
    margin-bottom: 12px;
    padding-left: 4px;
}

.instrument-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.instrument-card {
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.instrument-card:hover {
    border-color: #e94560;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(233, 69, 96, 0.15);
}

.instrument-card-icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.instrument-card-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.instrument-card-info {
    color: #888;
    font-size: 0.85rem;
}

/* ── Visualizer Header ──────────────────────────── */
.visualizer-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.visualizer-title h2 {
    font-size: 1.4rem;
    color: #e94560;
}

.visualizer-title p {
    color: #888;
    font-size: 0.85rem;
}

.visualizer-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    min-height: 44px;
    min-width: 44px;
    transition: all 0.2s;
}

.btn-primary { background: #e94560; color: white; }
.btn-primary:hover { background: #c73a52; }
.btn-secondary { background: #0f3460; color: #e0e0e0; }
.btn-secondary:hover { background: #1a4a8a; }

/* ── Progress & Status ──────────────────────────── */
.lug-status {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 0.9rem;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.tuned { background: #4ade80; }
.status-dot.untuned { background: #666; }

.progress-bar {
    height: 4px;
    background: #0f3460;
    border-radius: 2px;
    margin-top: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #e94560;
    transition: width 0.3s;
}

/* ── Instrument Container ───────────────────────── */
.instrument-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* ── String Visualizer ──────────────────────────── */
.string-visualizer {
    width: 100%;
    max-width: 500px;
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    padding: 16px;
}

.string-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.string-row {
    display: grid;
    grid-template-columns: 32px 80px 1fr 50px;
    align-items: center;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    min-height: 48px;
}

.string-row:hover { background: rgba(15, 52, 96, 0.5); }

.string-num {
    font-size: 0.8rem;
    color: #666;
    text-align: center;
    font-weight: 600;
}

.string-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.string-target-note {
    font-size: 0.85rem;
    color: #aaa;
}

.string-detected-note {
    font-size: 1.2rem;
    font-weight: 700;
    transition: color 0.1s;
}

.string-gauge {
    position: relative;
    height: 8px;
    background: #0f3460;
    border-radius: 4px;
    overflow: visible;
}

.string-bar-bg {
    position: absolute;
    inset: 0;
    background: #0f3460;
    border-radius: 4px;
}

.string-bar-fill {
    position: absolute;
    top: 0;
    left: 50%;
    height: 100%;
    border-radius: 4px;
    transition: width 0.1s;
}

.string-needle {
    position: absolute;
    top: -2px;
    width: 4px;
    height: 12px;
    background: #e94560;
    border-radius: 2px;
    transform: translateX(-50%);
    transition: left 0.1s ease-out;
}

.string-cents {
    font-size: 0.8rem;
    color: #666;
    text-align: right;
    font-weight: 600;
}

/* ── Piano Visualizer ───────────────────────────── */
.piano-visualizer {
    width: 100%;
    max-width: 800px;
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    padding: 16px;
    overflow-x: auto;
}

.piano-octave {
    display: flex;
    gap: 2px;
    margin-bottom: 2px;
    position: relative;
}

.piano-key {
    border-radius: 0 0 4px 4px;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 4px;
}

.piano-key:hover { opacity: 0.85; }

.white-key {
    background: #fff;
    border: 1px solid #ccc;
    width: 36px;
    color: #333;
    font-size: 10px;
}

.black-key {
    background: #222;
    border: 1px solid #111;
    width: 24px;
    margin: 0 -12px;
    z-index: 1;
}

/* ── Tuner Gauge ────────────────────────────────── */
.tuner-gauge {
    text-align: center;
    padding: 16px;
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
}

.tuner-status {
    color: #888;
    font-size: 0.8rem;
    margin-bottom: 6px;
}

.tuner-note {
    font-size: 2.5rem;
    font-weight: 700;
    color: #e94560;
    line-height: 1;
    margin-bottom: 2px;
}

.tuner-freq {
    color: #aaa;
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.tuner-bar {
    position: relative;
    height: 8px;
    background: #0f3460;
    border-radius: 4px;
    margin: 10px auto;
    max-width: 280px;
    overflow: visible;
}

.tuner-bar::before,
.tuner-bar::after {
    content: '';
    position: absolute;
    top: -6px;
    width: 2px;
    height: 20px;
    background: #333;
}

.tuner-bar::before { left: 0; }
.tuner-bar::after { right: 0; }

.tuner-needle {
    position: absolute;
    top: -8px;
    width: 4px;
    height: 24px;
    background: #e94560;
    border-radius: 2px;
    transform: translateX(-50%);
    transition: left 0.1s ease-out;
}

.tuner-cents {
    font-size: 0.85rem;
    margin-top: 6px;
    color: #666;
    font-weight: 600;
}

/* ── Tuning Guide ───────────────────────────────── */
.guide-panel {
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    padding: 20px;
    margin-top: 16px;
    width: 100%;
}

.guide-panel h3 { color: #e94560; margin-bottom: 14px; }

.pattern-list { display: flex; flex-direction: column; gap: 12px; }

.pattern-item {
    background: #0f3460;
    border-radius: 8px;
    padding: 14px;
}

.pattern-item h4 { color: #e94560; margin-bottom: 6px; font-size: 1rem; }
.pattern-item p { color: #aaa; font-size: 0.85rem; margin-bottom: 10px; }

.pattern-diagram {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.tuning-note-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
}

/* ── Journal ────────────────────────────────────── */
.journal-list { display: flex; flex-direction: column; gap: 12px; }

.journal-item {
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 10px;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.journal-item:hover { border-color: #e94560; }

.journal-info h4 { margin-bottom: 4px; }
.journal-info p { color: #888; font-size: 0.85rem; }

/* ── Note Selector Modal ────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: #16213e;
    border: 2px solid #0f3460;
    border-radius: 12px;
    padding: 20px;
    width: 95vw;
    max-width: 400px;
}

.modal h3 { margin-bottom: 14px; color: #e94560; }

.note-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.note-btn {
    padding: 12px 6px;
    background: #0f3460;
    border: 1px solid #1a4a8a;
    color: #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    min-height: 44px;
    transition: all 0.15s;
}

.note-btn:hover { background: #e94560; border-color: #e94560; }
.note-btn.selected { background: #e94560; border-color: #e94560; }

/* ── Mobile Responsive ──────────────────────────── */
@media (max-width: 768px) {
    .navbar { padding: 10px 12px; }
    .nav-brand { font-size: 1.1rem; }
    .nav-btn { padding: 8px 12px; font-size: 0.85rem; min-height: 40px; }

    main { padding: 12px; }

    .instrument-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 8px;
    }

    .instrument-card { padding: 16px; min-height: 80px; }
    .instrument-card-icon { font-size: 2rem; }
    .instrument-card-name { font-size: 1rem; }
    .instrument-card-info { font-size: 0.8rem; }

    .visualizer-header {
        flex-direction: column;
        align-items: stretch;
    }

    .visualizer-actions {
        justify-content: center;
        gap: 6px;
    }

    .btn { padding: 8px 12px; font-size: 0.85rem; min-height: 40px; }

    .string-visualizer { max-width: 100%; padding: 12px; }

    .string-row {
        grid-template-columns: 28px 60px 1fr 40px;
        min-height: 44px;
    }

    .string-target-note { font-size: 0.75rem; }
    .string-detected-note { font-size: 1rem; }
    .string-cents { font-size: 0.75rem; }

    .tuner-gauge { max-width: 100%; }
    .tuner-note { font-size: 2rem; }

    .journal-item { padding: 14px 16px; }

    /* Safe area for iPhone notch/home bar */
    body { padding-bottom: env(safe-area-inset-bottom, 0); }
}

@media (max-width: 480px) {
    .instrument-grid { grid-template-columns: repeat(2, 1fr); }

    .visualizer-actions { flex-wrap: wrap; }
    .btn { flex: 1; text-align: center; min-width: 60px; }

    .string-rows { gap: 4px; }
    .string-row { grid-template-columns: 24px 50px 1fr 36px; padding: 2px 4px; }
    .string-num { font-size: 0.7rem; }
    .string-target-note { font-size: 0.7rem; }
    .string-detected-note { font-size: 0.9rem; }
    .string-cents { font-size: 0.7rem; }

    .note-grid { grid-template-columns: repeat(3, 1fr); }
}
