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

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-control: #1c2128;
    --accent-primary: #58a6ff;
    --accent-secondary: #a371f7;
    --accent-hover: #79c0ff;
    --text-primary: #f0f6fc;
    --text-secondary: #8b949e;
    --border-color: #30363d;
    --fret-color: #4b5563;
    --string-color: #6b7280;
    --inlay-color: #374151;
    --hover-bg: rgba(0, 212, 255, 0.1);
    --root-note-bg: rgba(124, 58, 237, 0.3);
    --root-note-border: #7c3aed;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #0f1419 100%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 20px;
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 24px;
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

header h1 {
    font-size: clamp(1.5rem, 3.5vw, 2.2rem);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    margin: 0;
}

.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

select,
.btn {
    padding: 10px 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

select:hover,
.btn:hover {
    background: var(--bg-primary);
    border-color: var(--accent-primary);
    transform: translateY(-1px);
}

select:focus,
.btn:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.toggle-buttons {
    display: flex;
    gap: 8px;
}

.toggle-btn {
    flex: 1;
    padding: 8px 12px;
    background: var(--bg-control);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.toggle-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-hover);
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--accent-primary);
    color: var(--bg-primary);
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary);
}

.btn {
    background: var(--accent-secondary);
    color: white;
    border: 1px solid var(--accent-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn:hover {
    background: #8e4ef0;
    border-color: #8e4ef0;
}

#custom-tuning-container {
    grid-column: 1 / -1;
    padding: 16px;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.custom-tuning-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.tuning-string {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tuning-string label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
}

#guitar-wrapper {
    display: flex;
    align-items: center;
    gap: 0;
    overflow-x: auto;
    padding: 20px 0;
}

#headstock {
    flex-shrink: 0;
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: 16px 0 0 16px;
    border: 1px solid var(--border-color);
    border-right: none;
}

.headstock-shape {
    width: 180px;
    background: linear-gradient(135deg, #2d1810 0%, #1a0f0a 100%);
    border-radius: 12px 0 0 12px;
    padding: 20px;
    position: relative;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.5), 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 2px solid #3d2415;
}

.headstock-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: #8b6f47;
    text-align: center;
    margin-bottom: 15px;
    letter-spacing: 2px;
    opacity: 0.6;
}

#tuning-pegs {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tuning-peg {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    border: 1px solid #3d2415;
}

.peg-machine {
    width: 24px;
    height: 24px;
    background: radial-gradient(circle, #c0c0c0 0%, #808080 100%);
    border-radius: 50%;
    border: 2px solid #606060;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4), inset 0 1px 2px rgba(255, 255, 255, 0.3);
    position: relative;
}

.peg-machine::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 12px;
    background: #404040;
    border-radius: 2px;
}

.peg-note {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-primary);
    min-width: 40px;
    text-shadow: 0 2px 4px rgba(0, 212, 255, 0.5);
}

.peg-string-num {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: auto;
}

#nut {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 8px;
    background: linear-gradient(90deg, #f5f5dc 0%, #d4d4b8 50%, #f5f5dc 100%);
    border-radius: 2px;
    box-shadow:
        inset 0 0 4px rgba(0, 0, 0, 0.3),
        2px 0 6px rgba(0, 0, 0, 0.2);
    z-index: 5;
}

#fretboard-container {
    background: var(--bg-secondary);
    border-radius: 0 16px 16px 0;
    padding: 30px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow-x: auto;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0;
}

#fretboard {
    display: grid;
    grid-template-rows: repeat(6, 1fr);
    gap: 0;
    min-width: 900px;
    background: linear-gradient(90deg, #3d2415 0%, #2d1810 100%);
    padding: 30px 0;
    position: relative;
    box-shadow:
        inset 0 4px 12px rgba(0, 0, 0, 0.5),
        0 4px 16px rgba(0, 0, 0, 0.3);
    border-radius: 8px;
}

#fretboard::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        repeating-linear-gradient(90deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.1) 2px,
            rgba(0, 0, 0, 0.1) 3px);
    pointer-events: none;
    border-radius: 8px;
}

.fret-row {
    display: grid;
    gap: 0;
    position: relative;
    height: 40px;
}

.fret-row::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg,
            rgba(192, 192, 192, 0.4) 0%,
            rgba(192, 192, 192, 0.8) 50%,
            rgba(192, 192, 192, 0.4) 100%);
    transform: translateY(-50%);
    z-index: 1;
    pointer-events: none;
}

.fret-row:nth-child(1)::before {
    height: 1.5px;
}

.fret-row:nth-child(2)::before {
    height: 1.8px;
}

.fret-row:nth-child(3)::before {
    height: 2px;
}

.fret-row:nth-child(4)::before {
    height: 2.5px;
}

.fret-row:nth-child(5)::before {
    height: 3px;
}

.fret-row:nth-child(6)::before {
    height: 3.5px;
}

.fret-cell {
    position: relative;
    background: transparent;
    border: none;
    border-right: 3px solid #c0c0c0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    overflow: visible;
}

.fret-cell:first-child {
    border-left: none;
}

.fret-cell::after {
    content: '';
    position: absolute;
    top: 0;
    right: -3px;
    bottom: 0;
    width: 3px;
    background: linear-gradient(180deg,
            #e0e0e0 0%,
            #c0c0c0 20%,
            #a0a0a0 50%,
            #c0c0c0 80%,
            #e0e0e0 100%);
    box-shadow:
        1px 0 2px rgba(255, 255, 255, 0.3),
        -1px 0 2px rgba(0, 0, 0, 0.5);
    border-radius: 1px;
    pointer-events: none;
}

.fret-cell:hover {
    background: var(--hover-bg);
    z-index: 10;
}

.fret-cell:hover::before {
    content: '';
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    background: radial-gradient(circle, rgba(0, 212, 255, 0.2) 0%, transparent 70%);
    border-radius: 50%;
    pointer-events: none;
    z-index: -1;
}

.note-label {
    position: relative;
    z-index: 2;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    background: rgba(10, 14, 26, 0.9);
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.fret-cell.hover-mode .note-label {
    opacity: 0;
    transform: scale(0.8);
}

.fret-cell.hover-mode:hover .note-label {
    opacity: 1;
    transform: scale(1);
}

.fret-cell.root-note .note-label {
    background: linear-gradient(135deg, var(--accent-secondary) 0%, #6d28d9 100%);
    color: white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.6);
}

.fret-cell.hidden-note {
    opacity: 0.2;
}

.fret-cell.hidden-note .note-label {
    display: none;
}

.inlay-marker {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background: radial-gradient(circle, #f5f5dc 0%, #d4d4b8 50%, #8b7355 100%);
    border-radius: 50%;
    box-shadow:
        0 2px 6px rgba(0, 0, 0, 0.5),
        inset 0 1px 2px rgba(255, 255, 255, 0.4);
    border: 1px solid #6b5d4f;
    z-index: 0;
    pointer-events: none;
}

.inlay-marker.double {
    top: 25%;
}

.inlay-marker.double+.inlay-marker {
    top: 75%;
}

.fret-number {
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    color: var(--accent-primary);
    font-weight: 700;
    background: rgba(0, 212, 255, 0.1);
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid rgba(0, 212, 255, 0.3);
}


@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    header {
        margin-bottom: 20px;
        padding: 16px;
    }

    .controls {
        padding: 16px;
        gap: 12px;
    }

    .control-group {
        min-width: 100%;
    }

    #fretboard-container {
        padding: 16px;
    }

    #fretboard {
        min-width: 600px;
        padding: 12px;
    }

    .note-label {
        font-size: 0.75rem;
        padding: 3px 8px;
    }

    .custom-tuning-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    #fretboard {
        min-width: 500px;
    }

    .note-label {
        font-size: 0.7rem;
        padding: 2px 6px;
    }
}