:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --ink: #1e1d1a;
  --muted: #6b6860;
  --line: #ddd9d0;
  --accent: #1f4e9c;
  --accent-soft: #dbe6f7;
  --ok: #2f7d4a;
  --warn: #b3541e;
  --key-white: #fdfdfb;
  --key-black: #2a2926;
  --key-on: #ffd166;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  color-scheme: light;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 24px;
  gap: 18px;
  position: relative;
}

a { color: var(--accent); }

/* ---- header ------------------------------------------------------------ */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 32px;
  align-items: flex-start;
  padding-right: 240px; /* room for the velocity panel */
}

.brand h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.brand .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.midi { display: flex; flex-direction: column; gap: 8px; min-width: 280px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 14px;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 10px 18px;
}
button.primary:hover { filter: brightness(1.08); }
button.ghost { color: var(--muted); }
button:disabled { opacity: .55; cursor: default; }

.midi-controls { display: flex; flex-wrap: wrap; gap: 10px 16px; }
.midi-controls label, .vel-body label, .strip label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}
select, input[type="number"] {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 120px;
}

.status { font-size: 13px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }

.loadbar {
  height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; max-width: 320px;
}
#loadfill { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* ---- velocity panel (top right) ---------------------------------------- */
.vel-panel {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 220px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
  z-index: 5;
}
.vel-head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0;
  background: transparent;
  font-weight: 600;
  padding: 10px 12px;
}
.vel-panel:not(.open) .chev { transform: rotate(-90deg); }
.vel-panel:not(.open) .vel-body { display: none; }
.vel-body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.vel-body .row select { width: 100%; }

#velGraph { display: block; width: 100%; height: auto; border-radius: 6px; }
#velGraph .bg { fill: #f2f0ea; }
#velGraph .grid { stroke: #d3cfc5; stroke-width: 1; stroke-dasharray: 3 3; }
#velGraph .curve { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; }
#velGraph .dot { fill: var(--warn); transition: opacity .6s; }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: -6px; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fields label:last-child { grid-column: 1 / -1; }
.fields input, .fields select { min-width: 0; width: 100%; }

.readout { font-size: 13px; font-family: var(--mono); display: flex; flex-direction: column; gap: 2px; }
.readout .k { color: var(--muted); font-family: var(--font); font-size: 12px; margin-right: 4px; }

/* ---- main --------------------------------------------------------------- */
main { display: flex; flex-direction: column; gap: 12px; }

.strip { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; }
.strip .vol input { width: 180px; }
.pedal, .voices {
  font-size: 12px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; background: var(--panel);
}
.pedal.on { color: #fff; background: var(--accent); border-color: var(--accent); }

.piano-wrap { overflow-x: auto; padding-bottom: 6px; }
.piano {
  position: relative;
  display: flex;
  height: 190px;
  min-width: 720px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.key {
  position: relative;
  border: 1px solid #b9b5ab;
  border-radius: 0 0 5px 5px;
  cursor: pointer;
}
.key.white {
  flex: 1 0 0;
  background: var(--key-white);
  box-shadow: inset 0 -6px 0 #ebe8e0;
}
.key.black {
  position: absolute;
  top: 0;
  width: 2.1%;
  height: 62%;
  margin-left: -1.05%;
  background: var(--key-black);
  border-color: #111;
  box-shadow: inset 0 -6px 0 #000;
  z-index: 2;
}
.key.on { background: var(--key-on) !important; box-shadow: none; }
.key .lbl {
  position: absolute; bottom: 6px; left: 0; right: 0;
  text-align: center; font-size: 10px; color: var(--muted); pointer-events: none;
}

.hint { margin: 0; font-size: 13px; color: var(--muted); }

footer { margin-top: auto; font-size: 12px; color: var(--muted); }
footer p { margin: 0; }

@media (max-width: 720px) {
  .topbar { padding-right: 0; }
  .vel-panel { position: static; width: 100%; order: -1; }
}
