/**
 * MAIN STYLES
 * Pure Data / Max MSP inspired minimal aesthetics
 */

:root {
  /* Colors */
  --bg-color: #e8e8e8;
  --card-bg: #ffffff;
  --text-color: #000000;
  --border-color: #999999;
  --active-color: #000000;
  --input-color: #e74c3c;
  --output-color: #f39c12;
  --font-main: "JetBrains Mono", monospace;

  /* Layout dimensions */
  --keyboard-max-width: 840px;
  --keyboard-height: 150px;
  --keyboard-white-key-width: 40px;
  --keyboard-black-key-width: 28px;
  --keyboard-black-key-height: 100px;
  --module-min-height: 120px;

  /* Spacing */
  --gap-xs: 0.25rem;
  --gap-sm: 0.5rem;
  --gap-md: 0.75rem;
  --gap-lg: 1rem;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.4;
  overflow-x: hidden;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Checkbox and Radio Button Styling */
input[type="checkbox"],
input[type="radio"] {
  accent-color: #000000;
}

/* Header */
header {
  background: var(--card-bg);
  border-bottom: 2px solid var(--border-color);
  padding: 1.5rem 1rem;
  text-align: center;
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

header h1 a {
  color: #1a0dab;
  text-decoration: underline;
}

header h1 a:hover {
  color: #1a0dab;
  text-decoration: underline;
}

/* Main Layout */
main {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 120px);
}

.section {
  margin-bottom: 2rem;
  display: flex;
  justify-content: center;
  width: 100%;
  overflow-x: hidden;
}

.section-content {
  background: var(--card-bg);
  border: 2px solid var(--border-color);
  padding: 1.5rem;
  box-sizing: border-box;
  --scale-factor: 1;
  transform-origin: top center;
  transform: scale(var(--scale-factor));
  width: calc(100% / var(--scale-factor));
  max-width: calc(var(--keyboard-max-width) / var(--scale-factor));
  margin: 0 auto;
  /* Hardware acceleration for smooth scaling */
  will-change: transform;
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
}

.section h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  color: var(--text-color);
  font-weight: 700;
}

/* Compact BTAS Parameters & Clamp */
.compact-params {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--gap-lg);
  max-width: var(--keyboard-max-width);
  margin-left: auto;
  margin-right: auto;
}

.param-group {
  display: flex;
  gap: 2px;
}

.param-group-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

/* Unified Button Styles */
.param-btn,
#chord-names-module .name-btn,
#degrees-module .degree-btn {
  padding: 0.5rem 0.75rem;
  background: white;
  border: 1px solid var(--border-color);
  cursor: pointer;
  font-weight: normal;
  text-align: center;
  font-family: var(--font-main);
}

.param-btn {
  height: 35px;
  padding: 0 0.5rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.param-btn[data-voicing] {
  width: 35px;
  padding: 0;
}

#chord-names-module .name-btn,
#degrees-module .degree-btn {
  padding: 0.3rem;
  font-size: 0.7rem;
}

.param-btn:hover,
#chord-names-module .name-btn:hover,
#degrees-module .degree-btn:hover {
  background: #f0f0f0;
}

.param-btn:hover {
  border-color: var(--active-color);
}

.param-btn.active,
#chord-names-module .name-btn.active,
#degrees-module .degree-btn.active {
  background: var(--active-color);
  color: white;
  border-color: var(--active-color);
}

/* Keyboard Container */
.keyboard-module {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: var(--keyboard-max-width);
  margin: 0 auto;
}

.keyboard-container {
  position: relative;
  min-height: var(--keyboard-height);
  margin: var(--gap-lg) 0;
  width: 100%;
}

/* Piano Keyboard */
.piano-keyboard {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  height: var(--keyboard-height);
  position: relative;
  user-select: none;
  width: 100%;
  max-width: var(--keyboard-max-width);
  margin: 0 auto;
}

/* Four Modules Grid Under Keyboard */
.modules-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap-sm);
  width: 100%;
  max-width: var(--keyboard-max-width);
  margin-top: var(--gap-lg);
}

.module {
  background: white;
  border: 1px solid var(--border-color);
  padding: var(--gap-sm);
  min-height: var(--module-min-height);
}

.module h3 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-bottom: var(--gap-sm);
  padding-bottom: var(--gap-xs);
  border-bottom: 1px solid var(--border-color);
  color: var(--text-color);
}

/* Unified Label/Value Styles */
#parameters-module label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  margin-bottom: 0.2rem;
  font-weight: normal;
  color: var(--text-color);
}

#parameters-module .value,
#chord-info .value {
  font-family: var(--font-main);
  font-weight: 600;
  color: var(--text-color);
}

#chord-info .value {
  font-size: inherit;
}

/* Module-specific styling */
#parameters-module .param-item {
  margin-bottom: 0.5rem;
}

#parameters-module input[type="checkbox"] {
  cursor: pointer;
}

#parameters-module .param-item:last-child {
  margin-bottom: 0;
}

/* Range Sliders - Unified */
input[type="range"] {
  width: 100%;
  height: 2px;
  background: var(--border-color);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  background: var(--text-color);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--active-color);
}

input[type="range"]::-moz-range-thumb {
  width: 10px;
  height: 10px;
  background: var(--text-color);
  cursor: pointer;
  margin-bottom: 0;
}

#chord-names-module .name-grid,
#degrees-module .degree-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap-xs);
}

/* Chord Info Module (minimal, full width) */
.info-module {
  width: 100%;
  max-width: var(--keyboard-max-width);
  margin-top: var(--gap-sm);
  background: white;
  border: 1px solid var(--border-color);
  padding: var(--gap-sm);
}

#chord-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
}

#chord-info .info-item {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#chord-info .info-item-options {
  order: -1;
}

#chord-info .label {
  color: #666;
  font-weight: normal;
}

#chord-info .info-item-options .value {
  min-width: 2ch;
  text-align: right;
}

/* MIDI Modules Container */
.midi-modules-container {
  width: 100%;
  max-width: var(--keyboard-max-width);
  margin-top: var(--gap-sm);
  display: flex;
  gap: var(--gap-sm);
}

.midi-module {
  flex: 1;
  background: white;
  border: 1px solid var(--border-color);
  padding: var(--gap-sm);
}

#midi-from-module,
#midi-to-module {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
}

#midi-from-module label,
#midi-to-module label {
  color: #666;
  font-weight: normal;
}

#midi-from-module select,
#midi-to-module select {
  flex: 1;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-color);
  background: white;
  font-family: var(--font-main);
  font-size: 0.75rem;
  cursor: pointer;
}

#midi-from-module .midi-status,
#midi-to-module .midi-status {
  color: #999;
  font-size: 0.7rem;
}

#chord-info .value {
  font-family: var(--font-main);
  font-weight: 600;
  color: var(--text-color);
}

.key {
  position: relative;
  cursor: pointer;
  transition: none;
  border: 1px solid #000;
}

.key.white {
  width: var(--keyboard-white-key-width);
  height: var(--keyboard-height);
  background: white;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
}

.key.black {
  width: var(--keyboard-black-key-width);
  height: var(--keyboard-black-key-height);
  background: #333;
  z-index: 2;
  margin: 0 -14px;
  align-self: flex-start;
}

/* Key States */
.key.white:hover {
  background: #f0f0f0;
}

.key.black:hover {
  background: #444;
}

.key.white.pressed {
  background: #e0e0e0;
}

.key.black.pressed {
  background: #555;
}

/* Input note - Red */
.key.white.input {
  background: #e74c3c;
}

.key.black.input {
  background: #e74c3c;
}

/* Harmonized notes - Yellow/Gold */
.key.white.active {
  background: #f39c12;
}

.key.black.active {
  background: #f39c12;
}

.key.input.pale {
  background: #f4a998;
}

.key.active.pale {
  background: #f8c975;
}

.key.active.double {
  background: #00bcd4;
}

.key.active.double.pale {
  background: #7ddcea;
}

/* Key Signature Text */
.key-signature {
  position: absolute;
  bottom: 50%;
  left: 50%;
  transform: translate(-50%, 50%) rotate(-90deg);
  font-size: 0.8rem;
  font-weight: bold;
  color: #000;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

/* Modes Module - Multi-row Layout */
#modes-module {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#modes-module .mode-group {
  display: flex;
  gap: 0.5rem;
}

#modes-module label {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0;
  font-size: 0.7rem;
  white-space: nowrap;
}

#modes-module input[type="checkbox"],
#modes-module input[type="radio"] {
  margin-right: 0.25rem;
  cursor: pointer;
}

/* ===========================
   RESPONSIVE STYLES
   =========================== */

/* Responsive Design - scale to fit with zoom for compact view */
@media (max-width: 900px) {
  .section-content {
    --scale-factor: 0.85;
  }
}

@media (max-width: 768px) {
  header h1 {
    font-size: 1.6rem;
  }

  main {
    padding: 0 0.5rem;
  }

  .section-content {
    padding: 1rem;
    --scale-factor: 0.7;
  }
}

@media (max-width: 600px) {
  main {
    padding: 0 0.25rem;
  }

  .section-content {
    padding: 0.75rem;
    --scale-factor: 0.55;
  }
}

/* INFO PANEL */
.usage-info {
  width: 100%;
  max-width: var(--keyboard-max-width);
  margin-top: var(--gap-sm);
  padding: var(--gap-sm);
  background: white;
  border: 1px solid var(--border-color);
  font-size: 0.8125rem;
  line-height: 1.6;
}

.usage-info summary {
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.usage-info .info-content {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  margin-top: var(--gap-sm);
}

.info-group {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
}

.info-group + .info-group {
  margin-top: var(--gap-sm);
}

.usage-info span {
  display: block;
  font-size: 0.75rem;
}

.usage-info code {
  background: #f5f5f5;
  padding: 0.125rem 0.375rem;
  border-radius: 2px;
  font-size: 0.75rem;
  border: 1px solid var(--border-color);
}
