:root {
  --edge: #101114;
  --bar: #141518;
  --field: #1A1C20;
  --rule: #24272C;
  --line: #2C3036;
  --outline: #3A3E46;
  --track: #2A2D34;
  --cap: #1C1E22;
  --bright: #F2F4F8;
  --label: #C8CCD4;
  --muted: #8A909A;
  --attention: #77EA9A;
  --on-attention: #101114;
  --sink: #ff6b6b;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  --sheet-height: 45vh;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--edge);
  color: var(--bright);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

body {
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr);
  height: 100dvh;
}

[hidden] { display: none !important; }

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.solid { fill: currentColor; stroke: none; }

button, select, .file {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--outline);
  border-radius: 10px;
  background: var(--field);
  color: var(--bright);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

button:disabled, select:disabled { opacity: 0.5; cursor: default; }

:is(button, select, a, input, [tabindex]):focus-visible { outline: 2px solid var(--attention); outline-offset: 2px; }

/* Header */

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bar);
  border-bottom: 1px solid var(--rule);
  min-width: 0;
}

.brand { display: flex; }
.brand img { width: 32px; height: 32px; }

.back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  color: var(--muted);
}

.back:not([href]) { display: none; }
.back:hover { color: var(--attention); }

.heading { display: flex; flex-direction: column; justify-content: center; min-width: 0; }

#byline { font-size: 12px; line-height: 1.3; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

h1 {
  margin: 0;
  line-height: 1.2;
  min-width: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file { display: inline-flex; align-items: center; }
.file input { display: none; }

.sizer { display: flex; align-items: center; gap: 12px; }
header .sizer { margin-left: auto; }
.sizer label { font-size: 12px; color: var(--muted); }

#size { padding: 0 10px; font-family: var(--mono); font-size: 13px; font-weight: 400; }

optgroup { color: var(--muted); font-style: normal; }
option { color: var(--bright); background: var(--field); }

/* The picture, the transport under it and what the patch says it is */

.body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 0;
}

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

main {
  position: relative;
  flex: 1 1 0;
  min-height: 160px;
  overflow: hidden;
  background: #000;
}

main:fullscreen #status { display: none; }

#screen {
  display: block;
  width: 100%;
  height: 100%;
}

#cover, #off {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
}

#cover {
  color: var(--bright);
  font-size: 18px;
  background: rgba(16, 17, 20, 0.45);
  cursor: pointer;
}

.prompt {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 22px 10px 10px;
  border-radius: 999px;
  background: rgba(16, 17, 20, 0.78);
  border: 1px solid var(--outline);
  font-weight: 500;
}

.prompt span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--attention);
  color: var(--on-attention);
}

main:has(#cover:not([hidden])) #off { display: none; }

#off { color: var(--muted); font-size: 15px; }

#status {
  position: absolute;
  left: 12px;
  bottom: 10px;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(16, 17, 20, 0.7);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  pointer-events: none;
}

#status:empty { display: none; }
#status .warn { color: var(--attention); }
#status .error { color: var(--sink); }

.transport {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bar);
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.transport button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-color: var(--line);
  border-radius: 12px;
  flex: none;
}

#play {
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--attention);
  color: var(--on-attention);
}

#play svg { width: 22px; height: 22px; }
#play[aria-label="Pause"] .when-paused, #play[aria-label="Play"] .when-playing { display: none; }

#mute .when-silent, #mute.silent .when-sounding { display: none; }
#mute.silent .when-silent { display: block; }

#loop[aria-pressed="true"] {
  border-color: var(--attention);
  background: color-mix(in srgb, var(--attention) 18%, var(--field));
  color: var(--attention);
}

#clock, #length {
  min-width: 40px;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#clock { text-align: right; }
#length { color: var(--muted); }
#seek[hidden] ~ #length { display: none; }
#clock:has(+ #seek[hidden]) { margin-right: auto; }

input[type="range"] { accent-color: var(--attention); cursor: pointer; }

#seek { flex: 1; min-width: 60px; height: 44px; margin: 0; }
#seek:disabled { opacity: 0.5; cursor: default; }

#volume { width: 96px; margin: 0; accent-color: var(--muted); }

.notes-home {
  max-height: 190px;
  overflow-y: auto;
  padding: 16px 20px 20px;
}

.notes-home:not(:has(#notes > :not([hidden]))) { display: none; }

#credit { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 20px; padding-bottom: 6px; }
#credit[hidden], #credit [hidden] { display: none; }

#credit .author { display: flex; align-items: center; gap: 10px; }
#credit .author > div { display: flex; flex-direction: column; }
.who { font-size: 12px; line-height: 1.3; color: var(--muted); }
#author { font-size: 14px; line-height: 1.3; font-weight: 500; }

#initial {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--attention) 18%, var(--field));
  color: var(--attention);
  font-size: 14px;
  font-weight: 600;
}

#tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }

#tags li {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  height: 28px;
  padding: 0 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--field);
  color: var(--label);
  font-size: 13px;
}

#notes { display: flex; flex-direction: column; gap: 10px; }

#about {
  margin: 0;
  max-width: 80ch;
  color: var(--label);
  line-height: 1.6;
  text-wrap: pretty;
}

#keyboard {
  margin: 0;
  max-width: 90ch;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
}

/* The panel: a column beside the picture, or a sheet under it on a phone */

#sheet {
  display: flex;
  flex-direction: column;
  width: 380px;
  min-height: 0;
  background: var(--bar);
  border-left: 1px solid var(--rule);
}

:where(#grip, .tabs, #keys, #about-pane) { display: none; }

.pane { min-height: 0; }

#controls {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
}

.controls-head {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "title reset" "find find";
  align-items: center;
  gap: 10px 8px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--rule);
}

.controls-head h2 { grid-area: title; margin: 0; font-size: 15px; font-weight: 600; }

.count { margin-left: 4px; color: var(--muted); font-family: var(--mono); font-size: 12px; font-weight: 400; }

#reset-all { grid-area: reset; height: 32px; padding: 0 12px; border-radius: 8px; background: none; color: var(--label); font-size: 13px; }

.find { grid-area: find; position: relative; }

.find svg { position: absolute; left: 12px; top: 13px; width: 16px; height: 16px; color: var(--muted); }

#find {
  width: 100%;
  height: 42px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--bright);
  font: inherit;
}

#panel {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  align-content: start;
  gap: 18px 8px;
  padding: 16px 16px 28px;
}

#none { margin: 0 0 24px; text-align: center; color: var(--muted); }

.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.knob {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}

.knob:focus-within { outline: 2px solid var(--bright); outline-offset: 2px; }

.knob svg { width: 100%; height: 100%; stroke-width: 5; }
.knob .track { stroke: var(--track); }
.knob .arc { stroke: var(--attention); }
.knob circle { fill: var(--cap); stroke: var(--outline); stroke-width: 1; }
.knob line { stroke: var(--bright); stroke-width: 3; }

.knob input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.cell .name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--label);
  font-size: 13px;
  font-weight: 500;
}

.cell output { color: var(--attention); font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }

/* Keys played on the screen */

.keys-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

#keys-said { flex: 1 1 0; min-width: 0; color: var(--muted); font-size: 12px; }

.keys-head button { width: 44px; height: 44px; padding: 0; border-radius: 12px; background: none; font-size: 20px; }

#octave { min-width: 32px; text-align: center; font-family: var(--mono); }

#keybed {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(40px, 1fr);
  gap: 4px;
  overflow-x: auto;
}

#keybed button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  height: 200px;
  padding: 0 0 12px;
  border: 0;
  border-radius: 0 0 10px 10px;
  background: #e9e6df;
  color: var(--bar);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#keybed button.sharp { height: 150px; background: var(--outline); color: var(--bright); }
#keybed button.down { background: var(--attention); color: var(--on-attention); }
#keybed .note { font-size: 14px; font-weight: 600; }
#keybed .key { font-family: var(--mono); font-size: 11px; opacity: 0.6; }

/* A phone: the panel is a sheet under the picture, its parts behind tabs */
@media (max-width: 640px) {
  body { grid-template-rows: 52px minmax(0, 1fr); }

  header { gap: 4px; padding: 0 8px; }
  .brand { display: none; }
  .back { width: 44px; height: 44px; }
  h1 { flex: 1 1 0; }
  #edit { height: 44px; border-radius: 12px; }

  .body { display: flex; flex-direction: column; }
  .stage { flex: 1 1 0; }
  .notes-home { display: none; }

  .transport {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    justify-items: center;
    gap: 2px 4px;
    padding: 6px 16px 10px;
    border-bottom: 0;
  }

  #clock { grid-area: 1 / 1; justify-self: start; min-width: 0; font-size: 12px; }
  #seek { grid-area: 1 / 2 / 2 / 5; width: 100%; }
  #length { grid-area: 1 / 5; justify-self: end; min-width: 0; font-size: 12px; text-align: right; }
  #loop { grid-area: 2 / 1; }
  #rewind { grid-area: 2 / 2; }
  #play { grid-area: 2 / 3; width: 64px; height: 64px; }
  #play svg { width: 26px; height: 26px; }
  #mute { grid-area: 2 / 4; }
  #fullscreen { grid-area: 2 / 5; }
  #volume { display: none; }
  .transport button:not(#play) { width: 48px; height: 48px; border-radius: 14px; }
  #clock:has(+ #seek[hidden]) { grid-column: 1 / -1; justify-self: center; }

  #sheet {
    flex: none;
    width: auto;
    height: var(--sheet-height);
    /* The header, a strip of picture and the transport stay above it. */
    max-height: calc(100dvh - 330px);
    min-height: 88px;
    margin-top: -1px;
    border: 0;
    border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    background: var(--field);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.4);
  }

  #grip {
    display: flex;
    flex: 0 0 28px;
    align-items: center;
    justify-content: center;
    cursor: ns-resize;
    touch-action: none;
  }

  #grip::before { content: ""; width: 40px; height: 5px; border-radius: 3px; background: #5A606A; }

  .tabs {
    display: flex;
    flex: none;
    gap: 4px;
    margin: 0 16px 4px;
    padding: 4px;
    border-radius: 14px;
    background: var(--edge);
  }

  .tabs button {
    flex: 1 1 0;
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
  }

  .tabs button[aria-selected="true"] { background: var(--track); color: var(--bright); }

  .pane, #controls { display: none; }

  .pane.open {
    display: block;
    flex: 1 1 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px 16px 24px;
  }

  #controls.open { display: flex; padding: 0; overflow: hidden; }

  .controls-head {
    grid-template-areas: "find reset";
    padding: 12px 16px 4px;
    border: 0;
  }

  .controls-head h2 { display: none; }
  #reset-all { height: 44px; padding: 0 14px; border-radius: 12px; font-size: 14px; }
  #find { height: 44px; border-radius: 12px; background: var(--edge); font-size: 15px; }
  .find svg { top: 14px; }

  #panel { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 16px 4px; }
  .knob { width: 80px; height: 80px; }

  #about-pane #about { font-size: 15px; }
  #about-pane .sizer { margin-top: 18px; }
  #about-pane .sizer label { font-size: 14px; }
  #about-pane #size { height: 44px; border-radius: 12px; }
}

/* In a frame embed.js opened: the page around it has the title and the close button. */

body.embed { grid-template-rows: minmax(0, 1fr); }
body.embed > header, body.embed .notes-home, body.embed #sheet { display: none !important; }
body.embed .body { display: flex; flex-direction: column; }
body.embed .stage { flex: 1 1 0; }
body.embed .transport { gap: 8px; padding: 8px 12px; border-bottom: 0; }
body.embed .transport button { width: 36px; height: 36px; border-radius: 10px; }
body.embed .transport #play { width: 40px; height: 40px; }
body.embed .transport #edit { width: auto; padding: 0 12px; font-size: 13px; }
body.embed #volume { width: 72px; }

/* Narrow, as docked beside a page or on a phone: the same one row, with 44 px targets. */
@media (max-width: 640px) {
  body.embed .transport { display: flex; padding: 6px 8px; gap: 4px; }
  body.embed .transport > * { grid-area: auto; }
  body.embed .transport button:not(#play) { width: 44px; height: 44px; border-radius: 10px; }
  body.embed .transport #play { width: 48px; height: 48px; }
  body.embed #clock { margin-left: 4px; min-width: 36px; text-align: left; font-size: 12px; }
  body.embed #volume { display: block; width: 64px; }
}

/* A phone's frame: its own volume keys stand in for the slider and the mute button. */
@media (max-width: 419px) {
  body.embed #volume, body.embed #mute, body.embed #length { display: none; }
}

/* With something under the transport the picture keeps 16:9; without, it takes the height. */
body.embed .stage:has(.embed-foot:not([hidden])) main { flex: none; aspect-ratio: 16 / 9; }

.embed-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; }
.embed-foot .by { color: var(--muted); font-size: 13px; }
.embed-foot #edit { height: 36px; padding: 0 12px; font-size: 13px; }
