:root {
  --glow-intensity: 1;
}

@keyframes beat-flash {
  0% {
    box-shadow:
      inset 0 0 calc(20px * var(--glow-intensity)) rgba(34, 197, 94, 0.2),
      0 0 calc(10px * var(--glow-intensity)) rgba(34, 197, 94, 0.3);
  }
  50% {
    box-shadow:
      inset 0 0 calc(30px * var(--glow-intensity)) rgba(34, 197, 94, 0.4),
      0 0 calc(20px * var(--glow-intensity)) rgba(34, 197, 94, 0.6);
  }
  100% {
    box-shadow:
      inset 0 0 calc(20px * var(--glow-intensity)) rgba(34, 197, 94, 0.2),
      0 0 calc(10px * var(--glow-intensity)) rgba(34, 197, 94, 0.3);
  }
}

.beat-flash {
  animation: beat-flash 0.15s ease-out;
}

.piano-outer-container {
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #22c55e #111;
  -webkit-overflow-scrolling: touch;
}
.piano-outer-container::-webkit-scrollbar {
  height: 6px;
}
.piano-outer-container::-webkit-scrollbar-track {
  background: #111;
}
.piano-outer-container::-webkit-scrollbar-thumb {
  background: #22c55e;
  border-radius: 3px;
}
.piano-container {
  display: flex;
  position: relative;
  height: 120px;
  background: #000;
  padding: 5px;
  border-radius: 4px;
  border: 1px solid #111;
}
:root {
  --white-key-width: 30px;
  --black-key-width: 20px;
  --black-key-offset: -10px;
}
.piano-key {
  position: relative;
  flex: 0 0 var(--white-key-width);
  height: 100%;
  z-index: 1;
}
.white-key {
  background: linear-gradient(180deg, #fff 0%, #e8e8e8 100%);
  border: 1px solid #111;
  height: 100%;
  width: var(--white-key-width);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 5px;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.3);
  transition: all 0.1s;
  border-radius: 0 0 3px 3px;
  touch-action: manipulation;
}
.white-key:active,
.white-key.active {
  background: #22c55e;
  color: #000;
  box-shadow: inset 0 0 10px #000;
  transform: translateY(2px);
}
.black-key {
  position: absolute;
  width: var(--black-key-width);
  height: 70px;
  background: linear-gradient(180deg, #333 0%, #111 100%);
  border: 1px solid #000;
  z-index: 10;
  margin-left: var(--black-key-offset);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 5px;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
  transition: all 0.1s;
  border-radius: 0 0 2px 2px;
  top: 0;
  right: var(--black-key-offset);
  touch-action: manipulation;
}
.black-key:active,
.black-key.active {
  background: #16a34a;
  color: #fff;
  box-shadow: inset 0 0 10px #000;
  transform: translateY(2px);
}

.stylophone-outer-container {
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: #22c55e #111;
  -webkit-overflow-scrolling: touch;
}
.stylophone-outer-container::-webkit-scrollbar {
  height: 6px;
}
.stylophone-outer-container::-webkit-scrollbar-track {
  background: #111;
}
.stylophone-outer-container::-webkit-scrollbar-thumb {
  background: #22c55e;
  border-radius: 3px;
}
.stylophone-container {
  padding: 0;
  background: transparent;
  border: none;
  min-height: 0;
}
/* Classic pocket stylophone: cream case, recessed keybed, metal tines, round speaker */
.stylophone-board {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: min(100%, 720px);
  margin: 0 auto;
  padding: 10px 12px 12px;
  border-radius: 14px;
  background: linear-gradient(
    165deg,
    #f0e6d4 0%,
    #e4d5be 35%,
    #d8c9a8 70%,
    #cbb895 100%
  );
  border: 1px solid rgba(60, 45, 30, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.65),
    inset 0 -2px 6px rgba(0, 0, 0, 0.12),
    0 4px 14px rgba(0, 0, 0, 0.45);
}
.stylophone-brand {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.35em;
  text-align: center;
  color: #3d3530;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
  padding: 4px 4px 8px;
  border-bottom: 1px solid rgba(80, 60, 45, 0.2);
  margin-bottom: 8px;
}
.stylophone-main-row {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 10px;
  min-height: 112px;
}
.stylophone-speaker {
  flex: 0 0 56px;
  width: 56px;
  align-self: center;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, #5c5c5c 0%, #2a2a2a 45%, #1a1a1a 100%);
  border: 2px solid #3f3f3f;
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.85),
    inset 0 -1px 0 rgba(255, 255, 255, 0.08),
    0 2px 4px rgba(0, 0, 0, 0.35);
  position: relative;
  pointer-events: none;
}
.stylophone-speaker::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: repeating-conic-gradient(
    from 0deg,
    #333 0deg 8deg,
    #1f1f1f 8deg 16deg
  );
  opacity: 0.45;
  mix-blend-mode: multiply;
}
.stylophone-tine-bed {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  justify-content: flex-start;
  gap: 0;
  padding: 8px 6px 6px;
  background: linear-gradient(180deg, #0c0c0c 0%, #151515 40%, #0a0a0a 100%);
  border-radius: 6px;
  border: 2px solid #1f1f1f;
  box-shadow:
    inset 0 3px 12px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #71717a #0a0a0a;
}
.stylophone-tine-bed::-webkit-scrollbar {
  height: 5px;
}
.stylophone-tine-bed::-webkit-scrollbar-thumb {
  background: #52525b;
  border-radius: 3px;
}
.stylophone-stylus-col {
  flex: 0 0 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 6px;
  pointer-events: none;
}
.stylophone-stylus {
  width: 6px;
  height: 72px;
  border-radius: 2px;
  background: linear-gradient(
    90deg,
    #1a1a1a 0%,
    #3d3d3d 40%,
    #2a2a2a 100%
  );
  box-shadow:
    2px 2px 4px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  position: relative;
}
.stylophone-stylus::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -8px;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50% 50% 40% 40%;
  background: radial-gradient(circle at 30% 30%, #e8e8e8, #9ca3af 60%, #6b7280);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.stylophone-tine {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: 18px;
  min-width: 18px;
  height: 96px;
  margin: 0 1px;
  padding: 0 0 4px;
  border: none;
  border-radius: 0;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  background: transparent;
  color: #a1a1aa;
  transition: transform 0.06s ease;
}
.stylophone-tine-metal {
  display: block;
  width: 11px;
  flex: 1 1 auto;
  min-height: 52px;
  margin-bottom: 4px;
  border-radius: 2px 2px 1px 1px;
  background: linear-gradient(
    90deg,
    #71717a 0%,
    #d4d4d8 22%,
    #f4f4f5 45%,
    #a1a1aa 78%,
    #52525b 100%
  );
  box-shadow:
    inset 1px 0 0 rgba(255, 255, 255, 0.5),
    inset -1px 0 2px rgba(0, 0, 0, 0.35),
    0 2px 3px rgba(0, 0, 0, 0.5);
}
.stylophone-tine-label {
  font-size: 7px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: #71717a;
}
.stylophone-tine-num {
  font-size: 6px;
  font-weight: 600;
  color: #52525b;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.stylophone-tine:hover .stylophone-tine-metal {
  filter: brightness(1.08);
}
.stylophone-tine:hover .stylophone-tine-label {
  color: #d4d4d8;
}
.stylophone-tine:active,
.stylophone-tine.active {
  transform: translateY(1px);
}
.stylophone-tine:active .stylophone-tine-metal,
.stylophone-tine.active .stylophone-tine-metal {
  background: linear-gradient(
    90deg,
    #15803d 0%,
    #22c55e 40%,
    #4ade80 55%,
    #16a34a 100%
  );
  box-shadow:
    inset 0 0 8px rgba(0, 0, 0, 0.35),
    0 1px 2px rgba(34, 197, 94, 0.4);
}
.stylophone-tine:active .stylophone-tine-label,
.stylophone-tine.active .stylophone-tine-label,
.stylophone-tine:active .stylophone-tine-num,
.stylophone-tine.active .stylophone-tine-num {
  color: #052e16;
}

.drum-machine-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #22c55e #111;
}
.drum-machine-wrapper::-webkit-scrollbar {
  height: 6px;
}
.drum-machine-wrapper::-webkit-scrollbar-track {
  background: #111;
}
.drum-machine-wrapper::-webkit-scrollbar-thumb {
  background: #22c55e;
  border-radius: 3px;
}
.drum-machine-container {
  display: grid;
  grid-template-columns: 60px repeat(16, 1fr);
  gap: 3px;
  padding: 8px;
  background: #111;
  border-radius: 4px;
  border: 1px solid #333;
  min-width: 400px;
}
.track-label {
  grid-column: 1/2;
  padding: 4px 2px;
  text-align: right;
  color: #9ca3af;
  font-weight: bold;
  font-size: 10px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.step-button {
  width: 100%;
  aspect-ratio: 1;
  min-width: 16px;
  min-height: 16px;
  background-color: #333;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.1s;
  border: 1px solid #222;
  touch-action: manipulation;
}
.step-button.active {
  background-color: #22c55e;
  border-color: #16a34a;
  box-shadow: 0 0 calc(4px * var(--glow-intensity)) #22c55e;
}
.step-button.current-step {
  background-color: #4ade80 !important;
  box-shadow: 0 0 calc(8px * var(--glow-intensity)) #4ade80;
  border-color: #22c55e;
  transform: scale(1.1);
}
.step-button:hover {
  background-color: #444;
  transform: scale(1.05);
}
.step-button.active:hover {
  background-color: #16a34a;
}
.step-button[data-step="0"],
.step-button[data-step="4"],
.step-button[data-step="8"],
.step-button[data-step="12"] {
  border-bottom: 2px solid #22c55e44;
}
.track-volume {
  width: 60px;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #333;
  border-radius: 3px;
  cursor: pointer;
}
.track-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: #22c55e;
  border-radius: 50%;
  cursor: pointer;
}
.track-mute {
  font-size: 10px;
  padding: 6px 10px;
  background: transparent;
  border: 1px solid #444;
  color: #666;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.track-mute.muted {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

.tempo-display {
  font-size: 1.75rem;
  font-weight: bold;
  color: #22c55e;
  text-align: center;
  background: linear-gradient(135deg, #000 0%, #0a0a0a 100%);
  border: 2px solid #22c55e;
  padding: 12px 8px;
  border-radius: 4px;
  box-shadow:
    inset 0 0 calc(20px * var(--glow-intensity)) rgba(34, 197, 94, 0.2),
    0 0 calc(10px * var(--glow-intensity)) rgba(34, 197, 94, 0.3);
  letter-spacing: 2px;
  font-family: ui-monospace, monospace;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow 0.15s ease;
}
.tap-button {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
  color: #000;
  font-weight: bold;
  padding: 14px 32px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  transition:
    transform 0.1s,
    box-shadow 0.1s;
  font-size: 1rem;
  min-height: 52px;
  min-width: 120px;
  touch-action: manipulation;
}
.tap-button:active {
  transform: scale(0.95);
  box-shadow: 0 0 calc(20px * var(--glow-intensity)) #22c55e;
}
.visualizer-bar {
  width: 6px;
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
  border-radius: 2px;
  transition: height 0.05s ease;
  min-height: 4px;
}

.tool-card {
  background: #000;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  padding: 1rem 1.5rem;
  transition:
    border-color 0.3s ease,
    box-shadow 0.3s ease;
  overflow: hidden;
  min-width: 0;
}
.tool-card:hover {
  border-color: rgba(34, 197, 94, 0.3);
  box-shadow: 0 0 calc(15px * var(--glow-intensity)) rgba(34, 197, 94, 0.1);
}

.fun-tools-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 1.5rem;
}
.fun-tools-label {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: #888;
  font-family: ui-monospace, monospace;
  font-weight: 700;
}
.fun-tools-prompt {
  font-size: 12px;
  color: #4ade80;
  font-family: ui-monospace, monospace;
  opacity: 0.8;
}
.fun-tools-grid {
  gap: 1.5rem;
}
.fun-tools-grid > .tool-card {
  margin-bottom: 2rem;
}
.ft-divider {
  font-size: 10px;
  letter-spacing: 0.15em;
  color: #555;
  text-transform: uppercase;
  border-top: 0.5px solid rgba(255, 255, 255, 0.07);
  padding-top: 1rem;
  margin: 1.75rem 0 1rem;
  font-family: ui-monospace, monospace;
}
.ft-equal-card {
  min-height: 160px;
  display: flex;
  flex-direction: column;
}
.ft-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.ft-card-wide {
  background: #000;
  border: 0.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}

.metronome-display {
  font-size: 2.25rem;
  font-weight: bold;
  color: #22c55e;
  text-align: center;
  background: linear-gradient(135deg, #000 0%, #0a0a0a 100%);
  border: 2px solid #22c55e;
  padding: 14px;
  border-radius: 4px;
  box-shadow:
    inset 0 0 calc(20px * var(--glow-intensity)) rgba(34, 197, 94, 0.2),
    0 0 calc(10px * var(--glow-intensity)) rgba(34, 197, 94, 0.3);
  letter-spacing: 2px;
  font-family: ui-monospace, monospace;
  transition: box-shadow 0.15s ease;
}
.metronome-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.metronome-btn {
  background: #111;
  border: 1px solid #333;
  color: #22c55e;
  padding: 12px 18px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 12px;
  font-family: monospace;
  min-height: 44px;
  touch-action: manipulation;
}
.metronome-btn:hover {
  border-color: #22c55e;
  background: #0a0a0a;
}
.metronome-btn.active {
  background: #22c55e;
  color: #000;
  border-color: #22c55e;
}
.metronome-input {
  background: #000;
  border: 1px solid #333;
  color: #22c55e;
  padding: 12px;
  border-radius: 4px;
  width: 80px;
  text-align: center;
  font-family: monospace;
  font-size: 14px;
  min-height: 44px;
}
.metronome-input:focus {
  outline: none;
  border-color: #22c55e;
}
.time-sig-select {
  background: #000;
  border: 1px solid #333;
  color: #22c55e;
  padding: 12px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  cursor: pointer;
  min-height: 44px;
}
.swing-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100px;
  height: 8px;
  background: #333;
  border-radius: 4px;
  cursor: pointer;
}
.swing-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: #22c55e;
  border-radius: 50%;
  cursor: pointer;
}
.copy-bpm-btn {
  font-size: 10px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid #333;
  color: #666;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s;
  margin-top: 8px;
  min-height: 36px;
}
.copy-bpm-btn:hover {
  border-color: #22c55e;
  color: #22c55e;
}

.header-tempo-popover {
  position: fixed;
  z-index: 60;
  min-width: 140px;
  padding: 10px 12px;
  background: #0a0a0a;
  border: 1px solid rgba(34, 197, 94, 0.35);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.header-tempo-popover.hidden {
  display: none;
}

@media (max-width: 768px) {
  .drum-machine-container {
    grid-template-columns: 45px repeat(16, 1fr);
    gap: 2px;
    padding: 6px;
    min-width: 360px;
  }
  .track-label {
    font-size: 8px;
    padding: 2px;
  }
  .tempo-display {
    font-size: 1.5rem;
    min-height: 50px;
    padding: 10px 6px;
  }
  :root {
    --white-key-width: 22px;
    --black-key-width: 16px;
    --black-key-offset: -8px;
  }
  .piano-container {
    height: 100px;
  }
  .black-key {
    height: 60px;
  }
  .stylophone-main-row {
    min-height: 100px;
    gap: 8px;
  }
  .stylophone-speaker {
    flex-basis: 48px;
    width: 48px;
  }
  .stylophone-tine {
    width: 15px;
    min-width: 15px;
    height: 88px;
  }
  .stylophone-tine-metal {
    width: 9px;
    min-height: 46px;
  }
  .stylophone-stylus {
    height: 64px;
  }
  .metronome-display {
    font-size: 1.75rem;
    padding: 12px;
  }
  .track-volume {
    width: 50px;
  }
  .tool-card {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .drum-machine-container {
    grid-template-columns: 35px repeat(16, 1fr);
    gap: 1px;
    padding: 4px;
    min-width: 320px;
  }
  .track-label {
    font-size: 7px;
    padding: 1px;
  }
  .step-button {
    border-radius: 2px;
  }
  :root {
    --white-key-width: 20px;
    --black-key-width: 14px;
    --black-key-offset: -7px;
  }
  .piano-container {
    height: 90px;
  }
  .black-key {
    height: 55px;
  }
  .stylophone-board {
    padding: 8px 8px 10px;
    border-radius: 12px;
  }
  .stylophone-brand {
    font-size: 8px;
    letter-spacing: 0.28em;
    padding-bottom: 6px;
    margin-bottom: 6px;
  }
  .stylophone-main-row {
    min-height: 92px;
    gap: 6px;
  }
  .stylophone-speaker {
    flex-basis: 40px;
    width: 40px;
  }
  .stylophone-tine {
    width: 13px;
    min-width: 13px;
    height: 80px;
    margin: 0;
  }
  .stylophone-tine-metal {
    width: 8px;
    min-height: 42px;
  }
  .stylophone-tine-label {
    font-size: 6px;
  }
  .stylophone-tine-num {
    font-size: 5px;
  }
  .stylophone-stylus-col {
    flex-basis: 22px;
  }
  .stylophone-stylus {
    width: 5px;
    height: 56px;
  }
  .tool-card {
    padding: 0.875rem;
  }
  .metronome-display {
    font-size: 1.5rem;
    padding: 10px;
  }
  .track-volume {
    width: 40px;
  }
  .track-mute {
    font-size: 8px;
    padding: 4px 6px;
    min-width: 28px;
    min-height: 28px;
  }
  .metronome-controls {
    gap: 6px;
  }
  .metronome-btn,
  .metronome-input,
  .time-sig-select {
    padding: 10px;
    min-height: 40px;
    font-size: 11px;
  }
  .swing-slider {
    width: 70px;
  }
}
