:root {
  --bg-color: #121212;
  --text-color: #e0e0e0;
  --primary-color: #bb86fc;
  --secondary-color: #03dac6;
  --key-bg: #2c2c2c;
  --key-active: #bb86fc;
  --key-text: #ffffff;
}

body {
  font-family:
    "Inter",
    system-ui,
    -apple-system,
    sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  user-select: none;
}

/* Header & Help Button */
.title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
}

#help-btn {
  background: transparent;
  border: 2px solid var(--text-color);
  color: var(--text-color);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: bold;
  opacity: 0.6;
  cursor: pointer;
  box-shadow: none;
}

#help-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.1);
  box-shadow: none;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: #1e1e1e;
  border: 1px solid #333;
  padding: 1.5rem;
  margin: 1rem;
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
  margin-top: 0;
  color: var(--primary-color);
}

.modal-content ul {
  text-align: left;
  line-height: 1.6;
  padding-left: 1.2rem;
  color: #ccc;
}
.modal-content li {
  margin-bottom: 0.5rem;
}

.modal-content code {
  background: #333;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}

#close-modal {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: #888;
  cursor: pointer;
  padding: 0;
  width: auto;
  height: auto;
  box-shadow: none;
}

#close-modal:hover {
  color: #fff;
  transform: none;
  background: transparent;
}

/* Alternate Numpad Layout */
.numpad-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 70px);
  gap: 12px;
  margin-top: 1rem;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
  padding: 20px;

  /* Explicit Grid Areas */
  grid-template-areas:
    "clear div mul sub"
    "k7    k8  k9  add"
    "k4    k5  k6  add"
    "k1    k2  k3  ent"
    "k0    k0  dot ent";
}

/* Color Coding Groups */
.np-btn.btn-qual {
  background: #3b4d3d; /* Braun Green */
  border-color: #4b5d4d;
}
.np-btn.btn-root {
  background: #4a2c25; /* Muted Rust */
  border-color: #5a3c35;
}

.np-btn {
  background: #252525; /* Keycap color */
  border: none;
  border-radius: 6px;
  color: #eee;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.05s ease-out;
  user-select: none;
  text-align: center;
  padding: 5px;

  /* Pseudo-3D Bevel */
  box-shadow:
    0 -1px 0 #3a3a3a inset,
    /* Highlight top edge */ 0 4px 0 #111,
    /* Side depth */ 0 5px 5px rgba(0, 0, 0, 0.4); /* Drop shadow */
  position: relative;
  top: 0;
}

.np-btn:active,
.np-btn.active {
  transform: translateY(3px);
  box-shadow:
    0 -1px 0 #333 inset,
    0 1px 0 #111,
    0 1px 2px rgba(0, 0, 0, 0.4);

  color: var(--primary-color);
  background: #2a2a2a;
  border: 1px solid var(--primary-color);
}

.np-shortcut {
  position: absolute;
  top: 5px;
  right: 5px;
  font-size: 0.65rem;
  opacity: 0.4;
  font-family: inherit;
  font-weight: 700;
  pointer-events: none;
  text-transform: uppercase;
  color: #eee;
}

/* Specific Active States for Colored Keys */
.np-btn.btn-qual:active,
.np-btn.btn-qual.active {
  background: #465a48; /* Slightly lighter Braun Green */
  border-color: var(--key-active);
  color: #fff;
  box-shadow:
    0 -1px 0 #3b4d3d inset,
    0 1px 0 #333,
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 0 12px var(--key-active);
}
.np-btn.btn-root:active,
.np-btn.btn-root.active {
  background: #5a352d; /* Slightly lighter Rust */
  border-color: var(--key-active);
  color: #fff;
  box-shadow:
    0 -1px 0 #4a2c25 inset,
    0 1px 0 #333,
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 0 12px var(--key-active);
}

/* Modifiers Glow */
.np-btn.active {
  box-shadow: 0 0 12px var(--key-active);
  border-color: var(--key-active);
}

/* Grid Area Assignments */
#np-halfDiminished {
  grid-area: clear;
}
#np-dominant {
  grid-area: div;
}
#np-diminished {
  grid-area: mul;
}
#np-minor {
  grid-area: sub;
}

#np-key-7 {
  grid-area: k7;
}
#np-majorSixth {
  grid-area: k8;
}
#np-majorSeventh {
  grid-area: k9;
}
#np-augmented {
  grid-area: add;
  height: 100%;
}

#np-key-4 {
  grid-area: k4;
}
#np-key-5 {
  grid-area: k5;
}
#np-key-6 {
  grid-area: k6;
}

#np-key-1 {
  grid-area: k1;
}
#np-key-2 {
  grid-area: k2;
}
#np-key-3 {
  grid-area: k3;
}
#np-major {
  grid-area: ent;
  height: 100%;
}

#np-rootShiftDown {
  grid-area: k0;
  width: 100%;
}
#np-rootShiftUp {
  grid-area: dot;
}

/* Deprecated helpers (handled by grid-area) */
.tall-y {
  grid-row: auto;
  height: auto;
}
.wide-x {
  grid-column: auto;
  width: auto;
}

#app {
  text-align: center;
  max-width: 600px;
  width: 100%;
}

header h1 {
  font-weight: 300;
  letter-spacing: 2px;
  margin-bottom: 0.5rem;
}

header p {
  opacity: 0.7;
  margin-bottom: 2rem;
}

.controls {
  margin-bottom: 1.5rem;
  display: flex;
  gap: 1rem;
  justify-content: center;
  padding: 0 8px;
  align-items: center;
  flex-wrap: wrap;
}

button {
  background: var(--secondary-color);
  color: #000;
  border: none;
  padding: 0.8rem 1.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: bold;
  font-size: 1.1rem;
  transition: all 0.2s;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

#start-audio {
  background-color: #ee8f00; /* Braun-inspired amber/orange */
  color: #1a1a1a;
  padding: 1rem 2rem;
  border-radius: 8px;
  width: auto;
  min-width: 200px;
}

button:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.4);
}

.control-btn {
  background: #252525;
  color: #aaa;
  font-size: 0.8rem;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  box-shadow:
    0 -1px 0 #3a3a3a inset,
    0 2px 0 #111,
    0 3px 4px rgba(0, 0, 0, 0.4);
  border: 1px solid transparent;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.control-btn:hover {
  color: #eee;
  transform: translateY(-1px);
}

.control-btn.active {
  color: var(--primary-color);
  border-color: var(--key-active);
  box-shadow: 0 0 10px var(--key-active);
}

.control-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #111;
}

select {
  padding: 0.5rem 2.2rem 0.5rem 0.8rem; /* Extra right padding for arrow */
  border-radius: 6px;
  background: #252525;
  color: #eee;
  border: 1px solid transparent;
  font-size: 0.8rem;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow:
    0 -1px 0 #3a3a3a inset,
    0 2px 0 #111,
    0 3px 4px rgba(0, 0, 0, 0.4);
  transition: all 0.2s;
  height: auto;
  min-width: 65px; /* Ensure enough width for labels + arrow */
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.7rem center;
  background-size: 1rem;
}

select:hover {
  color: #fff;
  transform: translateY(-1px);
}

select:focus {
  outline: none;
  border-color: var(--key-active);
  box-shadow: 0 0 10px var(--key-active);
}

.display {
  margin-bottom: 1rem;
  height: 60px;
  display: flex;
  justify-content: center;
  align-items: center;
}

#current-chord {
  font-size: 1.5rem;
  margin: 0;
  color: var(--primary-color);
}

#notes-display {
  opacity: 0.8;
}

.keypad {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 2rem;
  padding: 8px;
}

.key {
  width: 70px;
  height: 60px;
  background: var(--key-bg);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: all 0.05s ease-out;
  border: 1px solid transparent;
  box-shadow:
    0 -1px 0 #3a3a3a inset,
    0 4px 0 #111,
    0 5px 5px rgba(0, 0, 0, 0.4);
}

.key .key-label {
  position: absolute;
  top: 5px;
  right: 8px;
  font-size: 0.7rem;
  opacity: 0.5;
  font-weight: bold;
  color: #eee;
}

.key .mod-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #eee;
}

.key:active,
.key.active {
  transform: translateY(3px);
  border-color: var(--key-active);
  box-shadow:
    0 -1px 0 #333 inset,
    0 1px 0 #111,
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 0 12px var(--key-active);
}

.key.active .mod-name {
  color: var(--primary-color);
}

.instructions {
  margin-top: 2rem;
}

.instructions h3 {
  font-size: 1rem;
  opacity: 0.7;
  margin-bottom: 1rem;
}

.qwerty-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin: 1.5rem 0;
}

.qwerty-row {
  display: flex;
  gap: 12px;
  margin-right: 8px;
}

.stagger-1 {
  margin-left: 20px;
}
.stagger-2 {
  margin-left: 40px;
}

.mod-key {
  width: 70px;
  height: 60px;
  background: #252525;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  transition: all 0.05s ease-out;
  border: 1px solid transparent; /* Reserve space for active border */
  box-shadow:
    0 -1px 0 #3a3a3a inset,
    0 4px 0 #111,
    0 5px 5px rgba(0, 0, 0, 0.4);
}

.mod-key.btn-qual {
  background: #3b4d3d; /* Braun Green */
}

.mod-key.btn-root {
  background: #4a2c25; /* Muted Rust */
}

.mod-key.wide {
  width: 152px; /* Wide for spacebar */
}

.mod-key .key-label {
  position: absolute;
  top: 5px;
  right: 8px;
  font-size: 0.7rem;
  opacity: 0.5;
  font-weight: bold;
  color: #eee;
}

.mod-key .mod-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #eee;
}

.mod-key:active,
.mod-key.active {
  transform: translateY(3px);
  border-color: var(--key-active); /* Only change color, not size */
  color: var(--primary-color);
  box-shadow:
    0 -1px 0 #333 inset,
    0 1px 0 #111,
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 0 12px var(--key-active);
}

.mod-key.btn-root.active {
  background: #5a352d; /* Lighter Rust */
}

.mod-key.active .mod-name {
  color: var(--primary-color);
}

.modifier-grid {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  margin-bottom: 2rem;
}

.mod-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  font-size: 0.95rem;
  opacity: 0.9;
  background: #252525;
  padding: 8px 15px;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  border: 1px solid #333;
}

.mod-item.btn-root {
  background: #4a2c25; /* Muted Rust */
}

.mod-item.active {
  border-color: var(--key-active);
  box-shadow: 0 0 10px var(--key-active);
}

.mod-item.active .key-badge {
  background: var(--key-active);
  color: #000;
  border-color: var(--key-active);
}

.mod-item.active span:not(.key-badge) {
  color: var(--key-active);
}

/* Theremin Styling */
#theremin-container {
  position: fixed;
  right: 30px;
  top: 50%;
  transform: translateY(-50%);
  height: 80vh;
  width: 40px;
  z-index: 1000;
  pointer-events: none; /* Let mouse pass through for global events only */
}

#theremin-bar {
  width: 10px;
  height: 100%;
  background: linear-gradient(
    to top,
    rgba(255, 255, 255, 0.1),
    rgba(255, 255, 255, 0.4),
    rgba(255, 255, 255, 0.1)
  );
  margin: 0 auto;
  border-radius: 5px;
  position: relative;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

/* Mobile Adjustments */
@media (max-width: 600px) {
  #theremin-container {
    right: 0;
    width: 25px;
  }

  #theremin-bar {
    margin-right: 0;
    border-radius: 5px 0 0 5px;
    width: 6px;
  }

  #start-audio {
    width: 90%;
    max-width: 320px;
    font-size: 1rem;
  }

  #start-audio-subtext {
    font-size: 0.7em !important;
    font-weight: bold !important;
  }

  .control-btn {
    font-size: 0.65rem;
    padding: 0.4rem 0.6rem;
  }

  select {
    font-size: 0.65rem;
    padding: 0.4rem 1.8rem 0.4rem 0.5rem; /* Preserve arrow space */
    min-width: 55px;
  }

  /* Anchored Round Amber Button on Mobile */
  #mobile-theremin-btn {
    display: block !important;
    position: absolute; /* Relative to .display or .chord-row */
    left: 18px; /* Moved further from edge */
    top: 50%;
    transform: translateY(-50%) !important;
    width: 60px !important;
    height: 60px !important;
    background-color: #ee8f00 !important; /* Braun-inspired amber */
    background-image: url("images/antenna.png");
    background-size: 50%; /* Scale the icon comfortably */
    background-position: center;
    background-repeat: no-repeat;
    border: 4px solid #c17400 !important;
    border-radius: 50% !important;
    z-index: 10;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(238, 143, 0, 0.4);
    transition:
      transform 0.1s,
      background-color 0.1s;
    pointer-events: auto;

    /* Override any default button styling */
    appearance: none !important;
    -webkit-appearance: none !important;
    padding: 0 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
    outline: none !important;
  }

  #mobile-theremin-btn:active {
    background-color: #d17d00 !important;
    transform: translateY(-50%) scale(0.9) !important;
    box-shadow: 0 2px 8px rgba(238, 143, 0, 0.6);
  }

  .display {
    position: relative; /* Anchor for the button */
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .chord-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
  }

  #background-fx {
    background-size: cover !important;
    background-position: center center !important;
  }
}

/* Hide by default for desktop */
#mobile-theremin-btn {
  display: none;
}

#pitch-indicator {
  position: absolute;
  bottom: 50%; /* Default center */
  left: 50%;
  transform: translate(-50%, 50%); /* Center vertically on the point */
  width: 30px;
  height: 4px;
  background: #00ff88;
  box-shadow:
    0 0 10px #00ff88,
    0 0 20px #00ff88;
  border-radius: 2px;
  opacity: 0; /* Hidden by default until activated */
  transition: opacity 0.1s;
}

#pitch-indicator.active {
  opacity: 1;
}

/* Interaction Blocking before Audio Start */
.disabled-interaction {
  pointer-events: none !important;
  opacity: 0.3 !important;
  filter: grayscale(0.8) !important;
  cursor: default !important;
}

.theremin-tick {
  position: absolute;
  left: 0;
  width: 6px; /* Base width */
  height: 1px;
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-50%);
}

.theremin-tick.natural {
  width: 10px; /* Full width */
  background: rgba(255, 255, 255, 0.6);
}

.theremin-tick.root {
  width: 14px; /* Sticks out */
  left: -2px; /* Center relative to bar width */
  height: 2px;
  background: #00ff88;
  box-shadow: 0 0 5px #00ff88;
}

.theremin-tick.accidental {
  width: 4px;
  background: rgba(255, 255, 255, 0.15);
}

/* Sepia Tint Layer */
#chord-tint {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -2;
  pointer-events: none;
  background-color: transparent;
  opacity: 0;
  transition:
    background-color 0.2s ease,
    opacity 0.3s ease;
}

#chord-tint.active {
  opacity: 0.8; /* Adjust for tint strength */
}

/* Background GIF Effect */
#background-fx {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  background: url("images/howl.gif") no-repeat left top;
  background-size: 100% auto;
  opacity: 0;
  transition: opacity 0.2s ease-out;
}

#background-fx.active {
  opacity: 0.4;
}

#background-fx.flipped {
  transform: scaleX(-1);
}
