.tl-panel {
  margin-bottom: 1.25rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.tl-panel__title {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 700;
}

.tl-panel__sub {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.tl-diatonic__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 108px), 1fr));
  gap: 0.5rem;
}

.tl-diatonic__cell {
  position: relative;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-left-width: 3px;
}

.tl-fn--tonic,
.tl-diatonic__cell.tl-fn--tonic {
  border-left-color: #6bc995;
}

.tl-fn--sd,
.tl-diatonic__cell.tl-fn--sd {
  border-left-color: #6c9eff;
}

.tl-fn--dominant,
.tl-diatonic__cell.tl-fn--dominant {
  border-left-color: #f0a050;
}

.tl-fn--substitute,
.tl-diatonic__cell.tl-fn--substitute {
  border-left-color: #b88cff;
}

.tl-fn--neutral,
.tl-diatonic__cell.tl-fn--neutral {
  border-left-color: var(--border);
}

.tl-fn-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  margin-bottom: 0.85rem;
}

.tl-fn-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.tl-fn-legend__dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 2px;
  background: currentColor;
}

.tl-fn-legend__item.tl-fn--tonic { color: #6bc995; }
.tl-fn-legend__item.tl-fn--sd { color: #6c9eff; }
.tl-fn-legend__item.tl-fn--dominant { color: #f0a050; }
.tl-fn-legend__item.tl-fn--substitute { color: #b88cff; }

.tl-diatonic__use-badge {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--accent);
}

.tl-diatonic__cell.is-active {
  border-color: rgba(108, 158, 255, 0.55);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(108, 158, 255, 0.2);
}

.tl-diatonic__degree {
  display: block;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--chord);
}

.tl-diatonic__chord {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0.1rem 0;
}

.tl-diatonic__role {
  display: block;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.tl-harmony__list,
.tl-cadence__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.tl-harmony__item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.65rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 0.78rem;
}

.tl-harmony__idx {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-weight: 600;
}

.tl-harmony__chord {
  flex: 0 0 auto;
  min-width: 2.25rem;
  font-weight: 700;
  color: var(--chord);
  font-family: "JetBrains Mono", monospace;
}

.tl-harmony__label {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-family: "JetBrains Mono", monospace;
}

.tl-harmony__status {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.68rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.tl-harmony__status-icon {
  font-size: 0.72rem;
  line-height: 1;
}

.tl-harmony__status--diatonic {
  background: rgba(100, 200, 140, 0.12);
  color: #7dd4a3;
  border-color: rgba(100, 200, 140, 0.25);
}

.tl-harmony__status--in-scale {
  background: rgba(108, 158, 255, 0.12);
  color: #8eb8ff;
  border-color: rgba(108, 158, 255, 0.25);
}

.tl-harmony__status--borrowed {
  background: rgba(240, 160, 80, 0.12);
  color: #f0a050;
  border-color: rgba(240, 160, 80, 0.25);
}

.tl-harmony__status--out-scale {
  background: rgba(240, 100, 100, 0.12);
  color: #f08888;
  border-color: rgba(240, 100, 100, 0.25);
}

.tl-harmony__intro {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.85rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--surface-2);
}

.tl-harmony__intro-text {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.tl-harmony__intro-text strong {
  color: var(--text);
}

.tl-venn {
  flex-shrink: 0;
  width: 200px;
}

.tl-venn__outer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 132px;
  padding: 1rem 1.1rem 1.15rem;
  border-radius: 12px;
  border: 2px solid rgba(108, 158, 255, 0.45);
  background: rgba(108, 158, 255, 0.08);
  text-align: center;
}

.tl-venn__outer-label,
.tl-venn__outer-title {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: #8eb8ff;
}

.tl-venn__outer-sub,
.tl-venn__outer-desc {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.tl-venn__inner {
  margin-top: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 2px solid rgba(100, 200, 140, 0.55);
  background: rgba(100, 200, 140, 0.12);
  min-width: 8.5rem;
}

.tl-venn__inner-label,
.tl-venn__inner-title {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: #7dd4a3;
}

.tl-venn__inner-sub,
.tl-venn__inner-desc {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.65rem;
  color: var(--text-muted);
}

.tl-status-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.tl-status-legend .tl-harmony__status {
  white-space: nowrap;
}

.tl-harmony__status.is-borrowed {
  background: rgba(240, 160, 80, 0.12);
  color: #f0a050;
}

.tl-harmony__role {
  flex: 1 1 100%;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.tl-cadence__item {
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
}

.tl-cadence__item--empty {
  border-left-color: var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.tl-cadence__label {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.82rem;
  margin-right: 0.5rem;
}

.tl-cadence__pair {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  color: var(--chord);
}

.tl-cadence__desc {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tl-term {
  display: inline;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  color: inherit;
  text-decoration: underline dotted rgba(108, 158, 255, 0.55);
  text-underline-offset: 0.15em;
  cursor: help;
}

.tl-term:hover,
.tl-term:focus-visible {
  color: var(--accent);
  text-decoration-color: var(--accent);
  outline: none;
}

.tl-cadence__label .tl-term {
  color: var(--accent);
  font-weight: 700;
}

.tl-term--desc {
  display: block;
  width: 100%;
  text-align: left;
  color: var(--text-muted);
}

.tl-panel__title .tl-term,
.tl-panel__sub .tl-term {
  font-size: inherit;
  font-weight: inherit;
}

.tl-term-popup {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.tl-term-popup[hidden] {
  display: none;
}

.tl-term-popup__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.tl-term-popup__card {
  position: relative;
  width: min(100%, 420px);
  padding: 1.1rem 1.25rem 1.15rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.tl-term-popup__close {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.tl-term-popup__close:hover,
.tl-term-popup__close:focus-visible {
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

.tl-term-popup__title {
  margin: 0 2rem 0.55rem 0;
  font-size: 1rem;
  color: var(--accent);
}

.tl-term-popup__body {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text);
}

body.tl-term-popup-open {
  overflow: hidden;
}

.tl-melody-theory__summary {
  margin: 0 0 0.85rem;
  padding-left: 1.2rem;
  font-size: 0.82rem;
  line-height: 1.55;
}

.tl-melody-theory__table-wrap {
  overflow-x: auto;
}

.tl-melody-theory__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.tl-melody-theory__table th,
.tl-melody-theory__table td {
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.tl-melody-theory__table th {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.tl-melody-theory__table tr.is-out td {
  color: #f0a050;
}

@media (max-width: 768px) {
  .tl-harmony__intro {
    grid-template-columns: 1fr;
  }

  .tl-venn {
    margin: 0 auto;
  }
}
