/* Scribble Synth — dark studio, paper-and-ink accents */

:root {
  --bg: #0c0d12;
  --bg-2: #11131b;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-2: rgba(255, 255, 255, 0.075);
  --line: rgba(255, 255, 255, 0.10);
  --line-2: rgba(255, 255, 255, 0.18);
  --fg: #eef0f6;
  --dim: #9aa2b4;
  --dimmer: #6a7285;
  --accent: #59e7c9;
  --accent-2: #ffd166;
  --hot: #ff6b8f;
  --r: 12px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --fast: 140ms cubic-bezier(.2,.8,.3,1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body, #app { height: 100%; }

body {
  background:
    radial-gradient(1200px 700px at 12% -10%, #1b2030 0%, transparent 60%),
    radial-gradient(900px 600px at 100% 110%, #1a1626 0%, transparent 55%),
    var(--bg);
  color: var(--fg);
  font: 14px/1.45 ui-sans-serif, -apple-system, "SF Pro Text", Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  touch-action: manipulation;
}

#app { display: flex; flex-direction: column; }

/* ------------------------------------------------------------- top bar -- */

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.015));
  backdrop-filter: blur(12px);
  flex: 0 0 auto;
}

.brand { display: flex; align-items: baseline; gap: 9px; user-select: none; }
.brand .mark {
  font-size: 22px; color: var(--accent);
  transform: translateY(2px);
  animation: wiggle 6s ease-in-out infinite;
}
@keyframes wiggle { 0%,100% { transform: translateY(2px) rotate(-6deg); } 50% { transform: translateY(0) rotate(8deg); } }
.brand .name { font-size: 15px; letter-spacing: .16em; text-transform: uppercase; color: var(--dim); }
.brand .name b { color: var(--fg); font-weight: 700; }

.modes { display: flex; gap: 4px; padding: 3px; background: var(--panel); border-radius: 999px; border: 1px solid var(--line); }
.mode {
  border: 0; background: transparent; color: var(--dim);
  padding: 7px 15px; border-radius: 999px; cursor: pointer;
  font: inherit; font-size: 13px; letter-spacing: .02em;
  transition: var(--fast);
}
.mode:hover { color: var(--fg); }
.mode.is-on { background: var(--fg); color: #0d0f16; font-weight: 600; }

.transport { display: flex; gap: 6px; }

.btn {
  border: 1px solid var(--line-2); background: var(--panel);
  color: var(--fg); font: inherit; cursor: pointer;
  padding: 8px 14px; border-radius: 10px;
  transition: var(--fast);
}
.btn:hover { background: var(--panel-2); border-color: rgba(255,255,255,.3); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--accent); color: #06231d; border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { padding: 8px 11px; color: var(--dim); }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.play { min-width: 52px; text-align: center; }
.btn.play.is-on { background: var(--accent); color: #06231d; border-color: transparent; }
.btn.rec.is-on { background: var(--hot); color: #23050f; border-color: transparent; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.musical { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.field { display: flex; flex-direction: column; gap: 2px; }
.field > span { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--dimmer); }
.field input, .field select {
  background: var(--panel); border: 1px solid var(--line); color: var(--fg);
  border-radius: 8px; padding: 5px 8px; font: inherit; font-size: 13px;
  outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field.tempo input { width: 64px; }
.field.wide select { width: 132px; }
.field.slider input { width: 84px; }

/* --------------------------------------------------------------- main -- */

main { flex: 1 1 auto; display: flex; min-height: 0; }

.stage {
  position: relative; flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
#canvas { display: block; touch-action: none; cursor: crosshair; }
#canvas.drawing { cursor: crosshair; }
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: none; }
#video.is-on { display: block; }

/* empty state */
.drop {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: radial-gradient(600px 400px at 50% 40%, rgba(89,231,201,.07), transparent 70%);
  text-align: center; padding: 24px;
}
.drop.hide { display: none; }
.drop.over .drop-inner { border-color: var(--accent); background: rgba(89,231,201,.07); }
.drop-inner {
  border: 1.5px dashed var(--line-2); border-radius: 22px;
  padding: 40px 46px; max-width: 520px;
  transition: var(--fast);
}
.drop .big { font-size: 34px; letter-spacing: .22em; color: var(--accent); opacity: .85; margin-bottom: 14px; }
.drop h1 { font-size: 24px; font-weight: 650; letter-spacing: -.01em; margin-bottom: 8px; }
.drop p { color: var(--dim); margin-bottom: 22px; }
.drop-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* floating stage tools */
.stage-tools {
  position: absolute; left: 14px; right: 14px; bottom: 14px;
  display: flex; gap: 6px; align-items: center;
  pointer-events: none;
}
.stage-tools > * { pointer-events: auto; }
.stage-tools .spacer { flex: 1 1 auto; }
.chip {
  border: 1px solid var(--line); background: rgba(14,16,22,.78);
  backdrop-filter: blur(10px);
  color: var(--dim); font: inherit; font-size: 12px;
  padding: 7px 12px; border-radius: 999px; cursor: pointer;
  transition: var(--fast);
}
.chip:hover { color: var(--fg); border-color: var(--line-2); }
.chip.is-on { background: var(--accent); color: #06231d; border-color: transparent; font-weight: 600; }
.chip.switch { display: inline-flex; align-items: center; gap: 6px; }
.chip.switch input { accent-color: var(--accent); }

.toast {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(14,16,22,.9); border: 1px solid var(--line-2);
  padding: 9px 16px; border-radius: 999px; font-size: 13px;
  backdrop-filter: blur(10px); box-shadow: var(--shadow);
  animation: drop-in 240ms cubic-bezier(.2,.9,.3,1.2);
}
@keyframes drop-in { from { opacity: 0; transform: translate(-50%,-12px); } }

.busy {
  position: absolute; inset: 0; display: grid; place-items: center; gap: 12px;
  grid-auto-flow: row; background: rgba(8,9,13,.55); backdrop-filter: blur(3px);
  color: var(--dim); font-size: 13px; z-index: 5;
}
.busy .spin {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.14); border-top-color: var(--accent);
  animation: spin .8s linear infinite; justify-self: center;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* -------------------------------------------------------------- panel -- */

.panel {
  flex: 0 0 336px; display: flex; flex-direction: column;
  border-left: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.012));
  backdrop-filter: blur(12px);
  min-height: 0;
}
.panel-tabs { display: flex; padding: 10px 10px 0; gap: 4px; }
.ptab {
  flex: 1; border: 0; background: transparent; color: var(--dimmer);
  font: inherit; font-size: 12px; letter-spacing: .1em; text-transform: uppercase;
  padding: 9px 4px; border-radius: 9px; cursor: pointer; transition: var(--fast);
}
.ptab:hover { color: var(--fg); }
.ptab.is-on { background: var(--panel-2); color: var(--fg); }
.panel-body { flex: 1 1 auto; overflow-y: auto; padding: 12px; min-height: 0; }
.panel-body::-webkit-scrollbar { width: 9px; }
.panel-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 9px; border: 3px solid transparent; background-clip: content-box; }

.tabpane { display: none; }
.tabpane.is-on { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  color: var(--dimmer); font-size: 12px; margin: 2px 2px 10px;
}
.mini-actions { display: flex; gap: 5px; }

.group { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 10px; background: rgba(255,255,255,.02); }
.group-title { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--dimmer); margin-bottom: 10px; }
.row.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.row.btns .btn { padding: 8px 6px; font-size: 13px; }

.ctl { display: grid; grid-template-columns: 74px 1fr 34px; align-items: center; gap: 8px; margin-bottom: 9px; font-size: 12px; color: var(--dim); }
.ctl:last-child { margin-bottom: 0; }
.ctl b { font-weight: 500; font-variant-numeric: tabular-nums; color: var(--dimmer); font-size: 11px; text-align: right; }
.ctl select { grid-column: 2 / span 2; background: var(--panel); border: 1px solid var(--line); color: var(--fg); border-radius: 8px; padding: 5px 8px; font: inherit; font-size: 12px; }
.ctl.check { grid-template-columns: 1fr auto; }
.ctl.check input { accent-color: var(--accent); width: 16px; height: 16px; }

input[type=range] {
  -webkit-appearance: none; appearance: none; height: 3px; border-radius: 3px;
  background: rgba(255,255,255,.16); outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--fg); cursor: pointer; transition: var(--fast);
  box-shadow: 0 0 0 0 rgba(89,231,201,.35);
}
input[type=range]::-webkit-slider-thumb:hover { background: var(--accent); box-shadow: 0 0 0 6px rgba(89,231,201,.16); }

/* ------------------------------------------------------------- voices -- */

.voices { display: flex; flex-direction: column; gap: 8px; }

.voice {
  border: 1px solid var(--line); border-radius: var(--r);
  background: rgba(255,255,255,.022);
  padding: 10px 11px; cursor: pointer;
  transition: var(--fast);
  position: relative; overflow: hidden;
}
.voice::after {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--vc, var(--accent)); opacity: .55; transition: var(--fast);
}
.voice:hover { background: rgba(255,255,255,.05); }
.voice.is-sel { border-color: var(--vc); background: rgba(255,255,255,.06); }
.voice.is-live::after { opacity: 1; box-shadow: 0 0 14px var(--vc); }
.voice.is-off { opacity: .42; }

.voice-top { display: flex; align-items: center; gap: 8px; }
.voice-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--vc); flex: 0 0 auto; transition: transform 90ms ease; }
.voice.is-live .voice-dot { transform: scale(1.5); box-shadow: 0 0 10px var(--vc); }
.voice-name { font-size: 13px; font-weight: 600; }
.voice-sub { font-size: 11px; color: var(--dimmer); margin-left: auto; letter-spacing: .04em; }

.voice-row { display: flex; align-items: center; gap: 6px; margin-top: 9px; }
.voice-row select {
  background: rgba(255,255,255,.05); border: 1px solid var(--line); color: var(--fg);
  border-radius: 7px; padding: 4px 6px; font: inherit; font-size: 11px; flex: 0 0 78px;
}
.voice-row input[type=range] { flex: 1 1 auto; min-width: 0; }
.mini {
  border: 1px solid var(--line); background: transparent; color: var(--dimmer);
  border-radius: 7px; font: inherit; font-size: 11px; padding: 4px 7px; cursor: pointer;
  transition: var(--fast); min-width: 26px;
}
.mini:hover { color: var(--fg); border-color: var(--line-2); }
.mini.on { background: var(--accent-2); color: #241c00; border-color: transparent; font-weight: 700; }
.mini.on.mute { background: var(--hot); color: #2a0611; }
.mini.on.latch { background: var(--accent); color: #06231d; }
.mini.v-del { margin-left: auto; }
.mini.v-del:hover { background: var(--hot); color: #2a0611; border-color: transparent; }

.empty-note { color: var(--dimmer); font-size: 13px; text-align: center; padding: 30px 10px; line-height: 1.6; }

/* -------------------------------------------------------------- hints -- */

.hints {
  flex: 0 0 auto; display: flex; gap: 18px; align-items: center;
  padding: 7px 16px; border-top: 1px solid var(--line);
  color: var(--dimmer); font-size: 11.5px;
  background: rgba(0,0,0,.2);
}
.hints span { display: inline-flex; align-items: center; gap: 5px; }
.hints #modeHint { margin-left: auto; color: var(--dim); font-style: italic; }
kbd {
  background: var(--panel-2); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 5px; font: inherit; font-size: 10.5px; color: var(--dim);
}

/* the drag grip only exists on the mobile sheet */
.grip { display: none; }

@media (max-width: 980px) {
  .musical .field.slider, .hints span:not(#modeHint) { display: none; }
  .panel { flex-basis: 290px; }
}

/* --------------------------------------------------------------- phone -- */

@media (max-width: 760px) {
  main { flex-direction: column; }

  /* one compact header row: mark · modes · transport */
  .topbar {
    gap: 8px;
    padding: 8px 10px;
    padding-top: max(8px, env(safe-area-inset-top));
  }
  .brand .name { display: none; }
  .brand .mark { font-size: 20px; }
  .modes { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .modes::-webkit-scrollbar { display: none; }
  /* size each tab to its own word: equal widths cut "Timeline" out of its pill */
  .mode { flex: 0 1 auto; padding: 9px 10px; font-size: 12.5px; white-space: nowrap; }
  .transport { flex: 0 0 auto; }
  .btn { padding: 9px 12px; }
  .btn.play { min-width: 46px; }
  .musical { display: none; }              /* moved into the Sound tab */
  #musicalHome .musical {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%;
  }
  #musicalHome .field.wide, #musicalHome .field.slider { grid-column: 1 / -1; }
  #musicalHome .field.slider { display: flex; }   /* master volume belongs here now */
  #musicalHome .field.wide select, #musicalHome .field.slider input,
  #musicalHome .field.tempo input { width: 100%; }
  #musicalHome .field input, #musicalHome .field select { padding: 9px 10px; font-size: 15px; }

  .stage { flex: 1 1 auto; min-height: 0; }   /* the sheet may take the room */
  .stage-tools { left: 8px; right: 8px; bottom: 8px; overflow-x: auto; scrollbar-width: none; }
  .stage-tools::-webkit-scrollbar { display: none; }
  .chip { padding: 9px 14px; font-size: 12.5px; white-space: nowrap; }

  /* the panel is a sheet you can pull open */
  .panel {
    flex: 0 0 auto; height: 42vh;
    border-left: 0; border-top: 1px solid var(--line-2);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -12px 30px rgba(0,0,0,.35);
    transition: height 220ms cubic-bezier(.2,.8,.3,1);
  }
  .panel.tall { height: 78vh; }
  .panel.short { height: 72px; }        /* pushed down: grip + tabs, nothing else */
  .grip {
    display: block; border: 0; background: transparent;
    width: 100%; padding: 12px 0 6px; cursor: grab;
    touch-action: none;                 /* the drag resizes the sheet, not the page */
  }
  .grip:active { cursor: grabbing; }
  .grip span { width: 44px; height: 5px; }
  .grip span {
    display: block; width: 40px; height: 4px; margin: 0 auto;
    background: var(--line-2); border-radius: 4px; transition: var(--fast);
  }
  .grip:hover span, .panel.tall .grip span { background: var(--dim); }
  .panel-tabs { padding: 4px 10px 0; }
  .ptab { padding: 11px 4px; }
  .panel-body { padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); }

  /* thumb-sized controls */
  .mini { padding: 9px 11px; font-size: 12px; min-width: 40px; }
  .voice { padding: 12px; }
  .voice-row { gap: 8px; flex-wrap: wrap; }
  .voice-row select { flex: 0 0 92px; padding: 8px; font-size: 12.5px; }
  .voice-row input[type=range] { flex: 1 1 90px; height: 4px; }
  input[type=range]::-webkit-slider-thumb { width: 20px; height: 20px; }
  .ctl { grid-template-columns: 82px 1fr 34px; margin-bottom: 14px; }
  .ctl select { padding: 9px 10px; font-size: 13px; }
  .row.btns .btn { padding: 12px 6px; }

  .hints {
    padding: 6px 12px calc(6px + env(safe-area-inset-bottom));
    justify-content: center;
  }
  .hints #modeHint { margin-left: 0; text-align: center; font-size: 11px; }
  .drop { overflow-y: auto; padding: 12px; align-items: start; }
  .drop-inner { padding: 24px 18px; margin: auto 0; }
  .drop h1 { font-size: 20px; }
  .drop .big { font-size: 26px; }
  .drop-actions .btn { width: 100%; }
}

@media (max-width: 400px) {
  .topbar { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .mode { padding: 9px 8px; font-size: 12px; }
  #panic { display: none; }
  .btn { padding: 9px 10px; }

  /* keep a voice's controls on their own two rows instead of one each */
  .voice { padding: 10px; }
  .voice-row { gap: 6px; }
  .voice-row select { flex: 0 0 76px; font-size: 11.5px; padding: 7px 6px; }
  .voice-row input[type=range] { flex: 1 1 56px; }
  .mini { min-width: 34px; padding: 8px 7px; font-size: 11.5px; }
  .ctl { grid-template-columns: 72px 1fr 30px; }
}

@media (max-width: 760px) and (orientation: landscape) {
  main { flex-direction: row; }
  .panel { height: auto; flex: 0 0 44%; border-radius: 0; border-left: 1px solid var(--line); }
  .panel.tall { height: auto; }
  .grip { display: none; }
  .hints { display: none; }
}
