/**
 * SBN Interactive Fretboard
 *
 * Standalone horizontal fretboard visualization.
 * Ported from the legacy WP leadsheet plugin (sbn-course-player).
 *
 * Theming: .sbn-fretboard-wrap.theme-dark (default) | .sbn-fretboard-wrap.theme-light
 * Used via: <sbn-fretboard> tag in course lessons, and the admin fretboard editor.
 *
 * Class namespace: .sbn-fretboard-*
 * WP --sbn-primary → var(--clr-accent)
 */

/* ==========================================================================
   WRAPPER + HEADER
   ========================================================================== */

.sbn-fretboard-wrap {
    display: flex;
    flex-direction: column;
    gap: 0;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--clr-border);
}

.sbn-fretboard-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--clr-bg-subtle, #f5f5f3);
    border-bottom: 1px solid var(--clr-border);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--clr-text-dim);
}

.sbn-fretboard-header-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Sequence step controls */
.sbn-fretboard-steps {
    display: flex;
    align-items: center;
    gap: 6px;
}

.sbn-fretboard-step-btn {
    width: 22px;
    height: 22px;
    border: 1px solid var(--clr-border);
    background: var(--clr-bg);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--clr-text);
    transition: background 0.12s;
}
.sbn-fretboard-step-btn:hover { background: var(--clr-border); }
.sbn-fretboard-step-btn:disabled { opacity: 0.35; cursor: default; }

.sbn-fretboard-step-counter {
    font-size: 11px;
    color: var(--clr-text-dim);
    min-width: 32px;
    text-align: center;
}

/* Guide tone + theme toggles */
.sbn-fretboard-guide-toggle {
    background: none;
    border: 1.5px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    transition: all 0.15s;
    letter-spacing: 0.5px;
}
.sbn-fretboard-guide-toggle:hover {
    border-color: rgba(255,255,255,0.6);
    color: rgba(255,255,255,0.8);
}
.sbn-fretboard-guide-toggle.is-active {
    background: rgba(var(--clr-accent-rgb, 232,93,59), 0.2);
    border-color: var(--clr-accent);
    color: var(--clr-accent);
}

.sbn-fretboard-theme-toggle {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s;
}
.sbn-fretboard-theme-toggle:hover { background: rgba(0,0,0,0.08); }

/* ==========================================================================
   FRETBOARD GRID — DARK THEME (default)
   ========================================================================== */

.sbn-fretboard {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.sbn-fretboard-grid {
    display: flex;
    align-items: stretch;
    background: linear-gradient(to bottom, #1a1a1a, #0d0d0d);
    overflow: hidden;
    min-height: 130px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
    position: relative;
}

/* String labels column (e B G D A E — high to low) */
.sbn-fretboard-string-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 6px 8px;
    background: #1a1a1a;
    border-right: 1px solid #333;
    min-width: 22px;
    flex-shrink: 0;
}

.sbn-fretboard-string-label {
    font-size: 10px;
    font-weight: 600;
    color: #888;
    text-align: center;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
}
.sbn-fretboard-string-label.is-highlighted { color: var(--clr-accent, #e85d3b); }

/* Open strings column (fret 0) */
.sbn-fretboard-open-fret {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 6px 8px;
    background: #151515;
    min-width: 28px;
    flex-shrink: 0;
}

.sbn-fretboard-open-string {
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* String line in open column */
.sbn-fretboard-open-string::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 50%;
    height: 1px;
    background: #555;
    transform: translateY(-50%);
    transition: background 0.1s;
}
.sbn-fretboard-open-string[data-string="3"]::before { height: 1.5px; }
.sbn-fretboard-open-string[data-string="4"]::before { height: 2px; }
.sbn-fretboard-open-string[data-string="5"]::before { height: 2.5px; background: #4a4a4a; }

.sbn-fretboard-open-string.is-muted::before { opacity: 0.25; }

/* Open-string dot (○) */
.sbn-fretboard-open-dot {
    width: 14px;
    height: 14px;
    border: 2px solid #888;
    border-radius: 50%;
    background: transparent;
    position: relative;
    z-index: 2;
    transition: border-color 0.15s, box-shadow 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Nut */
.sbn-fretboard-nut {
    width: 6px;
    background: linear-gradient(to right, #f5f5f0, #d8d8d0, #f5f5f0);
    border-right: 1px solid #333;
    flex-shrink: 0;
    box-shadow: 1px 0 3px rgba(0,0,0,0.3);
}

/* Frets container */
.sbn-fretboard-frets {
    display: flex;
    flex: 1;
    overflow-x: auto;
    padding-bottom: 20px; /* room for fret numbers */
}
.sbn-fretboard-frets::-webkit-scrollbar { height: 4px; }
.sbn-fretboard-frets::-webkit-scrollbar-track { background: #1a1a1a; }
.sbn-fretboard-frets::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

/* Individual fret column */
.sbn-fretboard-fret {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    min-width: 48px;
    flex: 1;
    border-right: 2px solid #c0a060;
    padding: 6px 3px;
    position: relative;
    background: linear-gradient(to right,
        rgba(255,255,255,0.02), transparent 20%,
        transparent 80%, rgba(255,255,255,0.01));
}
.sbn-fretboard-fret:last-child { border-right-color: #a08040; }

/* Fret markers — mother-of-pearl style */
.sbn-fretboard-fret.has-marker::before {
    content: '';
    position: absolute;
    width: 8px; height: 8px;
    background: radial-gradient(ellipse at 30% 30%, #e8e8e0, #c8c8c0, #a8a8a0);
    border-radius: 50%;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.7;
    box-shadow: inset 0 1px 2px rgba(255,255,255,0.3);
}
.sbn-fretboard-fret.double-marker::before { top: 30%; }
.sbn-fretboard-fret.double-marker::after {
    content: '';
    position: absolute;
    width: 8px; height: 8px;
    background: radial-gradient(ellipse at 30% 30%, #e8e8e0, #c8c8c0, #a8a8a0);
    border-radius: 50%;
    left: 50%; top: 70%;
    transform: translate(-50%, -50%);
    opacity: 0.7;
    box-shadow: inset 0 1px 2px rgba(255,255,255,0.3);
}

/* Fret number below the grid */
.sbn-fretboard-fret-num {
    position: absolute;
    bottom: -16px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    color: #666;
    font-weight: 500;
}

/* String cell within a fret */
.sbn-fretboard-string {
    height: 18px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* String line — metallic */
.sbn-fretboard-string::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 50%;
    height: 1px;
    background: linear-gradient(to bottom, #888, #666);
    transform: translateY(-50%);
    transition: background 0.1s, box-shadow 0.1s;
}
.sbn-fretboard-string[data-string="3"]::before { height: 1.5px; background: linear-gradient(to bottom, #777, #555); }
.sbn-fretboard-string[data-string="4"]::before { height: 2px;   background: linear-gradient(to bottom, #666, #444); }
.sbn-fretboard-string[data-string="5"]::before { height: 2.5px; background: linear-gradient(to bottom, #5a5a5a, #3a3a3a); }

/* Finger dot */
.sbn-fretboard-dot {
    width: 20px; height: 20px;
    background: linear-gradient(145deg, #e8e8e0, #c8c8c0);
    border-radius: 50%;
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #333;
    font-size: 10px;
    font-weight: 700;
    box-shadow: 0 2px 4px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.5);
    transition: transform 0.1s, box-shadow 0.1s;
}
.sbn-fretboard-dot.has-finger {
    background: linear-gradient(145deg, #f0e8d8, #d8d0c0);
}

/* ==========================================================================
   RIGHT-HAND FINGERING COLUMN (p i m a)
   ========================================================================== */

.sbn-fretboard-rh-fingers {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    padding: 6px 10px;
    background: rgba(0,0,0,0.2);
    border-left: 1px solid #333;
    min-width: 28px;
    flex-shrink: 0;
}

.sbn-fretboard-rh-finger {
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #d0d0d0;
    font-style: italic;
    transition: color 0.15s, transform 0.15s;
}
.sbn-fretboard-rh-finger.is-muted { opacity: 0.3; }

/* ==========================================================================
   GUIDE TONE DOT COLORS
   ========================================================================== */

.sbn-fretboard-dot.gt-seventh  { background: linear-gradient(145deg, #fbbf24, #d97706) !important; color: #1a1a1a !important; font-size: 8px; font-weight: 800; }
.sbn-fretboard-dot.gt-third    { background: linear-gradient(145deg, #60a5fa, #2563eb) !important; color: #fff     !important; font-size: 8px; font-weight: 800; }
.sbn-fretboard-dot.gt-root     { background: linear-gradient(145deg, #e8e8e0, #c8c8c0) !important; color: #333     !important; font-size: 8px; font-weight: 800; }
.sbn-fretboard-dot.gt-ninth    { background: linear-gradient(145deg, #a78bfa, #7c3aed) !important; color: #fff     !important; font-size: 8px; font-weight: 800; }
.sbn-fretboard-dot.gt-fifth    { background: linear-gradient(145deg, #9ca3af, #6b7280) !important; color: #fff     !important; font-size: 8px; font-weight: 800; }

.sbn-fretboard-open-dot.gt-seventh { border-color: #fbbf24; background: rgba(251,191,36,0.3);  color: #fbbf24; display:flex; align-items:center; justify-content:center; }
.sbn-fretboard-open-dot.gt-third   { border-color: #60a5fa; background: rgba(96,165,250,0.3);  color: #60a5fa; display:flex; align-items:center; justify-content:center; }
.sbn-fretboard-open-dot.gt-root    { border-color: #e8e8e0; background: rgba(232,232,224,0.3); color: #e8e8e0; display:flex; align-items:center; justify-content:center; }
.sbn-fretboard-open-dot.gt-ninth   { border-color: #a78bfa; background: rgba(167,139,250,0.3); color: #a78bfa; display:flex; align-items:center; justify-content:center; }
.sbn-fretboard-open-dot.gt-fifth   { border-color: #9ca3af; background: rgba(156,163,175,0.3); color: #9ca3af; display:flex; align-items:center; justify-content:center; }

/* Ghost dots (voice-leading resolution targets) */
.sbn-fretboard-ghost-dot {
    width: 18px; height: 18px;
    border-radius: 50%;
    position: relative;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 7px;
    font-weight: 800;
    opacity: 0.5;
    animation: sbn-fb-ghost-pulse 2s ease-in-out infinite;
}
.sbn-fretboard-ghost-dot.seventh-to-third { border: 2px dashed #fbbf24; color: #fbbf24; background: rgba(251,191,36,0.1); }
.sbn-fretboard-ghost-dot.third-to-root    { border: 2px dashed #60a5fa; color: #60a5fa; background: rgba(96,165,250,0.1); }

@keyframes sbn-fb-ghost-pulse {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50%       { opacity: 0.7; transform: scale(1.05); }
}

/* SVG guide-tone arrow overlay */
.sbn-gt-arrows {
    position: absolute;
    top: 0; left: 0;
    pointer-events: none;
    z-index: 10;
}

/* ==========================================================================
   LIGHT THEME
   ========================================================================== */

.sbn-fretboard-wrap.theme-light .sbn-fretboard-grid {
    background: linear-gradient(to bottom, #f5e6d3, #e8d4bc);
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}
.sbn-fretboard-wrap.theme-light .sbn-fretboard-string-labels {
    background: #e8dcc8;
    border-right-color: #d4c4a8;
}
.sbn-fretboard-wrap.theme-light .sbn-fretboard-string-label { color: #666; }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-open-fret    { background: #efe4d4; }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-open-string::before { background: #a89070; }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-open-string[data-string="5"]::before { background: #8a7a60; }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-open-dot { border-color: #666; }

.sbn-fretboard-wrap.theme-light .sbn-fretboard-nut {
    background: linear-gradient(to right, #f5f5f0, #e8e8e0, #f5f5f0);
    border-right: 2px solid #333;
    box-shadow: 1px 0 2px rgba(0,0,0,0.1);
}
.sbn-fretboard-wrap.theme-light .sbn-fretboard-fret {
    border-right-color: #a89070;
    background: linear-gradient(to right, rgba(0,0,0,0.02), transparent 20%, transparent 80%, rgba(0,0,0,0.03));
}
.sbn-fretboard-wrap.theme-light .sbn-fretboard-fret:last-child { border-right-color: #8a7a60; }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-fret.has-marker::before  { background: #d4c4a8; opacity: 0.8; box-shadow: none; }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-fret.double-marker::after { background: #d4c4a8; opacity: 0.8; }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-fret-num { color: #999; }

.sbn-fretboard-wrap.theme-light .sbn-fretboard-string::before              { background: linear-gradient(to bottom, #b8a080, #8a7a60); }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-string[data-string="3"]::before { background: linear-gradient(to bottom, #a89070, #7a6a50); }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-string[data-string="4"]::before { background: linear-gradient(to bottom, #988060, #6a5a40); }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-string[data-string="5"]::before { background: linear-gradient(to bottom, #887050, #5a4a30); }

.sbn-fretboard-wrap.theme-light .sbn-fretboard-dot {
    background: linear-gradient(135deg, #444, #222);
    color: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.2);
}
.sbn-fretboard-wrap.theme-light .sbn-fretboard-dot.has-finger {
    background: linear-gradient(135deg, var(--clr-accent, #e85d3b), #c04a2a);
}
.sbn-fretboard-wrap.theme-light .sbn-fretboard-rh-fingers { background: rgba(0,0,0,0.05); border-left-color: #d4c4a8; }
.sbn-fretboard-wrap.theme-light .sbn-fretboard-rh-finger  { color: #555; }

.sbn-fretboard-wrap.theme-light .sbn-fretboard-guide-toggle {
    border-color: rgba(0,0,0,0.2);
    color: rgba(0,0,0,0.4);
}
.sbn-fretboard-wrap.theme-light .sbn-fretboard-guide-toggle:hover {
    border-color: rgba(0,0,0,0.4);
    color: rgba(0,0,0,0.6);
}
.sbn-fretboard-wrap.theme-light .sbn-fretboard-guide-toggle.is-active {
    background: rgba(232,93,59,0.15);
    border-color: var(--clr-accent, #e85d3b);
    color: var(--clr-accent, #e85d3b);
}
.sbn-fretboard-wrap.theme-light .sbn-fretboard-dot.gt-third {
    background: linear-gradient(145deg, #3b82f6, #1d4ed8) !important;
    color: #fff !important;
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 640px) {
    .sbn-fretboard-fret   { min-width: 38px; }
    .sbn-fretboard-dot    { width: 16px; height: 16px; font-size: 9px; }
    .sbn-fretboard-grid   { min-height: 110px; }
    .sbn-fretboard-string-labels { min-width: 18px; padding: 6px 4px; }
    .sbn-fretboard-string-label  { font-size: 9px; }
    .sbn-fretboard-open-fret     { min-width: 24px; padding: 6px 4px; }
    .sbn-fretboard-open-dot      { width: 12px; height: 12px; border-width: 1.5px; }
    .sbn-fretboard-rh-fingers    { min-width: 20px; padding: 6px 4px; }
    .sbn-fretboard-rh-finger     { font-size: 9px; }
}

/* ==========================================================================
   ADMIN EDITOR — frame list sidebar
   ========================================================================== */

.sbn-fb-frame-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sbn-fb-frame-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--clr-bg);
    border: 1px solid var(--clr-border);
    border-radius: 6px;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
}
.sbn-fb-frame-item.is-active {
    border-color: var(--clr-accent);
    background: rgba(var(--clr-accent-rgb, 232,93,59), 0.04);
}
.sbn-fb-frame-item:hover:not(.is-active) { border-color: var(--clr-text-dim); }

.sbn-fb-frame-label {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--clr-text);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sbn-fb-frame-frets {
    font-size: 11px;
    font-family: var(--font-mono, monospace);
    color: var(--clr-text-dim);
}
.sbn-fb-frame-del {
    flex-shrink: 0;
    width: 20px; height: 20px;
    border: none;
    background: none;
    color: var(--clr-text-dim);
    cursor: pointer;
    border-radius: 3px;
    font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    transition: color 0.12s, background 0.12s;
}
.sbn-fb-frame-del:hover { color: var(--clr-error); background: rgba(239,68,68,0.08); }
