:root {
  --red: #a10a1e;
  --red-dark: #6e0613;
  --panel-text: #f1e6e6;
  --sel: #bdbdbd;
  --cur: #ff4a4a;
  --lcd-font: "Menlo", "Consolas", "DejaVu Sans Mono", monospace;
  --ui-font: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
/* 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). */
html, body { height: 100%; }
html { touch-action: pan-x pan-y; }
body {
  margin: 0; display: flex; font-family: var(--ui-font); font-size: 13px;
  background: #111; color: var(--panel-text);
}
button, select { font-family: inherit; font-size: 12px; }

/* ---------- left column ---------- */
.side {
  width: 380px; flex: none; height: 100vh; display: flex; flex-direction: column; gap: 4px;
  background: var(--red); padding: 10px 12px 12px; border-right: 4px solid var(--red-dark);
}
.brand { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 6px; }
/* The connection pill sits under the logo, left of the buttons. */
.logo { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; min-width: 0; }
.logo-text { display: flex; align-items: baseline; gap: 12px; }
.logo .status { font-size: 11px; }
.brand .korg { font: 900 26px/1 "Arial Black", Impact, sans-serif; letter-spacing: -1px; color: #e5d2d2; }
.brand .model { font: 700 17px/1 Arial, sans-serif; color: #e5d2d2; }

/* Reload and GLOBAL as two icon buttons side by side, at the right of the logo. */
.side-buttons { margin-left: auto; align-self: flex-start; display: flex; gap: 6px; }
button.icon {
  -webkit-appearance: none; appearance: none; margin: 0; padding: 0; width: 30px; height: 30px; flex: none;
  display: grid; place-items: center; border: 1px solid #222; border-radius: 4px; cursor: pointer; color: #fff;
  background: linear-gradient(#8a8a8a, #4b4b4b);
}
button.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
button.icon:disabled { opacity: .45; cursor: default; }
#btn-global.active { background: linear-gradient(#f2f2f2, #c4c4c4); color: #000; box-shadow: inset 0 1px 2px rgba(0,0,0,.35); }
/* The X that closes the GLOBAL page, at the right of its header. */
.det-head .close { margin-left: auto; align-self: flex-start; }
.status-line { font-size: 11px; min-height: 18px; display: flex; gap: 6px; align-items: center; color: #f4dede; }
.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; }
/* Under the program list, at the bottom of the column. Long messages wrap (up to 3 lines) rather than get cut off. */
.status-line { margin-top: 2px; }
#status-text { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }

.caption { font-size: 9px; font-weight: 700; letter-spacing: .3px; color: #f4dede; margin-top: 6px; }


#fav-table {
  background: #000; border-collapse: separate; border-spacing: 4px 2px; padding: 3px 4px;
  font-family: var(--lcd-font); font-size: 11px; width: 100%;
}
#fav-table th { color: #f4f4f4; font-weight: 700; font-size: 9.5px; font-family: var(--ui-font); padding: 0; }
#fav-table th.bank { text-align: left; }
#fav-table td { text-align: center; color: #fff; border: 1px solid #777; padding: 0; line-height: 14px; cursor: pointer; }
#fav-table td:hover { border-color: #fff; }
#fav-table td.viewed { background: var(--sel); color: #000; }
#fav-table td.cur { border-color: var(--cur); color: var(--cur); font-weight: 700; }
#fav-table td.cur.viewed { color: #a00; }

.list {
  flex: 1; min-height: 0; overflow-y: auto; background: #000; border: 1px solid #555;
  font-family: var(--lcd-font); font-size: 12px; outline: none;
}
.row { display: flex; gap: 8px; padding: 1px 6px; border-bottom: 1px solid #222; cursor: pointer; color: #f0f0f0; line-height: 17px; }
.row:hover { background: #262626; }
.row .num { color: #999; width: 26px; flex: none; }
.row .name { flex: none; width: 12ch; white-space: pre; }
.row .mode { flex: none; width: 38px; color: #bbb; font-family: var(--ui-font); font-size: 11px; }
.row .rscale { flex: 1; min-width: 0; color: #bbb; font-family: var(--ui-font); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .cat { flex: none; }
.row .cat { color: #888; font-family: var(--ui-font); font-size: 11px; }
.row.viewed { background: var(--sel); color: #000; }
.row.viewed .num, .row.viewed .mode, .row.viewed .rscale, .row.viewed .cat { color: #333; }
.row.cur { box-shadow: inset 3px 0 0 var(--cur); }
.row.cur .num, .row.cur .name { color: var(--cur); font-weight: 700; }
.row.cur.viewed .num, .row.cur.viewed .name { color: #a00; }

.empty { color: #999; padding: 24px; text-align: center; font-family: var(--ui-font); }

/* ---------- details ---------- */
.details { flex: 1; height: 100vh; overflow-y: auto; padding: 24px 32px; background: linear-gradient(#2b2b2b, #111 120px); }
.det-head { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin-bottom: 20px; }
.det-num {
  font: 700 28px/1 var(--lcd-font); background: #000; border: 1px solid #555; padding: 8px 12px; color: #f4f4f4;
}
.det-name { font: 700 30px/1.1 var(--lcd-font); color: #fff; white-space: pre; }
.details .empty { margin-top: 20vh; }

/* Sections styled after the old Sound Editor panels: red tab title, dark body, LCD value boxes. */
.sect { max-width: 820px; margin-bottom: 18px; border: 1px solid #444; border-top: 2px solid var(--red); background: linear-gradient(#3a3a3a, #262626); }
/* The red top border runs from the tab title to the right edge (like the STEP EDIT strip). */
.sect-title {
  display: inline-block; background: var(--red); color: #fff; font: 700 12px var(--ui-font); letter-spacing: .5px;
  padding: 3px 30px 3px 8px; clip-path: polygon(0 0, 100% 0, calc(100% - 18px) 100%, 0 100%);
}
.sect-body { padding: 10px 14px 12px; }
.sect.grid2 .sect-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 18px; }
.sect.grid3 .sect-body { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 18px; }
/* STEP EDIT strip inside ARPEGGIATOR (spans both columns). Buttons need appearance: none for WebKit. */
.step-edit { grid-column: 1 / -1; margin: 10px -14px -12px; padding: 0 14px 12px; border-top: 2px solid var(--red); }
.sub-title {
  display: inline-block; background: var(--red); color: #fff; font: 700 11px var(--ui-font); letter-spacing: .5px;
  padding: 2px 26px 3px 8px; margin: 0 0 8px -14px; clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 100%, 0 100%);
}
.step-row { display: flex; align-items: flex-end; gap: 6px; flex-wrap: wrap; }
/* The 8 steps stay on one line; they shrink (down to 16px) rather than wrap. */
.step-row .steps { flex: 1 1 auto; display: grid; grid-template-columns: repeat(8, minmax(16px, 30px)); gap: 6px; margin-left: 12px; }
.step-row button {
  -webkit-appearance: none; appearance: none; margin: 0; cursor: pointer; font-family: var(--ui-font); padding: 0;
}
.step-row .shift {
  width: 34px; height: 22px; border: 1px solid #222; border-radius: 2px; font-size: 11px; color: #222; -webkit-text-fill-color: #222;
  background: linear-gradient(#bdbdbd, #7d7d7d);
}
.step-row .shift:hover { background: linear-gradient(#d0d0d0, #8c8c8c); }
.step { display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: 0; }
.step .n { font: 700 11px var(--ui-font); color: #d8d8d8; -webkit-text-fill-color: #d8d8d8; }
.step .led {
  width: 100%; height: 22px; border-radius: 3px; border: 1px solid #111;
  background: linear-gradient(#4a4a4a, #2c2c2c); box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
}
.step.on .led { background: linear-gradient(#e0505a, #a8121f); box-shadow: 0 0 6px rgba(230, 40, 50, .5), inset 0 1px 0 rgba(255,255,255,.25); }
.step:hover .led { border-color: #aaa; }
.step.modified .led { border-color: #f5c400; box-shadow: 0 0 0 1px #f5c400; }
.step.on.modified .led { box-shadow: 0 0 0 1px #f5c400, 0 0 6px rgba(230, 40, 50, .5); }
.step.past { opacity: .35; }
/* Two small fields sharing one grid cell (LATCH + KEY SYNC). */
.pair { display: flex; gap: 18px; min-width: 0; }
.sect.grid1 .sect-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
/* Sections: one column, all the same width, until the window is 890 CSS px wide (1780 screen pixels on Retina;
   same threshold on non-Retina monitors). From there a 3-column grid: PROGRAM, ARPEGGIATOR and LONG RIBBON span 2
   columns, SCALE and SHORT RIBBON 1. ARPEGGIATOR's row keeps its third column empty (LONG RIBBON doesn't fit there). */
.sect-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px 14px; max-width: 820px; }
.sect-grid .sect { max-width: none; margin-bottom: 0; min-width: 0; }
@media (min-width: 890px) {
  .sect-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sect-grid .span2 { grid-column: span 2; }
  .sect-grid .span3 { grid-column: 1 / -1; }
}
.sect.ribbon .cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; }
.sect.short .sect-body { display: flex; flex-direction: column; gap: 4px; }
.sect.ribbon .cols > div { display: flex; flex-direction: column; gap: 4px; }

.field { min-width: 0; }
.field .cap { font: 700 9px var(--ui-font); color: #d8d8d8; letter-spacing: .3px; margin-bottom: 1px; white-space: nowrap; }
.field .val {
  display: block; width: 100%; background: #000; color: #f4f4f4; border: 1px solid #555; border-radius: 0;
  font: 12px var(--lcd-font); padding: 2px 6px; min-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Native dropdown styling off: WebKit/iOS draw their own control and ignore our borders (no yellow edit outline). */
.field select.val {
  cursor: pointer; padding: 2px 22px 2px 6px; -webkit-appearance: none; appearance: none;
  background: #000 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='%23bbb'/%3E%3C/svg%3E") no-repeat right 7px center;
  line-height: 14px;
}
.field select.val:hover { border-color: #aaa; }
/* Not used in the current voice mode. Explicit colours: WebKit fades disabled selects on its own otherwise. */
.field.off .cap { color: #777; }
.field.off select.val, .field.off select.val:hover {
  cursor: default; color: #666; -webkit-text-fill-color: #666; opacity: 1; border-color: #3a3a3a;
  background-color: #111; background-image: none;
}
.field.modified .val { border-color: #f5c400; box-shadow: 0 0 0 1px #f5c400; }
.field .check { display: flex; width: fit-content; align-items: center; gap: 8px; min-height: 20px; cursor: pointer; font: 12px var(--lcd-font); color: #f4f4f4; }
.field .check input {
  -webkit-appearance: none; appearance: none; margin: 0; width: 20px; height: 20px; flex: none; cursor: pointer;
  background: #000; border: 1px solid #555; border-radius: 0; display: grid; place-content: center;
}
.field .check input:hover { border-color: #aaa; }
.field .check input:checked::after {
  content: ""; width: 10px; height: 5px; margin-top: -3px;
  border: solid #f4f4f4; border-width: 0 0 2px 2px; transform: rotate(-45deg);
}
.field.modified .check input { border-color: #f5c400; box-shadow: 0 0 0 1px #f5c400; }


.save {
  -webkit-appearance: none; appearance: none;
  margin-left: 6px; padding: 6px 18px; border: 1px solid #8a6d00; border-radius: 3px; cursor: pointer;
  background: linear-gradient(#ffd84a, #e0ad00); color: #000; -webkit-text-fill-color: #000; font: 700 13px var(--ui-font); letter-spacing: .5px;
}
.save:hover:not(:disabled) { background: linear-gradient(#ffe27a, #f0bf10); }
.save:disabled { background: #4a4a4a; border-color: #555; color: #888; -webkit-text-fill-color: #888; opacity: 1; cursor: default; }

/* GLOBAL page: same grid as the program page. GLOBAL takes 1 column, USER SCALE 2 (wide layout). */
/* CC# MAP: name + dropdown per row; one column, two (1~32 | 33~64) in the wide layout. @media, not @container:
   the iPad's WebKit ignores container queries. */
.sect.ccmap .sect-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 3px 28px; }
.ccrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ccrow .name { font: 11px var(--ui-font); color: #e8e8e8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.field.ccrow select.val { width: 96px; flex: none; min-height: 19px; padding-top: 1px; padding-bottom: 1px; }
@media (min-width: 890px) {
  .sect.ccmap .sect-body { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(32, auto); grid-auto-flow: column; }
}
/* Text field with a unit (MASTER TUNE ... Hz). appearance: none so WebKit keeps our border. */
.field .with-unit { display: flex; align-items: center; gap: 6px; }
.field input.val { -webkit-appearance: none; appearance: none; width: 80px; flex: none; outline: none; -webkit-text-fill-color: #f4f4f4; }
.field input.val:hover, .field input.val:focus { border-color: #aaa; }
.field .unit { font: 12px var(--lcd-font); color: #d8d8d8; }
.field .val.invalid, .field.modified .val.invalid { border-color: #e03030; box-shadow: 0 0 0 1px #e03030; }
/* One octave drawn like the old editor: outlined white keys, black keys over the gaps, a cents box in each.
   Sized in % of the keyboard (no container units: the iPad's WebKit ignores cqw), up to 46px per white key. */
/* USER SCALE: the section is as tall as its row (GLOBAL beside it is taller); the keyboard sits in its middle. */
.sect.uscale { display: flex; flex-direction: column; }
.sect.uscale .sect-title { align-self: flex-start; }
.sect.uscale .sect-body { flex: 1; display: flex; align-items: center; justify-content: center; padding-top: 12px; }
.kbd { position: relative; display: flex; width: 100%; max-width: 323px; height: 116px; margin: 0; background: #000; }
.kbd .wkey {
  flex: 1 1 0; min-width: 0; border: 1px solid #bbb; margin-right: -1px;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 5px;
}
.kbd .bkey {
  position: absolute; top: 0; --bw: max(30px, 100% / 7 * .74); left: calc(100% / 7 * var(--gap) - var(--bw) / 2); width: var(--bw); height: 64px;
  background: #000; border: 1px solid #bbb; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px;
}
.kbd .cents {
  position: relative; display: flex; align-items: center; justify-content: center; width: calc(100% - 8px); max-width: 34px; height: 20px;
  background: #000; border: 1px solid #555; font: 11px var(--lcd-font); color: #f4f4f4;
}
.kbd .bkey .cents { width: calc(100% - 6px); max-width: none; }
.kbd .cents select {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; margin: 0; padding: 0; border: 0; opacity: 0; cursor: pointer;
  -webkit-appearance: none; appearance: none; font-size: 16px;
}
.kbd .cents:hover { border-color: #aaa; }
.kbd .cents.modified { border-color: #f5c400; box-shadow: 0 0 0 1px #f5c400; }

/* ---------- responsive ----------
   Driven by the width of the details pane (not the window), since the red column eats 380px
   and AUv3 host windows come in any size. */
.details { container-type: inline-size; }
@container (max-width: 420px) {
  .det-head .save { margin-left: 0; }
}
@container (max-width: 520px) {
  .sect.grid3 .sect-body { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container (max-width: 360px) {
  .sect.grid2 .sect-body, .sect.grid3 .sect-body, .sect.ribbon .cols { grid-template-columns: minmax(0, 1fr); }
  .sect.ribbon .cols { gap: 4px; }
}
@media (max-width: 760px) {
  .details { padding: 16px 14px; }
}

/* ---------- touch screens (the iPad) ----------
   Bigger text, less padding. pointer: coarse leaves the desktop layout alone. */
@media (pointer: coarse) {
  body { font-size: 15px; }
  button, select { font-size: 14px; }
  .side { padding: 6px 8px 8px; gap: 3px; }
  .brand { margin-bottom: 3px; }
  .status-line, .logo .status { font-size: 13px; }
  .caption { font-size: 11px; margin-top: 4px; }
  #fav-table { font-size: 14px; border-spacing: 3px 2px; padding: 2px 3px; }
  #fav-table th { font-size: 11px; }
  #fav-table td { line-height: 20px; }
  .list { font-size: 15px; }
  .row { gap: 6px; padding: 2px 4px; line-height: 20px; }
  .row .num { width: 30px; }
  .row .mode { width: 44px; font-size: 13px; }
  .row .rscale, .row .cat { font-size: 13px; }

  .details { padding: 12px 14px; }
  .det-head { gap: 8px 14px; margin-bottom: 12px; }
  .det-num { padding: 5px 9px; }
  .sect-grid { gap: 12px 10px; }
  .sect { margin-bottom: 12px; }
  .sect-title { font-size: 14px; padding: 2px 30px 2px 7px; }
  .sub-title { font-size: 13px; padding: 2px 26px 2px 7px; margin-left: -9px; }
  .sect-body { padding: 6px 9px 8px; }
  .sect.uscale .sect-body { padding-top: 8px; }
  .step-edit { margin: 8px -9px -8px; padding: 0 9px 8px; }
  .sect.grid2 .sect-body, .sect.grid3 .sect-body { gap: 4px 12px; }
  .field .cap { font-size: 11px; }
  .field .val { font-size: 15px; padding: 2px 5px; min-height: 26px; }
  .field select.val { padding: 2px 20px 2px 5px; line-height: 20px; }
  .field .check, .field .unit { font-size: 15px; }
  .step .n, .step-row .shift { font-size: 13px; }
  .ccrow .name { font-size: 13px; }
  .field.ccrow select.val { width: 110px; min-height: 24px; }
  .kbd .cents { font-size: 13px; }
  .save { font-size: 15px; padding: 5px 16px; }
}
