/* Layout and section tabs from the rk100s-simple page.
   iPad (AUv3 WebKit) is older than desktop WebKit: no container units/queries, no `inset`; use % and @media. */
:root {
  --bg: #36436A;
  --side: #2b3556;
  --side-dark: #1f2742;
  --panel: #2e3248;
  --panel-2: #262B30;
  --border: #50566a;
  --orange: #ff8e0c;
  --orange-soft: #EBA85B;
  --text: #e4e4e8;
  --text-dim: #b7c0d3;
  --sel: #b7c0d3;
  --lcd: #0e1016;
  --lcd-text: #ffd08a;
  --audio: #3d9bff;
  --mod: #ff4b4b;
  --title-font: "Arial Black", "Helvetica Neue", Helvetica, sans-serif;   /* system fonts only, like gokeys and the arranger */
  --lcd-font: "Menlo", "Consolas", monospace;   /* sizes below are for Menlo (about 1.3x wider than the old VT323) */
  --ui-font: -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
/* No iPadOS drag-and-drop: a long press then a move (a slow slider drag) lifted a preview of what was under the finger. */
* { -webkit-user-drag: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
/* No zooming on the iPad: pan-x pan-y leaves out pinch zoom and double-tap zoom (app.js also blocks Safari's pinch gesture). */
/* The page itself never scrolls: only the program list and the details panel do, inside it. Browsers such as the iOS
   Web MIDI Browser app show their toolbars when the page scrolls (a finger moving a slider nudged it), and an inner
   scroll doesn't count. */
html, body { height: 100%; overflow: hidden; }
html { touch-action: pan-x pan-y; }
body {
  /* No text selection or iOS long-press callout: dragging a finger over a heading shouldn't select it. */
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  margin: 0; display: flex; font-family: var(--ui-font); font-size: 15px;
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; /* iOS: keeps the page itself from scrolling or bouncing */
  background: var(--bg); color: var(--text);
}

/* ---------- left column ---------- */
.side {
  width: 266px; flex: none; height: 100%; display: flex; flex-direction: column; gap: 4px;
  background: var(--side); padding: 10px 8px 8px; border-right: 4px solid var(--side-dark);
  box-shadow: inset 0 0 25px 6px rgba(0, 0, 0, .35);
}
.brand { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
.logo { display: flex; flex-direction: column; line-height: 1; }
.logo .model { font: 700 30px/1 var(--title-font); color: var(--text); letter-spacing: 1px; }
.logo .sub { font: 700 17px/1.2 var(--title-font); color: var(--orange); letter-spacing: 4px; }
.btn {
  -webkit-appearance: none; appearance: none; display: inline-block; cursor: pointer; position: relative; overflow: hidden;
  padding: 3px 10px; border: 1px solid #111; border-radius: 3px; font: 14px var(--ui-font);
  color: #fff; -webkit-text-fill-color: #fff; background: linear-gradient(#5a6070, #333945);
}
.btn:hover { background: linear-gradient(#6a7080, #3d4352); }
/* The file input covers the button invisibly (a styled <label> is the only way to theme it on iOS). */
.btn input[type=file] { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

.port { display: flex; align-items: center; gap: 6px; font: 700 12px var(--ui-font); color: var(--text-dim); letter-spacing: .5px; }
.port select {
  -webkit-appearance: none; appearance: none; border-radius: 0; margin: 0; cursor: pointer; flex: 1; min-width: 0;
  background: var(--lcd) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23ff8e0c'/%3E%3C/svg%3E") no-repeat right 7px center;
  color: var(--lcd-text); -webkit-text-fill-color: var(--lcd-text); border: 1px solid var(--border);
  font: 14px/22px var(--lcd-font); padding: 1px 22px 1px 6px;
}
.status-line { font-size: 13px; min-height: 18px; display: flex; gap: 6px; align-items: center; color: var(--text-dim); }
.status { padding: 1px 7px; border-radius: 9px; white-space: nowrap; }
.status.off { background: #5b5b5b; color: #ddd; }
.status.on { background: #2f8f3a; color: #fff; }
.status.warn { background: #d08a00; color: #fff; }
#status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.caption { display: flex; align-items: flex-end; justify-content: space-between; font: 700 12px var(--title-font); letter-spacing: .6px; color: var(--orange); margin-top: 8px; }
.caption .btn { letter-spacing: 0; } /* Open .syx sits at the right of the PROGRAMS caption (the brand row is too narrow for it) */

.list {
  flex: 1; min-height: 0; overflow-y: auto; background: var(--lcd); border: 1px solid var(--border);
  font-family: var(--lcd-font); font-size: 15px; outline: none;
}
.list .empty { font: 15px/1.4 var(--ui-font); color: var(--text-dim); padding: 12px 10px; text-align: left; }
.list .empty b { color: var(--orange-soft); }
/* No programs yet: how to send a dump, as a card that stands out (and wraps, so it's all visible in the narrow column). */
.load-card { border: 2px solid var(--orange); border-radius: 8px; background: rgba(255, 142, 12, .1); padding: 12px 12px 12px; color: var(--text); }
.load-title { font: 700 15px/1.2 var(--title-font); color: var(--orange); letter-spacing: .5px; margin-bottom: 8px; }
.load-card ol { margin: 0; padding-left: 22px; font-size: 16px; line-height: 1.4; }
.load-card li { margin-bottom: 8px; overflow-wrap: break-word; }
.load-card li::marker { color: var(--orange); font-weight: 700; }
.load-card b { color: var(--lcd-text); }
.load-after { font-size: 14px; color: var(--text-dim); }
.load-alt { margin-top: 12px; font-size: 14px; }
.row { display: flex; gap: 4px; padding: 0 8px; border-bottom: 1px solid #1c2030; cursor: pointer; color: var(--text); line-height: 22px; }
.row:hover { background: #1d2234; }
.row .num { color: #7a8090; width: 2.2ch; flex: none; }
.row .name { flex: none; width: 9.2ch; white-space: pre; color: var(--lcd-text); }
.row .wave { flex: 0 0 50px; min-width: 0; color: var(--text-dim); font: 12px/22px var(--ui-font); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .wave:last-child { flex: 1 1 0; } /* first wave column fits "SupSaw"; the second takes the rest */
.row.viewed { background: var(--sel); color: #000; }
.row.viewed .num, .row.viewed .wave { color: #333; }
.row.viewed .name { color: #000; }
.row.cur { box-shadow: inset 3px 0 0 var(--orange); }
.row.cur .num { color: var(--orange); }

.empty { color: var(--text-dim); padding: 24px; text-align: center; }

/* ---------- details ---------- */
.details { flex: 1; height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 14px; background: linear-gradient(rgba(0,0,0,.15), rgba(0,0,0,0) 140px); }
.details > .empty { margin-top: 20vh; }
.det-head { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin-bottom: 10px; }
.det-num { font: 24px/1 var(--lcd-font); background: var(--lcd); border: 1px solid var(--border); padding: 4px 12px; color: var(--lcd-text); }
.det-name { font: 700 26px/1.1 var(--title-font); color: var(--text); white-space: pre; letter-spacing: 1px; }
.det-note { font-size: 14px; color: var(--orange-soft); }

/* Sections: orange slanted tab title with a 2px orange line along the top edge (rk100s-simple style). */
.sect { border: 1px solid var(--border); border-top: 2px solid var(--orange); background: linear-gradient(var(--panel), var(--panel-2)); min-width: 0; }
.sect-title {
  display: inline-block; background: var(--orange); color: #1a1d26; font: 700 14px var(--title-font); letter-spacing: .8px;
  padding: 4px 30px 4px 9px; clip-path: polygon(0 0, 100% 0, calc(100% - 18px) 100%, 0 100%);
}
.sect-body { padding: 8px 10px 10px; }
.sect.grid1 .sect-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; }
.sect.grid2 .sect-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 16px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px 10px; }

/* Signal-flow layout. Narrow windows: one column in signal order. From 900px window width (includes the 266px
   program list; the iPad's window is 1024px): audio path on the left, modulators in their own right column. */
.sect.grid-mixer .sect-body { display: grid; grid-template-columns: minmax(0, 2fr) auto minmax(0, 1fr); gap: 5px 14px; }
.sect.grid3 .sect-body { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px 14px; }
.flow { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
/* Sliders don't need to be wide: the panel takes 3/4 of the width (one column) or 215px columns, and the
   heading and the WRITE bar line up with it. */
.flow { max-width: 75%; }
@media (min-width: 900px) {
  .flow { max-width: 709px; } /* 444 + 50 + 215: fills the iPad's 1024px window */
  /* Audio column (two 215px columns wide) and modulator column (215px), each stacking on its own; 50px between
     them for the wires. The heading sits at the top of the audio column, so the modulator column starts at the top. */
  .flow { grid-template-columns: minmax(0, 444px) minmax(0, 215px); column-gap: 50px; align-items: start; }
  .col-audio > .det-head, .col-audio > .pending { grid-column: 1 / -1; }
  .col-audio > .det-head { margin-bottom: 2px; } /* + the 26px row gap: room for the LFO line above the oscillators */
  .col-audio { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 26px 14px; align-items: start; }
  .col-audio > .sect:not(.s-osc1):not(.s-osc2) { grid-column: 1 / -1; }
  /* Scrolls by itself (max-height set in app.js); the wires follow. */
  .col-mod { display: flex; flex-direction: column; gap: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .col-mod > .sect { flex: none; }
  .s-global { margin-top: 22px; } /* room for AUDIO OUT under AMP's arrow */
}
/* One column: both columns merge, in signal order. */
@media (max-width: 899px) {
  .col-audio, .col-mod { display: contents; }
  .s-osc1 { order: 1; } .s-osc2 { order: 2; } .s-lfo2 { order: 3; } .s-mixer { order: 4; } .s-lfo1 { order: 5; }
  .s-filter { order: 6; } .s-env1 { order: 7; } .s-amp { order: 8; } .s-env2 { order: 9; } .s-global { order: 10; }
}
/* Audio sections get blue tabs, modulators red ones, matching the wires; GLOBAL stays orange. */
.sect.audio { border-top-color: var(--audio); }
.sect.audio .sect-title { background: var(--audio); }
.sect.mod { border-top-color: var(--mod); }
.sect.mod .sect-title { background: var(--mod); }
.amp-note { font: 700 12px var(--ui-font); letter-spacing: .3px; color: var(--text-dim); }
.wires { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.wires polyline { fill: none; stroke-width: 2.5; stroke-linejoin: miter; }
.wires .w-audio { stroke: var(--audio); }
.wires .w-mod { stroke: var(--mod); }
.wires .h-audio { fill: var(--audio); }
.wires .h-mod { fill: var(--mod); }
.wires .w-label { font: 700 13px var(--title-font); fill: var(--audio); }
@media (max-width: 760px) {
  .details { padding: 10px 10px; }
  .side { width: 250px; }
}

.field { min-width: 0; }
.field.slider { touch-action: pan-y; } /* the whole field grabs the slider (app.js); up/down still scrolls */
.field .cap { font: 700 11px var(--ui-font); color: var(--text-dim); letter-spacing: .4px; margin-bottom: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.field .val {
  position: relative; display: block; width: 100%; background: var(--lcd); color: var(--lcd-text); border: 1px solid #444a5e;
  font: 15px/20px var(--lcd-font); padding: 1px 6px; min-height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sect-note { grid-column: 1 / -1; font: 700 12px var(--ui-font); letter-spacing: .3px; color: var(--orange-soft); margin-bottom: 2px; }
.field.off select.val { color: #5d6376; -webkit-text-fill-color: #5d6376; border-color: #353a4a; }
/* Checkbox (custom-drawn, like rk100s-simple). The label is a flex row so the tick can't shift the baseline. */
.field .check { display: flex; width: fit-content; align-items: center; gap: 8px; min-height: 22px; cursor: pointer; font: 15px var(--lcd-font); color: var(--lcd-text); }
.field .check input {
  -webkit-appearance: none; appearance: none; margin: 0; width: 22px; height: 22px; flex: none; cursor: pointer;
  background: var(--lcd); border: 1px solid #444a5e; border-radius: 0; display: grid; place-content: center;
}
.field .check input:hover { border-color: var(--orange-soft); }
.field .check input:checked::after {
  content: ""; width: 11px; height: 6px; margin-top: -3px;
  border: solid var(--orange); border-width: 0 0 2px 2px; transform: rotate(-45deg);
}
.field.modified .check input { border-color: #f5c400; box-shadow: 0 0 0 1px #f5c400; }
.field.off .check { cursor: default; color: #5d6376; }
.field.off .check input { cursor: default; border-color: #353a4a; }
.field.off .check input:checked::after { border-color: #5d6376; }

/* Dropdowns look like the value boxes. appearance: none + SVG arrow: WebKit/iOS ignore borders on native selects. */
.field select.val {
  -webkit-appearance: none; appearance: none; cursor: pointer; border-radius: 0; padding: 1px 22px 1px 6px; margin: 0;
  -webkit-text-fill-color: var(--lcd-text); line-height: 18px;
  background: var(--lcd) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23ff8e0c'/%3E%3C/svg%3E") no-repeat right 7px center;
}
.field select.val:hover { border-color: var(--orange-soft); }
.field select.val:disabled { cursor: default; opacity: 1; background-image: none; }
.field.modified .val { border-color: #f5c400; box-shadow: 0 0 0 1px #f5c400; }
/* Value bar along the bottom of a 0..99 box. */
.field .bar { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--orange); opacity: .8; }
.field.off .cap { color: #6d7386; }
.field.off .val { color: #5d6376; border-color: #353a4a; }

/* Sliders (horizontal: rotated/vertical range inputs handle touch badly on iOS). Track = LCD box with an orange
   fill up to the value (--pct, set inline and while dragging); the number sits to the right. touch-action: pan-y lets
   a vertical swipe still scroll the page while a sideways drag moves the slider. */
.srow { display: flex; align-items: center; gap: 8px; }
.srow .sval { cursor: pointer; flex: none; width: 3.2ch; text-align: right; font: 15px/22px var(--lcd-font); color: var(--lcd-text); }
.srow input[type=range] {
  -webkit-appearance: none; appearance: none; flex: 1; min-width: 0; height: 22px; margin: 0; padding: 0;
  background: transparent; cursor: pointer; touch-action: pan-y;
}
.srow input[type=range]::-webkit-slider-runnable-track {
  height: 10px; border: 1px solid #444a5e;
  background: linear-gradient(90deg, var(--orange) 0, var(--orange) var(--pct, 0%), var(--lcd) var(--pct, 0%));
}
.srow input[type=range]::-moz-range-track {
  height: 10px; border: 1px solid #444a5e;
  background: linear-gradient(90deg, var(--orange) 0, var(--orange) var(--pct, 0%), var(--lcd) var(--pct, 0%));
}
.srow input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 14px; height: 22px; margin-top: -7px;
  background: linear-gradient(#f4f4f6, #b7c0d3); border: 1px solid #111; border-radius: 2px; box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.srow input[type=range]::-moz-range-thumb {
  width: 14px; height: 22px; background: linear-gradient(#f4f4f6, #b7c0d3); border: 1px solid #111; border-radius: 2px;
}
.field.slider.modified .srow input[type=range]::-webkit-slider-runnable-track { border-color: #f5c400; box-shadow: 0 0 0 1px #f5c400; }
.field.slider.modified .srow input[type=range]::-moz-range-track { border-color: #f5c400; }
.field.slider.modified .sval { color: #f5c400; }
.field.slider.off .srow input[type=range] { cursor: default; }
.field.slider.off .srow input[type=range]::-webkit-slider-runnable-track { background: var(--lcd); border-color: #353a4a; }
.field.slider.off .srow input[type=range]::-webkit-slider-thumb { background: #4a5064; border-color: #2a2e3a; box-shadow: none; }
.field.slider.off .sval { color: #5d6376; }

/* ADSR drawing above the four envelope values. */
.adsr { display: block; width: 100%; height: 46px; margin-bottom: 8px; background: var(--lcd); border: 1px solid #444a5e; }
.adsr polyline { fill: rgba(255, 142, 12, .15); stroke: var(--orange); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

/* RANDOM button (die icon), next to Open .syx above the program list, the same height (28px). */
.cap-buttons { display: flex; gap: 6px; }
.cap-buttons .btn { height: 28px; display: inline-flex; align-items: center; justify-content: center; margin: 0; }
.cap-buttons .random { padding: 0 8px; border-color: #8a5200;
  color: #1a1d26; -webkit-text-fill-color: #1a1d26; background: linear-gradient(#ffb04a, var(--orange)); }
.cap-buttons .random svg { display: block; }
.cap-buttons .random:hover { background: linear-gradient(#ffc070, #ff9d2e); }
.cap-buttons .random:disabled { opacity: .4; cursor: default; }

/* Confirmation bar before writing a single-program .syx file into the current program. */
.pending { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-bottom: 10px; padding: 8px 10px;
  border: 1px solid var(--orange); background: rgba(255, 142, 12, .12); font-size: 14px; line-height: 1.4; }
.pending > div { flex: 1 1 300px; }
.pending b { color: var(--orange-soft); }
.pending .write { color: #1a1d26; -webkit-text-fill-color: #1a1d26; background: linear-gradient(#ffb04a, var(--orange)); border-color: #8a5200; font-weight: 700; }

/* ? in the top right corner of each section, and the help it opens: it takes over the whole left column. */
.side.helping > :not(#help) { display: none; }
.sect { position: relative; }
.sect-help {
  -webkit-appearance: none; appearance: none; position: absolute; top: 5px; right: 6px; width: 20px; height: 20px; padding: 0; margin: 0;
  border: 1px solid var(--border); border-radius: 50%; background: var(--panel-2); cursor: pointer;
  font: 700 12px/18px var(--ui-font); color: var(--text-dim); -webkit-text-fill-color: var(--text-dim); text-align: center;
}
.sect-help:hover { border-color: var(--orange-soft); }
.sect-help.on { background: var(--orange); border-color: var(--orange); color: #1a1d26; -webkit-text-fill-color: #1a1d26; }
.help { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--lcd); border: 1px solid var(--orange); }
.help[hidden] { display: none; }
.help-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px 6px 12px; border-bottom: 1px solid var(--border); }
#help-title { font: 700 14px var(--title-font); color: var(--orange); letter-spacing: .6px; }
.help-head .btn { padding: 2px 8px; }
.help-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 12px 12px; font: 14px/1.45 var(--ui-font); color: var(--text); }
.help-body p { margin: 8px 0; }
.help-body ul { margin: 6px 0; padding-left: 18px; }
.help-body li { margin: 4px 0; }
.help-body b { color: var(--lcd-text); }
