/* ═══════════════════════════════════════════════════════════════════
   theory-advanced.css — 6 collapsible advanced-theory widgets.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Section shell (shared by all 6 widgets) ──────────────────────── */
.thx-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;
}

/* "Top" jump button — sits absolutely-positioned in the section header,
   does not interfere with the section's own collapse toggle.  Used by
   .thx-section, .cof-section, .cofa-section. */
/* TOP + EXPAND chips share every box property (size, padding, border,
   font) so they render pixel-identical.  They live inside a flex
   wrapper at the right edge of each section header — TOP first, caret
   last, with a small gap.  No absolute positioning, so the wrapper
   reflows naturally when the caret label widens (EXPAND → COLLAPSE). */
.section-top-btn,
.thx-caret,
.cofa-caret,
.cof-toggle-icon {
  box-sizing: border-box;
  height: 24px;
}
.section-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.section-top-btn {
  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);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  user-select: none;
}
.section-top-btn:hover {
  background: var(--surface, #fff);
  border-color: var(--accent, #e8874a);
  color: var(--accent, #e8874a);
}
.thx-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: var(--sp-3, 12px) var(--sp-4, 16px);
  cursor: pointer;
  user-select: none;
  background: transparent;
  border: none;
  font: inherit;
  text-align: left;
  color: inherit;
}
.thx-toggle h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}
.thx-toggle .thx-sub {
  color: var(--text-muted, #888);
  font-weight: 400;
  font-size: 0.85em;
  margin-left: 4px;
}
/* Section expand/collapse caret — exact-match chip styling to .section-top-btn
   so the two header buttons render identically (same height, font, weight). */
.thx-caret {
  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;
}
.thx-toggle:hover .thx-caret {
  background: var(--surface, #fff);
  border-color: var(--accent, #e8874a);
  color: var(--accent, #e8874a);
}
.thx-toggle.open .thx-caret {
  background: rgba(232, 135, 74, 0.10);
  border-color: var(--accent, #e8874a);
  color: var(--accent, #e8874a);
}

.thx-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease;
}
.thx-body.open {
  max-height: 5000px;
}
.thx-content {
  padding: 0 var(--sp-4, 16px) var(--sp-4, 16px);
}
.thx-info {
  margin-top: var(--sp-3, 12px);
  font-size: 0.88rem;
  color: var(--text-muted, #888);
  line-height: 1.5;
}
.thx-info strong { color: var(--text); }
.thx-info em { color: var(--accent, #e8874a); font-style: normal; font-weight: 600; }
.thx-empty {
  color: var(--text-muted, #888);
  font-style: italic;
  text-align: center;
  padding: 20px;
}

/* ── Common controls bar — matches site-wide .form-control look ───── */
.thx-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: var(--sp-3, 12px);
  align-items: center;
}
.thx-controls label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, #888);
  font-weight: 600;
}
/* Selects — replicate .form-control: 34px, custom chevron, surface-2 bg */
.thx-controls select {
  height: 34px;
  padding: 0 26px 0 10px;
  font-family: var(--font, var(--font-sans, 'DM Sans', sans-serif));
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-2, #f5f4f0);
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 6px);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23999' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='4,6 8,10 12,6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 11px;
  cursor: pointer;
  transition: border-color 0.18s, box-shadow 0.18s;
}
.thx-controls select:focus {
  outline: none;
  border-color: var(--accent, #e8874a);
  box-shadow: 0 0 0 3px var(--accent-bg, rgba(232,135,74,0.20));
}
.thx-controls select:hover {
  border-color: var(--text-muted, #888);
}

/* Pill buttons — same height as selects, consistent padding */
.thx-controls button {
  height: 34px;
  padding: 0 14px;
  font-family: var(--font, var(--font-sans, 'DM Sans', sans-serif));
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted, #888);
  background: var(--surface-2, #f5f4f0);
  border: 1px solid var(--border);
  border-radius: var(--r-sm, 6px);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.18s;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
.thx-controls button:hover {
  border-color: var(--accent, #e8874a);
  color: var(--text);
}
.thx-controls button:focus-visible {
  outline: none;
  border-color: var(--accent, #e8874a);
  box-shadow: 0 0 0 3px var(--accent-bg, rgba(232,135,74,0.20));
}
.thx-controls button.active {
  background: rgba(232, 135, 74, 0.15);
  border-color: var(--accent, #e8874a);
  color: var(--accent, #e8874a);
  font-weight: 600;
}

/* ════════════════════════════════════════════════════════════════
   1 · TENSION GRID
   ════════════════════════════════════════════════════════════════ */
.thx-tension-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
}
.thx-tt-cell {
  text-align: center;
  padding: 12px 4px;
  border-radius: var(--r-sm, 6px);
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-weight: 700;
  font-size: 0.85rem;
  border: 1px solid var(--border);
}
.thx-tt-chord {
  background: rgba(232,135,74,0.30);
  border-color: var(--accent, #e8874a);
  color: var(--text);
}
.thx-tt-tens {
  background: rgba(91,143,217,0.20);
  border-color: #5b8fd9;
}
.thx-tt-avoid {
  background: rgba(180,80,80,0.18);
  border-color: #b45050;
  text-decoration: line-through;
  color: var(--text-muted, #888);
}
.thx-tt-out {
  background: var(--surface-2, #f5f4f0);
  color: var(--text-3, #aaa);
}

/* ════════════════════════════════════════════════════════════════
   2 · MODAL BRIGHTNESS LADDER
   ════════════════════════════════════════════════════════════════ */
.thx-brightness-ladder {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.thx-mb-row {
  display: grid;
  grid-template-columns: 110px 1fr 220px;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--r-sm, 6px);
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 0.88rem;
}
.thx-mb-row-active {
  background: rgba(232, 135, 74, 0.15);
  border: 1px solid var(--accent, #e8874a);
  font-weight: 700;
}
.thx-mb-name {
  color: var(--text);
}
.thx-mb-bar-wrap {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #5b3a72 0%, #5b8fd9 30%, #4abe82 50%, #c8a85a 65%, #e8874a 85%, #b45050 100%);
}
.thx-mb-pin {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 14px;
  background: var(--text);
  border-radius: 2px;
  pointer-events: none;
  transform: translateX(-50%);
}
.thx-mb-meta {
  color: var(--text-muted, #888);
  font-size: 0.82rem;
  text-align: right;
}
.thx-mb-row-active .thx-mb-meta { color: var(--accent, #e8874a); }

/* ════════════════════════════════════════════════════════════════
   3 · FUNCTIONAL HARMONY DIAGRAM
   ════════════════════════════════════════════════════════════════ */
.thx-fh-svg {
  width: 100%;
  height: 460px;
  background: var(--surface-2, #f5f4f0);
  border-radius: var(--r-md, 10px);
}
[data-theme="dark"] .thx-fh-svg {
  background: var(--surface-2, #2a2a2a);
}
.thx-fh-node-circle {
  fill: var(--surface);
  stroke: var(--border-strong, #c8c5be);
  stroke-width: 1.5;
}
.thx-fh-node-tonic .thx-fh-node-circle { stroke: var(--accent, #e8874a); stroke-width: 2.5; fill: rgba(232,135,74,0.10); }
.thx-fh-node-dom   .thx-fh-node-circle { stroke: #5b8fd9;                 stroke-width: 2.5; fill: rgba(91,143,217,0.10); }
.thx-fh-node-sub   .thx-fh-node-circle { stroke: #4abe82;                 stroke-width: 2.5; fill: rgba(74,190,130,0.10); }
.thx-fh-node-deg {
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 11px;
  font-weight: 600;
  fill: var(--text-muted, #888);
}
.thx-fh-node-name {
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 14px;
  font-weight: 700;
  fill: var(--text);
}
.thx-fh-arrow.strong { stroke: var(--accent, #e8874a); stroke-width: 2.5; }
.thx-fh-arrow.weak   { stroke: var(--text-muted, #888); stroke-width: 1.4; opacity: 0.7; }
.thx-fh-arrow.decep  { stroke: #aa6ec8; stroke-width: 1.8; stroke-dasharray: 4 3; }
.thx-fh-arrow.sec    { stroke: #5b8fd9; stroke-width: 1.4; stroke-dasharray: 2 3; }
.thx-fh-arrow.mi     { stroke: #4abe82; stroke-width: 1.4; }
.thx-fh-arrow.cycle  { stroke: #d4a54a; stroke-width: 2; stroke-dasharray: 6 3; }
.thx-fh-secdom-rect, .thx-fh-mi-rect {
  fill: var(--surface);
  stroke: #5b8fd9;
  stroke-width: 1;
}
.thx-fh-mi-rect { stroke: #4abe82; }
.thx-fh-secdom-text, .thx-fh-mi-text {
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 9px;
  font-weight: 700;
  fill: var(--text);
}

/* ════════════════════════════════════════════════════════════════
   4 · OVERTONE SERIES
   ════════════════════════════════════════════════════════════════ */
.thx-ot-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.thx-ot-row {
  display: grid;
  grid-template-columns: 36px 60px 1fr 84px 56px;
  gap: 12px;
  align-items: center;
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 0.84rem;
}
.thx-ot-num { color: var(--text-muted, #888); text-align: right; }
.thx-ot-note { font-weight: 700; }
.thx-ot-bar-wrap {
  background: var(--surface-2, #f5f4f0);
  border: 1px solid var(--border);
  border-radius: 3px;
  height: 14px;
  overflow: hidden;
}
.thx-ot-bar {
  background: var(--accent, #e8874a);
  height: 100%;
}
.thx-ot-row.in-scale .thx-ot-note { color: var(--accent, #e8874a); }
.thx-ot-row.in-scale .thx-ot-bar  { background: #4abe82; }
.thx-ot-freq, .thx-ot-cents {
  color: var(--text-muted, #888);
  text-align: right;
  font-size: 0.78rem;
}

/* ════════════════════════════════════════════════════════════════
   5 · CADENCE LIBRARY
   ════════════════════════════════════════════════════════════════ */
.thx-cadence-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.thx-cadence-card {
  padding: 12px 14px;
  background: var(--surface-2, #f5f4f0);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--r-md, 10px);
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s, background 0.12s;
}
.thx-cadence-card:hover { border-color: var(--accent, #e8874a); transform: translateY(-1px); }
.thx-cadence-card-tapped { background: rgba(232,135,74,0.20); }
.thx-cadence-card-cat {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3, #aaa);
}
.thx-cadence-card-name {
  font-weight: 700;
  font-size: 0.95rem;
  margin: 4px 0 6px 0;
}
.thx-cadence-card-prog {
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent, #e8874a);
  margin-bottom: 6px;
}
.thx-cadence-card-desc {
  font-size: 0.82rem;
  color: var(--text-muted, #888);
  line-height: 1.45;
}
.thx-cadence-cat-classical { border-left-color: #5b8fd9; }
.thx-cadence-cat-jazz      { border-left-color: var(--accent, #e8874a); }
.thx-cadence-cat-modal     { border-left-color: #4abe82; }
.thx-cadence-cat-pop       { border-left-color: #aa6ec8; }

/* ════════════════════════════════════════════════════════════════
   6 · NEGATIVE-HARMONY MIRROR
   ════════════════════════════════════════════════════════════════ */
.thx-negh-canvas { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }

/* Two-row strip view */
.thx-negh-strip {
  display: flex;
  gap: 12px;
  align-items: center;
}
.thx-negh-strip-label {
  width: 64px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted, #888);
  text-align: right;
  flex-shrink: 0;
}
.thx-negh-cells {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 4px;
  flex: 1;
}
.thx-negh-cell {
  text-align: center;
  padding: 10px 0;
  border-radius: var(--r-sm, 6px);
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-weight: 700;
  font-size: 0.84rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-3, #aaa);
}
.thx-negh-orig {
  background: rgba(232,135,74,0.30);
  border-color: var(--accent, #e8874a);
  color: var(--text);
}
.thx-negh-mirror {
  background: rgba(170,110,200,0.30);
  border-color: #aa6ec8;
  color: var(--text);
}
.thx-negh-axis-line {
  height: 1px;
  background: linear-gradient(to right, transparent, var(--accent, #e8874a) 20%, var(--accent, #e8874a) 80%, transparent);
  position: relative;
  margin: 4px 0 4px 76px;
}
.thx-negh-axis-line::after {
  content: 'mirror axis';
  position: absolute;
  top: -7px;
  right: 12px;
  font-size: 0.7rem;
  background: var(--surface);
  padding: 0 6px;
  color: var(--accent, #e8874a);
  font-weight: 600;
}

/* Circle view */
.thx-negh-svg { background: var(--surface-2, #f5f4f0); border-radius: var(--r-md, 10px); margin: 0 auto; display: block; }
[data-theme="dark"] .thx-negh-svg { background: var(--surface-2, #2a2a2a); }
.thx-negh-axis-svg {
  stroke: var(--accent, #e8874a);
  stroke-width: 2;
  stroke-dasharray: 4 4;
  opacity: 0.7;
}
.thx-negh-node {
  fill: var(--surface);
  stroke: var(--border-strong, #c8c5be);
  stroke-width: 1.5;
}
.thx-negh-node.orig    { fill: rgba(232,135,74,0.40); stroke: var(--accent, #e8874a); stroke-width: 2; }
.thx-negh-node.mirror  { fill: rgba(170,110,200,0.40); stroke: #aa6ec8; stroke-width: 2; }
.thx-negh-node.both    { fill: url(#thxNeghBoth); stroke: var(--text); stroke-width: 2; }
.thx-negh-node-text {
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-size: 11px;
  font-weight: 700;
  fill: var(--text);
}

/* Piano view (12-cell strip styled like piano) */
.thx-negh-piano {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 2px;
  background: var(--text-2, #444);
  padding: 2px;
  border-radius: var(--r-sm, 6px);
}
.thx-negh-pkey {
  height: 90px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 6px 0;
  font-family: var(--font-mono, 'DM Mono', monospace);
  font-weight: 700;
  font-size: 0.8rem;
  background: var(--surface);
  border-radius: 3px;
}
.thx-negh-pkey.black {
  background: var(--text-2, #444);
  color: white;
}
.thx-negh-pkey.thx-negh-orig   { background: rgba(232,135,74,0.55); color: var(--text); }
.thx-negh-pkey.thx-negh-mirror { background: rgba(170,110,200,0.55); color: var(--text); }
.thx-negh-pkey.thx-negh-both   { background: linear-gradient(135deg, rgba(232,135,74,0.55) 50%, rgba(170,110,200,0.55) 50%); color: var(--text); }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .thx-fh-svg { height: 380px; }
  .thx-mb-row { grid-template-columns: 90px 1fr 140px; font-size: 0.78rem; }
  .thx-ot-row { grid-template-columns: 28px 50px 1fr 70px 50px; font-size: 0.78rem; }
  .thx-negh-strip-label { width: 50px; font-size: 0.62rem; }
  .thx-negh-axis-line { margin-left: 62px; }
}
