/* ============================================================
   MIDI Studio – Dark Theme
   ============================================================ */
:root {
  --bg: #0b0e17;
  --card: rgba(255, 255, 255, .045);
  --card-strong: rgba(255, 255, 255, .07);
  --border: rgba(255, 255, 255, .09);
  --text: #e8ecf6;
  --muted: #8b93a8;
  --accent: #22d3ee;
  --accent2: #818cf8;
  --danger: #fb3b5c;
  --ok: #34d399;
  --warn: #fbbf24;
}

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

html, body { height: 100%; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 600px at 85% -10%, rgba(129, 140, 248, .16), transparent 60%),
    radial-gradient(900px 550px at -10% 110%, rgba(34, 211, 238, .13), transparent 60%),
    var(--bg);
  min-height: 100vh;
}

.app {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo { font-size: 34px; filter: drop-shadow(0 4px 14px rgba(34, 211, 238, .35)); }
.brand h1 {
  font-size: 21px;
  letter-spacing: .4px;
  background: linear-gradient(90deg, #7dd3fc, #a5b4fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.header-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.status-pill:hover { border-color: rgba(255, 255, 255, .25); background: var(--card-strong); }
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: #5a6275; transition: background .2s, box-shadow .2s; }
.status-pill.ok .dot { background: var(--ok); box-shadow: 0 0 10px rgba(52, 211, 153, .8); }
.status-pill.none .dot { background: var(--warn); box-shadow: 0 0 10px rgba(251, 191, 36, .7); }
.status-pill.error .dot, .status-pill.unsupported .dot { background: var(--danger); box-shadow: 0 0 10px rgba(251, 59, 92, .8); }

/* ---------- Form elements ---------- */
.sel { display: inline-flex; flex-direction: column; gap: 3px; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.sel select {
  background: #151a2b;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  max-width: 190px;
  outline: none;
  cursor: pointer;
}
.sel select:focus { border-color: rgba(34, 211, 238, .5); }
.sel.small { flex-direction: row; align-items: center; text-transform: none; letter-spacing: 0; font-size: 12.5px; color: var(--text); gap: 6px; }
.sel.small select { padding: 4px 6px; font-size: 12.5px; }
.sel.echo-prog select { max-width: 160px; }

.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; padding: 6px 4px; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.bpm-box { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
.bpm-box input {
  width: 64px;
  background: #151a2b;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  outline: none;
}
.bpm-box input:focus { border-color: rgba(34, 211, 238, .5); }

.speed-box { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.speed-box input[type="range"] {
  width: 110px;
  accent-color: var(--accent);
  cursor: pointer;
}
.speed-box .speed-val {
  min-width: 52px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(34, 211, 238, .4);
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  background: var(--card);
  transition: transform .08s, box-shadow .15s, background .15s;
}
.btn:hover:not(:disabled) { background: var(--card-strong); transform: translateY(-1px); }
.btn:disabled { opacity: .38; cursor: not-allowed; }
.btn-download {
  background: linear-gradient(135deg, #22d3ee, #818cf8);
  color: #0a0e1a;
  border: none;
  box-shadow: 0 6px 20px rgba(34, 211, 238, .25);
}
.btn-download:hover:not(:disabled) { box-shadow: 0 8px 26px rgba(34, 211, 238, .4); }

.btn-upload { border-color: rgba(129, 140, 248, .45); color: #dbe4ff; }
.btn-upload:hover:not(:disabled) { border-color: rgba(129, 140, 248, .85); background: rgba(129, 140, 248, .13); }

.mini {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.mini.active { color: var(--text); border-color: rgba(34, 211, 238, .55); background: rgba(34, 211, 238, .12); box-shadow: 0 0 14px rgba(34, 211, 238, .18); }
.mini:hover { border-color: rgba(255, 255, 255, .25); }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(8px);
}

/* ---------- Transport ---------- */
.transport {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 16px;
}
.transport-buttons { display: flex; gap: 8px; }
.tbtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 82px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .12s;
}
.tbtn .icon { font-size: 17px; line-height: 1; }
.tbtn:hover:not(:disabled) { background: var(--card-strong); transform: translateY(-1px); }
.tbtn:disabled { opacity: .35; cursor: not-allowed; }
.tbtn.rec { border-color: rgba(251, 59, 92, .45); }
.tbtn.rec .icon { color: var(--danger); }
.tbtn.rec.recording { background: rgba(251, 59, 92, .16); border-color: var(--danger); animation: recPulse 1.2s ease-out infinite; }
.tbtn.rec.recording .lbl { color: #ff8fa3; }
@keyframes recPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251, 59, 92, .4); }
  50% { box-shadow: 0 0 0 9px rgba(251, 59, 92, 0); }
}
.tbtn.play .icon { color: var(--ok); }

.transport-options { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.sustain {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  transition: all .2s;
}
.sustain .pedal { width: 12px; height: 12px; border-radius: 50%; background: #3a4154; border: 1px solid #4a5268; transition: all .2s; }
.sustain.on { color: var(--text); border-color: rgba(251, 191, 36, .5); background: rgba(251, 191, 36, .08); }
.sustain.on .pedal { background: var(--warn); box-shadow: 0 0 12px rgba(251, 191, 36, .9); }

.transport-stats { display: flex; align-items: center; gap: 16px; }
.time {
  font-variant-numeric: tabular-nums;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #dbeafe;
  min-width: 108px;
  text-align: right;
}
.note-indicator {
  min-width: 56px;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 0 16px rgba(34, 211, 238, .55);
}
.note-indicator.flash { animation: pop .18s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.28); } 100% { transform: scale(1); } }
.stat { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ---------- Stage: waterfall + piano ---------- */
.stage {
  position: relative;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#waterfall {
  width: 100%;
  height: 340px;
  display: block;
  border-radius: 10px 10px 0 0;
  cursor: crosshair;
}

#stage-hint {
  position: absolute;
  inset: 10px 10px calc(10px + 130px + 10px) 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  pointer-events: none;
  z-index: 5;
}
#stage-hint .hint-icon { font-size: 44px; animation: floaty 2.6s ease-in-out infinite; }
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
#stage-hint .hint-title { font-size: 17px; font-weight: 700; }
#stage-hint .hint-sub { font-size: 13px; color: var(--muted); max-width: 520px; line-height: 1.5; }

/* ---------- Piano ---------- */
.piano {
  position: relative;
  height: 130px;
  display: flex;
  border-radius: 0 0 10px 10px;
  overflow: hidden;
  background: #0d1119;
  box-shadow: 0 18px 34px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .18);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.key { cursor: pointer; }

.key.white {
  flex: 1;
  height: 100%;
  position: relative;
  background: linear-gradient(180deg, #fdfdfe 0%, #f1f3f8 82%, #e2e6ee 100%);
  border-right: 1px solid #c3c9d6;
  border-bottom: 4px solid #d5dae4;
  transition: background .05s, box-shadow .05s;
}
.key.white .key-label {
  position: absolute;
  bottom: 7px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-weight: 700;
  color: #9aa3b5;
  pointer-events: none;
  transition: color .05s;
}
.key.white.pressed {
  background: linear-gradient(180deg, #c9f2ff 0%, #8fd9f7 100%);
  box-shadow: inset 0 -3px 0 rgba(0, 150, 200, .4), 0 0 22px rgba(34, 211, 238, var(--vel, .4));
}
.key.white.pressed .key-label { color: #0b7fa8; }

.key.black {
  position: absolute;
  top: 0;
  height: 61%;
  z-index: 2;
  background: linear-gradient(180deg, #3a4150 0%, #171b23 88%, #0c0f15 100%);
  border: 1px solid #05070c;
  border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 6px 10px rgba(0, 0, 0, .55), inset 0 -3px 5px rgba(0, 0, 0, .4);
  transition: background .05s, box-shadow .05s;
}
.key.black.pressed {
  background: linear-gradient(180deg, #1e3a4d 0%, #0e2533 100%);
  box-shadow: 0 0 20px rgba(34, 211, 238, var(--vel, .5)), inset 0 -2px 4px rgba(0, 0, 0, .5);
}

/* ---------- Footer ---------- */
.hints {
  display: flex;
  gap: 8px 20px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 12.5px;
  color: var(--muted);
  padding: 2px 6px;
}
.hints kbd {
  background: #151a2b;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: #c7d2e4;
}

/* ---------- Drop-Overlay (Drag & Drop) ---------- */
#drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(8, 11, 20, .72);
  backdrop-filter: blur(4px);
}
#drop-overlay.show { display: flex; }
#drop-overlay .drop-box {
  border: 2px dashed rgba(34, 211, 238, .6);
  border-radius: 20px;
  padding: 48px 64px;
  font-size: 20px;
  font-weight: 700;
  color: #d9f7ff;
  background: rgba(34, 211, 238, .08);
  box-shadow: 0 0 60px rgba(34, 211, 238, .25);
  animation: floaty 2.6s ease-in-out infinite;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(16px);
  background: rgba(16, 21, 36, .92);
  border: 1px solid rgba(34, 211, 238, .35);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 50;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  .transport { justify-content: center; }
  .transport-stats { order: -1; width: 100%; justify-content: center; }
  #waterfall { height: 260px; }
  .piano { height: 100px; }
  #stage-hint { inset: 10px 10px calc(10px + 100px + 10px) 10px; }
}
