/* ═══════════════════════════════════════════════════════════════════
   circle-of-fifths.css — Circle of Fifths widget on the Theory page
   Two-ring SVG (major outer, relative minor inner) + info panel
   ═══════════════════════════════════════════════════════════════════ */

/* ── Section container & toggle ──────────────────────────────────── */
.cof-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 14px);
  box-shadow: var(--shadow);
  margin-top: var(--panel-gap, 20px);
  overflow: hidden;
  position: relative;        /* anchor for the .section-top-btn */
}

.cof-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-3, 12px) var(--sp-4, 16px);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.cof-header-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.cof-toggle-icon {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  padding: 0 8px;
  border-radius: var(--r-sm, 6px);
  background: var(--surface-2, #f5f4f0);
  border: 1px solid var(--border);
  color: var(--text-muted, #888);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.cof-header:hover .cof-toggle-icon {
  background: var(--surface, #fff);
  border-color: var(--accent, #e8874a);
  color: var(--accent, #e8874a);
}
.cof-toggle-open .cof-toggle-icon {
  background: rgba(232, 135, 74, 0.10);
  border-color: var(--accent, #e8874a);
  color: var(--accent, #e8874a);
}

/* ── Collapsible body ────────────────────────────────────────────── */
.cof-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease;
}
.cof-body.cof-open {
  /* Large enough that any combination of two circles + full info panel
     (parent-scale switcher + diatonic + sec doms + outside + outside-ness
     explorer + modes) never gets clipped at narrow viewports where the
     panel grows tall.  Closing transitions back to 0 cleanly. */
  max-height: 5000px;
}

/* Default layout: info BELOW the circles.  Row layout (info-on-the-right)
   only kicks in at very wide viewports — see the @media block at the
   bottom of this file. */
.cof-content {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4, 16px);
  padding: 0 var(--sp-4, 16px) var(--sp-4, 16px);
  align-items: stretch;
  min-width: 0;
  overflow: hidden;     /* nothing inside should ever paint past the card */
}

/* ── Dual-circle row ─────────────────────────────────────────────── */
.cof-circles {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4, 16px);
  justify-content: center;
  align-items: flex-start;
}

.cof-circle-wrap {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.cof-circle-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, #888);
}

/* ── SVG wrapper ─────────────────────────────────────────────────── */
.cof-svg-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
}

.cof-svg {
  width: 360px;
  height: 360px;
  max-width: 100%;
}

/* ── SVG ring styles ─────────────────────────────────────────────── */
.cof-bg-ring {
  fill: var(--surface-2, #f5f4f0);
  stroke: var(--border);
  stroke-width: 1.5;
}
[data-theme="dark"] .cof-bg-ring {
  fill: var(--surface-2, #2a2a2a);
}

.cof-mid-ring {
  fill: none;
  stroke: var(--border);
  stroke-width: 1;
}

.cof-center {
  fill: var(--surface);
  stroke: var(--border);
  stroke-width: 1;
}

.cof-center-text {
  font-size: 14px;
  font-weight: 700;
  fill: var(--text-muted, #888);
  font-family: var(--font-mono, 'DM Mono', monospace);
  letter-spacing: 0.05em;
}

.cof-wedge-line {
  stroke: var(--border);
  stroke-width: 0.8;
}

/* ── Wedge hit areas ─────────────────────────────────────────────── */
.cof-wedge {
  fill: transparent;
  cursor: pointer;
  transition: fill 0.15s ease;
}
.cof-wedge:hover {
  fill: rgba(232, 135, 74, 0.08);
}
[data-theme="dark"] .cof-wedge:hover {
  fill: rgba(232, 135, 74, 0.12);
}

/* Active (selected) key */
.cof-wedge.cof-active {
  fill: rgba(232, 135, 74, 0.25);
}
[data-theme="dark"] .cof-wedge.cof-active {
  fill: rgba(232, 135, 74, 0.30);
}

/* Relative key (minor↔major) */
.cof-wedge.cof-relative {
  fill: rgba(91, 143, 217, 0.20);
}
[data-theme="dark"] .cof-wedge.cof-relative {
  fill: rgba(91, 143, 217, 0.25);
}

/* Neighboring keys (one fifth up/down) */
.cof-wedge.cof-neighbor {
  fill: rgba(74, 190, 130, 0.15);
}
[data-theme="dark"] .cof-wedge.cof-neighbor {
  fill: rgba(74, 190, 130, 0.20);
}

/* ── Labels ──────────────────────────────────────────────────────── */
.cof-label {
  font-family: var(--font-sans, 'DM Sans', sans-serif);
  fill: var(--text);
}

.cof-label-major {
  font-size: 15px;
  font-weight: 700;
}

.cof-label-minor {
  font-size: 11px;
  font-weight: 500;
  fill: var(--text-muted, #888);
}

.cof-label-alt {
  font-size: 9px;
  font-weight: 400;
  fill: var(--text-3, #aaa);
}

/* Active/relative/neighbor text highlights */
.cof-text-active {
  fill: var(--accent, #e8874a);
  font-weight: 800;
}

.cof-text-relative {
  fill: #5b8fd9;
}

.cof-text-neighbor {
  fill: #4abe82;
}

/* ── Info panel ──────────────────────────────────────────────────── */
.cof-info {
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding: var(--sp-2, 8px) 0;
  box-sizing: border-box;
}

.cof-info-empty {
  color: var(--text-muted, #888);
  font-size: 0.92rem;
  margin: 0;
  padding: var(--sp-4, 16px) 0;
}

.cof-info-header {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3, 12px);
  margin-bottom: var(--sp-3, 12px);
  padding-bottom: var(--sp-2, 8px);
  border-bottom: 1px solid var(--border);
}

.cof-info-key {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}

.cof-info-sig {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted, #888);
  font-family: var(--font-mono, 'DM Mono', monospace);
}

.cof-info-row {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2, 8px);
  padding: 4px 0;
  font-size: 0.92rem;
  line-height: 1.5;
}

.cof-info-label {
  flex-shrink: 0;
  font-weight: 600;
  color: var(--text-muted, #888);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cof-info-value {
  color: var(--text);
}

/* ── Tritone-sub wedge tint (no floating badge — softer than a marker) ─ */
.cof-wedge.cof-tritone {
  fill: rgba(170, 110, 200, 0.10);
}
[data-theme="dark"] .cof-wedge.cof-tritone {
  fill: rgba(170, 110, 200, 0.18);
}

/* ── Rotor (rotates the wedges/labels into selection) ─────────────── */
.cof-rotor,
.cof-label-group {
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Meta info (definition list — relative, sig, neighbours, TT sub) ── */
.cof-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: var(--sp-3, 12px);
  row-gap: 6px;
  margin: 0 0 var(--sp-4, 16px) 0;
  padding-bottom: var(--sp-3, 12px);
  border-bottom: 1px solid var(--border);
}
.cof-meta dt {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted, #888);
  align-self: center;
}
.cof-meta dd {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text);
}
.cof-tt-name {
  color: rgba(170, 110, 200, 0.95);
  font-weight: 600;
  font-family: var(--font-mono, 'DM Mono', monospace);
}

/* ── Section blocks (Diatonic / Sec doms / Outside / Modes) ────────── */
.cof-section-block {
  margin-top: var(--sp-3, 12px);
  min-width: 0;          /* let the block shrink to its container */
  max-width: 100%;
  box-sizing: border-box;
}
.cof-section-block:first-of-type {
  margin-top: 0;
}
.cof-section-title {
  margin: 0 0 var(--sp-2, 8px) 0;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, #888);
}
.cof-section-tonic,
.cof-section-sub {
  margin-left: 4px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
  font-size: 0.9em;
  color: var(--text-3, #aaa);
}

/* ── Chord grid — equal-width, vertically stacked degree + name ────── */
.cof-chord-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}
.cof-chord {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--r-sm, 6px);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2, #f5f4f0);
  border: 1px solid var(--border);
}
[data-theme="dark"] .cof-chord {
  background: var(--surface-2, #2a2a2a);
}
.cof-chord-stacked {
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 8px 8px;
  text-align: center;
  min-height: 48px;
}
.cof-chord-degree {
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted, #888);
  letter-spacing: 0.02em;
}
.cof-chord-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  font-family: var(--font-mono, 'DM Mono', monospace);
}
.cof-chord-maj { border-color: rgba(232, 135, 74, 0.35); }
.cof-chord-min { border-color: rgba(91, 143, 217, 0.35); }
.cof-chord-dim { border-color: rgba(180, 80, 80, 0.35); }
.cof-chord-dom { border-color: rgba(170, 110, 200, 0.35); }

/* Coloured top accent on stacked chips so quality is readable at a glance */
.cof-chord-stacked.cof-chord-maj { box-shadow: inset 0 3px 0 rgba(232, 135, 74, 0.55); }
.cof-chord-stacked.cof-chord-min { box-shadow: inset 0 3px 0 rgba(91, 143, 217, 0.55); }
.cof-chord-stacked.cof-chord-dim { box-shadow: inset 0 3px 0 rgba(180, 80, 80, 0.55); }
.cof-chord-stacked.cof-chord-dom { box-shadow: inset 0 3px 0 rgba(170, 110, 200, 0.55); }

button.cof-chord {
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: background 0.12s, border-color 0.12s, transform 0.08s, box-shadow 0.12s;
}
button.cof-chord-stacked { text-align: center; }
button.cof-chord:hover {
  background: var(--surface-3, var(--surface-2, #ececec));
  border-color: var(--accent, #e8874a);
}
button.cof-chord:active { transform: translateY(1px); }
button.cof-chord:focus-visible {
  outline: 2px solid var(--accent, #e8874a);
  outline-offset: 2px;
}

/* ── Parallel major/minor toggle (in info header) ─────────────────── */
.cof-parallel-toggle {
  margin-left: auto;
  background: var(--surface-2, #f5f4f0);
  border: 1px solid var(--border);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: var(--r-sm, 6px);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
[data-theme="dark"] .cof-parallel-toggle {
  background: var(--surface-2, #2a2a2a);
}
.cof-parallel-toggle:hover {
  border-color: var(--accent, #e8874a);
  color: var(--accent, #e8874a);
}
.cof-parallel-toggle[aria-pressed="true"] {
  background: rgba(232, 135, 74, 0.15);
  border-color: var(--accent, #e8874a);
  color: var(--accent, #e8874a);
}

/* ── Modes list — "G Ionian" pills, tight 1-space gap, wrap freely ── */
.cof-modes-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.cof-mode {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;                  /* one visual space between tonic and name */
  padding: 4px 8px;
  border-radius: var(--r-sm, 6px);
  font-size: 0.92rem;
}
.cof-mode-current {
  background: rgba(232, 135, 74, 0.12);
}
.cof-mode-name {
  color: var(--text-muted, #888);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.cof-mode-current .cof-mode-name {
  color: var(--accent, #e8874a);
}
.cof-mode-tonic {
  color: var(--text);
  font-weight: 700;
  font-family: var(--font-mono, 'DM Mono', monospace);
}

/* ── Parent-scale switcher (above info header) ─────────────────────── */
.cof-parent-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: var(--sp-3, 12px);
  padding-bottom: var(--sp-2, 8px);
  border-bottom: 1px dashed var(--border);
}
.cof-parent-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, #888);
}
.cof-parent-scale {
  font: inherit;
  font-size: 0.92rem;
  padding: 5px 26px 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 6px);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.cof-parent-scale:hover {
  border-color: var(--accent, #e8874a);
}

/* ── Outside-ness explorer (slider + dynamic chord set) ───────────── */
.cof-outside-explorer {
  background: var(--surface-2, #f5f4f0);
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 6px);
  padding: var(--sp-3, 12px);
  /* Border + 12px padding must fit inside the .cof-info column, not push
     past it at narrow viewports.  box-sizing keeps the total width in check
     and min-width:0 lets the inner chord-grid shrink instead of forcing
     overflow. */
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}
[data-theme="dark"] .cof-outside-explorer {
  background: var(--surface-2, #2a2a2a);
}
.cof-outside-controls {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 var(--sp-3, 12px) 0;
}
.cof-outside-slider {
  width: 100%;
  accent-color: var(--accent, #e8874a);
  height: 4px;
}
.cof-outside-ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 0.72rem;
  color: var(--text-muted, #888);
}
.cof-outside-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: var(--sp-2, 8px);
}
.cof-outside-tier-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
}
.cof-outside-tier-desc {
  font-size: 0.82rem;
  color: var(--text-muted, #888);
  font-style: italic;
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE
   Default layout: info BELOW circles.  At very wide viewports we
   switch to a row layout (circles left, info right).
   ══════════════════════════════════════════════════════════════════ */
@media (min-width: 1400px) {
  .cof-content {
    flex-direction: row;
    align-items: flex-start;
  }
  .cof-circles {
    flex: 0 0 auto;
  }
  .cof-info {
    flex: 1 1 0;
    min-width: 0;
  }
}

/* Narrow: stack the two circles vertically too */
@media (max-width: 820px) {
  .cof-circles {
    flex-direction: column;
    align-items: center;
  }
}

@media (max-width: 580px) {
  .cof-svg {
    width: 300px;
    height: 300px;
  }
  .cof-info-key {
    font-size: 1.3rem;
  }
  .cof-chord {
    padding: 3px 8px;
    font-size: 0.82rem;
  }
  .cof-content {
    padding: 0 var(--sp-2, 8px) var(--sp-3, 12px);
  }
}
