/* Flat, sharp, two colours and one signal. Paper and ink swap in the dark; nothing is
   rounded but the knobs, nothing has a shadow, and every edge is the same hairline. */
/* Light is the base; dark is the system's choice, unless the user chose (data-theme, set by
   the button in the bar and kept in this browser). */
:root {
  --paper: #f0eee9; --ink: #1c1c1c; --mute: #7d7b76; --signal: #ff4a1c; --key: #fbfaf7;
  --screen-edge: #1c1c1c; --screen-out: transparent; --black-key-edge: #1c1c1c;
  --line: 1.5px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161616; --ink: #f0eee9; --mute: #8f8d88; --key: #f0eee9;
    --screen-edge: #000; --screen-out: #f0eee9; --black-key-edge: #f0eee9;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #161616; --ink: #f0eee9; --mute: #8f8d88; --key: #f0eee9;
  --screen-edge: #000; --screen-out: #f0eee9; --black-key-edge: #f0eee9;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column; color: var(--ink); background: var(--paper); user-select: none;
  font: 500 15px/1.25 "Neue Haas Grotesk Display Pro", "Neue Haas Grotesk Text Pro", "Helvetica Neue", Helvetica, Arial, sans-serif;
  letter-spacing: -0.02em; text-transform: lowercase;
}
/* a light smoothing of the headings alone (it shows where the system lets a page choose: macOS) */
h1, h2, h3 { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: geometricPrecision; }
.mute { color: var(--mute); }

/* scrollbars: a flat bar in the ink colour, square, no arrows */
::-webkit-scrollbar { width: 8px; height: 8px; background: transparent; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ink); border-radius: 0; }
::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
::-webkit-scrollbar-corner { background: transparent; }
@supports not selector(::-webkit-scrollbar) { * { scrollbar-width: thin; scrollbar-color: var(--ink) transparent; } }

/* ---------------------------------------------------------------- the bar */
:root { --bar: 54px; }
header { display: flex; align-items: center; gap: 18px; height: var(--bar); padding: 0 24px; background: var(--ink); color: var(--paper); }
h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -0.03em; white-space: nowrap; }
#theme { flex: none; padding: 4px 12px; color: var(--paper); border-color: var(--paper); }
#theme:hover, #menu:hover, #midi:hover, #source:hover { background: var(--paper); color: var(--ink); }
#source { flex: none; color: var(--paper); border-color: var(--paper); }
/* a phone: the bar's buttons sit closer, so the status line keeps some room */
@media (max-width: 520px) {
  header { gap: 8px; padding: 0 12px; }
  #midi, #theme, #source { padding: 4px 8px; }
}
/* the MIDI button: dim until MIDI is on, outlined while looking for a controller, solid when one is connected */
#midi { flex: none; padding: 4px 12px; color: var(--paper); border-color: var(--paper); }
#midi[data-state="off"] { opacity: .55; }
#midi[data-state="on"] { background: var(--paper); color: var(--ink); }
#midi-pop { position: fixed; z-index: 30; top: calc(var(--bar) + 8px); right: 24px; width: min(360px, calc(100vw - 32px)); padding: 14px 16px; background: var(--paper); color: var(--ink); border: var(--line) solid var(--ink); }
#midi-pop[hidden] { display: none; }
#midi-pop h3 { margin: 0 0 6px; }
#midi-pop p { margin: 0 0 10px; text-transform: none; }
#midi-pop .controls { max-height: calc(100vh - var(--bar) - 190px); overflow-y: auto; }
#midi-pop .row { display: grid; grid-template-columns: 116px 1fr auto; gap: 8px; align-items: center; padding: 6px 0; border-top: var(--line) solid var(--ink); }
#midi-pop .what { text-transform: none; color: var(--mute); overflow-wrap: anywhere; }
#midi-pop .foot { display: flex; gap: 8px; padding: 0 0 8px; }
#midi-pop .last { margin: 6px 0 0; font-size: 12px; color: var(--mute); overflow-wrap: anywhere; }
#status { flex: 1; text-align: right; text-transform: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .75; }
#status.bad { opacity: 1; color: var(--signal); }
/* the menu button: three lines */
#menu { flex: none; width: 36px; height: 30px; padding: 0; display: grid; place-items: center; color: var(--paper); border-color: var(--paper); }
#menu span { display: block; width: 16px; height: var(--line); background: currentColor; box-shadow: 0 -5px 0 currentColor, 0 5px 0 currentColor; }
body.menu #menu { background: var(--paper); color: var(--ink); }

/* ---------------------------------------------------------------- the firmware list: a drawer under the bar */
#drawer {
  position: fixed; z-index: 10; left: 0; top: var(--bar); bottom: 0; width: min(400px, 100vw); padding: 24px 24px 0;
  display: flex; flex-direction: column; background: var(--paper); border-right: var(--line) solid var(--ink);
  transform: translateX(-100%); visibility: hidden; transition: transform .15s ease-out, visibility 0s .15s;
}
body.menu #drawer { transform: none; visibility: visible; transition: transform .15s ease-out; }
@media (prefers-reduced-motion: reduce) { #drawer, body.menu #drawer { transition: none; } }
#lists { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-right: 14px; margin-right: -14px; }
#scrim { position: fixed; z-index: 9; inset: var(--bar) 0 0 0; display: none; background: rgb(0 0 0 / .4); }
body.menu #scrim { display: block; }

/* ---------------------------------------------------------------- the page: the screens, then the one panel */
main { flex: 1; display: flex; flex-direction: column; gap: 18px; width: 100%; max-width: 1600px; margin: 0 auto; padding: 22px 24px 28px; }

/* the stage (the chosen firmware, big) on the left; the slots, knobs and buttons on the right; the keys under both */
#device { --stage: clamp(260px, min(calc(100vh - 230px), calc(min(100vw, 1600px) - 620px)), 1000px); display: grid; grid-template-columns: var(--stage) 546px; gap: 16px 24px; align-items: stretch; align-self: center; margin-block: auto; }
#stage { min-width: 0; }
#stage-name { height: 36px; line-height: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#stage .glass { position: relative; }
#stage canvas { display: block; width: 100%; height: auto; aspect-ratio: 1; image-rendering: pixelated; background: #000; border: 6px solid var(--screen-edge); outline: var(--line) solid var(--screen-out); outline-offset: calc(var(--line) * -1); }
#stage.paused canvas { opacity: .45; }
#stage .choose { position: absolute; inset: 0; margin: auto; width: fit-content; height: fit-content; padding: 4px 12px; font-size: 13px; color: #f0eee9; border-color: #f0eee9; }
#stage .choose:hover { background: #f0eee9; color: #1c1c1c; }
#stage:not(.empty) .choose { display: none; }
/* a firmware from last time, waiting for the click that lets the page make sound: its play button */
#stage .choose.resume { display: block; padding: 8px 22px; font-size: 16px; background: var(--signal); border-color: var(--signal); color: #1c1c1c; }
#stage .choose.resume:hover { background: #f0eee9; border-color: #f0eee9; }
#side { min-width: 0; display: grid; grid-template-rows: auto auto auto minmax(90px, 1fr); gap: 20px; padding-top: 36px; }
/* (the chosen screen is empty, or its firmware stopped: nothing on the panel does anything) */
#device.locked:not(.mixing) .knobs, #device.locked .buttons, #device.locked #keys { opacity: .3; pointer-events: none; }
/* (the mix chosen: the knobs are the mixer's, whatever the firmware; buttons and keys stay with the screen chosen before) */
@media (max-width: 760px) { #device { grid-template-columns: minmax(0, 1fr); } #side { width: 100%; } #stage { width: 100%; } #side { padding-top: 0; } }
#slots { display: grid; grid-template-columns: repeat(var(--boxes, 4), 100px); justify-content: space-between; }
.slot { margin: 0; padding: 5px; border: var(--line) solid var(--ink); cursor: pointer; min-width: 0; }
.slot.selected { border-color: var(--signal); box-shadow: 0 0 0 var(--line) var(--signal); }
.slot .glass { position: relative; }
.slot canvas { display: block; margin: 0 auto; width: 86px; height: 86px; image-rendering: pixelated; background: #000; border: 3px solid var(--screen-edge); outline: var(--line) solid var(--screen-out); outline-offset: calc(var(--line) * -1); }
.slot.paused canvas { opacity: .45; }
.slot .choose { position: absolute; inset: 0; margin: auto; width: fit-content; max-width: 90%; height: fit-content; padding: 4px 10px; font-size: 13px; line-height: 1.15; color: #f0eee9; border-color: #f0eee9; }
.slot .choose:hover { background: #f0eee9; color: #1c1c1c; }
.slot:not(.empty) .choose { display: none; }
.slot .choose.resume { display: block; background: var(--signal); border-color: var(--signal); color: #1c1c1c; }
.slot .choose.resume:hover { background: #f0eee9; border-color: #f0eee9; }
.slot .bar { display: flex; gap: 6px; margin-top: 6px; font-size: 13px; }
.slot .num { font-feature-settings: "tnum"; }
.slot .num::after { content: "."; }
.slot.selected .num { color: var(--signal); }
.slot .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot .name[hidden] { display: none; }
.slot.empty .name { color: var(--mute); }
.slot .ctl { display: flex; gap: 8px; min-height: 20px; }
.slot .ctl button { font-size: 12px; }
.slot .ctl button::before, .slot .ctl button::after { content: none; }
.slot .ctl button[hidden] { display: none; }
.slot.muted .mute, .slot.paused .run { color: var(--signal); }
/* the mix chosen: the screen whose firmware the keys and buttons still play, outlined */
.slot.played { border-style: dashed; border-color: var(--signal); }
/* the mix: a box like the screens' (its preview the mixer drawn small), no controls under it */
.slot.mixbox canvas { image-rendering: auto; }
.slot.mixbox .ctl { display: none; }
.slot.mixbox .bar { min-height: 20px; }

/* ---------------------------------------------------------------- controls */
button { font: inherit; letter-spacing: inherit; text-transform: inherit; color: var(--ink); background: none; border: var(--line) solid var(--ink); border-radius: 0; padding: 8px 14px; cursor: pointer; }
button:hover { background: var(--ink); color: var(--paper); }
button.solid { background: var(--ink); color: var(--paper); }
button.solid:hover { background: var(--signal); border-color: var(--signal); color: #1c1c1c; }
button.compact { padding: 4px 12px; }
button:disabled { opacity: .3; pointer-events: none; }
/* a link that is a button (a firmware's source) */
a.button { display: inline-block; padding: 4px 12px; color: var(--ink); border: var(--line) solid var(--ink); text-decoration: none; }
a.button:hover { background: var(--ink); color: var(--paper); }
.list li.playing button.solid { background: var(--signal); border-color: var(--signal); color: #1c1c1c; }
.list li.playing button.solid:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }
button.text { border: 0; padding: 0; }
button.text::before { content: "["; }
button.text::after { content: "]"; }
button.text:hover { background: none; color: var(--signal); }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; }

#find { position: relative; margin-top: 10px; }
#search { display: block; width: 100%; padding: 10px 28px 10px 0; border: 0; border-bottom: var(--line) solid var(--ink); border-radius: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-transform: none; user-select: text; -webkit-appearance: none; appearance: none; }
#search::placeholder { color: var(--mute); }
#search::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
#clear { position: absolute; right: 0; top: 50%; transform: translateY(-50%); width: 24px; height: 24px; padding: 0; border: 0; font-size: 20px; line-height: 1; color: var(--mute); }
#clear[hidden] { display: none; }
#clear:hover { background: none; color: var(--signal); }
#search:focus { outline: 0; border-bottom-color: var(--signal); box-shadow: 0 var(--line) 0 var(--signal); }

.list { list-style: none; margin: 20px 0 0; padding: 0; }
.list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0 10px; padding: 10px 0; border-top: var(--line) solid var(--ink); }
.list li:last-child { border-bottom: var(--line) solid var(--ink); }
.list li.empty { display: block; color: var(--mute); }
.list li.unplayable { color: var(--mute); }
.list .name { font-size: 19px; overflow-wrap: anywhere; }
.list .meta { color: var(--mute); font-size: 13px; overflow-wrap: anywhere; text-transform: none; }
.list .row { display: flex; align-items: center; gap: 8px; }
/* the row a MIDI controller is on: its name on the signal colour */
.list li.cursor .name { justify-self: start; background: var(--signal); color: #1c1c1c; padding: 0 6px; margin-left: -6px; }

h3 { margin: 0; font-size: 30px; font-weight: 600; line-height: 1; letter-spacing: -0.04em; }

/* ---------------------------------------------------------------- the device */
/* One panel for all the screens. */
.knobs { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 0 2px; }
.knob { --turn: 0deg; display: flex; flex-direction: column; align-items: center; cursor: ns-resize; touch-action: none; }
.knob::before {
  content: ""; display: block; width: 44px; aspect-ratio: 1; border: var(--line) solid var(--ink); border-radius: 50%; transform: rotate(var(--turn));
  background: linear-gradient(var(--ink), var(--ink)) 50% 0 / var(--line) 50% no-repeat;
}
.knob:hover::before, .knob.turning::before { background-color: color-mix(in srgb, var(--ink) 8%, transparent); }
.knob.turning::before { border-color: var(--signal); background-image: linear-gradient(var(--signal), var(--signal)); }
.knob::after { content: attr(data-label); display: block; margin-top: 6px; font-size: 12px; white-space: nowrap; }

.buttons { display: grid; grid-template-columns: 70px 14px repeat(6, 70px); gap: 6px; justify-content: space-between; }
@media (max-width: 760px) { .buttons { grid-template-columns: 1fr 14px repeat(6, 1fr); } }
/* oct+ top, oct- bottom, a gap, then the other twelve in order, six to a row */
.btn[data-key="1"] { grid-area: 1 / 1; }
.btn[data-key="0"] { grid-area: 2 / 1; }
.btn[data-key="2"] { grid-area: 1 / 3; }
.btn[data-key="3"] { grid-area: 1 / 4; }
.btn[data-key="4"] { grid-area: 1 / 5; }
.btn[data-key="5"] { grid-area: 1 / 6; }
.btn[data-key="6"] { grid-area: 1 / 7; }
.btn[data-key="7"] { grid-area: 1 / 8; }
.btn[data-key="8"] { grid-area: 2 / 3; }
.btn[data-key="9"] { grid-area: 2 / 4; }
.btn[data-key="10"] { grid-area: 2 / 5; }
.btn[data-key="11"] { grid-area: 2 / 6; }
.btn[data-key="12"] { grid-area: 2 / 7; }
.btn[data-key="13"] { grid-area: 2 / 8; }
.btn { --led: 0; padding: 0; aspect-ratio: 1; font-size: 13px; touch-action: none; background: color-mix(in srgb, var(--signal) calc(var(--led) * 100%), transparent); }
.btn:hover { background: color-mix(in srgb, var(--signal) calc(var(--led) * 100%), color-mix(in srgb, var(--ink) 10%, transparent)); color: var(--ink); }
.btn.down, .btn.down:hover { background: var(--ink); color: var(--paper); }

#keys { position: relative; min-height: 90px; touch-action: none; }
.key { --led: 0; position: absolute; top: 0; cursor: pointer; border: var(--line) solid var(--black-key-edge); }
.key.white { bottom: 0; margin-right: calc(var(--line) * -1); background: color-mix(in srgb, var(--signal) calc(var(--led) * 100%), var(--key)); }
.key.black { height: 58%; z-index: 1; background: color-mix(in srgb, var(--signal) calc(var(--led) * 100%), #1c1c1c); }
.key.down, .key.held { background: var(--signal); }

.hints { margin: 0; text-align: center; color: var(--mute); font-size: 13px; line-height: 1.7; }
#playing-into { color: var(--ink); }
kbd { font: inherit; color: var(--ink); border: 1px solid var(--mute); padding: 0 5px; }

/* ---------------------------------------------------------------- a phone (last, so it wins over the rules above)
   the four slots share the width (their previews shrink with it), the knobs go four to a row */
@media (max-width: 600px) {
  main { padding: 16px 16px 24px; }
  #device { width: 100%; }
  #slots { grid-template-columns: repeat(var(--boxes, 4), minmax(0, 1fr)); gap: 6px; }
  .slot { padding: 4px; }
  .slot canvas { width: 100%; height: auto; aspect-ratio: 1; }
  .slot .choose { font-size: 11px; padding: 3px 5px; }
  .slot .ctl { gap: 6px; flex-wrap: wrap; }
  .knobs { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px 2px; }
  .buttons { grid-template-columns: minmax(0, 1fr) 6px repeat(6, minmax(0, 1fr)); gap: 4px; }
  .btn { font-size: 12px; }
}
