:root {
  --bg: #090d14;
  --panel: #111a28;
  --edge: #293750;
  --ink: #e7eef9;
  --muted: #9db0cc;
  --accent: #27e3aa;
  --beat: 52px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at 15% -10%, #1c2942 0%, #090d14 58%);
  font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--edge);
  background: #0e1521;
}

.brand h1 { margin: 0; font-size: 18px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

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

.transport label {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  gap: 6px;
  align-items: center;
}

input, select, textarea, button {
  border: 1px solid #385178;
  background: #0a1120;
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 8px;
}

button { cursor: pointer; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

#timeSigNum,
#timeSigDen {
  width: 56px;
}

#playBtn,
#recordBtn,
#pauseBtn,
#stopBtn,
#deleteAllBtn,
#addTrackBtn,
#removeTrackBtn,
#syncTracksBtn,
#copyBtn,
#pasteBtn,
#duplicateBtn,
#saveTextureBtn,
#loadTextureBtn {
  min-width: 72px;
  font-weight: 600;
}

#playBtn {
  border-color: #1a7a5e;
  background: #0d2e25;
}

#recordBtn {
  border-color: #9a2736;
  background: #3f1419;
}

#pauseBtn {
  border-color: #7f6a24;
  background: #2e2610;
}

#stopBtn {
  border-color: #8a2f2f;
  background: #341414;
}

#deleteAllBtn {
  border-color: #a01f1f;
  background: #4a0f0f;
}

#addTrackBtn,
#removeTrackBtn,
#syncTracksBtn {
  border-color: #3d6a91;
  background: #183248;
}

#copyBtn,
#pasteBtn,
#duplicateBtn,
#saveTextureBtn,
#loadTextureBtn {
  border-color: #3a5684;
  background: #17243a;
}

.shell {
  display: grid;
  grid-template-columns: minmax(780px, 1fr) 320px;
  gap: 12px;
  padding: 12px;
}

.timeline-shell {
  position: relative;
  overflow: hidden;
  min-height: calc(100vh - 88px);
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: var(--panel);
}

.timeline-scroller {
  position: relative;
  overflow: auto;
  height: 100%;
  display: flex;
}

.track-column {
  position: sticky;
  left: 0;
  z-index: 6;
  width: 110px;
  min-width: 110px;
  border-right: 1px solid #2d3f5d;
  background: #0c1422;
}

.track-column-header {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #b9cae4;
  border-bottom: 1px solid #2d3f5d;
}

.track-label {
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #9db0cc;
  border-bottom: 1px solid #2a354c;
  background: linear-gradient(90deg, #101a2b, #0f1826);
  cursor: pointer;
}

.track-label.selected {
  color: #e7f3ff;
  background: linear-gradient(90deg, #1b355a, #17314f);
  box-shadow: inset 0 0 0 1px #6bb7ff;
}

.timeline-canvas {
  position: relative;
}

.v-grid {
  position: absolute;
  top: 36px;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 1;
}

.v-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255, 255, 255, 0.06);
}

.v-line.beat {
  background: rgba(255, 255, 255, 0.12);
}

.v-line.bar {
  background: rgba(123, 174, 245, 0.36);
}

.grid {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 36px;
  display: flex;
  background: #0d1524;
  border-bottom: 1px solid #2d3f5d;
}

.grid-cell {
  flex: 0 0 var(--beat);
  width: var(--beat);
  border-right: 1px solid #23354f;
  font-size: 11px;
  text-align: center;
  padding-top: 10px;
  color: #9fb2cf;
}

.grid-cell.bar {
  background: #12223d;
  color: #c2d7f5;
}

.tracks { position: relative; }

.track-row {
  height: 74px;
  border-bottom: 1px solid #2a354c;
  background:
    linear-gradient(180deg, transparent 0, transparent 34px, #2a354c 34px, #2a354c 35px, transparent 35px),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.03) 0,
      rgba(255, 255, 255, 0.03) calc(var(--beat) / 4),
      transparent calc(var(--beat) / 4),
      transparent calc(var(--beat) / 2)
    ),
    linear-gradient(90deg, #121d2e, #101723);
  position: relative;
}

.track-row.selected {
  background:
    linear-gradient(180deg, transparent 0, transparent 34px, #2a354c 34px, #2a354c 35px, transparent 35px),
    repeating-linear-gradient(
      90deg,
      rgba(107, 183, 255, 0.08) 0,
      rgba(107, 183, 255, 0.08) calc(var(--beat) / 4),
      transparent calc(var(--beat) / 4),
      transparent calc(var(--beat) / 2)
    ),
    linear-gradient(90deg, #15243b, #101a2a);
}

.block {
  position: absolute;
  top: 7px;
  height: 24px;
  border-radius: 10px;
  border: 1px solid #6bb7ff;
  background: linear-gradient(120deg, #1d64d7, #2c82ff);
  padding: 4px 8px;
  overflow: hidden;
  cursor: grab;
  user-select: none;
}

.block.selected {
  border-color: #ffcd57;
  box-shadow: 0 0 0 2px rgba(255, 205, 87, 0.35);
}

.block .title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.1;
}

.block .meta {
  font-size: 10px;
  margin-top: 2px;
  opacity: 0.9;
}

.block.resizing {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3);
}

.playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(39, 227, 170, 0.8);
  z-index: 4;
  pointer-events: none;
}

.right-panel {
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 12px;
  background: #0f1724;
  align-self: start;
}

.preset-actions {
  display: flex;
  gap: 6px;
  margin: 8px 0;
}

.preset-actions button {
  flex: 1;
  font-weight: 600;
}

.preset-palette {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.preset-slot {
  border: 1px solid #385178;
  background: #111c30;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 4px;
  font-size: 12px;
}

.preset-slot.filled {
  border-color: #5f85bf;
  background: #1a2c49;
}

.event-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}

.note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

#editorDialog {
  width: min(540px, 95vw);
  border-radius: 12px;
  border: 1px solid #34507a;
  background: #101927;
  color: var(--ink);
}

#editorForm {
  display: grid;
  gap: 8px;
}

#editorForm label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: #afc2dd;
}

menu {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin: 8px 0 0;
  padding: 0;
}

.danger {
  margin-right: auto;
  border-color: #972b2b;
  background: #421111;
}

@media (max-width: 1160px) {
  .shell { grid-template-columns: 1fr; }
}
