body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #F5EFE6;
  color: #3D2B1F;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
header, footer {
  background: linear-gradient(135deg, #3D2415, #5C3D2E, #8B6914);
  color: #F5EFE6;
  text-align: center;
  padding: 1.2em 0;
}
header {
  position: relative;
}
#install-btn {
  position: absolute;
  right: 1em;
  top: 50%;
  transform: translateY(-50%);
  background: #FAF3E6;
  color: #3D2B1F;
  border: none;
  border-radius: 6px;
  padding: 0.4em 0.8em;
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
}
#install-btn:hover {
  background: #fff;
}
header h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-weight: 400;
  letter-spacing: 0.04em;
  font-size: 1.5em;
  margin: 0;
}
footer small {
  opacity: 0.8;
}
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Collapsible Sections */
.collapsible-section {
  width: 100%;
  max-width: 700px;
  margin: 0.5em auto;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
}

.collapsible-section summary {
  padding: 0.8em 1em;
  background: #f5f5f5;
  cursor: pointer;
  font-weight: 600;
  color: #4b2e83;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  list-style: none;
}

.collapsible-section summary::-webkit-details-marker {
  display: none;
}

.collapsible-section summary::after {
  content: '▶';
  font-size: 0.8em;
  transition: transform 0.2s;
}

.collapsible-section[open] summary::after {
  transform: rotate(90deg);
}

.collapsible-section summary:hover {
  background: #ebebeb;
}

.collapsible-section .section-content {
  padding: 1em;
}

#note-display {
  max-width: 400px;
}
#note-display .section-content {
  text-align: center;
}
#frequency {
  font-size: 2.5em;
  margin-bottom: 0.5em;
}
#string-name {
  font-size: 2em;
  color: #8B6914;
}

#averages {
  margin-top: 1em;
  font-size: 1.1em;
  color: #333;
}
#averages span {
  display: inline-block;
  min-width: 4em;
}

#freq-graph {
  display: block;
  margin: 0 auto;
  background: #FAF3E6;
  border: 1px solid #E8DCC8;
  border-radius: 6px;
}
#config-section {
  max-width: 700px;
}
#config-section .section-content {
  text-align: center;
}
.config-group {
  margin-bottom: 1em;
}
.config-group:last-child {
  margin-bottom: 0;
}
.config-group > label {
  display: block;
  font-weight: 600;
  color: #6B5744;
  margin-bottom: 0.4em;
  font-size: 0.95em;
}
#volume-bar-container {
  width: 100%;
  height: 28px;
  margin: 0.5em 0 1em 0;
  position: relative;
}
#volume-bar-bg {
  width: 100%;
  height: 16px;
  background: #e0e0e0;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}
#volume-bar {
  height: 100%;
  background: #8B6914;
  border-radius: 8px 0 0 8px;
  width: 0%;
  transition: width 0.1s;
}
#threshold-marker {
  position: absolute;
  top: -4px;
  width: 2px;
  height: 24px;
  background: #ff9800;
  left: 20%; /* Default at 20% */
  transition: left 0.1s;
}
/* Input source dropdown */
#input-source {
  font-size: 1em;
  padding: 0.3em 1em;
  margin: 0 0.5em;
  border-radius: 0.3em;
  border: 1px solid #D4C4A8;
  background: #FFFBF5;
  color: #3D2B1F;
}

/* Tuning Grid Layout */
#tuning-table-container {
  max-width: 700px;
}
#tuning-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tuning-string-group {
  border: 1px solid #e0d5c4;
  border-radius: 8px;
  overflow: hidden;
}
.tuning-string-label {
  background: #FAF3E6;
  color: #5C3D2E;
  font-weight: 600;
  font-size: 0.85em;
  padding: 4px 10px;
  border-bottom: 1px solid #e0d5c4;
}
.tuning-notes-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
}
.tuning-note-cell {
  padding: 8px 6px 28px;
  text-align: center;
  border-right: 1px solid #f0e8d8;
  position: relative;
  transition: background 0.2s;
}
.tuning-note-cell:last-child { border-right: none; }
.tuning-note-cell.open-string {
  background: rgba(139,105,20,0.06);
}
.tuning-note-cell.closest {
  background: rgba(139,105,20,0.14);
  box-shadow: inset 0 0 0 2px #C4A35A;
  border-radius: 2px;
}
.tuning-note-name {
  font-weight: 700;
  font-size: 0.95em;
  color: #3D2B1F;
}
.tuning-note-freq {
  font-size: 0.75em;
  color: #888;
  margin-bottom: 4px;
}
.freq {
  font-size: 0.95em;
  color: #888;
}

.proximity-bar {
  width: 120px;
  height: 18px;
  background: linear-gradient(
    to right,
    #e0e0e0 0%,
    #e0e0e0 49%,
    #666 49%,
    #666 51%,
    #e0e0e0 51%,
    #e0e0e0 100%
  );
  border-radius: 9px;
  margin: 0 auto;
  position: relative;
  overflow: visible;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
/* +/- labels under the bar */
.proximity-bar::before,
.proximity-bar::after {
  position: absolute;
  bottom: -16px;
  font-size: 0.9em;
  color: #666;
}
.proximity-bar::before {
  content: '-';
  left: 2px;
}
.proximity-bar::after {
  content: '+';
  right: 2px;
}

.proximity-diff {
  position: absolute;
  bottom: -32px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85em;
  color: #444;
  white-space: nowrap;
}
/* Movable indicator */
.proximity-indicator {
  position: absolute;
  top: 1px;
  width: 6px;
  height: 16px;
  background: #8B6914;
  border-radius: 3px;
  box-shadow: 0 0 2px #2222;
  z-index: 3;
  transition: left 0.15s cubic-bezier(.4,2,.6,1);
  border: 2px solid #fff;
}
.proximity-bar.in-tune .proximity-indicator {
  background: #4A7C2E;
}
.proximity-bar.too-low .proximity-indicator {
  background: #C4A35A;
}
.proximity-bar.too-high .proximity-indicator {
  background: #B8372B;
}

@media (max-width: 600px) {
  .tuning-notes-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===== Dark Mode ===== */
@media (prefers-color-scheme: dark) {
  body {
    background: #1A1510;
    color: #E8DDD0;
  }
  
  header, footer {
    background: linear-gradient(135deg, #1A1510, #2D2418, #5C3D2E);
  }
  
  .collapsible-section {
    background: #2D2418;
    border-color: #4A3928;
  }
  
  .collapsible-section summary {
    background: #3D2B1F;
    color: #C4A35A;
  }
  
  .collapsible-section summary:hover {
    background: #4A3928;
  }
  
  .collapsible-section summary::after {
    color: #8B6914;
  }
  
  #string-name {
    color: #C4A35A;
  }
  
  .config-group > label {
    color: #A89880;
  }
  
  #averages {
    color: #A89880;
  }
  
  #freq-graph {
    background: #2D2418;
    border-color: #4A3928;
  }
  
  #volume-bar-bg {
    background: #3D2B1F;
  }
  
  #volume-bar {
    background: #C4A35A;
  }
  
  #input-source {
    background: #3D2B1F;
    color: #E8DDD0;
    border-color: #5C3D2E;
  }

  #threshold-slider {
    width: 100%;
  }
  
  #tuning-table-container {
    background: #2D2418;
    border-color: #4A3928;
  }
  
  .tuning-string-group {
    border-color: #4A3928;
  }
  .tuning-string-label {
    background: #3D2B1F;
    color: #C4A35A;
    border-bottom-color: #4A3928;
  }
  .tuning-note-cell {
    border-right-color: #3D2B1F;
  }
  .tuning-note-cell.open-string {
    background: rgba(196,163,90,0.08);
  }
  .tuning-note-cell.closest {
    background: rgba(196,163,90,0.18);
    box-shadow: inset 0 0 0 2px #8B6914;
  }
  .tuning-note-name {
    color: #E8DDD0;
  }
  .tuning-note-freq {
    color: #8A7E6B;
  }
  
  .freq {
    color: #8A7E6B;
  }
  
  .proximity-bar {
    background: linear-gradient(
      to right,
      #3D2B1F 0%,
      #3D2B1F 49%,
      #8A7E6B 49%,
      #8A7E6B 51%,
      #3D2B1F 51%,
      #3D2B1F 100%
    );
  }
  
  .proximity-bar::before,
  .proximity-bar::after {
    color: #8A7E6B;
  }
  
  .proximity-diff {
    color: #A89880;
  }
  
  .proximity-indicator {
    background: #C4A35A;
    border-color: #2D2418;
  }
}
