@font-face {
  font-family: 'Areal';
  src: url('../fonts/ABCArealSuperfamilyVariable.woff2') format('woff2');
  font-weight: 400 700;
  font-style: oblique 0deg 12deg;
  font-display: swap;
}

:root {
  --canvas: #f2f2f2;
  --panel: #ffffff;
  --input: #f5f5f5;
  --hover: #f0f0f0;
  --border: #e6e6e6;
  --border-strong: #d4d4d4;
  --text: #1e1e1e;
  --text-2: rgba(0, 0, 0, 0.56);
  --text-3: rgba(0, 0, 0, 0.32);
  --accent: #0d99ff;
  --accent-text: #007be5;
  --accent-soft: rgba(13, 153, 255, 0.12);
  --fill: rgba(13, 153, 255, 0.13);
  --seg-on: #ffffff;
  --seg-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --rec: #f24822;
  --shadow: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 2px 6px rgba(0, 0, 0, 0.06), 0 10px 32px rgba(0, 0, 0, 0.1);
  --tip-bg: #1e1e1e;
  --tip-text: #ffffff;
  --key-white: #ffffff;
  --key-black: #2c2c2c;
  --track: rgba(0, 0, 0, 0.05);
  --drkm: 0;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #1e1e1e; --panel: #2c2c2c; --input: #383838; --hover: #383838;
    --border: #444444; --border-strong: #555555;
    --text: #ffffff; --text-2: rgba(255, 255, 255, 0.66); --text-3: rgba(255, 255, 255, 0.36);
    --accent-text: #4cb4ff; --accent-soft: rgba(13, 153, 255, 0.2); --fill: rgba(13, 153, 255, 0.22);
    --seg-on: #4a4a4a; --seg-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 2px 6px rgba(0, 0, 0, 0.3), 0 10px 32px rgba(0, 0, 0, 0.45);
    --tip-bg: #f5f5f5; --tip-text: #1e1e1e;
    --key-white: #e8e8e8; --key-black: #1a1a1a;
    --track: rgba(255, 255, 255, 0.06);
    --drkm: 1;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --canvas: #1e1e1e; --panel: #2c2c2c; --input: #383838; --hover: #383838;
  --border: #444444; --border-strong: #555555;
  --text: #ffffff; --text-2: rgba(255, 255, 255, 0.66); --text-3: rgba(255, 255, 255, 0.36);
  --accent-text: #4cb4ff; --accent-soft: rgba(13, 153, 255, 0.2); --fill: rgba(13, 153, 255, 0.22);
  --seg-on: #4a4a4a; --seg-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 0 0 1px rgba(255, 255, 255, 0.07), 0 2px 6px rgba(0, 0, 0, 0.3), 0 10px 32px rgba(0, 0, 0, 0.45);
  --tip-bg: #f5f5f5; --tip-text: #1e1e1e;
  --key-white: #e8e8e8; --key-black: #1a1a1a;
  --track: rgba(255, 255, 255, 0.06);
  --drkm: 1;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-family: 'Areal', system-ui, -apple-system, sans-serif;
  font-size: 11px;
  line-height: 16px;
  font-variation-settings: 'MONO' 0, 'DRKM' var(--drkm);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; font-variation-settings: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
.mono { font-variation-settings: 'MONO' 100, 'DRKM' var(--drkm); font-variant-numeric: tabular-nums; }
svg { display: block; }
::selection { background: var(--accent-soft); }

/* ---------- layout ---------- */
.app {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 272px;
  height: 100vh;
}
.panel {
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 2;
}
.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }
.panel-head {
  height: 48px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--border);
}
.panel-right .panel-head { padding: 0 12px; }
.panel-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
.panel-foot {
  flex: none; border-top: 1px solid var(--border); padding: 10px 16px; color: var(--text-3);
  display: flex; justify-content: space-between;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 12px; flex: 1; min-width: 0; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.brand small { font-weight: 400; color: var(--text-3); font-size: 11px; }

/* ---------- sections ---------- */
.sec { border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.sec.collapsed { padding-bottom: 0; }
.sec.collapsed .sec-body { display: none; }
.sec-head {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px 0 16px;
  font-weight: 600;
  user-select: none;
}
.sec-title { flex: 1; display: flex; align-items: center; gap: 6px; cursor: pointer; height: 100%; }
.sec-title .chev { color: var(--text-3); transition: transform .15s; margin-left: -2px; opacity: 0; }
.sec-head:hover .chev { opacity: 1; }
.sec.collapsed .chev { transform: rotate(-90deg); opacity: 1; }
.sec-title .meta { font-weight: 400; color: var(--text-3); margin-left: 2px; }
.sec-body { padding: 0 16px; display: grid; gap: 8px; }
.sec.off .sec-body { opacity: 0.42; }
.sec.off .sec-body:hover { opacity: 0.7; }
.sub-label { color: var(--text-2); margin-top: 4px; display: flex; justify-content: space-between; }
.sub-label span:last-child { color: var(--text-3); }
.hint { color: var(--text-3); line-height: 15px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row { display: grid; grid-template-columns: 64px minmax(0, 1fr); align-items: center; gap: 8px; }
.row > label { color: var(--text-2); }
.row.switch-row { grid-template-columns: 1fr auto; height: 28px; }
.row.switch-row > label { color: var(--text); }

/* ---------- controls ---------- */
.icon-btn {
  width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; color: var(--text-2); flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--accent-text); background: var(--accent-soft); }

.field {
  position: relative;
  height: 28px;
  border-radius: 6px;
  background: var(--input);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  overflow: hidden;
  user-select: none;
  border: 1px solid transparent;
  min-width: 0;
}
.field:hover { border-color: var(--border-strong); }
.field:focus-visible, .field.editing { outline: none; border-color: var(--accent); }
.scrub { cursor: ew-resize; }
.scrub.dragging { cursor: ew-resize; border-color: var(--accent); }
.scrub .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--fill); pointer-events: none; }
.scrub .fill::after { content: ''; position: absolute; right: 0; top: 0; bottom: 0; width: 1px; background: var(--accent); opacity: .7; }
.scrub .lab { position: relative; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scrub .val { position: relative; margin-left: auto; white-space: nowrap; }
.scrub input {
  position: relative; border: 0; outline: 0; background: transparent; width: 100%; text-align: right; padding: 0; margin-left: auto;
}

.select { position: relative; }
.select select {
  appearance: none; -webkit-appearance: none;
  width: 100%; height: 28px; border-radius: 6px; border: 1px solid transparent;
  background: var(--input); padding: 0 24px 0 8px; cursor: pointer; outline: none;
}
.select select:hover { border-color: var(--border-strong); }
.select select:focus-visible { border-color: var(--accent); }
.select svg { position: absolute; right: 7px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--text-2); }

.seg { display: flex; background: var(--input); border-radius: 6px; padding: 2px; height: 28px; gap: 2px; }
.seg button { flex: 1; border-radius: 4px; color: var(--text-2); white-space: nowrap; padding: 0 6px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--seg-on); color: var(--text); box-shadow: var(--seg-shadow); font-weight: 500; }
.seg.big { height: 32px; flex: 1; }

.switch { width: 28px; height: 16px; border-radius: 8px; background: var(--border-strong); position: relative; transition: background .15s; flex: none; }
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(12px); }

.btn {
  height: 28px; border-radius: 6px; padding: 0 10px; background: var(--input); display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid transparent;
}
.btn:hover { border-color: var(--border-strong); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
.kbd { color: var(--text-3); }

.text-input {
  height: 28px; border-radius: 6px; border: 1px solid transparent; background: var(--input); padding: 0 8px; width: 100%; outline: none;
}
.text-input:hover { border-color: var(--border-strong); }
.text-input:focus { border-color: var(--accent); }

/* ---------- left panel bits ---------- */
.samples { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sample { display: grid; gap: 4px; text-align: center; color: var(--text-2); }
.sample .sw {
  aspect-ratio: 4 / 3; border-radius: 6px; overflow: hidden; background: #000; position: relative;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06);
}
.sample .sw canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.sample:hover { color: var(--text); }
.sample.on .sw { box-shadow: 0 0 0 2px var(--accent); }
.sample.on { color: var(--text); }
.sample .sw.upload { background: var(--input); display: grid; place-items: center; color: var(--text-2); box-shadow: inset 0 0 0 1px var(--border); }
.sample:hover .sw.upload { color: var(--text); }

.file-chip {
  display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px; border-radius: 6px; background: var(--input);
}
.file-chip .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-chip .dm { color: var(--text-3); }
.file-chip .thumb { width: 20px; height: 20px; border-radius: 3px; overflow: hidden; flex: none; background: #000; }
.file-chip .thumb canvas { width: 100%; height: 100%; object-fit: cover; }

.list { display: grid; gap: 1px; margin: 0 -8px; }
.list-item {
  height: 32px; display: flex; align-items: center; gap: 10px; padding: 0 8px; border-radius: 6px; color: var(--text); text-align: left; width: 100%;
}
.list-item svg { color: var(--text-2); flex: none; }
.list-item:hover { background: var(--hover); }
.list-item.on { background: var(--accent-soft); }
.list-item.on svg { color: var(--accent-text); }
.list-item .kbd { margin-left: auto; }

.stack { display: grid; gap: 8px; }
.sub-label .mono { color: var(--text-3); }
.sample .sw img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile { position: relative; display: grid; }
.folder { display: grid; gap: 8px; }
.folder-head {
  display: flex; align-items: center; gap: 6px; height: 26px; margin: 0 -6px; padding: 0 6px; border-radius: 6px; text-align: left; color: var(--text);
}
.folder-head:hover { background: var(--hover); }
.folder-head svg { color: var(--text-2); flex: none; }
.folder-head .chev { color: var(--text-3); transition: transform .15s; }
.folder-head.closed .chev { transform: rotate(-90deg); }
.folder-head .fname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-head .mono { margin-left: auto; color: var(--text-3); }
.samples[hidden] { display: none; }
.tile .rm {
  position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--panel); color: var(--text-2); box-shadow: var(--shadow); display: grid; place-items: center;
  opacity: 0; transition: opacity .12s;
}
.tile:hover .rm, .tile .rm:focus-visible { opacity: 1; }
.tile .rm:hover { color: var(--rec); }

.banner {
  position: absolute; top: 12px; left: 12px; right: 140px; margin: 0 auto; max-width: 560px; z-index: 4;
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px;
  background: var(--panel); box-shadow: var(--shadow); line-height: 16px;
}
.banner::before { content: ''; flex: none; width: 8px; height: 8px; margin-top: 4px; border-radius: 50%; background: #ffb800; }
.banner b { font-weight: 600; }

/* ---------- right panel bits ---------- */
.keys { position: relative; height: 44px; display: flex; gap: 2px; }
.keys .w {
  flex: 1; background: var(--key-white); border-radius: 0 0 4px 4px; box-shadow: inset 0 0 0 1px var(--border);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; color: var(--text-3); font-size: 10px; position: relative;
}
:root[data-theme="dark"] .keys .w { color: rgba(0,0,0,.45); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .keys .w { color: rgba(0,0,0,.45); } }
.keys .b {
  position: absolute; top: 0; height: 26px; background: var(--key-black); border-radius: 0 0 3px 3px; z-index: 1;
}
.keys .w:hover, .keys .b:hover { filter: brightness(.93); }
.keys .dot { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); left: 50%; transform: translateX(-50%); }
.keys .w .dot { bottom: 18px; }
.keys .b .dot { bottom: 5px; }
.keys .root { background: var(--accent) !important; color: #fff !important; }
.keys .root .dot { background: #fff; }

.range-viz { display: grid; gap: 6px; }
.range-viz canvas { width: 100%; height: 28px; display: block; }
.range-viz .cap { color: var(--text-3); display: flex; justify-content: space-between; }

.instruments { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.inst {
  height: 50px; border-radius: 6px; background: var(--input); display: grid; place-items: center; align-content: center; gap: 4px;
  border: 1px solid transparent; color: var(--text-2);
}
.inst svg { color: var(--text-2); }
.inst:hover { border-color: var(--border-strong); color: var(--text); }
.inst.on { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.inst.on svg { color: var(--accent-text); }

.adsr { position: relative; height: 88px; border-radius: 6px; background: var(--input); overflow: hidden; touch-action: none; }
.adsr svg { width: 100%; height: 100%; }
.adsr .curve { fill: var(--fill); stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.adsr .guide { stroke: var(--border-strong); stroke-dasharray: 2 3; }
.adsr .h { fill: var(--panel); stroke: var(--accent); stroke-width: 1.5; cursor: grab; }
.adsr .h:hover, .adsr .h.drag { fill: var(--accent); }
.adsr .tag { fill: var(--text-3); font-size: 9px; font-variation-settings: 'MONO' 100; }

/* ---------- stage ---------- */
.stage { position: relative; overflow: hidden; background: var(--canvas); min-width: 0; container-type: inline-size; }
#imgCanvas { position: absolute; image-rendering: auto; cursor: crosshair; touch-action: none; box-shadow: 0 0 0 1px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.1); background: #000; }
#imgCanvas.pixel { image-rendering: pixelated; }
#ovCanvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.frame-label { position: absolute; color: var(--text-2); white-space: nowrap; display: flex; gap: 8px; pointer-events: none; }
.frame-label b { font-weight: 500; color: var(--text); }
.frame-dims {
  position: absolute; background: var(--accent); color: #fff; border-radius: 4px; padding: 0 5px; height: 18px; line-height: 18px;
  transform: translateX(-50%); font-size: 10px; pointer-events: none; opacity: 0; transition: opacity .15s;
}
.stage:hover .frame-dims { opacity: 1; }

.stage-tools { position: absolute; top: 12px; right: 12px; display: flex; gap: 8px; z-index: 3; }
.float { background: var(--panel); box-shadow: var(--shadow); border-radius: 8px; }
.stage-tools .seg { background: var(--panel); box-shadow: var(--shadow); height: 32px; padding: 3px; border-radius: 8px; }
.stage-tools .seg button { padding: 0 10px; }
.stage-tools .seg button.on { background: var(--input); box-shadow: none; }
.stage-tools .icon-btn { width: 32px; height: 32px; border-radius: 8px; background: var(--panel); box-shadow: var(--shadow); }
.stage-tools .icon-btn.on { background: var(--panel); }

.empty { position: absolute; inset: 0; display: none; place-items: center; color: var(--text-2); }

.drop-veil {
  position: absolute; inset: 12px; border: 1.5px dashed var(--accent); border-radius: 12px; background: var(--accent-soft);
  display: none; place-items: center; color: var(--accent-text); font-weight: 500; font-size: 12px; z-index: 5; pointer-events: none;
}
body.dragging .drop-veil { display: grid; }

/* ---------- toolbar ---------- */
.toolbar {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 4px; padding: 6px; height: 48px; border-radius: 12px;
  background: var(--panel); box-shadow: var(--shadow); z-index: 3; max-width: calc(100% - 24px);
}
.toolbar .sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; flex: none; }
.play {
  width: 36px; height: 36px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none;
}
.play:hover { filter: brightness(1.07); }
.toolbar .icon-btn { width: 32px; height: 32px; }
.toolbar .field { width: 92px; flex: none; height: 32px; }
.timeline { position: relative; width: 200px; height: 32px; flex: 1 1 200px; min-width: 80px; cursor: pointer; display: flex; align-items: center; }
.timeline .track { position: absolute; left: 0; right: 0; height: 4px; border-radius: 2px; background: var(--input); top: 50%; transform: translateY(-50%); overflow: hidden; }
.timeline .prog { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); width: 0; }
.timeline .knob { position: absolute; top: 50%; width: 2px; height: 16px; background: var(--accent); border-radius: 1px; transform: translate(-50%, -50%); left: 0; }
.time { color: var(--text-2); white-space: nowrap; padding: 0 6px; flex: none; min-width: 92px; text-align: center; }
.rec { color: var(--text-2); }
.rec .dot { width: 10px; height: 10px; border-radius: 50%; background: currentColor; }
.rec.on { color: var(--rec); background: rgba(242, 72, 34, .12); }
.rec.on .dot { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .35; } }
#scope { width: 64px; height: 32px; flex: none; border-radius: 6px; background: var(--input); }

/* ---------- tooltip & toast ---------- */
.tip {
  position: fixed; z-index: 50; background: var(--tip-bg); color: var(--tip-text); padding: 4px 8px; border-radius: 5px; pointer-events: none;
  white-space: nowrap; opacity: 0; transition: opacity .1s; display: flex; gap: 8px;
}
.tip.show { opacity: 1; }
.tip .k { opacity: .55; }
.toast {
  position: absolute; left: 50%; bottom: 76px; transform: translate(-50%, 8px); background: var(--tip-bg); color: var(--tip-text);
  padding: 8px 12px; border-radius: 8px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 6; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@container (max-width: 700px) {
  #scope, .toolbar .sep { display: none; }
  .timeline { flex-basis: 60px; }
  .time { min-width: 0; }
}
@container (max-width: 520px) {
  .toolbar .field { display: none; }
}

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; grid-template-rows: 60vh auto auto; height: auto; }
  .stage { grid-row: 1; height: 60vh; }
  .panel-left { grid-row: 2; border-right: 0; border-top: 1px solid var(--border); }
  .panel-right { grid-row: 3; border-left: 0; border-top: 1px solid var(--border); }
  .panel-scroll { overflow: visible; }
  .toolbar { bottom: 8px; gap: 2px; }
  .toolbar .field, #scope, .toolbar .sep { display: none; }
  .time { min-width: 0; }
}
