/* Design tokens — neutral dark surfaces, one vivid accent. */
:root {
  --bg-0: #111111;
  --bg-1: #1a1a1a;
  --bg-2: #222222;
  --bg-3: #2a2a2a;
  --bg-elev: #202020;

  --stroke-1: #2a2a2a;
  --stroke-2: #333333;
  --stroke-strong: #444444;

  --text-1: #e6e9f0;
  --text-2: #aab2c5;
  --text-3: #6b7589;
  --text-faint: #4a5366;

  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --accent-strong: #7aa1ff;

  --root: #e5484d;
  --chord: #2ec27e;
  --note-fg: #e6e9f0;

  --board-bg: #1a1a1a;
  --board-line: #3a3a3a;
  --board-nut: #555555;
  --board-inlay: #2e2e2e;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-3: 0 12px 32px rgba(0, 0, 0, 0.55);
  --shadow-focus: 0 0 0 2px var(--accent-soft);

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast: 90ms;
  --dur: 160ms;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", ui-monospace, Menlo,
    Consolas, monospace;

  --sidebar-w: 240px;
}

:root[data-theme="light"] {
  --bg-0: #f6f6f4;
  --bg-1: #efefec;
  --bg-2: #e7e7e3;
  --bg-3: #dededa;
  --bg-elev: #ffffff;

  --stroke-1: #dcdcd7;
  --stroke-2: #cfcfc9;
  --stroke-strong: #b8b8b1;

  --text-1: #2e2e2e;
  --text-2: #5a5a5a;
  --text-3: #8a8a85;
  --text-faint: #b0b0aa;

  --accent: #41788c;
  --accent-soft: rgba(65, 120, 140, 0.14);
  --accent-strong: #33606f;

  --root: #ab4642;
  --chord: #66763b;
  --note-fg: #2e2e2e;

  --board-bg: #efefec;
  --board-line: #c8c8c2;
  --board-nut: #9a9a94;
  --board-inlay: #d8d8d2;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-2: 0 4px 14px rgba(0, 0, 0, 0.1);
  --shadow-3: 0 12px 32px rgba(0, 0, 0, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  background: var(--bg-0);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-synthesis: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---- App shell -------------------------------------------------------- */

.shell {
  display: flex;
  height: 100%;
  /* Keep clear of notches / punch-hole cameras / home indicators where the
     platform exposes them to CSS (iOS; Android insets are handled natively). */
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}

/* ---- Sidebar ---------------------------------------------------------- */

.sidebar {
  width: var(--sidebar-w);
  min-width: 180px;
  max-width: 400px;
  flex: none;
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px;
  gap: 16px;
}

.shell.sidebar-closed .sidebar,
.shell.sidebar-closed .sidebar-resize {
  display: none;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

/* Circle of fifths */

.cof-wrap {
  width: 100%;
}

.cof {
  display: block;
  width: 100%;
  height: auto;
}

.cof-wedge {
  cursor: pointer;
}

.cof-fill {
  fill: var(--bg-2);
  stroke: var(--bg-1);
  stroke-width: 1.5;
  transition: fill var(--dur-fast) var(--ease);
}

.cof-minor .cof-fill {
  fill: var(--bg-1);
}

.cof-wedge:hover .cof-fill {
  fill: var(--bg-3);
}

.cof-wedge.is-active .cof-fill {
  fill: var(--accent-soft);
  stroke: var(--accent);
}

.cof-label {
  font-family: var(--font-mono);
  fill: var(--text-2);
  pointer-events: none;
  transition: fill var(--dur-fast) var(--ease);
}

.cof-label-major {
  font-size: 13px;
}

.cof-label-minor {
  font-size: 9.5px;
  fill: var(--text-3);
}

.cof-wedge:hover .cof-label,
.cof-wedge.is-active .cof-label {
  fill: var(--text-1);
}

.cof-center {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  fill: var(--root);
  pointer-events: none;
}

.scale-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.scale-btn {
  text-align: left;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}

.scale-btn:hover {
  background: var(--bg-3);
  color: var(--text-1);
}

.scale-btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text-1);
}

/* The 1px divider line IS the resize handle; ::before is an invisible
   wider hit area, ::after the hover/drag highlight centered on the line. */
/* Tuning */

.tuning-preset {
  appearance: none;
  -webkit-appearance: none;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}

.tuning-preset:hover {
  border-color: var(--stroke-strong);
  color: var(--text-1);
}

.tuning-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tuning-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tuning-step,
.tuning-remove {
  width: 24px;
  height: 24px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.tuning-step:hover,
.tuning-remove:hover:not(:disabled) {
  border-color: var(--stroke-strong);
  background: var(--bg-3);
  color: var(--text-1);
}

.tuning-note {
  width: 30px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-1);
}

.tuning-remove {
  margin-left: auto;
  border-color: transparent;
  background: transparent;
  color: var(--text-faint);
  font-size: 10px;
}

.tuning-remove:hover:not(:disabled) {
  color: var(--root);
}

.tuning-remove:disabled {
  opacity: 0.3;
  cursor: default;
}

.tuning-add {
  height: 26px;
  border: 1px dashed var(--stroke-2);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-3);
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}

.tuning-add:hover {
  border-color: var(--stroke-strong);
  color: var(--text-1);
}

.sidebar-resize {
  flex: none;
  width: 1px;
  background: var(--stroke-1);
  cursor: col-resize;
  position: relative;
  z-index: 5;
}

.sidebar-resize::before {
  content: "";
  position: absolute;
  inset: 0 -3px;
}

.sidebar-resize::after {
  content: "";
  position: absolute;
  inset: 0 -1px;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}

.sidebar-resize:hover::after,
.sidebar-resize.is-dragging::after {
  opacity: 1;
}

/* ---- Main area -------------------------------------------------------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border-bottom: 1px solid var(--stroke-1);
  background: var(--bg-1);
}

.tool-btn {
  height: 28px;
  min-width: 28px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: 12px;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.tool-btn:hover {
  border-color: var(--stroke-strong);
  background: var(--bg-3);
  color: var(--text-1);
}

.tool-btn:active {
  transform: translateY(0.5px);
}

.tool-btn.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text-1);
}

.tool-btn svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.context-label {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-2);
  padding: 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.context-label .ctx-key {
  color: var(--root);
  font-weight: 600;
}

.spacer {
  flex: 1;
}

/* ---- Panes ------------------------------------------------------------ */

.panes {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.pane-board {
  flex: 1;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  overflow: hidden;
}

.fretboard {
  width: 100%;
  height: 100%;
  max-height: 340px;
}

.pane-resize {
  flex: none;
  height: 1px;
  background: var(--stroke-1);
  cursor: row-resize;
  position: relative;
  z-index: 5;
}

.pane-resize::before {
  content: "";
  position: absolute;
  inset: -3px 0;
}

.pane-resize::after {
  content: "";
  position: absolute;
  inset: -1px 0;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}

.pane-resize:hover::after,
.pane-resize.is-dragging::after {
  opacity: 1;
}

.pane-chords {
  flex: none;
  /* Defaults to hugging its content (toolbar + one row of chips). An explicit
     px height is only applied once the user drags the resize handle. */
  height: auto;
  min-height: 0;
  max-height: 70%;
  background: var(--bg-1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.shell.chords-hidden .pane-chords,
.shell.chords-hidden .pane-resize {
  display: none;
}

.chords-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 0;
}

.chord-grid {
  /* basis auto so the grid is content-height by default, but still grows to
     fill (and scrolls) when the pane is dragged taller/shorter. */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  padding: 10px 12px 12px;
}

.chord-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 7px 12px;
  min-width: 74px;
  border: 1px solid var(--stroke-1);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text-2);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}

.chord-chip:hover {
  border-color: var(--stroke-strong);
  background: var(--bg-3);
  color: var(--text-1);
}

.chord-chip.is-active {
  border-color: var(--chord);
  background: var(--bg-3);
  color: var(--text-1);
  box-shadow: 0 0 0 1px var(--chord), 0 0 14px -6px var(--chord);
}

.chord-degree {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

.chord-chip.is-active .chord-degree {
  color: var(--chord);
}

.chord-symbol {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
}

/* ---- Fretboard SVG ---------------------------------------------------- */

.fretboard .nut {
  stroke: var(--board-nut);
  stroke-width: 7;
}

.fretboard .fret {
  stroke: var(--board-line);
  stroke-width: 2;
}

.fretboard .string {
  stroke: var(--board-line);
}

.fretboard .inlay {
  fill: var(--board-inlay);
}

.fretboard .note {
  transition: opacity var(--dur) var(--ease), fill var(--dur) var(--ease);
}

.fretboard .note-scale {
  fill: var(--note-fg);
}

.fretboard .note-root {
  fill: var(--root);
}

.fretboard .note-chord {
  fill: var(--chord);
}

.fretboard .note-dim {
  opacity: 0.16;
}

/* ---- Scrollbars ------------------------------------------------------- */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--stroke-2);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* ---- Mobile ----------------------------------------------------------- */

@media (max-width: 640px) {
  .sidebar {
    position: fixed;
    inset: calc(44px + env(safe-area-inset-top, 0px)) 25%
      env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
    z-index: 20;
    width: auto !important;
    min-width: 0;
    box-shadow: var(--shadow-3);
  }

  .sidebar-resize {
    display: none;
  }

  .pane-board {
    padding: 10px;
  }

  .context-label {
    font-size: 11px;
  }
}
