@keyframes pulse {
  0% {
    background-color: var(--grid-color-light); /* LED fully lit */
  }
  10% {
    background-color: var(--grid-color-base); /* peak brightness */
  }
  100% {
    background-color: var(--grid-color-settled); /* settled color */
  }
}

@keyframes redpulse {
  0% {
    background-color: color-mix(in srgb, var(--grid-color-light) 20%, transparent); /* LED fully lit */
  }
  10% {
    background-color: color-mix(in srgb, var(--grid-color-base) 60%, transparent); /* peak brightness */
  }
  100% {
    background-color: color-mix(in srgb, var(--grid-color-settled) 20%, transparent); /* settled color */
  }
}

@keyframes secondarymainpulse {
  0% {
    background-color: color-mix(in srgb, var(--grid-color-light) 1%, transparent); /* LED fully lit */
  }
  10% {
    background-color: color-mix(in srgb, var(--grid-color-base) 10%, transparent); /* peak brightness */
  }
  100% {
    background-color: color-mix(in srgb, var(--grid-color-settled) 1%, transparent); /* settled color */
  }
}

@keyframes bluepulse {
  0% {
    background-color: #b0b3ff20; /* Slight blue tint, low opacity */
  }
  10% {
    background-color: #4a4dff30; /* Brighter blue with more opacity */
  }
  100% {
    background-color: #1e1e1e; /* Settled blue, low opacity */
  }
}

/* Base animation styles */
.pulse-base {
  background-color: #bb767420;
}

.after-base {
  background-color: #7476bb20;
}

/* Animation classes with important to override */
.pulse-1 {
  animation: none !important; /* Reset animation first */
  background-color: #bb767420;
}
.pulse-1.animate {
  animation: redpulse 1s ease-out !important;
}

.pulse-2 {
  animation: none !important; /* Reset animation first */
  background-color: #bb767420;
}
.pulse-2.animate {
  animation: redpulse 1s ease-out !important;
}

.after-1 {
  animation: none !important; /* Reset animation first */
  background-color: #7476bb20;
}
.after-1.animate {
  animation: bluepulse 2s ease-out !important;
}

.after-2 {
  animation: none !important; /* Reset animation first */
  background-color: #7476bb20;
}
.after-2.animate {
  animation: bluepulse 2s ease-out !important;
}

body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  overflow: hidden;
  --header-height: 32px;
  background-color: #1e1e1e;
  font-size: 12px;
}

#main {
}
.container {
  width: 100%;
  height: 100vh;
}

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background-color: #2b2b2b;
  height: var(--header-height);
  z-index: 10;
  color: white;
}

.header-content {
  margin: 0 auto;
  max-width: 1200px;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%;
}

h1 {
  font-size: 20px;
  font-weight: 500;
  margin: 0;
}

.controls {
  display: flex;
  align-items: center;
}

.label {
  margin-right: 5px;
}

.grid-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: var(--header-height);
  width: 100%;
  height: calc(100vh - var(--header-height));
}

.grid-container {
  /* Calculate the size of the grid based on viewport dimensions
     ensuring it's always a square with the limiting dimension */
  --available-height: calc(100vh - var(--header-height)); /* Viewport height minus header height minus some padding */
  --available-width: 100vw;
  --grid-size: min(var(--available-height), var(--available-width)); /* Use the smaller dimension */

  width: var(--grid-size);
  height: var(--grid-size);
  display: grid;
}

.grid-container.quaternary {
  grid-template-rows: repeat(4, 1fr);
}

.grid-container.octal {
  grid-template-rows: repeat(3, 1fr);
}

.grid-row.quaternary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.grid-row.octal {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
}

.grid-cell {
  /* background-color: #1e1e1e; */
  border: 4px solid #1e1e1e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  /* Make text size responsive */
  font-size: calc(var(--grid-size) / 40);
}

.grid-cell.active {
  animation: pulse 1s ease-out;
  background-color: var(--grid-color-settled);
  color: white;
}

/* All cells after the active cell */
.grid-cell.active ~ .grid-cell {
  /* after style */
}

/* All cells before the active cell (requires browsers that support :has) */
.grid-cell:has(~ .grid-cell.active) {
  /* animation: redpulse 1s ease-out; */
  /* background-color: #bb767420; */
}

.pulse {
  animation: redpulse 1s ease-out;
  background-color: #bb767420;
}

select,
button {
  margin-left: 8px;
}

.internal-clock {
  display: flex;
  align-items: center;
}

.midi-bpm {
  display: flex;
  align-items: center;
  margin-left: 16px;
  gap: 5px;
}

.midi-bpm #midiBpm {
  font-family: monospace;
  font-size: 12px;
  min-width: 40px;
  text-align: right;
}

#gridTypeSelect {
  padding: 0;
  height: 24px;
  color: white;
  background-color: #2b2b2b;
  border: 1px solid #6e6e6e;
  margin-left: 8px;
}

#bpmInput {
  height: 20px;
  width: 40px;
  margin-right: 5px;
  color: white;
  background-color: #2b2b2b;
  border: 1px solid #6e6e6e;
  margin-left: 8px;
}
#bpmInput:disabled {
  opacity: 0.5;
}

#midiInputSelect {
  padding: 0;
  height: 24px;
  color: white;
  background-color: #2b2b2b;
  border: 1px solid #6e6e6e;
  margin-left: 8px;
}

#startStopButton {
  margin: 0;
  mergin-left: 8px;
  padding: 0;
  height: 24px;
  border-radius: none;
  color: white;
  background-color: #2b2b2b;
  border: 1px solid #6e6e6e;
  margin-left: 8px;
  padding: 0 8px;
}
#startStopButton:disabled {
  opacity: 0.5;
}
#startStopButton.active {
  background-color: #6e6e6e;
  border: 1px solid #6e6e6e;
  color: #2b2b2b;
}

/* Body animation classes */
.main-blue-pulse {
  animation: none !important;
}
.main-blue-pulse.animate {
  animation: bluepulse 1s ease-out !important;
}

/* Body animation classes */
.main-red-pulse {
  animation: none !important;
}
.main-red-pulse.animate {
  animation: secondarymainpulse 1s ease-out !important;
}

/* Full screen */
.full-screen-btn {
  background: none;
  color: #6e6e6e;
  line-height: 0;

  padding: 4px 4px;
  cursor: pointer;
  line-height: 0;
  border: none;
  font-size: 16px;
  margin: 0;
}

.full-screen-btn:hover {
  /* background: #666; */
  color: white;
}

.container.fullscreen {
  background: black;
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container.fullscreen .grid-wrapper {
  width: 90vmin;
  height: 90vmin;
  margin: 0;
}

:root {
  --grid-color-base: #ff4d4a;
  --grid-color-light: #ffb3b0;
  --grid-color-settled: #bb7674;
}

/* .metronome-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 16px;
} */

#metronomeButton {
  background: none;
  border: 1px solid #6e6e6e;
  padding: 4px 4px;
  margin: 8px;
  cursor: pointer;
  line-height: 0;
  transition: all 0.1s ease-in-out;
}

#metronomeButton:hover {
  border: 1px solid white;
}
#metronomeButton:hover .metronome-circle {
  stroke: white;
}
#metronomeButton:hover .metronome-circle-1 {
  fill: white;
}

#metronomeButton.active {
  background: #6e6e6e;
  border: 1px solid #6e6e6e;
}

#metronomeButton.active .metronome-circle {
  fill: #2b2b2b;
  stroke: #2b2b2b;
}
#metronomeButton.active .metronome-circle-1 {
  fill: transparent;
  stroke: #2b2b2b;
}

#metronomeButton.active.beat-1 .metronome-circle-1 {
  fill: #2b2b2b;
  stroke: #2b2b2b;
}

#metronomeButton.active.beat-1 .metronome-circle-2 {
  fill: transparent;
  stroke: #2b2b2b;
}

#metronomeButton.active.beat-2 .metronome-circle-1 {
  fill: transparent;
  stroke: #2b2b2b;
}

#metronomeButton.active.beat-2 .metronome-circle-2 {
  fill: #2b2b2b;
  stroke: #2b2b2b;
}

#resetButton {
  background: none;
  color: #6e6e6e;
  line-height: 0;
  font-size: 18px;
  padding: 4px 4px;
  cursor: pointer;
  line-height: 0;
  border: none;
  margin: 0;
}

#resetButton:hover {
  color: white;
}

.icon-button {
  background: none;
  border: 1px solid #6e6e6e;
  color: #6e6e6e;
  padding: 4px 8px;
  margin-left: 8px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
}

.icon-button:hover {
  border-color: white;
  color: white;
}

.icon-button.active {
  background: #e0e0e0;
  border-color: #999;
}

.editable-value {
  cursor: ns-resize;
  user-select: none;
  padding: 4px 8px;
  background-color: #2a2a2a;
  border-radius: 4px;
  max-width: 80px;
  min-width: 40px;
  text-align: center;
  transition: opacity 0.2s ease;
}

.editable-value.dragging {
  background-color: #3a3a3a;
}

/* Style for when pointer-events is none */
div[style*="pointer-events: none"] .editable-value {
  opacity: 0.5;
  cursor: not-allowed;
}

.editable-value-input {
  background: transparent;
  border: none;
  color: inherit;
  font-size: inherit;
  font-family: inherit;
  text-align: center;
  width: 100%px;
  padding: 0;
  margin: 0;
  outline: none;
}

.editable-value-input::-webkit-inner-spin-button,
.editable-value-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
