/* ============================================================
   MODE CHART  —  styles.css
   ============================================================ */

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design tokens ───────────────────────────────────────── */
:root {
  --bg:          #050610;
  --surface:     rgba(255, 255, 255, 0.055);
  --surface-2:   rgba(255, 255, 255, 0.085);
  --surface-3:   rgba(255, 255, 255, 0.115);
  --border:      rgba(255, 255, 255, 0.10);
  --border-hi:   rgba(255, 255, 255, 0.22);
  --text:        #d8e8ff;
  --text-sub:    #7888be;
  --text-dim:    #3c4468;
  --text-meta:   #5868a0;
  --radius-sm:   5px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --font:        'Inter', system-ui, -apple-system, sans-serif;
  --transition:  150ms ease;

  /* Per-mode accent colours */
  --c-ionian:     #f06b6b;
  --c-dorian:     #f0a050;
  --c-phrygian:   #e0d050;
  --c-lydian:     #58c970;
  --c-mixolydian: #50aaee;
  --c-aeolian:    #9060e8;
  --c-locrian:    #d458e8;

  /* Interactive accent & key-active */
  --accent:          #88c0ff;
  --key-active-bg:   #88c0ff;
  --key-active-text: #050610;
}

/* ── Global ──────────────────────────────────────────────── */
html { -webkit-font-smoothing: antialiased; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.4;
  min-height: 100dvh;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  outline: none;
}

button:focus-visible {
  outline: 2px solid var(--border-hi);
  outline-offset: 2px;
}

/* ── Header ──────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}

header h1 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--text) 60%, var(--text-sub));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── App wrapper ─────────────────────────────────────────── */
#app {
  max-width: 980px;
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* ── Controls bar (key + global extension) ──────────────── */
.controls {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.75rem 3rem 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.controls__group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.controls__label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-meta);
  min-width: 2.8rem;
}

.controls__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.controls__divider {
  width: 1px;
  align-self: stretch;
  min-height: 1.5rem;
  background: var(--border);
  margin: 0 0.25rem;
}

/* Key buttons */
.key-btn {
  padding: 0.32rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-sub);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition);
}

.key-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-hi);
  color: var(--text);
}

.key-btn.is-active {
  background: var(--key-active-bg);
  border-color: var(--key-active-bg);
  color: var(--key-active-text);
  font-weight: 700;
  box-shadow: 0 0 12px color-mix(in srgb, var(--key-active-bg) 35%, transparent);
}

/* Split enharmonic buttons (C#/Db, F#/Gb) */
.key-btn__sep {
  opacity: 0.35;
  margin: 0 1px;
}

.key-btn__alt {
  /* inactive button: both alts look the same as the button text */
}

/* Active button: dim the unselected alt, keep the selected one full */
.key-btn.is-active .key-btn__alt {
  color: color-mix(in srgb, var(--key-active-text) 32%, transparent);
  font-weight: 500;
}

.key-btn.is-active .key-btn__alt.is-selected {
  color: var(--key-active-text);
  font-weight: 700;
}

/* Extension buttons (global) */
.ext-btn {
  padding: 0.32rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-sub);
  font-size: 0.78rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition);
}

.ext-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-hi);
  color: var(--text);
}

.ext-btn.is-active {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface-2));
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 20%, transparent);
}

/* ── Mode row ────────────────────────────────────────────── */
.mode-row {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition);
}

.mode-row:hover {
  border-color: var(--border-hi);
}

/* Wire mode colour token to each row */
.mode-row[data-mode="Ionian"]     { --mode-color: var(--c-ionian);     }
.mode-row[data-mode="Dorian"]     { --mode-color: var(--c-dorian);     }
.mode-row[data-mode="Phrygian"]   { --mode-color: var(--c-phrygian);   }
.mode-row[data-mode="Lydian"]     { --mode-color: var(--c-lydian);     }
.mode-row[data-mode="Mixolydian"] { --mode-color: var(--c-mixolydian); }
.mode-row[data-mode="Aeolian"]    { --mode-color: var(--c-aeolian);    }
.mode-row[data-mode="Locrian"]    { --mode-color: var(--c-locrian);    }

/* Left column: coloured accent + mode name */
.mode-row__name-wrap {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0.6rem 0.7rem 0;
}

.mode-row__accent {
  width: 4px;
  align-self: stretch;
  background: var(--mode-color, var(--border));
  flex-shrink: 0;
  border-radius: 0 2px 2px 0;
}

.mode-row__name {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--mode-color, var(--text-sub));
  white-space: nowrap;
}

/* Middle: chord buttons */
.mode-row__chords {
  display: grid;
  grid-template-columns: repeat(7, minmax(7rem, 1fr));
  gap: 0.3rem;
  padding: 0.5rem 0.3rem;
  align-items: center;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-width: none;
}

.mode-row__chords::-webkit-scrollbar {
  display: none;
}

.chord-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  padding: 0.45rem 0.2rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background var(--transition), border-color var(--transition),
              box-shadow var(--transition), transform var(--transition);
  cursor: pointer;
  min-width: 0;
  position: relative;
}

.chord-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-hi);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.chord-btn:active {
  transform: translateY(0);
}

.chord-btn.is-active {
  background: color-mix(in srgb, var(--mode-color) 22%, var(--surface-2));
  border-color: var(--mode-color);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--mode-color) 40%, transparent),
              0 4px 14px color-mix(in srgb, var(--mode-color) 20%, transparent);
}

.chord-btn__numeral {
  font-size: 0.62rem;
  color: color-mix(in srgb, var(--text) 38%, transparent);
  line-height: 1;
  font-style: italic;
}

.chord-btn.is-active .chord-btn__numeral {
  color: color-mix(in srgb, var(--mode-color) 90%, #fff);
}

.chord-btn__symbol {
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  text-align: center;
  line-height: 1.25;
}

.chord-btn.is-active .chord-btn__symbol {
  color: var(--mode-color);
}

/* (per-row ext buttons removed — extension is now global) */

/* ── Chord info panel ────────────────────────────────────── */
.chord-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-height: 3rem;
}

.chord-info__left {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 9rem;
}

.chord-info__numeral {
  font-size: 0.72rem;
  font-style: italic;
  color: var(--text-meta);
}

.chord-info__symbol {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.chord-info__right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  border-left: 1px solid var(--border);
  padding-left: 1rem;
}

.chord-info__mode {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  white-space: nowrap;
}

.chord-info__notes {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-sub);
  letter-spacing: 0.03em;
}

.chord-info__hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-style: italic;
  margin-left: auto;
}

/* Hide hint once a chord is selected */
.chord-info:has(.chord-info__symbol:not(:empty)) .chord-info__hint {
  display: none;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 700px) {
  .controls {
    gap: 0.4rem 0.6rem;
  }

  .controls__divider {
    display: none;
  }

  .mode-row {
    grid-template-columns: 6rem 1fr;
  }

  .mode-row__chords {
    gap: 0.2rem;
    padding: 0.4rem 0.3rem;
  }

  .chord-btn__symbol {
    font-size: 0.72rem;
  }
}

/* Mobile: stack name above chords so 7 cells fill full width */
@media (max-width: 520px) {
  #app {
    padding: 0.75rem 0.5rem 2rem;
    gap: 0.4rem;
  }

  .controls {
    padding: 0.5rem 0.6rem;
  }

  .mode-row {
    display: flex;
    flex-direction: column;
  }

  .mode-row__name-wrap {
    padding: 0.35rem 0.6rem 0.35rem 0;
    border-bottom: 1px solid var(--border);
  }

  .mode-row__name {
    font-size: 0.62rem;
  }

  .mode-row__chords {
    grid-template-columns: repeat(7, minmax(5.5rem, 1fr));
    gap: 0.18rem;
    padding: 0.35rem 0.3rem;
  }

  .chord-btn {
    padding: 0.35rem 0.25rem;
  }

  .chord-btn__numeral {
    font-size: 0.55rem;
  }

  .chord-btn__symbol {
    font-size: 0.68rem;
    white-space: nowrap;
  }
}

/* ── Audio panel ─────────────────────────────────────────── */
.audio-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  padding: 0.55rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.audio-panel__group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.audio-panel__history {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;           /* force own row in the wrapping panel */
  border-top: 1px solid var(--border);
  padding-top: 0.45rem;
  flex-wrap: wrap;
}

/* Audio on/off toggle */
.audio-toggle-btn {
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 600;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition);
}

.audio-toggle-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-hi);
  color: var(--text-sub);
}

.audio-toggle-btn.is-on {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface-2));
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

/* History chips */
.history-chips {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  flex: 1;
}

.history-chip {
  padding: 0.28rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-sub);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  min-width: 3.2rem;
  text-align: center;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition);
}

.history-chip:not(.is-empty):hover {
  background: var(--surface-3);
  border-color: var(--border-hi);
  color: var(--text);
}

.history-chip.is-empty {
  color: var(--text-dim);
}

.history-chip.is-playing {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface-2));
  border-color: var(--accent);
  color: var(--accent);
}

/* Sequence play button */
.history-play-btn {
  padding: 0.28rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-sub);
  font-size: 0.7rem;
  font-weight: 700;
  transition: background var(--transition), border-color var(--transition),
              color var(--transition);
}

.history-play-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-hi);
  color: var(--text);
}

.history-play-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.history-clear-btn {
  color: #e07070;
  border-color: color-mix(in srgb, #e07070 35%, var(--border));
}

.history-clear-btn:hover {
  background: color-mix(in srgb, #e07070 12%, var(--surface-2));
  border-color: #e07070;
  color: #e07070;
}

/* ── Help button ─────────────────────────────────────────────────────────── */

.help-btn {
  position: absolute;
  top: 50%;
  right: 0.75rem;
  transform: translateY(-50%);
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition),
    color var(--transition);
}

.help-btn:hover {
  background: var(--surface-3);
  border-color: var(--border-hi);
  color: var(--text);
}

/* ── Help modal ──────────────────────────────────────────────────────────── */

.help-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.help-modal-backdrop.is-open {
  display: flex;
}

.help-modal {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.help-modal__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 0.8rem;
  line-height: 1;
  transition: background var(--transition), color var(--transition);
}

.help-modal__close:hover {
  background: var(--surface-3);
  color: var(--text);
}

.help-modal__title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 1.25rem;
  padding-right: 2rem;
}

.help-modal__body section {
  margin-bottom: 1.1rem;
}

.help-modal__body section:last-child {
  margin-bottom: 0;
}

.help-modal__body h3 {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.4rem;
}

.help-modal__body p,
.help-modal__body li {
  font-size: 0.82rem;
  color: var(--text-sub);
  line-height: 1.55;
  margin: 0;
}

.help-modal__body ul {
  margin: 0;
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.help-modal__body strong {
  color: var(--text);
  font-weight: 600;
}

/* ── Glassmorphism: cosmic gradient + frosted panels ────────── */

body {
  background:
    radial-gradient(ellipse 80% 55% at 15% 5%,  rgba(60, 100, 255, 0.15) 0%, transparent 65%),
    radial-gradient(ellipse 60% 45% at 85% 90%, rgba(140, 60, 255, 0.13) 0%, transparent 65%),
    #050610;
  background-attachment: fixed;
}

header,
.controls,
.mode-row,
.chord-info,
.audio-panel {
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
