/* Synthlab. Layout: a sticky stage (title, sample strip, keyboard) with the Tweaks panel below it on phones,
   and a side column on wide screens or landscape phones. Single dark look; every color is a token. */
:root {
  --bg: #04051a;
  --panel: #0a0d2e;
  --field: #02031a;
  --line: rgba(70, 210, 255, 0.22);
  --accent: #46d2ff;
  --hud: #9dff3d;
  --gold: #ffd23d;
  --danger: #ff5d8f;
  --text: #cfe8ff;
  --muted: #7d93b8;
  --loop: rgba(255, 210, 61, 0.18);
  --display: 'Audiowide', 'Trebuchet MS', sans-serif;
  --mono: 'Share Tech Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --tap: 44px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 48px 48px;
}

/* ---- layout ---- */
.app { display: grid; grid-template-columns: minmax(0, 1fr); }
.stage {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 14px max(16px, env(safe-area-inset-left));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(4, 5, 26, 0.7);
}
.panel {
  min-width: 0;
  padding: 16px max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(10, 13, 46, 0.72);
}
body.tweaks-off .panel { display: none; }
body.tweaks-off .stage { position: static; border-bottom: 0; box-shadow: none; }
@media (min-width: 900px), (orientation: landscape) and (min-width: 700px) and (max-height: 520px) {
  .app { grid-template-columns: minmax(0, 1fr) 340px; height: 100dvh; }
  body.tweaks-off .app { grid-template-columns: minmax(0, 1fr); }
  .stage { position: static; align-content: center; padding-block: 16px; border-bottom: 0; box-shadow: none; background: none; }
  .panel { height: 100dvh; overflow-y: auto; border-left: 1px solid var(--line); }
}

.bar { display: flex; align-items: center; gap: 10px; min-width: 0; }
h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 22px;
  line-height: 1;
  text-transform: uppercase;
  color: #9ff0ff;
  text-shadow: 0 0 10px var(--accent);
}
.pill {
  margin-left: auto;
  min-width: 0;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--gold);
  border: 1px solid var(--gold);
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill[hidden] + #tweaks-toggle { margin-left: auto; }

/* ---- buttons, fields ---- */
button, select, input[type=text] { font: inherit; color: var(--text); }
button {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: none;
  border: 2px solid rgba(207, 232, 255, 0.35);
  border-radius: 4px;
  cursor: pointer;
  touch-action: manipulation;
}
button:active { transform: scale(0.97); }
button:focus-visible, select:focus-visible, input:focus-visible, .key:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button[aria-pressed=true], .tab[aria-selected=true] { color: var(--gold); border-color: var(--gold); }
button.play { color: var(--hud); border-color: var(--hud); text-shadow: 0 0 8px rgba(157, 255, 61, 0.5); }
button.danger { color: var(--danger); border-color: var(--danger); }
select, input[type=text] {
  min-height: 40px;
  min-width: 0;
  padding: 6px 10px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 4px;
}
input[type=range] { width: 100%; min-width: 0; height: 28px; accent-color: var(--hud); }

/* ---- sample strip ---- */
.strip {
  position: relative;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.strip::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: var(--tap); padding-inline: 14px; border-radius: 999px; }
.chip.add { color: var(--accent); border-color: var(--line); }
.chip.vw { position: relative; display: inline-flex; align-items: center; padding: 0; border: 2px solid rgba(207, 232, 255, 0.35); }
.chip.vw[aria-pressed=true] { color: var(--gold); border-color: var(--gold); }
.chip.vw select {
  appearance: none;
  -webkit-appearance: none;
  min-height: calc(var(--tap) - 4px);
  padding: 0 32px 0 14px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: inherit;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23cfe8ff' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 12px center / 10px 6px;
  border: 0;
  border-radius: 999px;
}

/* ---- keyboard ---- */
.kb {
  --row-h: clamp(150px, 34dvh, 300px);
  display: grid;
  gap: 10px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.kb.stacked { --row-h: clamp(96px, 17dvh, 150px); }
@media (min-width: 900px) { .kb.single { --row-h: clamp(200px, 44dvh, 380px); } }
.kb .row { position: relative; height: var(--row-h); }
.key {
  position: absolute;
  top: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.08s, box-shadow 0.08s, transform 0.08s;
}
.key .lab { pointer-events: none; }
.key.white {
  height: 100%;
  z-index: 1;
  color: #2a4260;
  background: linear-gradient(#f6fbff, #cfe3f5);
  border: 1px solid #6f87a3;
  border-radius: 0 0 8px 8px;
}
.key.black {
  height: 62%;
  z-index: 2;
  color: #9fb6d8;
  background: linear-gradient(#2c3070, #0a0c28);
  border: 1px solid #000;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}
.key.down { transform: translateY(2px); }
.key.white.down { background: linear-gradient(#b9f3ff, var(--accent)); box-shadow: inset 0 -6px 18px rgba(0, 60, 90, 0.35), 0 0 18px rgba(70, 210, 255, 0.55); }
.key.black.down { background: linear-gradient(#5b6bff, #2b36b8); box-shadow: 0 0 16px rgba(91, 107, 255, 0.8); }

/* ---- tweaks panel ---- */
.panel-head h2 { margin: 0 0 10px; font-family: var(--display); font-weight: 400; font-size: 16px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--hud); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border-color: var(--line); color: var(--muted); }
.panel-body { display: grid; gap: 4px; margin-top: 12px; }
.tabpane { display: grid; gap: 14px; align-content: start; }
.section { display: grid; gap: 6px; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.sec { margin: 0 0 2px; font-family: var(--display); font-weight: 400; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.ctl { display: grid; grid-template-columns: minmax(5.5em, 8.5em) minmax(0, 1fr) 6.5ch; align-items: center; gap: 4px 10px; min-height: var(--tap); }
.ctl.select, .ctl.toggle, .ctl.text { grid-template-columns: minmax(5.5em, 8.5em) minmax(0, 1fr); }
.ctl.segmented { grid-template-columns: minmax(0, 1fr); }
.ctl.buttons { display: flex; flex-wrap: wrap; gap: 8px; min-height: 0; }
.ctl.info, .ctl.custom { display: block; min-height: 0; }
.ctl .lab { color: var(--muted); font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.ctl output { text-align: right; color: #fff; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ctl .help { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.ctl.buttons .help, .ctl.custom .help { flex-basis: 100%; }
.ctl.custom { display: grid; grid-template-columns: minmax(5.5em, 8.5em) minmax(0, 1fr); align-items: center; gap: 4px 10px; }
.ctl.custom:has(> canvas) { display: block; }
.info { margin: 0; color: var(--muted); font-size: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { min-height: 36px; padding-inline: 10px; font-size: 12px; }
.switch { position: relative; width: 54px; min-height: 30px; height: 30px; padding: 0; border-radius: 15px; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: transform 0.12s, background 0.12s; }
.switch[aria-checked=true] { border-color: var(--hud); }
.switch[aria-checked=true]::after { transform: translateX(24px); background: var(--hud); }
.wave { display: block; width: 100%; height: 64px; background: var(--field); border: 1px solid var(--line); border-radius: 4px; }
.panel-foot { display: grid; gap: 10px; margin-top: 16px; }
.panel-foot .row { display: flex; flex-wrap: wrap; gap: 8px; }
.panel-foot summary { color: var(--muted); cursor: pointer; }
pre { margin: 8px 0 0; padding: 12px; overflow-x: auto; background: var(--field); border: 1px solid var(--line); border-radius: 4px; color: #5dffb5; font-size: 13px; user-select: text; }

@media (prefers-reduced-motion: reduce) {
  .key, .switch::after { transition: none; }
  button:active, .key.down { transform: none; }
}
