:root {
  --bg: #131720;
  --surface: #1b2133;
  --border: #2a3450;
  --text: #e0e6f0;
  --muted: #6a7a9a;
  --accent: #4a8fff;
  --danger: #e94560;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

/* ── Header ───────────────────────────────────────────────────── */
header {
  width: 100%;
  padding: 0 16px;
  height: 42px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.header-title {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--accent);
  text-transform: uppercase;
}

.menu-trigger {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}

.menu-trigger:hover {
  background: var(--border);
}

.menu-trigger.active {
  background: var(--border);
  color: var(--accent);
}

/* ── Reset button (header, left of help) ─────────────────────── */
.reset-btn {
  /* margin-left: auto moved to #btn-add-fretboard (now the first right-side header item) */
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
}

.reset-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Help button (header, right side) ────────────────────────── */
.help-btn {
  /* margin-left: auto removed — reset-btn now owns the push */
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .85rem;
  font-weight: 700;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color .15s, border-color .15s, background .15s;
}

.help-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.help-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: #1a2a44;
}

/* ── Info / changelog button ─────────────────────────────────── */
.info-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .85rem;
  font-weight: 700;
  font-style: italic;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color .15s, border-color .15s, background .15s;
}

.info-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.info-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: #1a2a44;
}

/* ── Changelog panel ─────────────────────────────────────────── */
.vl-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 300;
}

.vl-overlay.active {
  display: block;
}

.vl-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(360px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 301;
  transform: translateX(100%);
  transition: transform .22s ease;
}

.vl-panel.active {
  transform: translateX(0);
}

.vl-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: 42px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.vl-title {
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.vl-body {
  overflow-y: auto;
  flex: 1;
  padding: 12px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.vl-hint {
  color: var(--muted);
  font-size: .82rem;
  margin-top: 8px;
}

.vl-entry {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.vl-entry:last-child {
  border-bottom: none;
}

.vl-entry-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .72rem;
}

.vl-version {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: .04em;
}

.vl-date {
  color: var(--muted);
}

.vl-commit {
  color: var(--muted);
  font-family: monospace;
  opacity: .6;
}

.vl-entry-title {
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
}

.vl-notes {
  margin: 2px 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vl-notes li {
  font-size: .8rem;
  color: var(--muted);
  list-style: disc;
}

/* ── Menu dropdown ────────────────────────────────────────────── */
.menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 49;
  /* transparent — only catches pointer events for outside-click close */
}

.menu-panel {
  position: fixed;
  z-index: 50;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 0;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .55);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  font-size: .88rem;
  padding: 8px 14px;
  text-align: left;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.menu-item:hover {
  background: #253050;
}

.menu-item.checked {
  color: var(--accent);
  padding-left: 8px;
}

.menu-item.checked::before {
  content: '✓';
  font-size: .8rem;
  margin-right: 2px;
  flex-shrink: 0;
}

/* Parent item with sub-panel */
.menu-item--parent {
  justify-content: space-between;
}

.menu-arrow {
  font-size: 1rem;
  color: var(--muted);
  line-height: 1;
}

.menu-item--parent[aria-expanded="true"] {
  background: #253050;
}

.menu-item--parent[aria-expanded="true"] .menu-arrow {
  color: var(--accent);
}

.menu-panel--sub {
  z-index: 51;
}

.menu-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.menu-label {
  font-size: .68rem;
  color: var(--muted);
  padding: 4px 14px 2px;
  letter-spacing: .04em;
}

.menu-item--icon-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: none;
  cursor: default;
}

.icon-radio-label {
  font-size: .75rem;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.icon-radio-btn {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 5px;
  padding: 4px 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, border-color .12s, color .12s;
}

.icon-radio-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.icon-radio-btn.checked {
  background: #1a2a4a;
  border-color: var(--accent);
  color: var(--accent);
}

.menu-item--slider {
  display: flex;
  flex-direction: column;
  padding: 6px 12px 8px;
  gap: 4px;
  cursor: default;
}

.menu-item--slider span {
  font-size: .8rem;
  color: var(--muted);
}

.menu-item--slider input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Back button — hidden on desktop, shown on mobile */
.menu-back {
  display: none;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 11px 14px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  color: var(--accent);
  font-size: .95rem;
  cursor: pointer;
  text-align: left;
}

.menu-back-arrow {
  font-size: 1.2rem;
  line-height: 1;
}

/* ── Mobile menu ─────────────────────────────────────────────── */
@media (max-width: 599px) {

  .menu-panel,
  .menu-panel--sub {
    left: 0 !important;
    right: 0 !important;
    width: auto !important;
    min-width: unset;
    max-height: 75vh;
    overflow-y: auto;
    border-radius: 0 0 12px 12px;
    border-left: none;
    border-right: none;
  }

  .menu-item {
    min-height: 44px;
    padding: 0 18px;
    font-size: 1rem;
  }

  .menu-item--slider {
    display: grid;
    grid-template-columns: 3.5rem 1fr;
    align-items: center;
    padding: 4px 18px;
    gap: 8px;
    min-height: unset;
  }

  .menu-item--slider span {
    font-size: .78rem;
  }

  .menu-item--slider input[type="range"] {
    height: 28px;
  }

  /* Tighter separators inside slider-heavy submenus */
  .menu-sep {
    margin: 2px 0;
  }

  .menu-back {
    display: flex;
  }
}

/* ── Main content wrapper ─────────────────────────────────────── */
#main-content {
  width: 100%;
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0 clamp(6px, 2vw, 16px);
  padding: 0 clamp(4px, 2vw, 12px);
  overflow: hidden;
}

/* ── Shared section ──────────────────────────────────────────── */
.section {
  min-width: 0;
  padding-inline: clamp(2px, 1vw, 8px);
  /* vertical: zero at ≤400px svh, scales up to full above ~800px */
  padding-block: clamp(0px, 3svh - 12px, 12px) clamp(0px, 6svh - 24px, 24px);
  display: flex;
  flex-direction: column;
}

/* ── Fretboard section ───────────────────────────────────────── */

#fretboards-container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 1rem;
}

.fretboard-instance {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
}

.fretboard-instance.active>.fretboard-instance-header {
  color: var(--accent);
}

.fretboard-instance:has(.fb-wheel-sync-btn[data-synced="false"]) {
  opacity: .75;
}

.fretboard-instance-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
  font-size: .72rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  letter-spacing: .05em;
  text-transform: uppercase;
  cursor: pointer;
}

.fb-drag-handle {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  cursor: grab;
  overflow: hidden;
}

.fb-scale-name {
  text-transform: none;
}

.fb-drag-handle:active {
  cursor: grabbing;
}

.fb-drag-icon {
  color: var(--muted);
  opacity: .5;
  font-size: .9rem;
  line-height: 1;
  flex-shrink: 0;
}

.fb-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.fb-close-btn {
  margin-left: 8px;
}

.fb-wheel-sync-btn {
  background: none;
  border: none;
  padding: 2px 3px;
  margin-right: 8px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
}

/* synced (default) — accent coloured */
.fb-wheel-sync-btn[data-synced="true"] {
  color: var(--accent);
}

/* unsynced / pinned — muted, strikethrough effect via opacity */
.fb-wheel-sync-btn[data-synced="false"] {
  color: var(--muted);
  opacity: .45;
}

.fb-wheel-sync-btn:hover {
  background: var(--border);
  opacity: 1;
}

.fb-log-listen-btn {
  background: none;
  border: none;
  padding: 2px 3px;
  margin-right: 4px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s, background .15s;
  color: var(--muted);
  opacity: .45;
}
.fb-log-listen-btn[data-listening="true"] {
  color: var(--accent);
  opacity: 1;
}
.fb-log-listen-btn:hover {
  background: var(--border);
  opacity: 1;
}

.fb-board-container {
  display: inline-block;
  overflow-x: auto;
  max-width: 100%;
}

/* ── Wheel ───────────────────────────────────────────────────── */
#wheel-section {
  flex: 1 1 300px;
  max-width: 700px;
  align-items: center;
  gap: clamp(4px, 1vw, 8px);
}

#wheel-header {
  width: 100%;
}

/* sizing only — interaction/visual styles live in cof-wheel.css */
#wheel-svg {
  width: 100%;
  aspect-ratio: 1;
}

/* ── Wheel wrap (SVG + overlaid rotation buttons) ────────────── */
#wheel-wrap {
  position: relative;
  width: 100%;
}

.ctrl-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}

.ctrl-btn:hover {
  background: #253050;
}

.wheel-btn {
  position: absolute;
  bottom: 7%;
  opacity: .7;
  transition: background .15s, opacity .15s;
}

.wheel-btn:hover {
  opacity: 1;
}

.wheel-btn--left {
  left: 4%;
}

.wheel-btn--right {
  right: 4%;
}

.wheel-btn--random {
  top: 4%;
  right: 4%;
  bottom: auto;
}

.wheel-btn--play {
  top: 4%;
  left: 4%;
  bottom: auto;
  flex-direction: column;
  height: auto;
  min-height: 36px;
  padding: 5px 4px;
}

/* Toggle play/stop icon */
#btn-play .icon-stop {
  display: none;
}

#drone-note {
  display: block;
  font-size: 0.85rem;
  line-height: 1;
  margin-top: 2px;
  opacity: 0.7;
  letter-spacing: 0;
  text-transform: none;
  pointer-events: none;
}

#btn-play.playing .icon-play {
  display: none;
}

#btn-play.playing .icon-stop {
  display: inline;
}

#btn-play.playing {
  background: #1a3a7a;
  color: var(--accent);
  animation: pulse-play 1.6s ease-in-out infinite;
  box-shadow: 0 0 0 0 #4a8fff66;
}


@keyframes pulse-play {
  0%, 100% {
    background: #1a3a7a;
    box-shadow: 0 0 0 0 #4a8fff44;
  }
  50% {
    background: #1e4899;
    box-shadow: 0 0 0 6px #4a8fff00;
  }
}


#notate-wrap {
  display: flex;
  justify-content: center;
  padding: 4px 0 2px;
  color: var(--text);
}

/* ── Help overlay (full-screen capture layer) ────────────────── */
#help-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, .38);
  cursor: crosshair;
}

/* ── Help highlight ring ─────────────────────────────────────── */
#help-highlight {
  position: fixed;
  z-index: 101;
  pointer-events: none;
  border: 2px solid var(--accent);
  border-radius: 6px;
  box-shadow: 0 0 0 3px rgba(74, 143, 255, .22);
  transition: top .18s ease, left .18s ease, width .18s ease, height .18s ease;
}

/* ── Help popup ──────────────────────────────────────────────── */
#help-popup {
  position: fixed;
  z-index: 102;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(340px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .65);
}

/* Future anchored mode: override centering via JS #positionAnchored() */
#help-popup[data-mode="anchored"] {
  top: unset;
  left: unset;
  transform: none;
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.help-title {
  font-weight: 700;
  font-size: .95rem;
  color: var(--accent);
}

.help-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 5px;
  border-radius: 4px;
  line-height: 1;
  transition: color .15s;
}

.help-close:hover {
  color: var(--danger);
}

.help-text {
  font-size: .85rem;
  color: var(--text);
  line-height: 1.55;
}

.help-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.help-nav-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: .8rem;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.help-nav-btn:hover:not(:disabled) {
  background: #253050;
  border-color: var(--accent);
}

.help-nav-btn:disabled {
  opacity: .38;
  cursor: default;
}

.help-nav-counter {
  font-size: .75rem;
  color: var(--muted);
}

/* ── Log section ─────────────────────────────────────────────── */
#right-column {
  flex: 1 1 300px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#log-section {
  container-type: inline-size;
}

/* ── Wheel preview (2-row state above the log) ───────────────── */
#preview-section {
  padding: 8px 4px 0;
}

#preview-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-group--preview {
  border-color: transparent !important;
  gap: 4px;
}

.log-group--preview .log-row {
  border-color: #1f2c48;
  background: #141c2e;
}


.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 2px;
  font-size: .78rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 2px 3px;
  cursor: pointer;
  opacity: .4;
  transition: opacity .15s, color .15s;
  display: flex;
  align-items: center;
}
.header-icon-btn:hover { opacity: .8; color: var(--text); }
.header-icon-btn.active { opacity: 1; color: var(--accent); }

.section-close-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  opacity: .5;
  transition: opacity .15s;
}

.section-close-btn:hover {
  opacity: 1;
  color: var(--text);
}

#log-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}


#btn-new-group,
#btn-add-fretboard {
  margin-left: auto;  /* pushes this + reset + help + info to the right in the header */
  background: #3c3d5f;
  border: 1px solid var(--border);
  color: #9da9c1;
  font-size: .72rem;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: .04em;
  transition: color .15s, border-color .15s;
}


#btn-new-group:hover,
#btn-add-fretboard:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.log-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-radius: 8px;
  padding: 4px;
  border: 1px solid transparent;
  transition: border-color .15s;
}

.log-group--active {
  border-color: var(--accent);
}

.log-group-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

.log-group-empty {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: .75rem;
  padding: 6px 8px 6px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
}

.del-group-btn {
  pointer-events: all;
  flex-shrink: 0;
}

.log-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: border-color .15s;
}

.log-identity {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.log-row.sortable-ghost {
  opacity: .35;
}

.log-row.sortable-chosen {
  border-color: var(--accent);
}

.log-row.sortable-drag {
  opacity: .9;
}

.log-row--active {
  border-color: var(--accent);
  background: #1a2540;
}

.drag-handle {
  color: var(--border);
  cursor: grab;
  font-size: 1.1rem;
  padding: 0 2px;
  touch-action: none;
  line-height: 1;
}

.drag-handle:hover {
  color: var(--muted);
}

.log-key {
  font-weight: 700;
  font-size: 1rem;
  min-width: 36px;
  flex-shrink: 1;
  color: #7c8597;
}

.log-row--first .log-key {
  color: #bf2727fa;
}

.log-badge {
  font-size: .65rem;
  padding: 2px 5px;
  border-radius: 4px;
  background: #1e2a44;
  color: var(--muted);
  min-width: 36px;
  text-align: center;
  letter-spacing: .04em;
}

.log-grade {
  font-size: .68rem;
  font-weight: 700;
  color: #e8a020;
  min-width: 32px;
  text-align: center;
  flex-shrink: 0;
  letter-spacing: .02em;
}

.log-notes {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: 2px;
  flex: 1;
  min-width: 0;
  align-items: center;
  background: #090e18;
  border-radius: 5px;
  padding: 3px 4px;
}

.note-chip {
  font-size: .75rem;
  padding: 2px 4px;
  border-radius: 4px;
  background: #2b3a5b;
  color: #a0b4cc;
  border: 1px solid transparent;
  transition: background .12s, color .12s;
  font-variant-numeric: tabular-nums;
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
}

.note-chip--empty {
  background: transparent;
  border-color: transparent;
  pointer-events: none;
}

.note-chip.common {
  background: #2f572f;
  color: #6ddf6d;
  border-color: #2a5a2a;
  font-weight: 700;
}


.del-btn {
  background: none;
  border: none;
  color: var(--border);
  cursor: pointer;
  font-size: .95rem;
  padding: 3px 5px;
  border-radius: 4px;
  line-height: 1;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}

.del-btn:hover {
  color: var(--danger);
  background: #2a1a20;
}

#empty-log {
  text-align: center;
  color: var(--muted);
  font-size: .85rem;
  padding: 28px 16px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  margin-top: 4px;
}

@container (max-width: 480px) {
  .log-row {
    gap: 4px;
    padding: 5px 6px;
  }

  .log-key {
    font-size: .9rem;
    min-width: 28px;
  }

  .note-chip {
    font-size: .68rem;
    padding: 1px 3px;
  }
}

@container (max-width: 360px) {
  .log-row {
    gap: 3px;
    padding: 4px 5px;
  }

  .log-key {
    font-size: .82rem;
    min-width: 22px;
  }

  .note-chip {
    font-size: .62rem;
    padding: 1px 2px;
  }

  .drag-handle {
    font-size: .9rem;
    padding: 0 1px;
  }
}