:root {
  --back: #14161c;
  --section: #1d2029;
  --panel: #242836;
  --off: #333845;
  --on: #f28c26;
  --accent: #f28c26;
  --text: #e9ebf2;
  --dim: #a6adbf;
  --rec: #d8343a;
  --line: #3a3f4d;
  --cyan: #46d2f0;
  --pink: #f05fb0;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--back); color: var(--text);
  font: 13px/1.35 "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  display: flex; flex-direction: column; overflow: hidden; user-select: none;
}
button, select, input, textarea { font: inherit; color: var(--text); }
button, .button {
  background: var(--off); border: 1px solid #454b5a; border-radius: 4px; padding: 4px 9px; cursor: pointer; white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(1.15); }
button.on { background: var(--on); border-color: var(--on); color: #1a1008; font-weight: bold; }
button.recOn { background: var(--rec); border-color: var(--rec); color: #fff; }
button.armed { background: #8a2a2a; border-color: #c44; }
button.big { font-weight: bold; padding: 6px 14px; }
button.wide { min-width: 170px; }
button:disabled { opacity: .5; cursor: default; }
select, input[type=number], textarea { background: #10121a; border: 1px solid #454b5a; border-radius: 4px; padding: 3px 5px; }
input[type=number] { width: 58px; }
input[type=range] { accent-color: var(--accent); }
.hidden { display: none !important; }
.dim { color: var(--dim); }
.hint { color: var(--dim); font-size: 12px; }
.label { color: var(--dim); }
.spacer { flex: 1; }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
.field { display: inline-flex; align-items: center; gap: 5px; color: var(--dim); }
.field input[type=range] { width: 90px; }
.row { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.group { display: inline-flex; gap: 2px; }
.status { color: var(--accent); min-height: 1.4em; }

#start { position: fixed; inset: 0; background: rgba(8, 9, 12, .92); display: flex; align-items: center; justify-content: center; z-index: 50; }
.startBox { max-width: 520px; text-align: center; }
.startBox h1 { color: var(--accent); letter-spacing: 2px; }
.startBox button { font-size: 18px; padding: 10px 30px; margin: 10px; }

#top { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--section); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.title { color: var(--accent); font-weight: bold; font-size: 18px; letter-spacing: 1px; margin-right: 8px; }
.title small, h1 small { font-size: 11px; color: var(--dim); font-weight: normal; }
#meter { background: #0c0d12; border-radius: 3px; }

/* 右の列 (音色・FX XY) は、ミキサーが左の幅に収まるときは下まで伸ばす (main.js の fitMixer が mixerLeft を付ける) */
#app { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 470px; grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "left right" "mixer mixer"; }
#app.mixerLeft { grid-template-areas: "left right" "mixer right"; }
#app.mixerLeft #mixer { border-top: none; margin: 0 0 6px 6px; border-radius: 6px; justify-content: space-between; } /* 中身の幅は変えずに余りを間に配る (fitMixer の測り方が変わらない) */
#left { grid-area: left; flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 6px; gap: 6px; }
#right { grid-area: right; min-height: 0; padding: 6px 6px 6px 0; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
#sound { flex: none; }
/* 音色のつまみの下の空き。残りの高さいっぱいに広げ、狭いときは隠す (main.js の drawXY) */
#xyArea { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; gap: 4px; background: var(--section); border-radius: 6px; padding: 6px; }
#xyArea.cramped > * { visibility: hidden; }
#xyArea .tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#xyTrack { font-weight: bold; }
#xyPad { flex: 1 1 0; min-height: 0; width: 100%; display: block; border-radius: 4px; cursor: crosshair; touch-action: none; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--section); border-radius: 6px; padding: 6px; gap: 6px; }
.tools { padding: 2px; }
.gridWrap, .songWrap, .graphWrap { flex: 1; min-height: 0; position: relative; }
.songWrap { overflow-x: auto; overflow-y: hidden; }
#grid, #graphCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#songCanvas { display: block; height: 100%; }
.graphBody { flex: 1; display: flex; gap: 6px; min-height: 0; }
#graphSide { width: 300px; overflow-y: auto; background: var(--panel); border-radius: 5px; padding: 8px; }
#graphSide h4 { margin: 2px 0 6px; }
.pRow { display: grid; grid-template-columns: 80px minmax(0, 1fr) 74px; align-items: center; gap: 4px; margin: 3px 0; }
.pRow input[type=range] { width: 100%; min-width: 0; margin: 0; }
.pRow > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#graphSide { overflow-x: hidden; }
.pRow .v { text-align: right; color: var(--dim); font-size: 12px; }
.pRow button.x { padding: 0 6px; }

#trackTabs button { min-width: 54px; }
#trackTabs button.t0 { border-bottom: 3px solid #4c8ee0; }
#trackTabs button.t1 { border-bottom: 3px solid #49c08a; }
#trackTabs button.t2 { border-bottom: 3px solid #d8b13c; }
#trackTabs button.t3 { border-bottom: 3px solid #c46ad8; }
#trackTabs button.t4 { border-bottom: 3px solid #e0703c; }
#trackTabs button.on { color: #1a1008; }

#padArea { background: var(--section); border-radius: 6px; padding: 6px; }
#pad { width: 100%; height: 118px; display: block; border-radius: 4px; cursor: crosshair; touch-action: none; }

#sound { background: var(--panel); border-radius: 6px; padding: 8px; }
#sound .head { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
#sound .engineName { flex: 1; text-align: center; font-weight: bold; font-size: 15px; }
#sound .presetBtn { width: 100%; margin-bottom: 6px; text-align: left; }
/* minmax(0, 1fr): 長い名前 (フォントで幅が変わる) で列が広がって右へはみ出さないように */
.knobs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px 8px; }
.knob { min-width: 0; border-top: 3px solid transparent; padding-top: 2px; min-height: 40px; }
.knob .l { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.knob input { width: 100%; margin: 0; }
.knob.empty { visibility: hidden; }
.knob.auto0 .l::after { content: " ●"; color: var(--cyan); }
.knob.auto1 .l::after { content: " ●"; color: var(--pink); }
.drumRows { display: grid; grid-template-columns: 1fr; gap: 6px; }
.drumRow { display: grid; grid-template-columns: 150px 1fr 1fr 1fr; gap: 6px; align-items: end; }
.drumRow select { width: 100%; }

.popup { position: fixed; z-index: 20; background: #1b1e27; border: 1px solid #4a5062; border-radius: 6px; padding: 8px; box-shadow: 0 8px 30px rgba(0, 0, 0, .5); max-height: 80vh; overflow-y: auto; }
.popup .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.popup .grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.popup button { text-align: left; }
.popup h4 { margin: 8px 0 4px; color: var(--dim); font-weight: normal; }

#mixer > * { flex-shrink: 0; }
#mixer { grid-area: mixer; min-width: 0; display: flex; gap: 6px; padding: 6px; background: var(--section); border-top: 1px solid var(--line); align-items: stretch; overflow-x: auto; }
.strip { background: var(--panel); border-radius: 5px; padding: 5px 7px; min-width: 150px; display: grid; grid-template-columns: 34px 1fr; gap: 2px 4px; align-items: center; font-size: 11px; }
.strip .name { grid-column: 1 / 3; display: flex; justify-content: space-between; align-items: center; font-weight: bold; font-size: 12px; }
.strip input[type=range] { width: 100%; }
.strip .ms button { padding: 1px 6px; font-size: 11px; }
.strip canvas { width: 100%; height: 6px; grid-column: 1 / 3; background: #0c0d12; border-radius: 2px; }
.fx { background: var(--panel); border-radius: 5px; padding: 5px 7px; display: grid; grid-template-columns: 70px 120px 60px; gap: 2px 6px; align-items: center; font-size: 11px; }
.fx .name { grid-column: 1 / 4; font-weight: bold; font-size: 12px; }
.fx .v { color: var(--dim); text-align: right; }

dialog { background: #1b1e27; color: var(--text); border: 1px solid #4a5062; border-radius: 8px; padding: 0; max-width: 1000px; width: 92vw; }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dlgHead { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); margin: 0; }
.dlgBody { padding: 10px 14px 14px; max-height: 80vh; overflow-y: auto; user-select: text; }
.dlgBody h3 { margin: 12px 0 6px; font-size: 14px; color: var(--accent); }
.cols { display: grid; grid-template-columns: 360px 1fr; gap: 18px; }
#slots .slot { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 5px; align-items: center; margin: 3px 0; }
#slots .slot .info { font-size: 12px; color: var(--dim); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#songText { width: 100%; height: 170px; font-family: Consolas, monospace; font-size: 11px; resize: vertical; }
.help li { margin: 3px 0; }
#settingsDialog .field { margin: 8px 0; }

#toast { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: #2b2f3c; border: 1px solid var(--accent); padding: 7px 14px; border-radius: 6px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 60; }
#toast.show { opacity: 1; }
#playTabs button, #arpTabs button, #rateTabs button { padding: 3px 7px; }
.gateGrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; width: 520px; }
.gateGrid button { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 8px; }
.gateBar { position: relative; height: 14px; background: repeating-linear-gradient(90deg, rgba(255,255,255,.18) 0 2px, transparent 2px 25%); border-radius: 2px; }
.gateBar i { position: absolute; top: 2px; bottom: 2px; background: #4fe3ff; border-radius: 2px; }
.gateGrid button.on .gateBar i { background: #1a1008; }
