:root {
    --bg: #f7f8f6;
    --surface: #ffffff;
    --panel: #eef0ee;
    --ink: #171918;
    --muted: #68706d;
    --line: #d7dcd8;
    --line-strong: #aeb7b1;
    --teal: #137d73;
    --teal-soft: #d8eeea;
    --amber: #d9992c;
    --danger: #a43838;
    --shadow: 0 24px 70px rgba(23, 25, 24, 0.13);
    --panel-bg: rgba(255, 255, 255, 0.82);
    --fretboard-bg:
        radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.9), transparent 28%),
        linear-gradient(145deg, #f4f5f2, #e2e7e4);
    --string-ink: #050505;
    --dot-fill: #050505;
    --dot-stroke: var(--surface);
    --tooltip-bg: var(--ink);
    --tooltip-text: #ffffff;
    --warm-hover: #fff4df;
    --warm-soft: #fff9ed;
    --warm-strong: #ffe9bd;
    --danger-soft: #f9e6e6;
    --radius: 8px;
}

body[data-theme="dark"] {
    --bg: #101312;
    --surface: #181d1b;
    --panel: #202724;
    --ink: #f1f4ef;
    --muted: #a8b2ad;
    --line: #33413b;
    --line-strong: #607068;
    --teal: #49bbae;
    --teal-soft: #1d3a35;
    --amber: #f0b34a;
    --danger: #ef7777;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
    --panel-bg: rgba(24, 29, 27, 0.9);
    --fretboard-bg:
        radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.08), transparent 30%),
        linear-gradient(145deg, #252d29, #161b19);
    --string-ink: #f4f7f1;
    --dot-fill: #f6f7f2;
    --dot-stroke: #151917;
    --tooltip-bg: #eef2ec;
    --tooltip-text: #111412;
    --warm-hover: #3b2f1b;
    --warm-soft: #261f14;
    --warm-strong: #4b3719;
    --danger-soft: #3a1e21;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    background:
        linear-gradient(120deg, rgba(19, 125, 115, 0.06), transparent 38%),
        var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.app-shell {
    display: grid;
    grid-template-columns: minmax(230px, 280px) minmax(480px, 1fr) minmax(260px, 330px);
    gap: 18px;
    min-height: 100vh;
    padding: 18px;
}

.library-panel,
.editor-panel,
.fretboard-panel {
    border: 1px solid var(--line);
    background: var(--panel-bg);
    box-shadow: 0 10px 35px rgba(23, 25, 24, 0.05);
}

.library-panel,
.editor-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    border-radius: var(--radius);
    padding: 18px;
}

.fretboard-panel {
    display: grid;
    grid-template-rows: auto minmax(420px, 1fr) auto;
    gap: 18px;
    border-radius: var(--radius);
    padding: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
}

.brand-mark {
    width: 34px;
    height: 34px;
    border: 3px solid var(--ink);
    border-radius: 50%;
    box-shadow: inset 10px 0 0 var(--teal-soft);
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 12px;
    color: var(--ink);
    background: var(--surface);
    font-size: 13px;
    font-weight: 850;
}

.theme-toggle:hover {
    border-color: var(--teal);
    background: var(--teal-soft);
}

.theme-icon {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    color: var(--surface);
    background: var(--ink);
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: 20px;
    line-height: 1.1;
}

.brand p,
.eyebrow,
.mode-switch,
.canvas-footer,
.field-label,
.position-header {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.eyebrow {
    margin-bottom: 4px;
    text-transform: uppercase;
}

.canvas-header,
.canvas-footer,
.position-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.canvas-header h2 {
    font-size: clamp(44px, 8vw, 96px);
    line-height: 0.9;
}

.header-tools {
    display: flex;
    align-items: flex-end;
    flex-direction: column;
    gap: 10px;
}

.mode-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: max-content;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
}

.mode-bar {
    display: flex;
    align-items: stretch;
    flex-wrap: wrap;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px;
    background: color-mix(in srgb, var(--surface) 78%, transparent);
}

.mode-button,
.mode-action {
    min-height: 36px;
    border: 0;
    border-radius: 6px;
    padding: 0 12px;
    color: var(--muted);
    background: transparent;
    font-size: 13px;
    font-weight: 850;
}

.mode-button.active,
.mode-action.primary {
    color: var(--surface);
    background: var(--teal);
}

.mode-action {
    color: var(--ink);
}

.mode-action:hover {
    color: var(--ink);
    background: var(--warm-hover);
}

.mode-select {
    display: flex;
    align-items: center;
    min-width: 150px;
    padding-left: 8px;
    border-left: 1px solid var(--line);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}

.mode-select select {
    border: 0;
    color: var(--ink);
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 850;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--teal);
}

.field-label {
    display: block;
    margin-bottom: -6px;
}

.text-input,
.text-area {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    background: var(--surface);
    outline: none;
}

.text-input {
    min-height: 42px;
    padding: 0 12px;
}

.text-area {
    resize: vertical;
    min-height: 120px;
    padding: 11px 12px;
    line-height: 1.45;
}

.text-input:focus,
.text-area:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--teal-soft);
}

.library-actions,
.storage-actions,
.save-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.save-actions {
    grid-template-columns: 1fr 1fr auto;
    align-items: center;
}

.storage-actions {
    grid-template-columns: 1fr;
    margin-top: auto;
}

.icon-button,
.save-button,
.secondary-button {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
    background: var(--surface);
}

.save-button {
    min-height: 40px;
    padding: 0 12px;
    color: var(--surface);
    background: var(--teal);
    border-color: var(--teal);
    font-size: 13px;
    font-weight: 850;
}

.icon-button {
    display: grid;
    place-items: center;
    min-height: 40px;
    font-size: 22px;
    font-weight: 800;
}

.secondary-button {
    min-height: 40px;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 800;
}

.icon-button:hover,
.save-button:hover,
.secondary-button:hover,
.chord-button:hover {
    border-color: var(--teal);
    background: var(--teal-soft);
}

.save-button:hover {
    color: var(--ink);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

.edit-status {
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
    white-space: nowrap;
}

.edit-status.dirty {
    color: var(--amber);
}

.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
    background: var(--danger-soft);
}

.chord-list {
    display: grid;
    gap: 8px;
    overflow: auto;
    padding-right: 2px;
}

.chord-button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 12px;
    color: var(--ink);
    background: var(--surface);
    text-align: left;
}

.chord-button strong {
    font-size: 19px;
}

.chord-button span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.chord-button.active {
    border-color: var(--teal);
    background: var(--teal-soft);
}

.fretboard-stage {
    display: grid;
    place-items: center;
    overflow: hidden;
    min-height: 420px;
    border-radius: 28px;
    background: var(--fretboard-bg);
    box-shadow: var(--shadow);
}

.fretboard {
    width: min(100%, 900px);
    height: auto;
    overflow: visible;
}

.string-line,
.nut-line,
.guide-line {
    vector-effect: non-scaling-stroke;
}

.string-line,
.nut-line {
    stroke: var(--string-ink);
    stroke-width: 5;
    stroke-linecap: round;
}

.string-line.vibrating {
    stroke: var(--amber);
    animation: string-vibrate 110ms linear infinite;
    filter: drop-shadow(0 0 8px rgba(217, 153, 44, 0.65));
}

.nut-line {
    stroke-width: 6;
}

.guide-line {
    stroke: var(--string-ink);
    stroke-width: 5;
    stroke-dasharray: 10 13;
}

.hit-target {
    fill: transparent;
    stroke: transparent;
    cursor: pointer;
}

.tuner-string-hit {
    stroke: transparent;
    stroke-width: 42;
    stroke-linecap: round;
    cursor: pointer;
}

.hit-target:hover + .ghost-dot,
.hit-target:focus + .ghost-dot {
    opacity: 1;
}

.ghost-dot {
    fill: var(--amber);
    opacity: 0;
    pointer-events: none;
}

.finger-dot {
    fill: var(--dot-fill);
    stroke: var(--dot-stroke);
    stroke-width: 4;
    cursor: pointer;
}

.finger-dot:hover {
    fill: var(--amber);
}

.finger-dot.playing {
    fill: var(--amber);
    stroke: #fff4df;
    stroke-width: 7;
    filter: drop-shadow(0 0 12px rgba(217, 153, 44, 0.75));
}

.finger-dot:focus,
.hit-target:focus {
    outline: none;
}

.note-label {
    opacity: 0;
    pointer-events: none;
    transition: opacity 140ms ease, transform 140ms ease;
}

.note-label rect {
    fill: var(--tooltip-bg);
    stroke: rgba(255, 255, 255, 0.8);
    stroke-width: 2;
}

.note-label text {
    fill: var(--tooltip-text);
    font-size: 14px;
    font-weight: 850;
    text-anchor: middle;
}

.hit-target:hover + .ghost-dot + .note-label,
.hit-target:focus + .ghost-dot + .note-label,
.finger-dot:hover + .note-label,
.finger-dot:focus + .note-label {
    opacity: 1;
}

.active-note-label rect {
    fill: var(--teal);
}

.fret-label {
    fill: var(--muted);
    font-size: 18px;
    font-weight: 800;
}

.position-editor,
.sound-panel {
    display: grid;
    gap: 10px;
    border-top: 1px solid var(--line);
    padding-top: 14px;
}

.position-list {
    display: grid;
    gap: 8px;
}

.position-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0 10px;
    background: var(--surface);
    font-size: 13px;
    font-weight: 800;
}

.position-row.out-of-range {
    border-style: dashed;
    color: var(--muted);
    background: transparent;
}

.note-name {
    margin-left: auto;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 8px;
    color: var(--teal);
    background: var(--teal-soft);
    font-size: 12px;
}

.small-play {
    min-width: 46px;
    height: 28px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--ink);
    background: var(--warm-soft);
    font-size: 12px;
    font-weight: 850;
}

.small-play:hover {
    border-color: var(--amber);
    background: var(--warm-strong);
}

.small-remove {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    color: var(--danger);
    background: transparent;
    font-size: 18px;
}

.sound-panel p {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.empty-state {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

@media (max-width: 1050px) {
    .app-shell {
        grid-template-columns: 240px minmax(0, 1fr);
    }

    .editor-panel {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }

    .panel-heading {
        grid-column: 1 / -1;
    }
}

@media (max-width: 760px) {
    .app-shell {
        grid-template-columns: 1fr;
        padding: 10px;
    }

    .fretboard-panel {
        grid-template-rows: auto minmax(300px, auto) auto;
        padding: 14px;
    }

    .fretboard-stage {
        min-height: 300px;
        border-radius: 18px;
    }

    .canvas-header,
    .canvas-footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .header-tools {
        align-items: flex-start;
    }

    .editor-panel {
        display: flex;
    }
}

@keyframes string-vibrate {
    0% {
        transform: translateY(-1px);
    }

    50% {
        transform: translateY(1px);
    }

    100% {
        transform: translateY(-1px);
    }
}
