:root {
  --body: #2a211d; --body2: #3a2e28; --panel: #1b1512; --text: #e9dfd2; --dim: #a8988a;
  --maroon: #8e2a3c; --teal: #3fa59b; --cream: #d9c9a8; --lcd: #9fd36a; --lcd-bg: #24321b;
  --white-key: #f4efe6; --black-key: #1a1412;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; background: var(--body); color: var(--text);
  font: 13px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace; overscroll-behavior: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) 0 env(safe-area-inset-left, 0);
}
button { font: inherit; color: inherit; }

/* header: logo stripes + LCD */
.panel { flex: 0 0 auto; display: flex; gap: 10px; align-items: stretch; padding: 10px 12px 8px; background: linear-gradient(var(--body2), var(--body)); }
.brand { position: relative; flex: 0 0 auto; display: flex; flex-direction: column; justify-content: center; }
.stripes { display: flex; flex-direction: column; gap: 2px; width: 74px; margin-bottom: 4px; }
.stripes i { display: block; height: 3px; background: var(--maroon); }
.stripes i:nth-child(2) { background: var(--cream); } .stripes i:nth-child(3) { background: var(--teal); }
.logo { font: 800 26px/1 "Helvetica Neue", Arial, sans-serif; letter-spacing: 1px; color: var(--cream); }
.logo small { font-size: 11px; margin-left: 4px; color: var(--teal); letter-spacing: 2px; }
.sub { font-size: 7px; letter-spacing: 1.5px; color: var(--dim); margin-top: 3px; }
.lcd {
  position: relative; flex: 1 1 auto; min-width: 0; background: var(--lcd-bg); border: 3px solid #0e0b09; border-radius: 4px;
  padding: 5px 8px; box-shadow: inset 0 0 12px rgba(0,0,0,.7); overflow: hidden;
}
.lcd-line { position: relative; z-index: 1; color: var(--lcd); font-size: 15px; letter-spacing: 1px; white-space: nowrap; overflow: hidden;
  text-overflow: clip; text-shadow: 0 0 4px rgba(159,211,106,.5); text-transform: uppercase; }
#scope { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .45; }

/* voice buttons, membrane style */
.presets { flex: 0 0 auto; display: flex; gap: 6px; overflow-x: auto; padding: 6px 12px 8px; scrollbar-width: none; background: var(--body); }
.presets::-webkit-scrollbar { display: none; }
.pbtn {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 76px; padding: 6px 8px 7px;
  border: 0; border-radius: 3px; background: var(--maroon); color: #f5e9e2; text-align: left; box-shadow: 0 2px 0 #4b1520;
}
.pbtn:nth-child(even) { background: var(--teal); box-shadow: 0 2px 0 #1d5650; }
.pbtn b { font-size: 10px; opacity: .8; } .pbtn span { font-size: 11px; white-space: nowrap; }
.pbtn[aria-pressed="true"] { outline: 2px solid var(--lcd); outline-offset: 1px; }
.pbtn:active { transform: translateY(2px); box-shadow: none; }

/* editor */
.editor { flex: 1 1 auto; overflow-y: auto; padding: 4px 12px 10px; background: var(--panel); -webkit-overflow-scrolling: touch; }
.row { margin: 8px 0 12px; }
.label { font-size: 10px; letter-spacing: 1.5px; color: var(--dim); margin-bottom: 6px; }
.algs { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.alg { aspect-ratio: 3/4; border: 1px solid #4a3c33; border-radius: 3px; background: #241c18; padding: 2px; display: grid; place-items: center; }
.alg svg { width: 100%; height: 100%; }
.alg[aria-pressed="true"] { border-color: var(--lcd); background: #2c3a22; }
.knobs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
label { display: block; font-size: 10px; letter-spacing: 1px; color: var(--dim); }
output { float: right; color: var(--lcd); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 30px; background: transparent; margin: 0; touch-action: pan-y; }
input[type=range]::-webkit-slider-runnable-track { height: 4px; background: #4a3c33; border-radius: 2px; }
input[type=range]::-moz-range-track { height: 4px; background: #4a3c33; border-radius: 2px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 3px; background: var(--cream); border: 2px solid #0e0b09; }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 3px; background: var(--cream); border: 2px solid #0e0b09; }
.optabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-bottom: 8px; }
.optab { border: 0; border-radius: 3px; padding: 8px 0 6px; background: #3a2e28; color: var(--text); font-size: 12px; position: relative; }
.optab[aria-selected="true"] { background: var(--cream); color: #1b1512; font-weight: 700; }
.optab .meter { position: absolute; left: 6px; right: 6px; bottom: 2px; height: 2px; background: rgba(0,0,0,.25); }
.optab .meter i { display: block; height: 100%; background: var(--maroon); }
.optab.carrier::after { content: "OUT"; position: absolute; top: 1px; right: 4px; font-size: 7px; color: var(--teal); }
.opedit { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; }
.opedit canvas { grid-column: 1 / -1; width: 100%; height: 56px; background: #241c18; border-radius: 3px; margin-bottom: 4px; }
.actions { display: flex; gap: 8px; }
.btn { border: 0; border-radius: 3px; padding: 9px 12px; background: #3a2e28; color: var(--text); letter-spacing: 1px; box-shadow: 0 2px 0 #120e0c; }
.btn:active, .btn[aria-pressed="true"] { transform: translateY(2px); box-shadow: none; background: var(--cream); color: #1b1512; }
.actions .btn { flex: 1; }
.btn.small { padding: 6px 10px; font-size: 11px; }

/* keyboard */
.kbd-wrap { flex: 0 0 auto; background: #120e0c; padding: 6px 4px calc(4px + var(--safe-b)); border-top: 3px solid var(--maroon); }
.kbd-bar { display: flex; align-items: center; gap: 6px; padding: 0 4px 6px; }
.oct { min-width: 32px; text-align: center; color: var(--lcd); }
#hold { margin-left: auto; }
.kbd { position: relative; display: flex; height: clamp(130px, 26vh, 210px); touch-action: none; }
.key { position: relative; flex: 1 1 0; margin: 0 1px; border-radius: 0 0 5px 5px; background: linear-gradient(#fff, var(--white-key) 85%, #d8d0c2); }
.key.black {
  position: absolute; top: 0; z-index: 2; height: 60%; margin: 0; border-radius: 0 0 3px 3px;
  background: linear-gradient(#3b302b, var(--black-key) 80%); box-shadow: 0 2px 2px rgba(0,0,0,.6);
}
.key.down { background: var(--cream); } .key.black.down { background: var(--maroon); }
.key .name { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 9px; color: #9c8f80; pointer-events: none; }

@media (orientation: landscape) and (max-height: 520px) {
  .panel { padding: 6px 10px 4px; } .sub { display: none; }
  .presets { padding: 4px 10px; }
  .editor { display: none; }
  body.edit .editor { display: block; }
  body.edit .kbd { height: 32vh; }
  .kbd { height: auto; flex: 1; }
  .kbd-wrap { flex: 1 1 auto; display: flex; flex-direction: column; }
}
.edit-toggle { display: none; }
@media (orientation: landscape) and (max-height: 520px) { .edit-toggle { display: inline-block; } }
