  :root {
      --bg-dark: #0f1117;
      --panel-bg: #181b24;
      --accent-purple: #9333ea;
      --accent-green: #10b981;
      --accent-amber: #f59e0b;
      --accent-blue: #3b82f6;
      --accent-red: #ef4444;
      --border-color: #2e3447;
      --text-main: #f3f4f6;
      --text-muted: #9ca3af;
  }

  * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      font-family: 'Segoe UI', system-ui, sans-serif;
  }

  body {
      background: var(--bg-dark);
      color: var(--text-main);
      padding: 10px;
  }

  .top-bar {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      background: var(--panel-bg);
      padding: 12px;
      border-radius: 8px;
      border: 1px solid var(--border-color);
      margin-bottom: 10px;
      align-items: center;
      justify-content: space-between;
  }

  .control-group {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      align-items: center;
  }

  .input-dark {
      padding: 6px 10px;
      background: #0f1117;
      border: 1px solid var(--border-color);
      border-radius: 6px;
      color: #fff;
      font-size: 13px;
      text-align: center;
  }

  .input-dark:disabled {
      opacity: 0.4;
      cursor: not-allowed;
  }

  .btn {
      padding: 8px 12px;
      border: none;
      border-radius: 6px;
      font-weight: bold;
      cursor: pointer;
      color: white;
      font-size: 12px;
      min-height: 38px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 4px;
      transition: background-color 0.2s;
  }

  .btn-purple {
      background: var(--accent-purple);
  }

  .btn-green {
      background: var(--accent-green);
  }

  .btn-blue {
      background: var(--accent-blue);
  }

  .btn-amber {
      background: var(--accent-amber);
  }

  .btn-red {
      background: var(--accent-red);
  }

  .grid-container {
      overflow: auto;
      background: var(--panel-bg);
      border: 1px solid var(--border-color);
      border-radius: 8px;
      padding: 10px;
      margin-bottom: 10px;
      max-height: 600px;
  }

  table {
      border-collapse: collapse;
      width: 100%;
      min-width: max-content;
      table-layout: auto;
  }

  th,
  td {
      border: 1px solid var(--border-color);
      padding: 0;
      text-align: center;
      vertical-align: stretch;
      height: 55px;
      min-width: 30px;
  }

  .piece-header-cell {
      min-width: 170px;
      width: 170px;
      position: sticky;
      left: 0;
      z-index: 10;
      background: #0f1117;
  }

  .step-header-cell {
      min-width: 40px;
      width: 40px;
  }

  .piece-cell {
      cursor: pointer;
      background: #131620;
      text-align: left;
      padding: 6px;
      user-select: none;
      border-right: 2px solid var(--border-color);
      width: 170px !important;
      min-width: 170px !important;
      max-width: 170px !important;
      position: sticky;
      left: 0;
      z-index: 5;
  }

  .step-cell {
      width: 100%;
      height: 100%;
      background: #0f1117;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      padding: 4px;
      position: relative;
      user-select: none;
      touch-action: none;
      min-width: 30px;
  }

  th {
      font-size: 11px;
      color: var(--text-muted);
      background: #0f1117;
      height: 28px;
  }

  th.bar-start {
      background: var(--accent-purple) !important;
      color: #ffffff !important;
      font-weight: bold;
      font-size: 13px;
  }

  th.beat-marker {
      background: #1a1e2d;
      color: var(--accent-blue);
  }

  .piece-cell {
      cursor: pointer;
      background: #131620;
      text-align: left;
      padding: 6px;
      user-select: none;
      border-right: 2px solid var(--border-color);
      width: 170px !important;
      min-width: 170px !important;
      max-width: 170px !important;
  }

  .piece-cell:hover {
      background: #1e2330;
  }

  .piece-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 6px;
      height: 100%;
  }

  .step-cell {
      width: 100%;
      height: 100%;
      background: #0f1117;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-between;
      padding: 4px;
      position: relative;
      user-select: none;
      touch-action: none;
  }

  .step-cell.bar-start-cell {
      border-left: 3px solid var(--accent-purple) !important;
      background: #12101d;
  }

  .step-cell.beat-marker-cell {
      background: #141722;
      border-left: 1px solid var(--border-color);
  }

  .step-cell.active {
      background: #1e3a8a;
      border: 1px solid var(--accent-blue);
  }

  .step-cell.playing {
      border: 2px solid var(--accent-amber) !important;
      box-shadow: inset 0 0 8px var(--accent-amber);
  }

  .dur-tag {
      font-size: 10px;
      color: #a5b4fc;
      font-weight: bold;
      pointer-events: none;
  }

  .vel-slider {
      -webkit-appearance: none;
      appearance: none;
      width: 95%;
      height: 14px;
      border-radius: 7px;
      background: rgba(255, 255, 255, 0.2);
      outline: none;
      margin-top: auto;
      margin-bottom: 2px;
      cursor: pointer;
  }

  .vel-slider::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background: var(--accent-green);
      cursor: pointer;
      box-shadow: 0 0 4px rgba(0, 0, 0, 0.5);
  }


  /* =========================================================
   VELOCITY EDITOR (alinhado com o grid)
   ========================================================= */

  .velocity-editor {
      background: var(--panel-bg);
      border: 1px solid var(--border-color);
      border-radius: 8px;
      padding: 10px;
      margin-bottom: 10px;
      display: none;
  }

  .velocity-editor.visible {
      display: block;
  }

  .velocity-editor-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 8px;
  }

  .velocity-bars-container {
      overflow-x: auto;
  }

.velocity-bars-table {
    border-collapse: collapse;
    width: 100%;
    min-width: max-content;
    table-layout: auto;
}

  .velocity-bars-table colgroup col:first-child {
      width: 170px !important;
      min-width: 170px !important;
      max-width: 170px !important;
  }

 .velocity-bars-table td {
    border: 1px solid var(--border-color);
    padding: 0;
    text-align: center;
    vertical-align: bottom;
    height: 120px;
    position: relative;
    min-width: 30px;
}

.velocity-bars-table td.velocity-label-cell {
    background: #131620;
    text-align: left;
    padding: 6px;
    font-size: 10px;
    color: var(--accent-blue);
    font-weight: bold;
    vertical-align: middle;
    min-width: 170px;
    width: 170px;
    position: sticky;
    left: 0;
    z-index: 5;
}


  .velocity-bar {
      width: 100%;
      cursor: pointer;
      border-radius: 2px 2px 0 0;
      transition: background-color 0.1s;
      margin: 0 auto;
      position: relative;
      display: flex;
      align-items: flex-start;
      justify-content: center;
      min-height: 4px;
  }

  .velocity-value-label {
      position: absolute;
      top: 2px;
      font-size: 12px;
      color: #fff;
      font-weight: bold;
      pointer-events: none;
      text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  }

  .velocity-bar.active {
      background: var(--accent-blue);
  }

  .velocity-bar.inactive {
      background: #1a1e2d;
  }

  .velocity-bar:hover {
      opacity: 0.7;
  }