/* Modus — an Antroposoft AI app.
   Dark by default (practice rooms are dark), light theme fully supported.
   Colour never carries meaning alone: every note function also has a shape
   and prints its own name. */

:root {
  --bg: #fcfcfb;
  --surface: #ffffff;
  --surface-2: #f2f1ee;
  --line: #dedcd5;
  --line-soft: #ebe9e3;
  --ink: #1a1a19;
  --ink-2: #57564f;
  --ink-3: #898781;

  --accent: #2a78d6;          /* chord tones */
  --accent-2: #eb6834;        /* distinguishing tones */
  --warn: #d99500;            /* avoid / tension */
  --root-fill: #0b0b0b;
  --root-ink: #ffffff;

  --fb-surface: #f7f6f3;
  --fb-wire: #c3c2b7;
  --fb-string: #b6b5ab;
  --fb-inlay: #dedcd5;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px -12px rgba(0,0,0,.18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
  :root:not([data-theme="light"]) {
    --bg: #131315;
    --surface: #1a1a1d;
    --surface-2: #212125;
    --line: #34343a;
    --line-soft: #26262b;
    --ink: #ecebe8;
    --ink-2: #a9a8a3;
    --ink-3: #7c7b77;

    --accent: #3987e5;
    --accent-2: #f0764a;
    --warn: #fab219;
    --root-fill: #ffffff;
    --root-ink: #0e0e10;

    --fb-surface: #1e1e21;
    --fb-wire: #45454c;
    --fb-string: #55555d;
    --fb-inlay: #303036;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.7);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131315;
  --surface: #1a1a1d;
  --surface-2: #212125;
  --line: #34343a;
  --line-soft: #26262b;
  --ink: #ecebe8;
  --ink-2: #a9a8a3;
  --ink-3: #7c7b77;
  --accent: #3987e5;
  --accent-2: #f0764a;
  --warn: #fab219;
  --root-fill: #ffffff;
  --root-ink: #0e0e10;
  --fb-surface: #1e1e21;
  --fb-wire: #45454c;
  --fb-string: #55555d;
  --fb-inlay: #303036;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.7);
}

:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }

/* Layout rules below set display, which would otherwise beat [hidden]. */
[hidden] { display: none !important; }

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

body {
  min-height: 100dvh;
  display: grid;
  /* Explicit column: an implicit `auto` track sizes to max-content, so one
     long sentence would widen the whole page past the viewport. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand-mark {
  font-size: 19px; font-weight: 650; letter-spacing: .16em; text-transform: uppercase;
}
.brand-sub { font-size: 10.5px; color: var(--ink-3); letter-spacing: .1em; text-transform: uppercase; }

.chordpick { display: flex; align-items: center; gap: 14px; flex: 1 1 auto; flex-wrap: wrap; min-width: 0; }

/* min-width:0 everywhere a scrolling strip lives, or its content width leaks
   out and drags the whole page into horizontal overflow. */
.roots { display: flex; gap: 3px; flex-wrap: wrap; min-width: 0; }

.roots button {
  min-width: 38px;
  padding: 7px 6px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  transition: background .12s, color .12s;
}
.roots button:hover { background: var(--line-soft); color: var(--ink); }
.roots button[aria-checked="true"] {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}

#quality {
  padding: 8px 12px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface-2);
  font-weight: 550;
}

.topright { display: flex; align-items: center; gap: 14px; margin-left: auto; }

.families { display: flex; gap: 4px; }
.families button {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-3);
  font-size: 12.5px;
  font-weight: 550;
}
.families button[aria-pressed="true"] {
  background: var(--surface-2);
  border-color: var(--ink-3);
  color: var(--ink);
}

.icon-btn {
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: transparent;
  font-size: 16px;
}

/* -------------------------------------------------------------------- main */

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 18px;
  padding: 18px 24px 22px;
  min-height: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}

.candidates-panel { grid-column: 1; grid-row: 1; padding: 16px 18px 18px; }
/* Floor the neck: on a short window let the page scroll rather than squash
   the fretboard down to a sliver. */
.board-panel { grid-column: 1; grid-row: 2; display: flex; flex-direction: column; min-height: 300px; padding: 8px 10px 12px; }
.rail { grid-column: 2; grid-row: 1 / span 2; padding: 18px; overflow-y: auto; }

.panel-head {
  display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 550; color: var(--ink-3); letter-spacing: .04em; }
.panel-head h2 b { color: var(--ink); font-size: 15px; font-weight: 650; }
.shared-line { margin: 0; font-size: 12.5px; color: var(--ink-3); flex: 1 1 320px; min-width: 0; }
.shared-line b { color: var(--ink-2); font-weight: 600; }

/* ------------------------------------------------------------- candidates */

.candidates { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px; }

.card {
  flex: 1 1 0;
  min-width: 208px;
  text-align: left;
  padding: 13px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  transition: border-color .12s, background .12s, transform .12s;
}
.card:hover { border-color: var(--ink-3); }
.card[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, var(--surface-2));
  box-shadow: inset 0 0 0 1px var(--accent);
}

.card-name { display: block; font-size: 15.5px; font-weight: 650; margin-bottom: 2px; }
.card-parent { display: block; font-size: 11.5px; color: var(--ink-3); margin-bottom: 9px; }
.card-notes {
  font-family: var(--mono); font-size: 12px; color: var(--ink-2);
  letter-spacing: .02em; margin-bottom: 9px; word-spacing: .25em;
}
.card-notes .is-diff { color: var(--accent-2); font-weight: 700; }

.card-row { display: flex; align-items: baseline; gap: 6px; font-size: 11.5px; margin-top: 5px; }
.card-row-label { color: var(--ink-3); flex: 0 0 auto; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  border: 1px solid transparent;
}
.chip-diff { background: color-mix(in srgb, var(--accent-2) 16%, transparent); color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 34%, transparent); }
.chip-avoid { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 36%, transparent); }
.chip-none { color: var(--ink-3); border-color: var(--line); }
.chip small { opacity: .7; font-weight: 500; }

.card-flag {
  display: inline-block; margin-top: 8px; font-size: 10.5px;
  color: var(--ink-3); font-style: italic;
}

.empty { padding: 6px 2px 2px; }
.empty h3 { margin: 0 0 6px; font-size: 14px; }
.empty p { margin: 0 0 12px; font-size: 13px; color: var(--ink-2); max-width: 62ch; }
.empty ul { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); }
.empty li { margin-bottom: 3px; }
.empty li b { color: var(--ink); font-weight: 600; }

.solid-btn {
  padding: 8px 14px; border: 0; border-radius: 9px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 13px;
  margin-bottom: 12px;
}

/* -------------------------------------------------------------- fretboard */

/* The SVG is absolutely positioned so it always has a definite box to measure
   against — a percentage height on an auto-height parent resolves to auto and
   the board silently overflows its panel. */
.board-wrap { flex: 1 1 auto; min-height: 0; position: relative; }
.fretboard { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; }

.fb-surface { fill: var(--fb-surface); }
.fb-wire { stroke: var(--fb-wire); stroke-width: 1.4; }
.fb-wire.is-nut { stroke: var(--ink-2); stroke-width: 4; stroke-linecap: round; }
.fb-string { stroke: var(--fb-string); }
.fb-inlay { fill: var(--fb-inlay); }
.fb-number { fill: var(--ink-3); font-size: 11px; font-family: var(--mono); text-anchor: middle; }

.fb-dot { cursor: pointer; }
.fb-hit { fill: transparent; }
.fb-label {
  text-anchor: middle; font-weight: 650; pointer-events: none;
  font-family: var(--font); fill: var(--ink);
}
.fb-shape { pointer-events: none; }
.fb-ring { fill: none; pointer-events: none; }

.fb-dot[data-fn="root"] .fb-shape { fill: var(--root-fill); stroke: none; }
.fb-dot[data-fn="root"] .fb-label { fill: var(--root-ink); }

.fb-dot[data-fn="chord"] .fb-shape { fill: var(--accent); stroke: none; }
.fb-dot[data-fn="chord"] .fb-label { fill: #fff; }

.fb-dot[data-fn="dist"] .fb-shape { fill: var(--accent-2); stroke: none; }
.fb-dot[data-fn="dist"] .fb-label { fill: #fff; }
.fb-dot[data-fn="dist"] .fb-ring { stroke: var(--accent-2); opacity: .55; }

.fb-dot[data-fn="scale"] .fb-shape { fill: var(--fb-surface); stroke: var(--ink-3); stroke-width: 1.5; }
.fb-dot[data-fn="scale"] .fb-label { fill: var(--ink-2); }

.fb-dot[data-fn="avoid"] .fb-shape,
.fb-dot[data-fn="tension"] .fb-shape {
  fill: var(--fb-surface); stroke: var(--warn); stroke-width: 1.8; stroke-dasharray: 3 2.4;
}
.fb-dot[data-fn="avoid"] .fb-label,
.fb-dot[data-fn="tension"] .fb-label { fill: var(--warn); }

.fb-dot.is-pulsing .fb-shape { transform: scale(1.28); transform-box: fill-box; transform-origin: center; }
.fb-dot .fb-shape { transition: transform .12s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .fb-dot .fb-shape { transition: none; }
  .fb-dot.is-pulsing .fb-shape { transform: none; }
}

/* --------------------------------------------------------------- boardbar */

.boardbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 8px 8px 2px;
  border-top: 1px solid var(--line-soft);
  margin-top: 6px;
}

.legend { display: flex; gap: 14px; margin: 0; padding: 0; list-style: none; flex-wrap: wrap; }
.legend li { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); }
.legend i { width: 13px; height: 13px; display: inline-block; flex: 0 0 auto; }
.legend .sw-root { background: var(--root-fill); transform: rotate(45deg); border-radius: 2px; }
.legend .sw-chord { background: var(--accent); border-radius: 50%; }
.legend .sw-dist { background: var(--accent-2); border-radius: 50%; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent-2) 45%, transparent); }
.legend .sw-scale { border: 1.5px solid var(--ink-3); border-radius: 50%; }
.legend .sw-avoid { border: 1.8px dashed var(--warn); border-radius: 3px; }

.boardctl { display: flex; align-items: center; gap: 16px; margin-left: auto; flex-wrap: wrap; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button {
  padding: 6px 11px; border: 0; background: transparent;
  font-size: 12px; font-weight: 550; color: var(--ink-3);
}
.seg button.is-on { background: var(--surface-2); color: var(--ink); }

.rangectl { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--ink-3); }
.rangectl input { width: 92px; accent-color: var(--accent); }
.rangectl output { font-family: var(--mono); color: var(--ink-2); min-width: 16px; }

.ghost-btn {
  padding: 6px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; font-size: 12px; color: var(--ink-2);
}

/* The sliders are fine with a mouse; on a phone you want a thumb-sized
   shove up and down the neck. */
.stepper { display: none; align-items: center; gap: 4px; }
.stepper button {
  width: 44px; min-height: 40px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface-2); font-size: 13px;
}
.stepper output {
  font-family: var(--mono); font-size: 12px; color: var(--ink-2);
  min-width: 52px; text-align: center;
}

/* ------------------------------------------------------------------- rail */

.rail-block + .rail-block { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line-soft); }
.rail-title {
  margin: 0 0 9px; font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .11em; color: var(--ink-3);
}
.parent-line { margin: 0; font-size: 17px; font-weight: 600; line-height: 1.35; }
.parent-line b { color: var(--accent); }
.parent-note { margin: 8px 0 0; font-size: 12.5px; color: var(--ink-2); }

.siblings { list-style: none; margin: 0; padding: 0; }
.siblings li + li { margin-top: 2px; }
.siblings button {
  display: flex; align-items: baseline; gap: 8px; width: 100%;
  padding: 7px 9px; border: 1px solid transparent; border-radius: 8px;
  background: transparent; text-align: left; font-size: 13px;
}
.siblings button:hover { background: var(--surface-2); }
.siblings button[aria-current="true"] {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
  font-weight: 600;
}
.sib-root { font-weight: 650; min-width: 26px; }
.sib-mode { color: var(--ink-2); }
.sib-chord { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--ink-3); }

.rail-hint, .character { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-3); line-height: 1.55; }
.character { color: var(--ink-2); margin: 0; }

/* -------------------------------------------------------------- transport */

.transport {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 11px 24px calc(11px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.tbtn {
  padding: 9px 18px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface-2); font-weight: 600; font-size: 13.5px;
}
.tbtn[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.tbtn-primary[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.tctl { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--ink-3); }
.tctl input { width: 120px; accent-color: var(--accent); }
.tctl span { font-family: var(--mono); color: var(--ink-2); min-width: 26px; text-align: right; }
.tctl-vol { margin-left: auto; }
.tctl-vol input { width: 90px; }

.tselect {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); font-size: 12.5px;
}

.audio-badge {
  padding: 5px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 38%, transparent);
}

.hint {
  position: fixed; left: 50%; bottom: calc(78px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  max-width: min(92vw, 420px);
  padding: 9px 10px 9px 14px; border-radius: 10px;
  background: var(--ink); color: var(--bg);
  font-size: 12.5px; box-shadow: var(--shadow); z-index: 20;
}
.hint button { border: 0; background: transparent; color: inherit; font-size: 17px; line-height: 1; padding: 0 4px; }

/* ----------------------------------------------------------- narrow desktop */

@media (max-width: 1100px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; }
  .candidates-panel { grid-column: 1; grid-row: 1; }
  .board-panel { grid-column: 1; grid-row: 2; min-height: 46vh; }
  .rail { grid-column: 1; grid-row: 3; }
  .rail { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
  .rail-block + .rail-block { margin-top: 0; padding-top: 0; border-top: 0; }
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 760px) {
  body { font-size: 14px; }

  /* Three header rows: brand, roots, then quality + families. */
  .topbar {
    position: sticky; top: 0; z-index: 10;
    gap: 8px 10px; padding: 10px 12px 9px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  .brand { flex-direction: row; align-items: baseline; gap: 8px; }
  .brand-sub { display: none; }

  .chordpick { order: 2; flex-basis: 100%; gap: 8px; flex-wrap: nowrap; }
  .roots {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    -webkit-overflow-scrolling: touch; padding-bottom: 2px; flex: 1 1 auto;
  }
  .roots::-webkit-scrollbar { display: none; }
  .roots button { min-width: 42px; min-height: 40px; flex: 0 0 auto; }
  #quality { order: 3; flex: 1 1 auto; min-width: 0; max-width: 58%; }

  .topright {
    order: 4; flex-basis: 100%; margin-left: 0; gap: 8px;
    justify-content: flex-start; min-width: 0;
  }
  .families { flex: 1 1 auto; overflow-x: auto; scrollbar-width: none; min-width: 0; }
  .families::-webkit-scrollbar { display: none; }
  .families button { padding: 7px 10px; font-size: 11.5px; flex: 0 0 auto; }
  .icon-btn { margin-left: auto; flex: 0 0 auto; }

  /* Let the page scroll rather than crushing the neck: the chord, the
     candidates and the board stay above the fold, the rail sits below. */
  main {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    gap: 10px; padding: 10px;
  }
  .board-panel { height: 46vh; min-height: 300px; }
  .panel { border-radius: 10px; }
  .candidates-panel { padding: 11px 12px 12px; }
  .panel-head { margin-bottom: 9px; gap: 8px; }

  .candidates {
    margin: 0 -12px; padding: 0 12px 4px; gap: 8px;
    scroll-snap-type: x mandatory;
  }
  /* Compact enough that the chord, the modes and the whole neck fit on one
     phone screen — the neck is what you stare at while playing. */
  .card { flex: 0 0 auto; min-width: 166px; max-width: 192px; scroll-snap-align: start; padding: 9px 10px 10px; }
  .card-name { font-size: 14px; }
  .card-parent { font-size: 10.5px; margin-bottom: 6px; }
  .card-notes { font-size: 10.5px; margin-bottom: 6px; }
  .card-row { margin-top: 3px; font-size: 10.5px; }
  .card-row-label { font-size: 10.5px; }
  .chip { font-size: 10px; padding: 1px 6px; }
  .shared-line { font-size: 11.5px; flex-basis: 100%; }

  .board-panel { padding: 4px 4px 8px; }
  /* Controls first, legend second: if anything falls below the fold it
     should be the reference key, never the position stepper. */
  .boardbar { flex-direction: column; align-items: stretch; gap: 9px; padding: 8px 6px 0; }
  .boardctl { order: -1; margin-left: 0; width: 100%; gap: 10px; justify-content: space-between; }
  .legend { gap: 8px 12px; width: 100%; }
  .legend li { font-size: 10.5px; }
  .rangectl { display: none; }
  .stepper { display: flex; }
  .ghost-btn { min-height: 40px; }

  .rail { display: block; padding: 12px 14px; }
  .rail-block + .rail-block { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
  .parent-line { font-size: 15px; }

  .transport {
    position: sticky; bottom: 0; z-index: 10;
    gap: 8px; padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  }
  .tbtn { padding: 10px 6px; font-size: 13px; flex: 1 1 0; min-width: 0; min-height: 44px; }
  .tctl { font-size: 11px; flex: 1 1 100%; gap: 10px; }
  .tctl input { flex: 1 1 auto; width: auto; }
  .tctl-vol { display: none; }
  .tselect { display: none; }
  .audio-badge { flex: 1 1 100%; text-align: center; }
}
