html, body, #app-wrapper, .main-content {
  height: 100%; min-height: 0; min-width: 0;
  margin: 0; padding: 0; box-sizing: border-box;
}

#app-wrapper { 
  display: flex; 
  flex-direction: column; 
  height: 100vh; 
}

.controls-bar {
  width: 100vw;
  box-sizing: border-box;
  padding: 1vmin;
  background: #001f3f; /* Default color */
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  gap: 1vw;
  border-bottom: 1px solid #001a33;
  z-index: 10;
  flex-shrink: 0;
  flex-grow: 0;
  flex-basis: auto;
  transition: background-color 0.4s ease, border-color 0.4s ease;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 1vmin;
  justify-content: center;
  align-items: stretch;
  flex: 1 1 0;
  min-width: 0;
}

.main-content {
  flex: 1 1 0;
  display: flex; 
  flex-direction: column;
  min-height: 0; 
  min-width: 0; 
  height: 100%;
  overflow: hidden; 
  position: relative;
  margin-top: 1vmin; /* Add space between menu and grid */
}

.proportional-grid-wrapper {
  flex: 1 1 0;
  min-height: 0; 
  min-width: 0;
  display: flex; 
  align-items: center; 
  justify-content: center;
  position: relative; 
  width: 100vw; 
  overflow: hidden;
  transition: transform 0.3s ease-out;
}

.grid {
  position: relative;
  width: 100%; 
  height: 100%;
}

.cell, .note-button {
  border-radius: 1vmin;
  position: absolute;
  display: flex; 
  justify-content: center; 
  align-items: center;
  font-weight: bold;
  color: white;
  user-select: none;
  transition: transform 0.1s, background-color 0.3s, font-size 0.2s, color 0.3s;
  outline: none;
  min-width: 0; 
  min-height: 0;
  background: transparent;
  z-index: 1;
  font-family: 'EB Garamond', Garamond, 'Times New Roman', Times, serif;
  letter-spacing: 0.02em;
  text-shadow: 1px 1px 3px rgba(0,0,0,0.2);
}

.note-button { 
  z-index: 2; 
}

.active { 
  transform: scale(1.30); 
}

.control-area {
  outline: none;
  border-radius: 0.8vmin;
  display: flex; 
  align-items: center; 
  justify-content: center;
  font-size: clamp(1.1rem, min(3vw, 3vh, 2em), 2em);
  padding: 0.3em 1em;
  background: #fff;
  color: #333;
  white-space: nowrap;
  margin: 0;
  font-family: inherit;
  transition: background-color 0.3s, color 0.3s;
  cursor: pointer;
  border: 1px solid #ddd;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.scale-control {
  padding: 0.3em 0.5em;
}

.scale-dropdown {
  background: transparent;
  border: none;
  font-size: inherit;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  outline: none;
  padding: 0;
  margin: 0;
  text-align: center;
  text-align-last: center; /* For Firefox */
  width: 100%;
}
select.scale-dropdown {
  -moz-appearance: none;
  -webkit-appearance: none;
  appearance: none;
}

.control-area.selected {
  box-shadow: 0 0 0 0.6vmin #444a, 0 1px 8px #0002;
  background: #ffff;
}

.keyboard-button.active-control {
  background-color: #007AFF;
  color: white;
}

.arrow {
  cursor: pointer;
  padding: 0.2em 0.5em;
  user-select: none;
  font-size: 1.2em;
  font-family: inherit;
}

.cell img.solfege-img {
  max-width: 80%;
  max-height: 80%;
  width: auto;
  height: auto;
  display: block;
  pointer-events: none;
  user-select: none;
  margin: auto;
  background: transparent;
}

/* Chord toggle button (Note/S) in grid cell */
.chord-toggle-btn {
  padding: 0;
  margin: 0;
  background: transparent;
  border: none;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2em, 6vw, 2em);
  line-height: 1;
  overflow: hidden;
  font-family: 'EB Garamond', Garamond, 'Times New Roman', Times, serif;
  font-weight: bold;
  color: #222;
  cursor: pointer;
  outline: none;
  transition: background 0.15s, color 0.15s, font-size 0.15s;
}

.chord-toggle-btn .music-symbol {
  font-size: 1em;
  line-height: 1;
  vertical-align: middle;
  display: inline-block;
  max-width: 100%;
  max-height: 100%;
  text-align: center;
}

.chord-toggle-btn:focus {
  outline: 2px solid #007AFF;
  background: #f4f8ff;
}

/* Smaller font for keyboard binding text */
.keybinding-text {
  font-size: 0.71em;
  font-weight: normal;
  letter-spacing: 0.02em;
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.5);
  animation: fadeIn 0.3s;
}

.modal-content {
  background-color: #fefefe;
  margin: 10% auto;
  padding: 20px;
  border: 1px solid #888;
  width: 80%;
  max-width: 650px;
  border-radius: 10px;
  position: relative;
  animation: slideIn 0.3s;
}

.close-button {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  position: absolute;
  top: 10px;
  right: 20px;
}

.close-button:hover,
.close-button:focus {
  color: black;
  text-decoration: none;
  cursor: pointer;
}

/* Simulated Keyboard Styles */
#simulated-keyboard {
  padding: 15px;
  background: #d1d5db;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border: 1px solid #bbb;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.5);
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  background: linear-gradient(to bottom, #fcfcfc, #e8e8e8);
  border: 1px solid #b4b4b4;
  border-radius: 4px;
  padding: 10px;
  font-size: 1.1em;
  font-family: Arial, sans-serif;
  flex-grow: 1;
  min-width: 30px;
  text-align: center;
  box-shadow: 0 2px 0px rgba(0,0,0,0.1);
  text-transform: uppercase;
  font-weight: bold;
  color: #333;
  cursor: default;
  transition: all 0.05s ease;
}

.key-spacer {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  pointer-events: none;
}

.key.pressed {
  background: linear-gradient(to top, #fcfcfc, #e8e8e8);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.15);
  transform: translateY(1px);
}

.key-do { background: #FF3B30; color: white; }
.key-re { background: #FF9500; color: white; }
.key-mi { background: #FFCC00; color: white; }
.key-fa { background: #34C759; color: white; }
.key-so { background: #30c0c6; color: white; }
.key-la { background: #007AFF; color: white; }
.key-ti { background: #AF52DE; color: white; }

.key-sharp { background: #990000; color: white; }
.key-flat { background: #000099; color: white; }


@keyframes fadeIn {
  from {opacity: 0;}
  to {opacity: 1;}
}

@keyframes slideIn {
  from {transform: translateY(-50px);}
  to {transform: translateY(0);}
}

@media (max-width: 680px) {
  .modal-content {
    width: 95%;
    margin: 5% auto;
    padding: 10px;
  }

  #simulated-keyboard {
    gap: 3px;
    padding: 10px;
  }
  
  .keyboard-row {
    gap: 3px;
  }

  .key {
    padding: 6px;
    font-size: 0.9em;
    min-width: 20px;
    border-radius: 3px;
  }
}
