/* =========================================================================
 * Harp page-specific styles. Vertical strings between a stylized neck (top)
 * and soundboard (bottom). String hit-zones span the full vertical column;
 * the visible string is a thin gradient line in the centre of each column.
 * ========================================================================= */

:root {
  /* Harp palette. Soundboard / strings sit inside a dark wood frame —
   * intentional instrument identity (real harps are stained dark wood,
   * not slate-blue). String labels and pluck-glow route through brand
   * tokens so they recolor with the rest of the site.
   *
   * Wood tones (c04 / c05 / c07 / c08 / c10) match the existing
   * --play-wood-* family in /play/styles/chrome.css. */
  --play-harp-c01: rgba(26, 18, 8, 0.4);
  --play-harp-c02: #2a1d10;
  --play-harp-c03: #1a1208;
  --play-harp-c04: #4a3520;
  --play-harp-c05: #2a1d10;
  --play-harp-c06: rgba(255, 220, 180, 0.18);
  --play-harp-c07: #c89868;
  --play-harp-c08: #6b4824;
  --play-harp-c09: rgba(255, 220, 180, 0.25);
  --play-harp-c10: #1a1208;
  --play-harp-c11: rgba(255, 220, 180, 0.1);
  /* Pluck glow + string labels route through brand accent so they
   * stay in sync with the site palette. */
  --play-harp-glow-soft: var(--accent-primary-soft);
  --play-harp-label: rgba(255, 220, 180, 0.55);
  --play-harp-glow: var(--accent-primary-soft);
}

.harp-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px 24px;
  width: 100%;
}

.harp-frame {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 960px);
  height: clamp(320px, 56vh, 520px);
  border-radius: 18px;
  background: linear-gradient(
      180deg,
      var(--play-harp-c01, rgba(15, 23, 42, 0.4)),
      color-mix(in srgb, var(--pure-black) 35%, transparent)
    ),
    linear-gradient(180deg, var(--play-harp-c02, #1e293b), var(--play-harp-c03, #0f172a));
  border: 1px solid var(--border);
  box-shadow: 0 24px 40px -20px color-mix(in srgb, var(--pure-black) 60%, transparent),
    inset 0 1px 0 color-mix(in srgb, var(--pure-white) 4%, transparent);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.harp-neck,
.harp-soundboard {
  flex: 0 0 auto;
  height: 22px;
  background: linear-gradient(
    180deg,
    var(--play-harp-c04, #4a3520),
    var(--play-harp-c05, #2a1d10) 60%,
    var(--play-harp-c04, #4a3520)
  );
  border-bottom: 1px solid color-mix(in srgb, var(--pure-black) 40%, transparent);
  position: relative;
  z-index: 2;
  box-shadow: inset 0 1px 0 var(--play-harp-c06, rgba(255, 220, 180, 0.18)),
    inset 0 -2px 4px color-mix(in srgb, var(--pure-black) 45%, transparent);
}

.harp-neck {
  background: linear-gradient(
    180deg,
    var(--play-harp-c07, #c89868),
    var(--play-harp-c08, #6b4824) 70%,
    var(--play-harp-c04, #4a3520)
  );
  border-radius: 18px 18px 4px 4px;
  border-top: 1px solid var(--play-harp-c09, rgba(255, 220, 180, 0.25));
  border-bottom: 2px solid color-mix(in srgb, var(--pure-black) 50%, transparent);
}

.harp-soundboard {
  background: linear-gradient(
    180deg,
    var(--play-harp-c04, #4a3520),
    var(--play-harp-c05, #2a1d10) 40%,
    var(--play-harp-c10, #1a1208)
  );
  border-radius: 4px 4px 18px 18px;
  border-top: 2px solid color-mix(in srgb, var(--pure-black) 50%, transparent);
  border-bottom: 1px solid var(--play-harp-c11, rgba(255, 220, 180, 0.1));
  height: 28px;
}

.harp-strings {
  flex: 1;
  position: relative;
  display: grid;
  /* JS sets --strings to the count; columns split the area evenly. */
  grid-template-columns: repeat(var(--strings, 15), 1fr);
  /* Touch-action none so swipes don't scroll the page on phones. */
  touch-action: none;
  background: radial-gradient(800px 200px at 50% 50%, var(--play-harp-glow-soft), transparent 70%),
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--pure-black) 25%, transparent),
      color-mix(in srgb, var(--pure-black) 0%, transparent)
    );
}

.harp-string {
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: center;
  cursor: pointer;
  /* Each string's hit zone is the full column; the visual is just the
   * centred line. CSS variable --string-color is set per string from JS
   * (red for root, blue for the perfect-fourth/F-equivalent).
   *
   * --deflect:  set live by JS while the pointer drags on this string;
   *             pulls the visible line sideways under the finger.
   * --from:     captured at release time so the snap-back wobble starts
   *             from wherever the string was being held. */
  --string-color: rgba(220, 220, 230, 0.9);
  --deflect: 0px;
  --from: 0px;
}

/* The visible string line. Thin gradient line, slightly thicker on touch
 * targets so it reads as plucked steel/nylon. The transform is updated
 * live (no transition) while the user is dragging; on release the
 * .plucked class kicks in a keyframe animation that wobbles back. */
.harp-string::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--pure-white) 5%, transparent),
    var(--string-color) 8%,
    var(--string-color) 92%,
    color-mix(in srgb, var(--pure-white) 5%, transparent)
  );
  border-radius: 1px;
  box-shadow: 0 0 6px color-mix(in srgb, var(--pure-white) 5%, transparent);
  transform: translateX(var(--deflect));
  pointer-events: none;
  will-change: transform, filter;
}

.harp-string.root::before {
  width: 3px;
  margin-left: -1.5px;
}

/* Plucked: snap-back wobble from the held position to centre, plus a
 * brightness/blur flash that reads as a standing wave. The wobble
 * over-shoots and decays, mimicking how a plucked harp string oscillates
 * with diminishing amplitude. The starting offset comes from --from,
 * which JS sets to whatever --deflect was at release time. */
.harp-string.plucked::before {
  animation: harp-release 0.55s ease-out;
}

@keyframes harp-release {
  0% {
    transform: translateX(var(--from));
    filter: brightness(1.7) blur(0);
  }
  18% {
    transform: translateX(calc(var(--from) * -0.45));
    filter: brightness(2.1) blur(1.4px);
  }
  40% {
    transform: translateX(calc(var(--from) * 0.22));
    filter: brightness(1.5) blur(0.7px);
  }
  62% {
    transform: translateX(calc(var(--from) * -0.1));
    filter: brightness(1.25) blur(0.3px);
  }
  82% {
    transform: translateX(calc(var(--from) * 0.04));
    filter: brightness(1.1) blur(0.1px);
  }
  100% {
    transform: translateX(0);
    filter: brightness(1) blur(0);
  }
}

.harp-string-label {
  position: absolute;
  top: 4px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--play-harp-label);
  font-weight: 700;
  pointer-events: none;
  z-index: 3;
}

.harp-string.root .harp-string-label {
  color: color-mix(in srgb, var(--danger) 95%, transparent);
}

.harp-strings.hide-labels .harp-string-label {
  display: none;
}

/* Touch-target padding: each string is at least 28px wide for hit-testing
 * via grid columns. On dense layouts (chromatic, 3 octaves) the columns
 * shrink, so we widen the visible glow on press for feedback. */
.harp-string.plucked {
  background: radial-gradient(circle at 50% 50%, var(--play-harp-glow), transparent 60%);
}

@media (prefers-reduced-motion: reduce) {
  .harp-string.plucked::before {
    animation: none !important;
    filter: brightness(1.4);
    transform: translateX(0);
  }
  .harp-string::before {
    transform: translateX(0) !important;
  }
}

@media (max-width: 640px) {
  .harp-frame {
    height: clamp(280px, 60vh, 460px);
  }
  .harp-string-label {
    font-size: 9px;
    top: 2px;
  }
  .harp-neck {
    height: 16px;
  }
  .harp-soundboard {
    height: 20px;
  }
}

/* The toggle-label class is shared with metronome's accent toggle. */
.control-toggle .toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--fg);
}

.control-toggle .toggle-label input[type='checkbox'] {
  accent-color: var(--accent);
  transform: scale(1.15);
  cursor: pointer;
}
