/* MyDawsons Studio — same night-stage palette as the classic DAW. */
:root {
  --bg: #0e0a1a;
  --panel: #1a1330;
  --panel-2: #221a40;
  --border: #3d2c66;
  --text: #f5eefe;
  --dim: #b6a4dd;
  --purple: #c264ff;
  --pink: #ff5c96;
  --cyan: #39c9ff;
  --orange: #ffab2e;
  --lime: #c8ea3f;
  --teal: #2fe0c0;
  --red: #ff4d6d;
  --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
[hidden] { display: none !important; }
body {
  background: radial-gradient(1200px 600px at 10% -10%, #2a1650 0%, transparent 60%), radial-gradient(900px 500px at 110% 0%, #3a0f3a 0%, transparent 55%), var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; color: inherit; }
kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78em; background: #2d2350; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; }
.dim { color: var(--dim); }
.hint { color: var(--dim); font-size: 0.8rem; line-height: 1.35; margin: 0.5rem 0 0; }

/* ------------------------------------------------------------ header */
.st-top {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: rgba(20, 14, 40, 0.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.st-logo { text-decoration: none; color: var(--text); display: flex; align-items: baseline; gap: 2px; font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.st-logo__my { color: var(--dim); font-weight: 600; }
.st-logo__d { background: linear-gradient(90deg, var(--purple), var(--pink), var(--orange)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.st-logo__tag { margin-left: 8px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--bg); background: var(--lime); padding: 2px 6px; border-radius: 6px; align-self: center; }
.st-transport { display: flex; align-items: center; gap: 6px; }
.tbtn { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel-2); font-size: 1.05rem; cursor: pointer; display: grid; place-items: center; transition: transform 0.06s, background 0.15s; }
.tbtn:hover { background: #2e2355; }
.tbtn:active { transform: scale(0.94); }
.tbtn--play { width: 48px; height: 48px; background: linear-gradient(135deg, var(--teal), var(--cyan)); color: #04121a; border: none; font-size: 1.2rem; }
.tbtn--play.is-on { background: linear-gradient(135deg, var(--orange), var(--pink)); }
.tbtn--rec { color: var(--red); font-size: 1.3rem; }
.tbtn--rec.is-on { background: var(--red); color: white; animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(255, 77, 109, 0.2); } }
.st-time { display: flex; flex-direction: column; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; margin-left: 6px; min-width: 76px; }
#time-main { font-size: 1.05rem; font-weight: 700; }
#time-bars { font-size: 0.75rem; color: var(--dim); }
.st-opts, .st-keysmode { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.st-keysmode span { color: var(--dim); font-size: 0.8rem; }
.st-bpm { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--dim); }
.st-bpm input { width: 58px; padding: 5px 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); font-weight: 700; }
#btn-export { margin-left: auto; }

.chip, .seg { border: 1px solid var(--border); background: var(--panel-2); border-radius: 999px; padding: 5px 11px; font-size: 0.82rem; cursor: pointer; white-space: nowrap; transition: background 0.15s, border-color 0.15s; }
.chip:hover, .seg:hover { border-color: var(--purple); }
.chip.is-on, .seg.is-on { background: var(--purple); border-color: var(--purple); color: #140a24; font-weight: 700; }
.chip--danger:hover { border-color: var(--red); }
.chip--file { display: inline-flex; align-items: center; }
.btn { border: none; border-radius: 10px; padding: 9px 14px; font-weight: 700; cursor: pointer; }
.btn--accent { background: linear-gradient(135deg, var(--purple), var(--pink)); color: white; }
.btn:disabled { opacity: 0.6; cursor: progress; }

/* --------------------------------------------------------- keyboard */
.st-keys { padding: 10px 16px 12px; border-bottom: 1px solid var(--border); background: rgba(26, 19, 48, 0.6); }
.st-keys__bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.field { display: flex; align-items: center; gap: 6px; }
select { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; max-width: 100%; }
#inst-select { min-width: 250px; font-weight: 600; }
.oct { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
.st-status { margin-left: auto; color: var(--orange); font-size: 0.8rem; }
.piano { position: relative; height: 128px; user-select: none; touch-action: none; border-radius: 10px; overflow: hidden; background: #000; box-shadow: inset 0 6px 12px rgba(0,0,0,0.6); }
.pk { position: absolute; top: 0; cursor: pointer; }
.pk--white { height: 100%; background: linear-gradient(#fdfbff, #e9e3f5); border-left: 1px solid #b9b0cc; border-radius: 0 0 6px 6px; z-index: 1; }
.pk--black { height: 62%; background: linear-gradient(#2c2440, #0c0916); border-radius: 0 0 5px 5px; z-index: 2; box-shadow: 0 2px 4px rgba(0,0,0,0.6); }
.pk--white.is-down { background: linear-gradient(#f3c9ff, var(--purple)); }
.pk--black.is-down { background: linear-gradient(#ff9ec4, var(--pink)); }
.pk__label { position: absolute; bottom: 5px; left: 0; right: 0; text-align: center; font-size: 0.65rem; color: #7a6f92; font-weight: 700; }
.pk__hint { position: absolute; bottom: 20px; left: 0; right: 0; text-align: center; font-size: 0.62rem; font-family: ui-monospace, monospace; color: #9a8bbd; opacity: 0; transition: opacity 0.2s; }
.pk--black .pk__hint { bottom: 6px; color: #d9cdf7; }
body[data-keys="piano"] .pk__hint { opacity: 1; }

/* ------------------------------------------------------------- main */
.st-main { flex: 1; display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 14px; padding: 14px 16px; align-items: stretch; }
.st-left { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.panel h2 { margin: 0; font-size: 0.95rem; }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
#kit-select { font-weight: 600; }

.pads { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; touch-action: none; }
.pad { position: relative; aspect-ratio: 1; border-radius: 10px; border: 1px solid rgba(255,255,255,0.08); cursor: pointer; user-select: none; overflow: hidden; padding: 4px; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; text-align: left; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.35), 0 2px 6px rgba(0,0,0,0.35); transition: transform 0.05s, filter 0.2s; }
.pad--row0 { background: linear-gradient(160deg, #2a3f6e, #1b2748); }
.pad--row1 { background: linear-gradient(160deg, #3c2a6e, #261a48); }
.pad--row2 { background: linear-gradient(160deg, #6e2a55, #481a36); }
.pad__name { font-size: 0.6rem; line-height: 1.1; font-weight: 700; color: rgba(255,255,255,0.85); pointer-events: none; }
.pad__key { align-self: flex-end; font-size: 0.62rem; opacity: 0.75; pointer-events: none; }
body[data-keys="piano"] .pad__key { opacity: 0.25; }
.pad:active { transform: scale(0.96); }
.pad.is-hit { animation: hit 0.28s ease-out; }
.pad--row0.is-hit { --glow: var(--cyan); }
.pad--row1.is-hit { --glow: var(--purple); }
.pad--row2.is-hit { --glow: var(--pink); }
@keyframes hit { 0% { filter: brightness(2.1); box-shadow: 0 0 18px var(--glow), inset 0 0 12px var(--glow); } 100% { filter: none; } }

.meter { height: 6px; border-radius: 3px; background: #0a0714; overflow: hidden; margin-bottom: 8px; }
#mic-level { height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--lime), var(--orange), var(--red)); transition: width 0.05s; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; margin: 6px 0 10px; }
.segs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 0.82rem; margin-top: 8px; }
.vm { border-top: 1px dashed var(--border); margin-top: 8px; padding-top: 4px; }
.vm-note { font-family: ui-monospace, monospace; font-size: 1.6rem; font-weight: 800; margin-top: 8px; color: var(--lime); min-height: 2rem; }
.teach b { color: var(--lime); }

/* ----------------------------------------------------------- arrange */
.st-arrange { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; }
.st-arrange__bar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.grow { flex: 1; }
.clip-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--panel-2); border: 1px solid var(--purple); border-radius: 10px; padding: 8px 10px; font-size: 0.82rem; }
.clip-bar label { display: inline-flex; align-items: center; gap: 5px; }
.clip-bar input[type="range"] { width: 90px; }
.clip-bar output { font-family: ui-monospace, monospace; min-width: 44px; }
.clip-bar .cb-audio, .clip-bar .cb-notes { display: none; align-items: center; gap: 8px; flex-wrap: wrap; }
.clip-bar.is-audio .cb-audio, .clip-bar.is-notes .cb-notes { display: inline-flex; }
#cb-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.timeline { position: relative; flex: 1; min-height: 340px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.timeline.is-drop { outline: 2px dashed var(--lime); outline-offset: -4px; }
.tl-scroll { position: absolute; inset: 0; overflow: auto; }
.tl-inner { position: relative; min-height: 100%; }
.tl-ruler { position: sticky; top: 0; height: 26px; background: #140f28; border-bottom: 1px solid var(--border); z-index: 5; cursor: pointer; }
.tl-ruler__pad { position: sticky; left: 0; height: 100%; background: #140f28; display: flex; align-items: center; padding-left: 10px; font-size: 0.7rem; color: var(--dim); z-index: 2; border-right: 1px solid var(--border); }
.tl-bar { position: absolute; top: 0; height: 100%; border-left: 1px solid #4a3a7a; padding-left: 4px; font-size: 0.7rem; color: var(--dim); display: flex; align-items: center; }
.tl-rows { position: relative; }
.tl-row { display: flex; height: 76px; border-bottom: 1px solid #2a2048; }
.tl-row.is-selected .tl-head { background: #2b2152; box-shadow: inset 3px 0 0 var(--track-color); }
.tl-row.is-target .tl-lane { background-color: rgba(200, 234, 63, 0.08); }
.tl-head { position: sticky; left: 0; z-index: 3; flex: none; background: #1d1636; border-right: 1px solid var(--border); padding: 6px 8px; display: flex; flex-direction: column; gap: 3px; box-shadow: inset 3px 0 0 var(--track-color); cursor: pointer; }
.tl-head__top { display: flex; align-items: center; gap: 6px; }
.tl-head__name { font-weight: 700; font-size: 0.85rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-head__sub { font-size: 0.68rem; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-head__ctrls { display: flex; align-items: center; gap: 4px; }
.tl-head__ctrls input[type="range"] { width: 58px; height: 14px; accent-color: var(--track-color); }
.tl-head__ctrls input.tl-pan { width: 38px; }
.tl-btn { width: 22px; height: 20px; border-radius: 5px; border: 1px solid var(--border); background: var(--panel-2); font-size: 0.68rem; font-weight: 800; cursor: pointer; padding: 0; }
.tl-btn.is-on { background: var(--orange); color: #1a1000; border-color: var(--orange); }
.tl-btn--solo.is-on { background: var(--lime); border-color: var(--lime); }
.tl-btn--x { border: none; background: none; color: var(--dim); font-size: 1rem; }
.tl-btn--x:hover { color: var(--red); }
.tl-lane { position: relative; flex: none; background-image: repeating-linear-gradient(90deg, rgba(255,255,255,0.07) 0 1px, transparent 1px var(--bar-px)), repeating-linear-gradient(90deg, rgba(255,255,255,0.025) 0 1px, transparent 1px var(--beat-px)); }
.clip { position: absolute; top: 5px; height: 66px; border-radius: 8px; background: color-mix(in srgb, var(--track-color) 55%, #1a1330); border: 1px solid color-mix(in srgb, var(--track-color) 80%, white 10%); cursor: grab; overflow: hidden; touch-action: none; }
.clip:active { cursor: grabbing; }
.clip.is-selected { outline: 2px solid white; outline-offset: 1px; z-index: 2; }
.clip.is-busy { opacity: 0.6; background-image: repeating-linear-gradient(45deg, transparent 0 8px, rgba(255,255,255,0.08) 8px 16px); }
.clip canvas { position: absolute; left: 0; top: 0; pointer-events: none; }
.clip__label { position: absolute; left: 6px; top: 3px; right: 6px; font-size: 0.68rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; text-shadow: 0 1px 2px rgba(0,0,0,0.7); }
.clip__label em { font-style: normal; color: var(--lime); font-weight: 800; margin-left: 4px; }
.clip__h { position: absolute; top: 0; bottom: 0; width: 9px; cursor: ew-resize; z-index: 2; }
.clip__h--l { left: 0; }
.clip__h--r { right: 0; }
.clip__h:hover, .clip.is-selected .clip__h { background: rgba(255,255,255,0.18); }
.tl-playhead { position: absolute; top: 0; left: 0; width: 2px; background: var(--lime); box-shadow: 0 0 8px var(--lime); pointer-events: none; z-index: 6; }
.tl-playhead.is-rec { background: var(--red); box-shadow: 0 0 8px var(--red); }
.tl-empty { position: absolute; inset: 26px 0 0 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; color: var(--dim); gap: 8px; pointer-events: none; }
.tl-empty > * { pointer-events: auto; }
.tl-empty .rec { color: var(--red); }
.tl-empty[hidden] { display: none; }

.loop-lib { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; max-height: 280px; overflow: auto; }
.loop-lib__head { display: flex; justify-content: space-between; align-items: center; }
.loop-lib h3 { margin: 0; font-size: 0.9rem; }
.loop-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 8px; }
.loop-cat h4 { margin: 4px 0 6px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); }
.loop-item { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 8px; background: var(--panel-2); margin-bottom: 4px; cursor: grab; font-size: 0.82rem; }
.loop-item span { flex: 1; }
.loop-item .chip { padding: 2px 8px; }

.st-foot { display: flex; gap: 16px; flex-wrap: wrap; padding: 8px 16px 14px; font-size: 0.75rem; color: var(--dim); }
.st-foot a { color: var(--cyan); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #2b2152; border: 1px solid var(--purple); padding: 10px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,0.5); font-size: 0.9rem; max-width: 90vw; }
.toast[hidden] { display: none; }
body.is-recording .st-top { box-shadow: inset 0 -2px 0 var(--red); }

/* ------------------------------------------------------------ mobile */
@media (max-width: 900px) {
  .st-top { position: static; }
  .st-main { grid-template-columns: 1fr; }
  .st-left { order: 1; }
  .st-arrange { order: 2; }
  .timeline { min-height: 320px; }
  #btn-export { margin-left: 0; }
  .st-keysmode span { display: none; }
  .piano { height: 110px; }
  #inst-select { min-width: 0; width: 100%; }
  .field { flex: 1 1 100%; }
}
@media (max-width: 520px) {
  .st-top { gap: 8px; padding: 8px 10px; }
  .st-opts .chip { padding: 4px 8px; font-size: 0.75rem; }
  .st-main { padding: 10px; }
  .pads { gap: 5px; }
}
