/* Tonic — design tokens + primitives (buttons, fields, menus, modals, tooltips …).
   White + dusty indigo, matching the portfolio. Dark theme via [data-theme="dark"]. */

:root {
  --bg: #f3f4fb;
  --bg-2: #eceef9;
  --panel: #ffffff;
  --panel-2: #f8f9fe;
  --panel-3: #f1f2fb;
  --raised: #ffffff;
  --ink: #12142b;
  --ink-2: #464a6a;
  --muted: #858aa5;
  --faint: #b3b7cd;
  --line: rgba(18, 20, 43, .085);
  --line-2: rgba(18, 20, 43, .15);
  --accent: #5260bd;
  --accent-hi: #6c7ad8;
  --accent-lo: #3a4690;
  --accent-soft: #aab3ec;
  --accent-tint: #e9ebfa;
  --accent-ghost: rgba(82, 96, 189, .1);
  --accent-ink: #ffffff;
  --ok: #3f9a82;
  --warn: #c58b3f;
  --bad: #c25a70;

  /* harmonic functions */
  --f-T: #5260bd;
  --f-S: #3f9a82;
  --f-D: #c9788f;
  --f-C: #d4a24f;
  /* tracks */
  --t-chords: #5260bd;
  --t-bass: #3f9a82;
  --t-melody: #c9788f;

  --roll-white: #ffffff;
  --roll-black: #f4f5fc;
  --roll-grid: rgba(18, 20, 43, .06);
  --roll-beat: rgba(18, 20, 43, .1);
  --roll-bar: rgba(18, 20, 43, .22);
  --key-white: #ffffff;
  --key-black: #2a2e57;

  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Instrument Serif", "Iowan Old Style", Georgia, serif;
  --mono: "DM Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-io: cubic-bezier(.65, 0, .35, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);

  --shadow-xs: 0 1px 2px rgba(18, 20, 43, .06);
  --shadow-sm: 0 1px 2px rgba(18, 20, 43, .05), 0 4px 14px rgba(18, 20, 43, .05);
  --shadow-md: 0 2px 4px rgba(18, 20, 43, .04), 0 14px 40px rgba(40, 48, 110, .12);
  --shadow-lg: 0 4px 10px rgba(18, 20, 43, .05), 0 34px 80px rgba(40, 48, 110, .2);
  --ring: 0 0 0 3px rgba(82, 96, 189, .28);

  --r-sm: 7px;
  --r-md: 11px;
  --r-lg: 16px;
  --topbar: 56px;
  --scheme: light;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1021;
  --bg-2: #11152b;
  --panel: #151933;
  --panel-2: #1a1f3d;
  --panel-3: #1f2547;
  --raised: #20264a;
  --ink: #e8eafa;
  --ink-2: #b5b9d6;
  --muted: #7d83a8;
  --faint: #4b5178;
  --line: rgba(255, 255, 255, .075);
  --line-2: rgba(255, 255, 255, .14);
  --accent: #7b88e6;
  --accent-hi: #98a3f5;
  --accent-lo: #5c69c9;
  --accent-soft: #3a4290;
  --accent-tint: rgba(123, 136, 230, .16);
  --accent-ghost: rgba(123, 136, 230, .14);
  --accent-ink: #0d1021;
  --ok: #5cc2a6;
  --warn: #e0ac5b;
  --bad: #e07890;

  --f-T: #8693ee;
  --f-S: #5cc2a6;
  --f-D: #e58aa2;
  --f-C: #e6b866;
  --t-chords: #8693ee;
  --t-bass: #5cc2a6;
  --t-melody: #e58aa2;

  --roll-white: #171b38;
  --roll-black: #12162f;
  --roll-grid: rgba(255, 255, 255, .045);
  --roll-beat: rgba(255, 255, 255, .08);
  --roll-bar: rgba(255, 255, 255, .2);
  --key-white: #e9ebfa;
  --key-black: #070918;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, .3), 0 14px 40px rgba(0, 0, 0, .4);
  --shadow-lg: 0 4px 10px rgba(0, 0, 0, .35), 0 34px 80px rgba(0, 0, 0, .55);
  --ring: 0 0 0 3px rgba(123, 136, 230, .38);
  --scheme: dark;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 500 13px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
  overflow: hidden; overscroll-behavior: none;
}
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
svg, canvas { display: block; }
::selection { background: var(--accent); color: var(--accent-ink); }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { flex: none; }
[hidden] { display: none !important; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; border: 3px solid transparent; }
::-webkit-scrollbar-corner { background: transparent; }

kbd {
  font: 500 10.5px/1 var(--mono); padding: 3px 5px; border-radius: 5px; background: var(--panel-3); color: var(--muted);
  border: 1px solid var(--line); border-bottom-width: 2px; letter-spacing: .02em; white-space: nowrap;
}

/* ─────────── buttons ─────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 34px; padding: 0 14px; border-radius: 9px;
  font-weight: 700; font-size: 13px; letter-spacing: -.005em; white-space: nowrap; transition: background .18s, color .18s, box-shadow .18s, transform .18s var(--ease-out), border-color .18s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 6px 16px -6px var(--accent); }
.btn.primary:hover { background: var(--accent-hi); }
.btn.ghost { color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--line-2); }
.btn.ghost:hover { background: var(--panel-3); color: var(--ink); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.soft { background: var(--accent-ghost); color: var(--accent); }
.btn.soft:hover { background: var(--accent-tint); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 8px; }
.btn.lg { height: 42px; padding: 0 20px; font-size: 14px; border-radius: 11px; }
.btn:disabled { opacity: .4; }

.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; color: var(--ink-2);
  transition: background .16s, color .16s, transform .16s var(--ease-out);
}
.icon-btn:hover:not(:disabled) { background: var(--panel-3); color: var(--ink); }
.icon-btn:active:not(:disabled) { transform: scale(.92); }
.icon-btn:disabled { opacity: .35; }
.icon-btn.on { background: var(--accent-ghost); color: var(--accent); }
.icon-btn.sm { width: 26px; height: 26px; border-radius: 7px; }

/* segmented control */
.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--panel-3); border-radius: 9px; }
.seg button { height: 26px; padding: 0 10px; border-radius: 7px; font-weight: 700; font-size: 12px; color: var(--muted); transition: background .16s, color .16s, box-shadow .16s; white-space: nowrap; }
.seg button:hover { color: var(--ink); }
.seg button.on, .seg button[aria-pressed="true"], .seg button[aria-checked="true"] { background: var(--panel); color: var(--accent); box-shadow: var(--shadow-xs), 0 0 0 1px var(--line); }
:root[data-theme="dark"] .seg button.on, :root[data-theme="dark"] .seg button[aria-pressed="true"] { background: var(--raised); }

/* chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 11px; border-radius: 99px; font-weight: 700; font-size: 12px; color: var(--ink-2);
  background: var(--panel-3); box-shadow: inset 0 0 0 1px transparent; transition: background .16s, color .16s, box-shadow .16s;
}
.chip:hover { background: var(--accent-ghost); color: var(--accent); }
.chip.on, .chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.chip.outline { background: transparent; box-shadow: inset 0 0 0 1px var(--line-2); }

.badge { display: inline-flex; align-items: center; height: 18px; padding: 0 7px; border-radius: 99px; font: 700 10px/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; background: var(--accent-ghost); color: var(--accent); }
.badge.T { background: color-mix(in srgb, var(--f-T) 16%, transparent); color: var(--f-T); }
.badge.S { background: color-mix(in srgb, var(--f-S) 16%, transparent); color: var(--f-S); }
.badge.D { background: color-mix(in srgb, var(--f-D) 18%, transparent); color: var(--f-D); }
.badge.C { background: color-mix(in srgb, var(--f-C) 20%, transparent); color: var(--f-C); }

/* ─────────── fields ─────────── */
.field {
  height: 32px; width: 100%; padding: 0 11px; border-radius: 9px; background: var(--panel-3); border: 1px solid transparent; color: var(--ink);
  font-weight: 600; transition: background .16s, border-color .16s, box-shadow .16s;
}
.field::placeholder { color: var(--muted); font-weight: 500; }
.field:hover { background: var(--panel-2); border-color: var(--line); }
.field:focus { outline: none; background: var(--panel); border-color: var(--accent); box-shadow: var(--ring); }
select.field { appearance: none; -webkit-appearance: none; padding-right: 28px; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23858aa5' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; }
select.field option { background: var(--panel); color: var(--ink); }

/* range slider */
input[type="range"].slider { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; cursor: pointer; --p: 50%; }
input[type="range"].slider::-webkit-slider-runnable-track { height: 4px; border-radius: 99px; background: linear-gradient(to right, var(--accent) var(--p), var(--line-2) var(--p)); }
input[type="range"].slider::-moz-range-track { height: 4px; border-radius: 99px; background: var(--line-2); }
input[type="range"].slider::-moz-range-progress { height: 4px; border-radius: 99px; background: var(--accent); }
input[type="range"].slider::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--panel); border: 2px solid var(--accent); box-shadow: var(--shadow-sm); transition: transform .15s var(--ease-out); }
input[type="range"].slider::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: var(--panel); border: 2px solid var(--accent); }
input[type="range"].slider:hover::-webkit-slider-thumb { transform: scale(1.18); }
input[type="range"].slider:focus-visible { box-shadow: none; }
input[type="range"].slider:focus-visible::-webkit-slider-thumb { box-shadow: var(--ring); }

/* switch */
.switch { position: relative; width: 32px; height: 19px; border-radius: 99px; background: var(--line-2); transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-xs); transition: transform .24s var(--ease-spring); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(13px); }

/* ─────────── menus & popovers ─────────── */
.popover {
  position: fixed; z-index: 1000; min-width: 200px; max-width: min(92vw, 420px); background: var(--raised); border-radius: var(--r-md); box-shadow: var(--shadow-lg), 0 0 0 1px var(--line-2);
  opacity: 0; transform: translateY(-4px) scale(.98); transform-origin: top left; transition: opacity .14s, transform .18s var(--ease-out); pointer-events: none; overflow: hidden;
}
.popover.in { opacity: 1; transform: none; pointer-events: auto; }
.menu { display: flex; flex-direction: column; padding: 5px; min-width: 220px; max-height: min(70vh, 520px); overflow: auto; }
.menu hr { border: 0; height: 1px; background: var(--line); margin: 5px 4px; }
.menu-head { padding: 8px 10px 4px; font: 700 10px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 10px; border-radius: 7px; text-align: left; font-weight: 600; color: var(--ink-2); transition: background .12s, color .12s; }
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--accent-ghost); color: var(--ink); box-shadow: none; }
.menu-item:disabled { opacity: .4; }
.menu-item.danger { color: var(--bad); }
.menu-item .mi-ico { width: 16px; height: 16px; display: grid; place-items: center; color: var(--muted); }
.menu-item .mi-label { flex: 1; }

/* ─────────── tooltips ─────────── */
.tip {
  position: fixed; z-index: 3000; display: flex; align-items: center; gap: 8px; padding: 6px 9px; border-radius: 8px; background: var(--deep, #141838); color: #eef0ff; font: 600 11.5px/1.2 var(--sans);
  box-shadow: var(--shadow-md); pointer-events: none; opacity: 0; transform: translateY(2px); transition: opacity .12s, transform .12s; max-width: 260px;
}
.tip.show { opacity: 1; transform: none; }
.tip kbd { background: rgba(255, 255, 255, .12); color: #c9cdf2; border-color: rgba(255, 255, 255, .12); }
:root { --deep: #141838; }
:root[data-theme="dark"] .tip { background: #0a0c1d; box-shadow: 0 0 0 1px var(--line-2), var(--shadow-md); }

/* ─────────── toasts ─────────── */
.toasts { position: fixed; z-index: 4000; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 14px; padding: 10px 14px; border-radius: 11px; background: var(--deep); color: #eef0ff; font-weight: 600; font-size: 12.5px; box-shadow: var(--shadow-lg);
  animation: toast-in .4s var(--ease-spring); pointer-events: auto; max-width: min(90vw, 460px);
}
:root[data-theme="dark"] .toast { background: #eceefd; color: #12142b; }
.toast.out { opacity: 0; transform: translateY(8px) scale(.97); transition: opacity .28s, transform .28s; }
.toast.error { background: var(--bad); color: #fff; }
.toast-btn { font-weight: 800; color: var(--accent-soft); padding: 2px 6px; border-radius: 6px; }
.toast-btn:hover { background: rgba(255, 255, 255, .12); }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }

/* ─────────── modal ─────────── */
.modal { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 24px; background: rgba(14, 16, 40, .42); backdrop-filter: blur(7px) saturate(1.1); -webkit-backdrop-filter: blur(7px) saturate(1.1); animation: fade-in .22s; }
.modal.out { opacity: 0; transition: opacity .18s; }
.modal-card {
  width: min(520px, 100%); max-height: min(88vh, 860px); display: flex; flex-direction: column; background: var(--panel); border-radius: 18px; box-shadow: var(--shadow-lg), 0 0 0 1px var(--line);
  animation: modal-in .42s var(--ease-out); overflow: hidden;
}
.modal-card.wide { width: min(860px, 100%); }
.modal.out .modal-card { transform: scale(.97) translateY(6px); transition: transform .18s; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 22px 6px; }
.modal-head h2 { font: 800 19px/1.2 var(--sans); letter-spacing: -.02em; }
.modal-head p { color: var(--muted); font-weight: 500; margin-top: 3px; }
.modal-body { padding: 14px 22px 22px; overflow: auto; flex: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--panel-2); }
.modal-text { color: var(--ink-2); line-height: 1.6; font-size: 13.5px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(18px) scale(.96); } }

/* ─────────── misc ─────────── */
.label { font: 700 10px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.mono { font-family: var(--mono); font-feature-settings: "tnum"; }
.serif { font-family: var(--serif); font-style: italic; font-weight: 400; letter-spacing: -.01em; }
.dot-sep::before { content: "·"; margin: 0 .5em; color: var(--faint); }
.empty { display: grid; place-items: center; text-align: center; gap: 6px; color: var(--muted); padding: 28px 18px; }
.empty b { color: var(--ink-2); font-weight: 700; }
.fade-up { animation: fade-up .5s var(--ease-out) both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
