/* Chord library: stage (focused chord) + wall (rows of chord tiles). */

.library {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-4);
  padding: var(--s-5) var(--gutter) var(--s-7);
}

/* ---------- Stage ---------- */

.stage {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) auto minmax(260px, 320px);
  gap: var(--s-6);
  align-items: start;
}

.stage .segmented {
  justify-self: start;
}

.stage-info {
  display: grid;
  gap: var(--s-4);
  align-content: start;
  padding-top: var(--s-2);
}

.stage-name {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s-1) var(--s-4);
}

.stage-name h1 {
  font: 800 var(--t-chord) / 0.86 var(--font-display);
  letter-spacing: -0.035em;
}

.stage-name p {
  font: 600 var(--t-title) / 1.15 var(--font-display);
  color: var(--ink-2);
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.meta li {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 var(--s-3);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--t-small);
  font-weight: 600;
}

.meta li strong {
  margin-left: 0.35em;
  color: var(--ink);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stage-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-top: var(--s-2);
}

/* Diagram / photo frame */

.stage-visual {
  display: grid;
  place-items: center;
  margin: 0;
  width: clamp(300px, 27vw, 380px);
  padding: var(--s-3);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chord-diagram--stage {
  width: 100%;
  height: auto;
  max-height: 460px;
}

.cd-nut {
  fill: var(--ink);
}

.cd-fret {
  stroke: var(--line-strong);
  stroke-width: 2;
}

.chord-diagram--tile .cd-fret {
  stroke-width: 1;
}

.cd-string {
  stroke: var(--ink);
  stroke-opacity: 0.62;
}

.cd-open {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
}

.chord-diagram--tile .cd-open {
  stroke-width: 1.4;
}

.cd-muted {
  stroke: var(--ink-2);
  stroke-width: 3.5;
  stroke-linecap: round;
}

.chord-diagram--tile .cd-muted {
  stroke-width: 1.5;
}

.cd-fret-label,
.cd-notes text {
  fill: var(--ink-2);
  font: 700 22px var(--font-ui);
}

.cd-fret-label--tile {
  font-size: 11px;
  font-weight: 800;
}

.cd-finger--1 .cd-dot { fill: var(--finger-1); }
.cd-finger--2 .cd-dot { fill: var(--finger-2); }
.cd-finger--3 .cd-dot { fill: var(--finger-3); }
.cd-finger--4 .cd-dot { fill: var(--finger-4); }

.cd-num {
  fill: var(--on-finger);
  font: 800 23px var(--font-display);
  pointer-events: none;
}

/* Signature: fingers land in placing order (1 → 4). */
/* Listen: the sounding string is the lamp for that moment. */
.listen {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
}

.listen .btn {
  min-height: 48px;
  padding: 0 var(--s-4);
}

.cd-string,
.cd-open,
.cd-notes text {
  transition: stroke 120ms var(--ease-out), fill 120ms var(--ease-out), stroke-width 120ms var(--ease-out);
}

.cd-string.is-sounding {
  stroke: var(--accent-edge);
  stroke-opacity: 1;
  stroke-width: 6;
}

.cd-open.is-sounding {
  stroke: var(--accent-edge);
}

.cd-dot.is-sounding {
  stroke: var(--accent-edge);
  stroke-width: 5;
}

.cd-notes text.is-sounding {
  fill: var(--ink);
  font-weight: 800;
}

.string-strip li {
  transition: box-shadow 120ms var(--ease-out);
}

.string-strip li.is-sounding {
  box-shadow: inset 0 0 0 2px var(--accent-edge);
}

@media (prefers-reduced-motion: reduce) {
  .cd-string,
  .cd-open,
  .cd-notes text,
  .string-strip li {
    transition: none;
  }
}

.stage-visual .cd-finger {
  transform-box: fill-box;
  transform-origin: center;
}

.is-drawing .cd-finger {
  animation: finger-land 420ms var(--ease-out) both;
  animation-delay: calc(var(--order, 0) * 110ms + 60ms);
}

@keyframes finger-land {
  from {
    opacity: 0;
    transform: scale(0.55);
  }
}

.is-released .cd-finger {
  opacity: 0.18;
  transition: opacity 320ms var(--ease-out);
}

.photo-pending {
  display: grid;
  justify-items: center;
  gap: var(--s-3);
  max-width: 260px;
  text-align: center;
}

.photo-pending .icon {
  width: 56px;
  height: 56px;
  stroke-width: 1.5;
  color: var(--ink-2);
}

.photo-pending strong {
  font: 700 var(--t-title) / 1.15 var(--font-display);
}

.photo-pending p {
  color: var(--ink-2);
  font-size: var(--t-small);
}

/* Right column: fingers, strings, tips */

.stage-aside {
  display: grid;
  gap: var(--s-4);
  padding-top: var(--s-2);
}

.stage-aside h2 {
  margin-bottom: var(--s-3);
  font: 700 var(--t-body) / 1.2 var(--font-display);
}

.finger-key {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2) var(--s-4);
}

.finger-key li {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.finger-key li.is-unused {
  color: var(--ink-2);
}

.finger-key li.is-unused .finger-badge {
  background: var(--surface-2);
  color: var(--ink-2);
}

.finger-badge {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--on-finger);
  font: 800 1rem / 1 var(--font-display);
  flex: none;
}

.finger-badge--1 { background: var(--finger-1); }
.finger-badge--2 { background: var(--finger-2); }
.finger-badge--3 { background: var(--finger-3); }
.finger-badge--4 { background: var(--finger-4); }

.string-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--s-1);
}

.string-strip li {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: var(--s-2) 0;
  border-radius: var(--r-sm);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}

.string-strip .n {
  color: var(--ink-2);
  font-size: 0.8125rem;
  font-weight: 600;
}

.string-strip .v {
  font: 800 1.25rem / 1.1 var(--font-display);
}

.string-strip .is-muted .v {
  color: var(--ink-2);
}

.tips {
  display: grid;
  gap: var(--s-2);
}

.tips li {
  position: relative;
  padding-left: var(--s-5);
  font-size: 1rem;
  line-height: 1.4;
  text-wrap: pretty;
}

.tips li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 0.6em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-2);
}

/* Practice panel (replaces the actions while practising) */

.practice {
  display: grid;
  gap: var(--s-3);
  max-width: 440px;
  margin-top: var(--s-2);
  padding: var(--s-4);
  border: 1.5px solid var(--accent-edge);
  border-radius: var(--r-lg);
  background: var(--surface);
}

.practice-phase {
  font: 800 2.25rem / 1.05 var(--font-display);
  letter-spacing: -0.02em;
}

.practice-meter {
  height: 10px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: var(--surface-2);
}

.practice-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transform-origin: left;
  transform: scaleX(0);
}

.practice-count {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.practice-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.practice-controls .btn {
  min-height: 48px;
}

/* ---------- Wall ---------- */

.wall {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--s-3);
  padding-top: var(--s-4);
  border-top: 1px solid var(--line);
}

.wall-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3);
}

.search {
  position: relative;
  flex: 0 1 300px;
}

.search .icon {
  position: absolute;
  left: 14px;
  top: 50%;
  translate: 0 -50%;
  color: var(--ink-2);
  pointer-events: none;
}

.search input {
  width: 100%;
  min-height: 48px;
  padding: 0 var(--s-4) 0 46px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  caret-color: var(--accent);
}

.search input::placeholder {
  color: var(--ink-2);
}

.search input:focus-visible {
  outline: none;
  border-color: var(--focus);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.filters + .filters {
  padding-left: var(--s-3);
  border-left: 1px solid var(--line);
}

.wall-rows {
  display: grid;
  gap: var(--s-2);
}

.row {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: var(--s-4);
  align-items: center;
  transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out);
}

.row-head h2 {
  font: 800 var(--t-title) / 1 var(--font-display);
  letter-spacing: -0.02em;
}

.row-head p {
  margin-top: var(--s-1);
  color: var(--ink-2);
  font-size: var(--t-small);
  font-variant-numeric: tabular-nums;
}

.tiles {
  display: flex;
  gap: var(--s-3);
  padding: 6px 4px;
  margin: -6px -4px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}

/* Signature: the focused row lifts, the rest of the wall steps back (fine pointers). */
@media (hover: hover) {
  .wall-rows:has(.tile:is(:hover, :focus-visible)) .row:not(:has(.tile:is(:hover, :focus-visible))) {
    opacity: var(--dim);
  }

  .row:has(.tile:is(:hover, :focus-visible)) {
    transform: translateY(-3px);
  }
}

.tile {
  --tile-w: 130px;
  --tile-open: 232px;
  position: relative;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  gap: var(--s-3);
  flex: none;
  width: var(--tile-w);
  min-height: 70px;
  padding: var(--s-2) var(--s-3) var(--s-2) var(--s-2);
  overflow: hidden;
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  text-align: left;
  scroll-snap-align: start;
  transition:
    width var(--dur) var(--ease-out),
    border-color var(--dur-fast) var(--ease-out),
    background-color var(--dur-fast) var(--ease-out);
}

.tile-art .chord-diagram--tile {
  display: block;
  width: 52px;
  height: auto;
}

/* Thumbnails are too small to carry finger numbers, so they carry no finger colour either. */
.chord-diagram--tile .cd-dot {
  fill: var(--ink);
}

.tile-text {
  display: grid;
  gap: 2px;
  min-width: 0;
  white-space: nowrap;
}

.tile-name {
  padding-bottom: 6px;
  font: 800 1.3rem / 1 var(--font-display);
  letter-spacing: -0.01em;
}

.tile-more {
  display: grid;
  gap: 1px;
  max-width: 0;
  max-height: 0;
  overflow: hidden;
  font-size: var(--t-small);
  line-height: 1.25;
}

.tile-more b {
  font-weight: 600;
}

.tile-more span {
  color: var(--ink-2);
}

.tile-check {
  position: absolute;
  right: 4px;
  bottom: 4px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
}

.tile-check .icon {
  width: 13px;
  height: 13px;
  stroke-width: 3;
}

/* The selected chord stays open on every input; hover previews any other. */
.tile[aria-current="true"] .tile-more,
.tile:focus-visible .tile-more {
  max-width: 160px;
  max-height: 3em;
}

.tile[aria-current="true"] {
  width: var(--tile-open);
  border-color: var(--accent-edge);
  background: var(--surface-2);
}

@media (hover: hover) {
  .tile:hover {
    width: var(--tile-open);
    background: var(--surface-2);
  }

  .tile:hover .tile-more {
    max-width: 160px;
  max-height: 3em;
  }
}

.tile:focus-visible {
  width: var(--tile-open);
  outline: none;
  border-color: var(--focus);
  background: var(--surface-2);
}

.wall-empty {
  display: grid;
  justify-items: start;
  gap: var(--s-3);
  padding: var(--s-6) 0;
}

.wall-empty p {
  font: 700 var(--t-title) / 1.2 var(--font-display);
}

/* ---------- Responsive ---------- */

@media (max-width: 1240px) {
  .stage {
    grid-template-columns: minmax(220px, 1fr) auto minmax(280px, 310px);
    gap: var(--s-5);
  }

  .stage-visual {
    width: clamp(280px, 28vw, 330px);
  }

  .row {
    grid-template-columns: 108px 1fr;
  }

  .tiles {
    gap: var(--s-2);
  }

  .tile {
    --tile-w: 120px;
    --tile-open: 204px;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: var(--s-2);
  }

  .tile-art .chord-diagram--tile {
    width: 44px;
  }

  .tile-name {
    font-size: 1.25rem;
  }

  .wall-tools .chip {
    padding: 0 var(--s-3);
  }

  .search {
    flex-basis: 210px;
  }



  .row-head h2 {
    font-size: 1.375rem;
  }

  .filters + .filters {
    padding-left: 0;
    border-left: 0;
  }

  .tips li {
    font-size: 1rem;
  }
}

@media (max-width: 1040px) {
  .stage {
    grid-template-columns: minmax(260px, 1fr) auto;
  }

  .stage-aside {
    grid-column: 1 / -1;
    grid-template-columns: minmax(220px, auto) minmax(260px, 320px) 1fr;
    gap: var(--s-6);
  }
}

@media (max-width: 900px) {
  .stage {
    grid-template-columns: 1fr;
    gap: var(--s-5);
  }

  .stage-visual {
    width: min(100%, 380px);
    justify-self: center;
  }

  .stage-aside {
    grid-template-columns: 1fr;
  }

  .row {
    grid-template-columns: 1fr;
    gap: var(--s-2);
  }

  .row-head {
    display: flex;
    align-items: baseline;
    gap: var(--s-3);
  }

  .filters + .filters {
    padding-left: 0;
    border-left: 0;
  }

  .search {
    flex-basis: 100%;
  }
}

@media (max-width: 900px) {
  /* Phone and portrait tablet: the diagram right under the name, actions after it. */
  .stage-info {
    display: contents;
  }

  .stage-name { order: 1; }
  .meta { order: 2; }
  .stage-visual { order: 3; }
  .stage .segmented { order: 4; justify-self: center; }
  .stage-actions,
  .practice { order: 5; }
  .stage-aside { order: 6; }

  .stage {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--s-4);
  }

  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    width: calc(100% + var(--gutter) * 2);
    margin: 0 calc(var(--gutter) * -1);
    padding: 2px var(--gutter);
    scrollbar-width: none;
  }

  .filters + .filters {
    padding-left: var(--gutter);
  }
}

@media (max-width: 520px) {
  .stage-actions .btn {
    flex: 1 1 100%;
  }

  .stage-visual {
    width: min(100%, 300px);
    padding: var(--s-3);
  }

  .finger-key {
    grid-template-columns: 1fr 1fr;
  }

}



/* Count before Escuchar: 3 · 2 · 1 over the diagram. */
.stage-visual {
  position: relative;
}

.listen-count {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  display: grid;
  place-items: center;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font: 800 5rem / 1 var(--font-display);
  outline: 8px solid var(--bg);
  pointer-events: none;
}

@media (max-width: 520px) {
  .listen-count {
    width: 104px;
    height: 104px;
    font-size: 3.5rem;
  }
}
