:root {
  --red: #f00412;
  --white: #f4f4f4;
  --muted: #6a6a6a;
  --line: #222;
  --panel: #050505;
  --cell: #111;
  --cell-hot: #e93128;
  --amber: #ffcc00;
  --cyan: #00e5ff;
  --green: #00e676;
  --violet: #b38cff;
  --font: Poppins, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: var(--white);
  background: #000;
  font-family: var(--font);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 0, rgba(240, 4, 18, .18), transparent 27rem),
    radial-gradient(circle at 88% 12%, rgba(255, 255, 255, .07), transparent 18rem),
    #000;
  overflow-x: hidden;
}

button,
select,
input {
  font: inherit;
}

button {
  color: inherit;
  background: transparent;
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .28;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

.app {
  width: min(1740px, calc(100% - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
  border: 1px solid var(--line);
  background: #020202;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(170px, 320px) 1fr;
  align-items: center;
  gap: 14px;
  min-height: 78px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.logo-link {
  display: inline-flex;
  align-items: center;
  width: min(320px, 44vw);
  min-width: 170px;
  text-decoration: none;
}

.logo-link img {
  display: block;
  width: 100%;
  height: auto;
}

h2,
h3,
p {
  margin: 0;
}

.panel-head span,
.keyboard-hints,
.status-strip,
.control span,
.track-key,
.step-numbers,
.module-head p {
  font-family: var(--mono);
}

.genre-nav {
  justify-self: end;
  display: grid;
  grid-template-columns: repeat(7, minmax(72px, 1fr));
  width: min(880px, 100%);
  border: 1px solid #181818;
}

.genre-nav button,
.switch-group button,
.transport-button,
.module-actions button {
  min-height: 42px;
  padding: 0 12px;
  border-right: 1px solid #181818;
  color: #777;
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
  position: relative;
}

.genre-nav button:last-child,
.switch-group button:last-child {
  border-right: 0;
}

.genre-nav button.active,
.switch-group button.active,
.transport-button.active,
.module-actions button:hover {
  color: var(--white);
}

.genre-nav button.active::after,
.switch-group button.active::after,
.transport-button.active::after {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 0;
  height: 2px;
  background: var(--red);
  box-shadow: 0 0 14px rgba(240, 4, 18, .9);
}

.transport {
  display: grid;
  grid-template-columns: minmax(270px, 390px) 118px 118px minmax(170px, 230px) repeat(3, minmax(140px, 1fr));
  gap: 10px;
  align-items: stretch;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.modes-wrap {
  display: grid;
  gap: 5px;
}

.modes-label {
  font: 900 .52rem var(--mono);
  letter-spacing: .22em;
  color: #3a3a3a;
  text-transform: lowercase;
  padding-left: 3px;
}

.switch-group {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  border: 1px solid #282828;
}

.transport-button,
.module-actions button {
  border: 1px solid #282828;
  background: #030303;
}

.control {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.control span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: #777;
  font-size: .64rem;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.control em {
  color: var(--red);
  font-style: normal;
}

.control select,
.note-pair select {
  width: 100%;
  height: 42px;
  color: var(--white);
  background: #030303;
  border: 1px solid #282828;
  border-radius: 0;
  padding: 0 12px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

input[type="range"] {
  --value: 50%;
  width: 100%;
  height: 22px;
  margin: 0;
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 7px;
  background: linear-gradient(90deg, var(--red) 0 var(--value), var(--white) var(--value) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 14px rgba(240, 4, 18, .7);
}

input[type="range"]::-moz-range-track {
  height: 7px;
  background: var(--white);
}

input[type="range"]::-moz-range-progress {
  height: 7px;
  background: var(--red);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: var(--red);
}

.status-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  color: #666;
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.status-strip strong {
  color: var(--white);
}

#barReadout {
  margin-left: auto;
}

.machine-area {
  display: grid;
  grid-template-columns: minmax(680px, 1fr) 310px;
  align-items: stretch;
  gap: 0;
}

.side-rack {
  height: 100%;
  box-sizing: border-box;
}

.sequencer {
  min-width: 0;
  padding: 22px 26px 26px;
  border-right: 1px solid var(--line);
  overflow-x: auto;
}

.module-head {
  min-width: calc(272px + var(--steps, 16) * 43px);
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

h2 {
  color: var(--red);
  font-size: 1.7rem;
  line-height: 1;
  font-weight: 900;
  letter-spacing: .18em;
}

.module-head p {
  margin-top: 7px;
  color: #555;
  font-size: .68rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.module-actions {
  display: flex;
  gap: 8px;
}

.module-actions button {
  min-width: 60px;
}

.module-actions #prevButton,
.module-actions #nextButton {
  min-width: 44px;
  font-size: .9rem;
}

.step-numbers,
.track-row {
  min-width: calc(272px + var(--steps, 16) * 43px);
  display: grid;
  grid-template-columns: 180px repeat(var(--steps, 16), minmax(42px, 1fr)) 92px;
  gap: 1px;
}

.step-numbers {
  margin-bottom: 5px;
  color: #4b4b4b;
  text-align: center;
  font-size: .58rem;
  font-weight: 900;
}

.step-numbers span.bar {
  color: var(--white);
}

.step-numbers span.triplet-accent {
  color: var(--red);
}

.track-row {
  min-height: 58px;
  margin-bottom: 6px;
  border: 1px solid #181818;
  background: #000;
}

.track-head {
  display: grid;
  grid-template-columns: 1fr 26px 26px 28px;
  align-items: center;
  gap: 6px;
  padding: 0 8px 0 14px;
  border-right: 1px solid #242424;
}

.track-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--white);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .04em;
  text-align: left;
}

.track-key {
  color: #565656;
  font-size: .56rem;
  font-weight: 900;
  text-align: center;
}

.mute,
.solo {
  height: 28px;
  border: 1px solid #252525;
  color: #555;
  font-size: .6rem;
  font-weight: 900;
}

.mute.active {
  color: var(--red);
  border-color: #421015;
}

.solo.active {
  color: var(--amber);
  border-color: #5a4800;
  box-shadow: 0 0 6px rgba(255, 200, 0, .4);
}

.track-row.muted {
  opacity: .36;
}

.track-row.soloed-out {
  opacity: .2;
}

/* ─── DOT CELLS ─── */
.step {
  min-height: 54px;
  border: 0;
  background: transparent;
  border-left: 1px solid #0a0a0a;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.step.bar-start {
  margin-left: 4px;
}

.step.triplet-start {
  margin-left: 4px;
}

/* The dot */
.step::before {
  content: '';
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #141414;
  border: 1px solid #242424;
  transition: background .07s ease, box-shadow .07s ease, transform .06s ease, border-color .07s ease;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.step:hover::before {
  background: #252525;
  transform: scale(1.18);
}

/* Triplet accent — red ring on inactive dot */
.step.triplet-accent:not(.on):not(.accent):not(.note-a):not(.note-b):not(.bass)::before {
  border-color: rgba(240, 4, 18, .55);
}

.step.on::before {
  background: #8c1a20;
  border-color: #c02030;
}

.step.accent::before {
  background: var(--cell-hot);
  border-color: #f06050;
}

.step.note-a::before {
  background: #1e3da0;
  border-color: #3a6aea;
}

.step.note-b::before {
  background: #6022a8;
  border-color: #9040e0;
}

.step.bass::before {
  background: #8c1a22;
  border-color: #c82535;
}

.step.bass.accent::before {
  background: #c88000;
  border-color: var(--amber);
}

/* Playhead — brighter fill only, no glow */
.step.playhead::before {
  background: var(--red);
  border-color: #ff4050;
}

/* Note-length tails — thin bar spanning held cells */
.step.tail-a::before,
.step.tail-b::before,
.step.tail-bass::before,
.step.tail-bass-accent::before {
  width: calc(100% + 2px);
  height: 3px;
  border-radius: 0;
  border: none;
}

.step.tail-a::before           { background: rgba(30,  61, 160, 0.38); }
.step.tail-b::before           { background: rgba(96,  34, 168, 0.38); }
.step.tail-bass::before        { background: rgba(140, 26,  34, 0.38); }
.step.tail-bass-accent::before { background: rgba(200,128,   0, 0.38); }

.step-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 900 .6rem var(--mono);
  color: rgba(255, 255, 255, .85);
  z-index: 2;
  pointer-events: none;
}

.track-volume {
  align-self: center;
  margin: 0 10px;
}

.side-rack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 16px;
}

.device-card,
.panel {
  border: 1px solid var(--line);
  background: #030303;
  padding: 15px;
}

.device-card {
  min-height: 146px;
  display: grid;
  align-content: space-between;
  gap: 18px;
}

.device-open {
  min-height: 46px;
  border: 1px solid #2a2a2a;
  background: #080808;
  color: var(--white);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .16em;
}

.device-open:hover {
  border-color: var(--red);
  color: var(--red);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  padding-bottom: 12px;
  margin-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

h3 {
  color: var(--white);
  font-size: .86rem;
  font-weight: 900;
  letter-spacing: .14em;
}

.panel-head span {
  color: #555;
  font-size: .58rem;
  font-weight: 900;
}

.note-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.note-pair label,
.stacked {
  display: grid;
  gap: 8px;
}

.note-pair span {
  color: #777;
  font: 900 .58rem var(--mono);
  letter-spacing: .1em;
}

.stacked {
  margin-top: 14px;
}

.device-dialog {
  width: min(520px, calc(100vw - 28px));
  border: 1px solid #333;
  padding: 0;
  background: #020202;
  color: var(--white);
  box-shadow: 0 0 80px rgba(240, 4, 18, .3);
}

.device-dialog::backdrop {
  background: rgba(0, 0, 0, .76);
  backdrop-filter: blur(2px);
}

.device-window {
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-head strong {
  color: var(--red);
  font-size: 1.6rem;
  line-height: 1;
  font-weight: 900;
  letter-spacing: .12em;
}

.dialog-head button {
  min-height: 36px;
  border: 1px solid #2a2a2a;
  padding: 0 12px;
  color: #777;
  font-size: .65rem;
  font-weight: 900;
  letter-spacing: .12em;
}

/* ─── STING BUTTON ─── */
.sting-btn {
  flex: 1;                /* fill remaining vertical space in side-rack */
  width: 100%;
  min-height: 100px;
  border: none;
  background: transparent;
  padding: 12px 8px 8px;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sting-btn:hover .sting-img {
  opacity: .82;
  transform: scale(1.04);
}

.sting-img {
  display: block;
  max-width: 180px;
  max-height: 200px;
  width: 80%;
  height: auto;
  object-fit: contain;
  transition: opacity .15s ease, transform .15s ease;
}

@keyframes sting-fire {
  0%   { opacity: .3; transform: scale(0.88); }
  30%  { opacity: 1;  transform: scale(1.12); }
  70%  { opacity: 1;  transform: scale(1.05); }
  100% { opacity: 1;  transform: scale(1); }
}

.sting-btn.firing .sting-img {
  animation: sting-fire .4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

/* ─── FOOTER ─── */
.keyboard-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  padding: 14px 18px 17px;
  border-top: 1px solid var(--line);
  color: #555;
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.keyboard-hints span {
  border: 1px solid #1e1e1e;
  padding: 7px 9px;
}

.built-by {
  margin-left: auto;
  border: 0 !important;
  padding: 7px 0 !important;
  color: #383838;
  letter-spacing: .06em;
}

.audio-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, .84);
  backdrop-filter: blur(2px);
}

.audio-gate.is-hidden {
  display: none;
}

.audio-gate button {
  display: grid;
  gap: 10px;
  place-items: center;
  min-width: min(420px, calc(100vw - 36px));
  min-height: 200px;
  border: 1px solid #333;
  background: #050505;
  color: var(--white);
  box-shadow: 0 0 50px rgba(240, 4, 18, .22);
}

.gate-logo {
  display: block;
  width: 54px;
  height: auto;
  opacity: .9;
  margin-bottom: 4px;
}

.audio-gate span {
  color: var(--white);
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: .03em;
}

.audio-gate small {
  color: var(--red);
  font: 900 .7rem var(--mono);
  letter-spacing: .14em;
  text-transform: uppercase;
}

.footer-logo {
  display: inline-block;
  height: 13px;
  width: auto;
  vertical-align: middle;
  opacity: .55;
  margin: 0 2px;
}

@media (max-width: 1180px) {
  .topbar,
  .transport,
  .machine-area {
    grid-template-columns: 1fr;
  }

  .genre-nav {
    justify-self: stretch;
    grid-template-columns: repeat(4, 1fr);
  }

  .logo-link {
    width: 240px;
  }

  .sequencer {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 680px) {
  .app {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border-left: 0;
    border-right: 0;
  }

  .genre-nav {
    display: flex;
    overflow-x: auto;
    width: 100%;
    scrollbar-width: none;
  }

  .genre-nav::-webkit-scrollbar {
    display: none;
  }

  .genre-nav button {
    min-width: 90px;
    flex-shrink: 0;
  }

  .transport {
    grid-template-columns: 1fr 1fr;
    padding: 12px;
    gap: 8px;
  }

  .switch-group {
    grid-column: span 2;
    grid-template-columns: 1.2fr 1fr 1fr;
  }

  .transport-button {
    min-height: 48px;
  }

  /* preset select spans full width */
  .transport > .control:not(.compact) {
    grid-column: span 2;
  }

  .sequencer {
    padding: 18px 12px;
  }

  /* Smaller step cells on mobile so grid is scrollable but not absurdly wide */
  .step-numbers,
  .track-row {
    min-width: calc(160px + var(--steps, 16) * 32px);
    grid-template-columns: 110px repeat(var(--steps, 16), minmax(30px, 1fr)) 60px;
  }

  .step {
    min-height: 48px;
  }

  .track-head {
    padding: 0 6px 0 10px;
  }

  .track-name {
    font-size: .64rem;
  }

  .side-rack {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 14px 12px;
  }

  .side-rack .device-card {
    flex: 1 1 calc(50% - 7px);
    min-height: 120px;
  }

  .sting-btn {
    flex: 1 1 100%;
    min-height: 140px;
  }

  .status-strip {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  #barReadout {
    margin-left: 0;
  }

  .audio-gate button {
    min-height: 132px;
  }

  .audio-gate span {
    font-size: 1.05rem;
  }

  .keyboard-hints {
    display: none;
  }
}
