:root {
  color-scheme: dark;
  --app-bg: #101214;
  --surface: #1b1f23;
  --surface-strong: #24282d;
  --surface-soft: #15181c;
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.28);
  --text-soft: #b9c1cc;
  --accent: #d17a19;
  --playhead: #f0c859;
  --green: #88bc55;
  --blue: #57b7c5;
  --red: #dc6b58;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 14% 0%, rgba(209, 122, 25, 0.16), transparent 23rem),
    linear-gradient(145deg, var(--app-bg), #161a1f 58%, #101214);
}

.app-nav {
  min-height: 3rem;
  border-bottom: 1px solid var(--line);
  background: rgba(25, 28, 32, 0.94);
  backdrop-filter: blur(0.75rem);
}

.brand-mark {
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 0.35rem;
}

.navbar-brand {
  font-size: 0.92rem;
  font-weight: 800;
}

.page-title {
  color: #fff;
  font-size: 0.88rem;
  font-weight: 900;
}

.fifths-shell {
  width: min(100%, 76rem);
  margin: 0 auto;
  padding: 1rem;
}

.fifths-heading,
.circle-layout,
.instrument-heading,
.instrument-grid,
.selection-title-row {
  display: grid;
  gap: 1rem;
}

.fifths-heading {
  margin: 0.6rem 0 1rem;
}

.fifths-heading h1,
.selection-panel h2,
.instrument-heading h2,
.instrument-block h3 {
  margin: 0;
}

.fifths-heading h1 {
  font-size: clamp(1.75rem, 9vw, 3.4rem);
  line-height: 1;
}

.fifths-heading p {
  max-width: 42rem;
  margin: 0.42rem 0 0;
  color: var(--text-soft);
}

.spin-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.spin-controls .btn {
  display: grid;
  place-items: center;
  width: 2.25rem;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: 0.28rem;
  font-size: 1.25rem;
  font-weight: 900;
}

.spin-select-wrap {
  min-width: 8.5rem;
}

.circle-layout {
  align-items: start;
}

.circle-stage,
.selection-panel,
.instrument-panel {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(27, 31, 35, 0.88);
  box-shadow: 0 0.85rem 2.2rem rgba(0, 0, 0, 0.22);
}

.circle-stage {
  position: relative;
  width: min(100%, 42rem);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background:
    radial-gradient(circle, transparent 0 30%, rgba(240, 200, 89, 0.1) 30.2% 30.9%, transparent 31.2% 46.5%, rgba(255, 255, 255, 0.18) 46.8% 47.6%, transparent 48%),
    rgba(27, 31, 35, 0.88);
}

.circle-stage::before,
.circle-stage::after {
  content: "";
  position: absolute;
  inset: 12%;
  border: 3px solid rgba(255, 255, 255, 0.28);
  border-radius: 999rem;
  box-shadow:
    inset 0 0 1.4rem rgba(255, 255, 255, 0.08),
    0 0 1rem rgba(240, 200, 89, 0.12);
  pointer-events: none;
}

.circle-stage::after {
  inset: 31%;
  border-color: rgba(240, 200, 89, 0.36);
  border-width: 4px;
  background: radial-gradient(circle, rgba(16, 18, 20, 0.78), rgba(21, 24, 28, 0.3));
}

.circle-cell {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  width: clamp(5.45rem, 21vw, 9.15rem);
  min-height: clamp(4rem, 13.5vw, 5.55rem);
  padding: 0.5rem 0.58rem 0.38rem;
  border: 0;
  color: #fff;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--cell-color), white 8%), color-mix(in srgb, var(--cell-color), black 45%));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.22),
    0 0.45rem 1.3rem rgba(0, 0, 0, 0.26);
  clip-path: polygon(16% 0, 84% 0, 100% 100%, 0 100%);
  text-align: center;
  transform: translate(-50%, -50%) translate(var(--x), var(--y)) rotate(var(--cell-rotation));
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease, filter 160ms ease;
}

.circle-cell.minor-cell {
  z-index: 4;
  width: clamp(4.55rem, 14vw, 6.45rem);
  min-height: clamp(3.24rem, 9.7vw, 4.35rem);
  clip-path: polygon(18% 0, 82% 0, 100% 100%, 0 100%);
}

.circle-cell.is-t-highlight {
  z-index: 6;
}

.circle-cell.is-selected {
  z-index: 8;
}

.circle-cell.minor-cell .cell-main {
  font-size: clamp(0.92rem, 3.4vw, 1.42rem);
}

.circle-cell.minor-cell .cell-sub {
  margin-top: 0.1rem;
}

.circle-cell:hover,
.circle-cell:focus-visible {
  filter: brightness(1.08);
  outline: 0.18rem solid rgba(255, 255, 255, 0.64);
  outline-offset: 0.06rem;
}

.circle-cell.is-selected {
  box-shadow:
    inset 0 0 0 7px rgba(97, 217, 255, 0.98),
    0 0 1.65rem rgba(87, 183, 197, 0.68);
}

.circle-cell.is-t-highlight {
  box-shadow:
    inset 0 0 0 6px rgba(240, 200, 89, 0.96),
    0 0 1.45rem rgba(240, 200, 89, 0.58);
}

.circle-cell.is-selected.is-t-highlight {
  box-shadow:
    inset 0 0 0 7px rgba(97, 217, 255, 0.98),
    0 0 1.65rem rgba(87, 183, 197, 0.68);
}

.circle-cell > span {
  display: block;
  transform: rotate(var(--label-rotation));
  pointer-events: none;
}

.degree-label {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  display: grid;
  place-items: center;
  min-width: 1.75rem;
  min-height: 1.3rem;
  color: rgba(255, 255, 255, 0.72);
  font-size: clamp(0.58rem, 1.75vw, 0.86rem);
  font-weight: 950;
  letter-spacing: 0;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.65);
  pointer-events: none;
  transform: translate(-50%, -50%) translate(var(--x), var(--y));
}

.major-degree {
  color: rgba(255, 226, 122, 0.9);
}

.minor-degree {
  color: rgba(182, 228, 234, 0.86);
  font-size: clamp(0.52rem, 1.45vw, 0.76rem);
}

.degree-label.is-tonic {
  color: #fff;
  text-shadow:
    0 1px 0 rgba(0, 0, 0, 0.65),
    0 0 0.75rem rgba(255, 255, 255, 0.5);
}

.cell-main {
  display: block;
  font-size: clamp(1.02rem, 4.25vw, 1.58rem);
  font-weight: 950;
  line-height: 1;
}

.cell-sub {
  display: block;
  margin-top: 0.16rem;
  color: rgba(255, 255, 255, 0.84);
  font-size: clamp(0.54rem, 2vw, 0.76rem);
  font-weight: 800;
  line-height: 1.1;
}

.cell-sig {
  display: block;
  max-width: 100%;
  margin-top: 0.22rem;
  color: rgba(255, 255, 255, 0.72);
  font-size: clamp(0.47rem, 1.7vw, 0.64rem);
  font-weight: 700;
  line-height: 1.08;
}

.selection-panel,
.instrument-panel {
  padding: 1rem;
}

.selection-title-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.selection-panel h2 {
  font-size: clamp(2rem, 12vw, 3.6rem);
  line-height: 0.95;
}

.selection-kicker {
  display: block;
  color: var(--playhead);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08rem;
  text-transform: uppercase;
}

.play-icon-button {
  display: grid;
  place-items: center;
  width: 2.5rem;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 0.3rem;
}

.play-icon {
  width: 0;
  height: 0;
  border-top: 0.48rem solid transparent;
  border-bottom: 0.48rem solid transparent;
  border-left: 0.75rem solid currentColor;
  transform: translateX(0.08rem);
}

.key-facts {
  display: grid;
  gap: 0.65rem;
  margin: 1rem 0 0;
}

.key-facts div {
  display: grid;
  gap: 0.15rem;
  padding: 0.75rem;
  border-radius: 0.42rem;
  background: rgba(255, 255, 255, 0.055);
}

.key-facts dt {
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 800;
}

.key-facts dd {
  margin: 0;
  color: #fff;
  font-weight: 850;
}

.selection-options {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.option-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  color: var(--text-soft);
  font-size: 0.86rem;
  font-weight: 800;
}

.option-check-sub {
  margin-left: 1.35rem;
}

.option-check.is-disabled {
  opacity: 0.58;
}

.option-field,
.bpm-field {
  display: grid;
  gap: 0.3rem;
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 900;
}

.option-field span,
.bpm-field span {
  text-transform: uppercase;
}

.instrument-panel {
  margin-top: 1rem;
}

.recorder-panel {
  display: grid;
  gap: 0.8rem;
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(27, 31, 35, 0.88);
  box-shadow: 0 0.85rem 2.2rem rgba(0, 0, 0, 0.22);
}

.recorder-topline {
  display: grid;
  gap: 0.75rem;
}

.recorder-topline h2 {
  margin: 0;
  font-size: 1.25rem;
}

.recorder-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.record-button,
.progression-play-button {
  display: grid;
  place-items: center;
  width: 2.35rem;
  min-width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border-radius: 0.32rem;
}

.record-button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
}

.record-button span {
  width: 1rem;
  height: 1rem;
  border-radius: 999rem;
  background: rgba(255, 75, 67, 0.72);
  box-shadow: none;
}

.record-button.is-recording {
  border-color: rgba(255, 110, 100, 0.95);
  background: #8d1e1b;
  box-shadow: 0 0 0 0.2rem rgba(255, 75, 67, 0.28);
}

.record-button.is-recording span {
  background: #ff4b43;
  box-shadow: 0 0 0.7rem rgba(255, 75, 67, 0.55);
}

.progression-play-button.active .play-icon {
  width: 0.74rem;
  height: 0.74rem;
  border: 0;
  background: linear-gradient(90deg, currentColor 0 35%, transparent 35% 65%, currentColor 65% 100%);
  transform: none;
}

.recorded-chord-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: 2.35rem;
}

.bpm-field {
  max-width: 8rem;
}

.recorded-empty {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.9rem;
}

.recorded-chord {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.35rem;
  padding: 0.35rem 0.62rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 0.38rem;
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
  font-weight: 900;
}

.recorded-chord span {
  color: var(--text-soft);
  font-size: 0.78rem;
}

.recorded-chord.is-selected {
  border-color: var(--blue);
  box-shadow: 0 0 0 0.18rem rgba(87, 183, 197, 0.28);
}

.recorded-chord.is-playing {
  border-color: var(--playhead);
  background: rgba(240, 200, 89, 0.16);
  box-shadow: 0 0 0.95rem rgba(240, 200, 89, 0.38);
}

.instrument-heading {
  align-items: start;
  margin-bottom: 1rem;
}

.instrument-heading h2 {
  font-size: clamp(1.45rem, 7vw, 2.4rem);
}

.chord-notes {
  margin: 0;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 900;
}

.instrument-block {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.instrument-block h3 {
  font-size: 0.92rem;
  font-weight: 900;
}

.ear-piano {
  position: relative;
  width: 100%;
  max-width: 50rem;
  aspect-ratio: 15 / 3.4;
  margin: 0 auto;
  touch-action: manipulation;
}

.piano-whites {
  display: grid;
  grid-template-columns: repeat(15, minmax(0, 1fr));
  height: 100%;
}

.piano-key {
  position: relative;
  border: 1px solid #29313b;
  color: #12161c;
  font-weight: 800;
  line-height: 1;
}

.piano-key.white {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0.1rem 0.45rem;
  border-radius: 0 0 0.28rem 0.28rem;
  background: linear-gradient(#f8f7ee, #d7d5c9);
  font-size: clamp(0.62rem, 2.4vw, 0.84rem);
}

.piano-key.black {
  position: absolute;
  top: 0;
  z-index: 3;
  width: 5.25%;
  height: 61%;
  padding: 0 0.05rem 0.35rem;
  border-color: #06080a;
  border-radius: 0 0 0.24rem 0.24rem;
  background: linear-gradient(#252b32, #050607);
  color: #f3f5f7;
  font-size: clamp(0.52rem, 1.9vw, 0.72rem);
}

.piano-key.is-highlighted {
  border-color: #ffe27a;
  outline: 0.28rem solid #ffe27a;
  outline-offset: -0.34rem;
  box-shadow:
    inset 0 0 0 999rem rgba(255, 226, 122, 0.34),
    0 0 1.15rem rgba(255, 226, 122, 0.86);
  transform: translateY(-0.16rem);
}

.piano-key.is-root {
  border-color: #61d9ff;
  outline-color: #61d9ff;
  box-shadow:
    inset 0 0 0 999rem rgba(97, 217, 255, 0.34),
    0 0 1.15rem rgba(97, 217, 255, 0.84);
}

.piano-key:focus-visible {
  outline: 0.2rem solid var(--accent);
  outline-offset: -0.2rem;
}

.piano-key.is-flashing {
  animation: piano-key-flash 220ms ease-out;
}

@keyframes piano-key-flash {
  50% {
    filter: brightness(1.38);
    box-shadow: 0 0 1rem rgba(255, 255, 255, 0.8);
  }
}

.guitar-diagram {
  display: grid;
  gap: 0.45rem;
  width: min(100%, 27rem);
  margin: 0 auto;
}

.guitar-neck {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  min-height: 12rem;
  border-top: 0.38rem solid rgba(255, 255, 255, 0.62);
  border-right: 1px solid rgba(255, 255, 255, 0.18);
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  border-left: 1px solid rgba(255, 255, 255, 0.18);
  background:
    repeating-linear-gradient(180deg, transparent 0 calc(20% - 1px), rgba(255, 255, 255, 0.2) calc(20% - 1px) 20%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.11) 0 1px, transparent 1px);
  background-size: 100% 100%, calc(100% / 12) 100%;
  background-position: 0 0, 0 0;
}

.guitar-string {
  position: relative;
  border-left: 1px solid rgba(255, 255, 255, 0.3);
}

.guitar-string:last-child {
  border-right: 1px solid rgba(255, 255, 255, 0.3);
}

.fret-marker {
  position: absolute;
  left: 50%;
  display: grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border: 2px solid rgba(16, 18, 20, 0.8);
  border-radius: 999rem;
  color: #101214;
  background: #ffe27a;
  box-shadow: 0 0 0.75rem rgba(255, 226, 122, 0.55);
  font-size: 0.82rem;
  font-weight: 950;
  transform: translate(-50%, -50%);
}

.fret-marker,
.open-muted-row button {
  cursor: pointer;
}

.fret-marker:focus-visible,
.open-muted-row button:focus-visible {
  outline: 0.2rem solid var(--blue);
  outline-offset: 0.12rem;
}

.fret-marker.is-playing,
.open-muted-row button.is-playing {
  filter: brightness(1.3);
  box-shadow: 0 0 1rem rgba(255, 226, 122, 0.88);
}

.fret-marker.is-root {
  background: #61d9ff;
  box-shadow: 0 0 0.75rem rgba(97, 217, 255, 0.6);
}

.open-muted-row,
.string-name-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0;
  text-align: center;
}

.open-muted-row span,
.open-muted-row button,
.string-name-row span {
  color: var(--text-soft);
  font-size: 0.75rem;
  font-weight: 900;
}

.open-muted-row button {
  display: grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  margin: 0 auto;
  border: 2px solid rgba(16, 18, 20, 0.8);
  border-radius: 999rem;
  color: #101214;
  background: #ffe27a;
  box-shadow: 0 0 0.75rem rgba(255, 226, 122, 0.55);
}

.open-muted-row span.is-played,
.open-muted-row button.is-played {
  color: #ffe27a;
}

.open-muted-row button.is-played {
  color: #101214;
}

@media (min-width: 48rem) {
  .fifths-heading,
  .instrument-heading {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .circle-layout {
    grid-template-columns: minmax(0, 1fr) minmax(16rem, 21rem);
  }

  .recorder-topline {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }
}

@media (min-width: 62rem) {
  .instrument-grid {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
  }
}

@media (max-width: 28rem) {
  .circle-cell {
    width: clamp(4.85rem, 21vw, 5.55rem);
    min-height: 3.48rem;
  }

  .circle-cell.minor-cell {
    width: clamp(3.95rem, 16.5vw, 4.5rem);
    min-height: 2.92rem;
  }

  .circle-cell.minor-cell .cell-sub {
    display: none;
  }
}
