/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --text: #e0e0e0;
  --muted: #8888aa;
  --accent: #e94560;
  --root-color: #e94560;
  --note-color: #0f9b8e;
  --fret-wire: #555;
  --string-color: #c0a060;
  --nut-color: #ddd;
  --inlay: #333;
  --btn-bg: #223;
  --btn-hover: #334;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 1rem;
}

.app {
  width: 100%;
}

/* ── Header ── */
header {
  text-align: center;
  padding: 1rem 0 0.25rem;
}

.page-title-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
  padding: 0.25rem 0.5rem;
  outline: none;
  transition: border-color 0.2s;
}

.page-title-input::placeholder {
  color: var(--muted);
  font-weight: 400;
}

.page-title-input:hover {
  border-bottom-color: var(--fret-wire);
}

.page-title-input:focus {
  border-bottom-color: var(--accent);
}

/* ── Top bar ── */
.top-bar {
  display: flex;
  justify-content: flex-end;
  padding: 0.5rem 0;
  gap: 0.5rem;
}

/* ── Shared form styles ── */
select, .board-caption {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--fret-wire);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
}

select:focus, .board-caption:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

select:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

button {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--fret-wire);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover { background: var(--btn-hover); }
button:active { transform: scale(0.97); }

/* ── Export Dropdown ── */
.dropdown {
  position: relative;
  display: flex;
}

.dropdown > .dropdown-toggle {
  height: 100%;
}

.dropdown-toggle::after {
  content: ' \25BE';
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--fret-wire);
  border-radius: 4px;
  min-width: 150px;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

.dropdown-menu button:hover {
  background: var(--btn-hover);
}

.dropdown-menu button + button {
  border-top: 1px solid var(--fret-wire);
}

.dropdown.open .dropdown-menu {
  display: block;
}

.app.dropdown-open .fret-cell {
  pointer-events: none;
}

/* ── Board Card ── */
.board-card {
  border: 1px solid var(--fret-wire);
  border-radius: 6px;
  padding: 0.5rem 0.75rem 0.75rem;
  margin-bottom: 1rem;
  background: rgba(255,255,255,0.02);
}

/* ── Board Inline Controls ── */
.board-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding-bottom: 0.4rem;
  margin-bottom: 0.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.board-caption {
  flex: 1;
  min-width: 120px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--fret-wire);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.25rem 0.2rem;
  outline: none;
}

.board-caption::placeholder {
  color: var(--muted);
  font-weight: 400;
}

.board-caption:focus {
  border-bottom-color: var(--accent);
}

.board-export-label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.board-clear {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
}

.board-delete {
  font-size: 1rem;
  line-height: 1;
  padding: 0.15rem 0.45rem;
  color: var(--muted);
  border-color: transparent;
  background: transparent;
}

.board-delete:hover {
  color: var(--accent);
  background: rgba(233,69,96,0.1);
}

/* ── Add Fretboard Button ── */
.add-board-btn {
  display: block;
  width: 100%;
  padding: 0.6rem;
  font-size: 0.9rem;
  border: 2px dashed var(--fret-wire);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.add-board-btn:hover {
  border-color: var(--accent);
  color: var(--text);
  background: transparent;
}

/* ── Fretboard ── */
.fretboard-wrapper {
  display: flex;
  gap: 0;
  margin-top: 0.25rem;
}

.string-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  padding-right: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.string-label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  user-select: none;
}

.string-label:hover { color: var(--text); }

.string-label .string-name.dimmed {
  opacity: 0.35;
}

.mute-x {
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}

/* Muted string: fade the string line and any remaining dots */
.fret-cell.string-muted::before {
  opacity: 0.2;
}

.fret-cell.string-muted .note-dot {
  opacity: 0.25;
}

.fretboard-col {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.fretboard {
  display: grid;
  /* grid-template-columns set dynamically in JS */
  grid-template-rows: repeat(6, 1fr);
  border: none;
  position: relative;
  min-height: 240px;
}

/* Individual fret cell */
.fret-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-height: clamp(30px, 3.5vw, 46px);
  border-right: 2px solid var(--fret-wire);
  user-select: none;
}

/* Nut (fret 0 column) */
.fret-cell[data-fret="0"] {
  border-right: 4px solid var(--nut-color);
  background: rgba(255,255,255,0.03);
}

/* Left-handed: fret wires move from right to left; nut is on the left side of fret 0 */
.fretboard-wrapper.lefty .string-labels {
  padding-right: 0;
  padding-left: 0.5rem;
}

.fretboard-wrapper.lefty .fret-cell {
  border-right: none;
  border-left: 2px solid var(--fret-wire);
}

.fretboard-wrapper.lefty .fret-cell[data-fret="0"] {
  border-left: 4px solid var(--nut-color);
  border-right: none;
}

/* String line through each cell */
.fret-cell::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 3px;
  transform: translateY(-50%);
  background: var(--string-color);
  z-index: 0;
}

/* Thicker strings for lower strings */
.fret-cell[data-string="2"]::before { height: 3.5px; }
.fret-cell[data-string="3"]::before { height: 4px; }
.fret-cell[data-string="4"]::before { height: 4.5px; }
.fret-cell[data-string="5"]::before { height: 5px; }

/* Fret inlays */
.fret-cell.inlay::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--inlay);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: -1;
}

/* Note dot */
.note-dot {
  width: clamp(22px, 2.5vw, 36px);
  height: clamp(22px, 2.5vw, 36px);
  border-radius: 50%;
  background: var(--note-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(0.55rem, 0.8vw, 0.85rem);
  font-weight: 700;
  color: var(--dot-text);
  z-index: 1;
  transition: transform 0.1s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.note-dot.root {
  background: var(--root-color);
}

.note-dot.has-finger {
  font-size: clamp(0.65rem, 1vw, 1rem);
  font-weight: 800;
}

/* Sequence: active dot in the sequence path — green glow */
.note-dot.seq-active {
  box-shadow: 0 0 0 3px #22c55e, 0 1px 4px rgba(0,0,0,0.4);
}

/* Sequence SVG lines overlay — behind dots (z-index 0), dots are z-index 1 */
.seq-lines {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

/* Overlay: chord tone that overlaps with a scale note — gold ring */
.note-dot.overlay-hit {
  box-shadow: 0 0 0 3px #ffd700, 0 1px 4px rgba(0,0,0,0.4);
}

/* Overlay: chord tone NOT in the scale — hollow gold circle */
.note-dot.overlay-only {
  background: transparent;
  border: 2.5px solid #ffd700;
  color: #ffd700;
  box-shadow: none;
}

.fret-cell:hover .note-dot { transform: scale(1.1); }
.fret-cell:hover:not(:has(.note-dot))::after {
  content: '';
  width: clamp(22px, 2.5vw, 36px);
  height: clamp(22px, 2.5vw, 36px);
  border-radius: 50%;
  border: 2px dashed var(--muted);
  position: absolute;
  z-index: 1;
}

/* ── Fret numbers ── */
.fret-numbers-row {
  display: flex;
  align-items: center;
  padding-top: 0.25rem;
  gap: 0.2rem;
}

.fret-numbers {
  display: grid;
  /* grid-template-columns set dynamically in JS */
  flex: 1;
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.fret-numbers .fret-num {
  text-align: center;
}

.fret-numbers .fret-removable {
  cursor: pointer;
}

.fret-numbers .fret-removable:hover {
  color: var(--accent);
  font-weight: 700;
}

.fret-add {
  width: 1.2rem;
  height: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  border: 1px dashed var(--fret-wire);
  border-radius: 3px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.fret-add:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ── Settings Modal ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--fret-wire);
  border-radius: 8px;
  width: min(600px, 90vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--fret-wire);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  padding: 0 0.4rem;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-tabs {
  display: flex;
  gap: 0;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--fret-wire);
}

.modal-tab {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
}

.modal-tab:hover { color: var(--text); background: transparent; }

.modal-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
}

.modal-panel { display: none; }
.modal-panel.active { display: block; }

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  padding: 0.5rem 0;
}

.setting-label strong {
  display: block;
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.setting-desc {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
  max-width: 340px;
}

.setting-control {
  display: flex;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* Segmented toggle control */
.segmented {
  display: inline-flex;
  border: 1px solid var(--fret-wire);
  border-radius: 4px;
  overflow: hidden;
}

.seg-btn {
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--muted);
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.seg-btn + .seg-btn {
  border-left: 1px solid var(--fret-wire);
}

.seg-btn:hover {
  background: var(--btn-hover);
  color: var(--text);
}

.seg-btn.active {
  background: var(--accent);
  color: #fff;
}

.seg-btn.active:hover {
  background: var(--accent);
}

/* Settings button in top bar */
#btn-settings {
  font-size: 1rem;
  padding: 0.3rem 0.55rem;
}

/* Themes tab */
.themes-intro {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.themes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem;
}

.theme-card {
  border: 2px solid;
  border-radius: 6px;
  padding: 0;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  transition: transform 0.1s, box-shadow 0.15s;
  font-family: inherit;
}

.theme-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

.theme-card.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-preview {
  padding: 0.6rem;
  height: 48px;
  display: flex;
  align-items: center;
}

.theme-swatches {
  display: flex;
  gap: 0.35rem;
  width: 100%;
}

.theme-swatches span {
  flex: 1;
  height: 18px;
  border-radius: 3px;
  display: block;
}

.theme-meta {
  padding: 0.5rem 0.6rem 0.6rem;
}

.theme-name {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.theme-desc {
  font-size: 0.72rem;
  line-height: 1.3;
}

/* Archive tab */
.archive-intro,
.archive-note {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.archive-note {
  margin-top: 0.75rem;
  margin-bottom: 0;
  font-size: 0.8rem;
}

.archive-intro code,
.archive-note code {
  background: var(--btn-bg);
  color: var(--text);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.85em;
}

.archive-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.archive-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}

.archive-btn:hover {
  filter: brightness(1.1);
  background: var(--accent);
}

.archive-btn + .archive-btn {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--fret-wire);
  font-weight: 500;
}

.archive-btn + .archive-btn:hover {
  background: var(--btn-hover);
}

.archive-status {
  font-size: 0.85rem;
  color: var(--accent);
  padding: 0.4rem 0.6rem;
  background: var(--btn-bg);
  border-radius: 4px;
  margin-bottom: 0.5rem;
}

.archive-status.error {
  color: #ff6b6b;
}

/* Help tab */
.help-content h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--fret-wire);
}

.help-content h3:first-child {
  margin-top: 0;
}

.help-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 1rem;
  row-gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.help-list dt {
  font-weight: 600;
  color: var(--text);
  font-size: 0.85rem;
  padding-top: 0.1rem;
}

.help-list dd {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
  margin: 0;
}

.help-list dd strong {
  color: var(--text);
}

.help-list dd em {
  color: var(--text);
  font-style: italic;
}

@media (max-width: 600px) {
  .help-list {
    grid-template-columns: 1fr;
    row-gap: 0.25rem;
  }
  .help-list dt {
    margin-top: 0.5rem;
  }
}

/* Feedback form */
.feedback-intro {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
  margin-bottom: 1rem;
}

.feedback-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.feedback-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.feedback-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.feedback-field textarea,
.feedback-field select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--fret-wire);
  border-radius: 4px;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  width: 100%;
}

.feedback-field textarea:focus,
.feedback-field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.feedback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.feedback-send {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}

.feedback-send:hover {
  filter: brightness(1.1);
  background: var(--accent);
}

.feedback-send.secondary {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--fret-wire);
  font-weight: 500;
}

.feedback-send.secondary:hover {
  background: var(--btn-hover);
}

.feedback-status {
  font-size: 0.85rem;
  color: var(--accent);
  padding: 0.25rem 0;
}

/* ── Toast notification ── */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.6rem 1.2rem;
  font-size: 0.85rem;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.show { opacity: 1; }

/* ── Print styles ── */
@media print {
  body { background: #fff; color: #000; padding: 0; }
  .top-bar, .toast, .add-board-btn, .modal,
  .board-controls select, .board-clear, .board-delete, .board-export-label { display: none !important; }
  .page-title-input { color: #000; font-size: 1.3rem; border: none; }
  .app { padding: 0; }
  .board-card {
    border-color: #ccc;
    background: #fff;
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 0.4rem;
    padding: 0.3rem 0.5rem 0.4rem;
  }
  .board-caption { border: none; font-size: 0.85rem; color: #000; padding: 0.1rem 0; }
  .board-controls { margin-bottom: 0; padding-bottom: 0.15rem; }
  .board-controls select { border-color: #ccc; color: #000; background: #fff; }
  .fretboard { min-height: 0; }
  .fret-cell { min-height: 22px; }
  .fret-cell::before { background: none; border-top: 3px solid #333; height: 0; }
  .seq-lines { z-index: 0; }
  .seq-lines line { stroke: #22c55e !important; }
  .board-clear-seq { display: none !important; }
  .fret-add { display: none !important; }
  .fret-removable { color: #333 !important; font-weight: normal !important; cursor: default !important; }
  .note-dot {
    width: 18px; height: 18px;
    font-size: 0.5rem;
    color: var(--dot-text);
  }
  .note-dot.root { background: #c00; }
  .string-labels { font-size: 0.7rem; }
  .string-labels, .fret-numbers { color: #333; }
  .fret-numbers { font-size: 0.6rem; }
  .string-label .string-name.dimmed { opacity: 0.3; }
  .mute-x { color: #c00; }
  .fret-cell.string-muted::before { opacity: 0.15; }
  .fret-cell.string-muted .note-dot { opacity: 0.2; }
  .fret-cell { border-right-color: #999; }
  .fret-cell[data-fret="0"] { border-right-color: #333; }
  .fretboard-wrapper { margin-top: 0.1rem; }
  .page-title-input { font-size: 1.1rem; padding: 0.15rem; }
  header { padding: 0.25rem 0 0; }
}

/* ── Responsive ── */
@media (max-width: 700px) {
  .board-controls { gap: 0.3rem; }
  .board-controls select { font-size: 0.7rem; padding: 0.2rem 0.3rem; }
  .fretboard { min-height: 180px; }
}
