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: row; 
  height: 100vh; 
  padding-top: 0;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}

.back-hub-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 9999px;
  margin-bottom: 6px;
  transition: all 0.2s ease;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.back-hub-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  color: #38bdf8;
  border-color: #38bdf8;
}

/* Hide back button when embedded inside an iframe */
.in-iframe .back-hub-btn {
  display: none !important;
}

.app-title {
  font-family: 'Pacifico', cursive;
  margin: 4px 0 4px 0;
  font-size: 24px;
  font-weight: normal;
  color: white;
  text-align: center;
  text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.35);
  user-select: none;
}

.controls-bar {
  width: 270px;
  max-width: 85vw;
  box-sizing: border-box;
  padding: 16px 14px;
  background: #001f3f; /* Default color */
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 16px;
  border-right: 2px solid #001a33;
  z-index: 10;
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  position: relative;
  transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.4s ease, border-color 0.4s ease;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.sidebar-section-title {
  font-family: 'EB Garamond', Garamond, 'Times New Roman', Times, serif;
  font-size: 1.1rem;
  font-weight: bold;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 1px 1px 2px rgba(0,0,0,0.4);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-left: 2px;
}

.control-row {
  display: flex;
  flex-direction: row;
  gap: 8px;
  width: 100%;
  align-items: stretch;
}

.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: 0;
  padding: clamp(16px, 3.5vh, 32px) 16px;
  box-sizing: border-box;
}

.proportional-grid-wrapper {
  flex: 1 1 0;
  min-height: 0; 
  min-width: 0;
  display: flex; 
  align-items: center; 
  justify-content: center;
  position: relative; 
  width: 100%; 
  height: 100%;
  overflow: visible;
  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); 
  z-index: 10;
}

.control-area {
  outline: none;
  border-radius: 8px;
  display: flex; 
  align-items: center; 
  justify-content: center;
  font-size: 1rem;
  padding: 0.45em 0.6em;
  background: #fff;
  color: #333;
  white-space: nowrap;
  margin: 0;
  font-family: inherit;
  transition: background-color 0.3s, color 0.3s, box-shadow 0.2s;
  cursor: pointer;
  border: 1px solid #ddd;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
  box-sizing: border-box;
}

.key-control {
  flex: 1.1;
  min-width: 0;
  display: flex;
  justify-content: space-between;
  padding: 0.4em 0.5em;
}

.key-control #key-name {
  font-weight: bold;
  font-size: 1.15rem;
}

.scale-control {
  flex: 1.4;
  min-width: 0;
  padding: 0.4em 0.5em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scale-dropdown {
  background: transparent;
  border: none;
  font-size: 0.95rem;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  outline: none;
  padding: 0;
  margin: 0;
  text-align: center;
  text-align-last: center; /* For Firefox */
  width: 100%;
  font-weight: 600;
}
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;
}

.timbre-control {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0.5em 0.8em;
}

.timbre-control #waveform-name {
  font-weight: 600;
  text-transform: capitalize;
}

.keyboard-button {
  width: 100%;
  padding: 0.65em 0.8em;
  background-color: #ffffff;
  color: #111;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  border-radius: 8px;
  border: 1px solid #ddd;
  transition: background-color 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.keyboard-button:hover {
  background-color: #f0f4f8;
  box-shadow: 0 3px 6px rgba(0,0,0,0.15);
}

.keyboard-button:active {
  transform: translateY(1px);
}

.share-section {
  margin-top: 2px;
}

.share-button {
  width: 100%;
  padding: 0.65em 0.8em;
  background-color: #ffffff;
  color: #111;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  border-radius: 8px;
  border: 1px solid #ddd;
  transition: background-color 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.share-button:hover {
  background-color: #f0f4f8;
  box-shadow: 0 3px 6px rgba(0,0,0,0.15);
}

.share-button:active {
  transform: translateY(1px);
}

.share-output-container {
  display: flex;
  flex-direction: row;
  gap: 6px;
  margin-top: 8px;
  align-items: center;
  background: rgba(255, 255, 255, 0.95);
  padding: 6px 8px;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
  animation: fadeIn 0.2s ease-in-out;
}

.share-url-input {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.82rem;
  background: #f8f9fa;
  color: #333;
  font-family: inherit;
  outline: none;
  text-overflow: ellipsis;
}

.share-url-input:focus {
  border-color: #007AFF;
  background: #fff;
}

.share-copy-btn {
  padding: 6px 12px;
  background-color: #007AFF;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.2s, transform 0.1s;
}

.share-copy-btn:hover {
  background-color: #0056b3;
}

.share-copy-btn:active {
  transform: scale(0.96);
}

.share-copy-btn.copied {
  background-color: #34C759;
}

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

.arrow {
  cursor: pointer;
  padding: 0.2em 0.4em;
  user-select: none;
  font-size: 1.1em;
  font-family: inherit;
  transition: transform 0.1s;
}

.arrow:hover {
  transform: scale(1.2);
}

.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; }

/* Octave button styles */
.octave-btn {
  width: 100%;
  height: 100%;
  border: 1px solid #ccc;
  border-radius: 1vmin;
  background-color: white;
  color: black;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'EB Garamond', Garamond, 'Times New Roman', Times, serif;
}

.octave-btn.active {
  background-color: #34C759; /* Green */
  color: white;
}

.octave-sup {
  vertical-align: top;
  font-size: 0.75em;
  position: relative;
  top: -0.4em;
}


@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;
  }
}

/* Menu toggle button - anchored on the left sidebar */
.menu-toggle-btn {
  position: fixed;
  top: 15px;
  left: 270px;
  z-index: 10000;
  background-color: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-left: none;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  padding: 8px 10px;
  cursor: pointer;
  box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.18);
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.3s ease, transform 0.2s ease;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-toggle-btn:hover {
  background-color: rgba(255, 255, 255, 1);
  transform: scale(1.05);
}

.menu-toggle-btn:focus {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.arrow-icon {
  display: inline-block;
  font-size: 13px;
  color: #333;
  line-height: 1;
}

/* Hide the controls bar when menu is collapsed */
.menu-hidden .controls-bar {
  margin-left: -270px;
  opacity: 0;
  pointer-events: none;
}

.menu-hidden .menu-toggle-btn {
  left: 0;
  border-left: none;
}

@media (max-width: 550px) {
  .controls-bar {
    width: 230px;
  }
  .menu-toggle-btn {
    left: 230px;
  }
  .menu-hidden .controls-bar {
    margin-left: -230px;
  }
}
