/* ===========================
   Unified Arpeggiator Styling
   =========================== */

:root {
  --primary: #A0458D;
  --secondary: #F17F33;
  --success: #28a745;
  --info: #FCD9C3;
  --warning: #ffc107;
  --danger: #E22D3F;
  --light: #D8D0D7;
  --dark: #0C0A0A;
  --white: #fff;
  --gray: #6c757d;
  --gray-light: #f5f5f5;
  --gray-border: #e0e0e0;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --transition: all 0.3s ease;
}

/* ===== RESET & BASE ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-family: var(--font-family);
  line-height: 1.15;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: #212529;
  background-color: var(--white);
  margin: 0;
  padding: 0;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 0.5rem 0;
  font-weight: 600;
  color: var(--primary);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.75rem; }
h4 { font-size: 1.5rem; }
h5 { font-size: 1.25rem; }
h6 { font-size: 1rem; }

p {
  margin: 0 0 1rem 0;
}

/* ===== CONTAINERS ===== */
.container {
  max-width: 800px;
  margin: 0 auto;
  background: var(--white);
  border-radius: 12px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  padding: 40px;
}

.header {
  text-align: center;
  margin-bottom: 40px;
}

.header h1 {
  color: var(--primary);
  margin-bottom: 10px;
}

.header p {
  color: var(--gray);
  font-size: 1.1em;
}

/* ===== FORMS ===== */
.form-container {
  margin-bottom: 30px;
}

.form-group {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--dark);
  font-size: 1em;
}

.form-group input,
.form-group textarea,
.form-group select {
  padding: 12px;
  border: 2px solid var(--gray-border);
  border-radius: 6px;
  font-size: 1em;
  font-family: inherit;
  transition: var(--transition);
  background-color: var(--white);
  color: #212529;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(160, 69, 141, 0.1);
}

.form-group input:disabled,
.form-group textarea:disabled,
.form-group select:disabled {
  background-color: var(--gray-light);
  cursor: not-allowed;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  display: inline-block;
  text-align: center;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
}

.btn-primary:hover:not(:disabled) {
  background: #8c3878;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(160, 69, 141, 0.3);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--white);
}

.btn-secondary:hover:not(:disabled) {
  background: #d66d2b;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(241, 127, 51, 0.3);
}

.btn-success {
  background: var(--success);
  color: var(--white);
}

.btn-success:hover:not(:disabled) {
  background: #218838;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(40, 167, 69, 0.3);
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.btn-danger:hover:not(:disabled) {
  background: #c41c35;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(226, 45, 63, 0.3);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.btn-outline:hover:not(:disabled) {
  background: var(--primary);
  color: var(--white);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.9em;
}

.btn-lg {
  padding: 14px 32px;
  font-size: 1.1em;
  width: 100%;
}

/* ===== BUTTON GROUPS ===== */
.button-group {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.button-group-vertical {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== ALERTS & MESSAGES ===== */
.message-container {
  display: none;
  padding: 15px;
  border-radius: 6px;
  margin-top: 20px;
  text-align: center;
  font-weight: 500;
}

.message-container.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.message-container.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.message-container.info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

.message-container.warning {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeaa7;
}

/* ===== MODAL / DIALOG ===== */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  animation: fadeIn 0.3s;
}

.modal.show {
  display: block;
}

.modal-content {
  background-color: var(--white);
  margin: 5% auto;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 600px;
  animation: slideIn 0.3s;
}

.close-button {
  color: var(--gray);
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  border: none;
  background: transparent;
  transition: var(--transition);
}

.close-button:hover {
  color: var(--dark);
}

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

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

/* ===== GRID & LAYOUT ===== */
.grid {
  display: grid;
  gap: 15px;
}

.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.grid-4 {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.flex {
  display: flex;
  gap: 10px;
}

.flex-center {
  justify-content: center;
  align-items: center;
}

.flex-between {
  justify-content: space-between;
  align-items: center;
}

.flex-col {
  flex-direction: column;
}

/* ===== PATTERN EDITOR SPECIFIC ===== */
.pattern-details {
  margin-top: 20px;
  padding: 20px;
  background: var(--gray-light);
  border-radius: 6px;
  border-left: 4px solid var(--primary);
}

#patternGrid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-gap: 5px;
  margin-top: 10px;
}

.pattern-row {
  display: flex;
}

.grid-header {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  font-weight: bold;
  margin-bottom: 5px;
  gap: 5px;
}

.pattern-cell {
  padding: 10px;
  border: 1px solid var(--gray-border);
  text-align: center;
  cursor: pointer;
  background: var(--white);
  border-radius: 4px;
  transition: var(--transition);
}

.pattern-cell:hover {
  background: var(--light);
  border-color: var(--primary);
}

.pattern-cell.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

/* ===== HELPER APP SPECIFIC ===== */
.output-container {
  margin-top: 30px;
  padding: 20px;
  background: var(--gray-light);
  border-radius: 6px;
  border-left: 4px solid var(--primary);
}

#patternPreview {
  background: var(--white);
  padding: 15px;
  border-radius: 6px;
  border: 1px solid var(--gray-border);
  overflow-x: auto;
  font-size: 0.9em;
  line-height: 1.4;
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 15px;
  font-family: 'Courier New', monospace;
}

/* ===== ACCOMPANATOR SPECIFIC ===== */
.chord-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 20px;
  width: 100%;
}

.grid-button {
  padding: 10px;
  background: var(--primary);
  color: var(--white);
  border: 2px solid var(--gray-border);
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
  font-weight: 600;
  
  /* Layout and Sizing */
  min-height: 80px;
  height: auto;           /* Allow button to grow if text wraps */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  /* Text Wrapping Fixes */
  white-space: normal;       /* Crucial: allow text to wrap */
  word-wrap: break-word;     /* Break long words */
  overflow-wrap: break-word; /* Modern alias */
}

.grid-button:hover {
  border-color: var(--primary);
  background-color: var(--secondary);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(160, 69, 141, 0.2);
}

.grid-button.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--secondary);
}

.chord-name {
  font-size: 1.2em;
  margin-bottom: 5px;
  color: var(--white);
}

.duration-pattern {
  font-size: 0.85em;
  color: var(--white);
}

.grid-button.active .duration-pattern {
  color: var(--secondary);
}

/* ===== TABLES ===== */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

thead {
  background: var(--primary);
  color: var(--white);
}

th {
  padding: 12px;
  text-align: left;
  font-weight: 600;
}

td {
  padding: 12px;
  border-bottom: 1px solid var(--gray-border);
}

tbody tr:hover {
  background: var(--gray-light);
}

/* ===== INPUTS ===== */
input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--gray-border);
  outline: none;
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: #8c3878;
  box-shadow: 0 0 0 8px rgba(160, 69, 141, 0.1);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
  transition: var(--transition);
}

input[type="range"]::-moz-range-thumb:hover {
  background: #8c3878;
}

/* ===== BADGES & TAGS ===== */
.badge {
  display: inline-block;
  padding: 4px 8px;
  background: var(--gray);
  color: var(--white);
  border-radius: 12px;
  font-size: 0.85em;
  font-weight: 600;
  margin-right: 5px;
}

.badge.primary { background: var(--primary); }
.badge.secondary { background: var(--secondary); }
.badge.success { background: var(--success); }
.badge.danger { background: var(--danger); }
.badge.info { background: var(--info); }

/* ===== UTILITIES ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-muted { color: var(--gray); }
.text-primary { color: var(--primary); }
.text-secondary { color: var(--secondary); }
.text-danger { color: var(--danger); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }

.d-none { display: none; }
.d-block { display: block; }
.d-flex { display: flex; }
.d-grid { display: grid; }

.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }

.rounded { border-radius: 6px; }
.rounded-lg { border-radius: 12px; }
.rounded-full { border-radius: 50%; }

.shadow { box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); }
.shadow-md { box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); }
.shadow-lg { box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .container {
    padding: 20px;
  }

  h1 { font-size: 2rem; }
  h2 { font-size: 1.5rem; }
  h3 { font-size: 1.25rem; }

  .button-group {
    flex-direction: column;
  }

  .button-group .btn {
    width: 100%;
  }

  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .chord-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-content {
    width: 95%;
    margin: 20% auto;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 0.95rem;
  }

  .container {
    padding: 15px;
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }

  .header {
    margin-bottom: 20px;
  }

  .form-group {
    margin-bottom: 15px;
  }

  .btn {
    padding: 10px 16px;
    font-size: 0.9em;
  }

  #patternPreview {
    max-height: 300px;
    font-size: 0.85em;
  }
}
