/* Tuner component in the Music with Marco "Stage" style: a dark card with an
   arc gauge and a small headstock. Everything is scoped under .tuner so it
   can drop into any page. */

.tuner {
  --tuner-ink: #1a1612;
  --tuner-ink-card: #2a241d;
  --tuner-cream: #fbf7ee;
  --tuner-muted: rgb(251 247 238 / 0.55);
  --tuner-faint: rgb(255 255 255 / 0.07);
  --tuner-accent: #f0b429;
  --tuner-accent-deep: #b8860b;
  --tuner-good: #7fd08c;
  --mood: var(--tuner-accent);

  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 18px 20px 16px;
  border-radius: 24px;
  background: radial-gradient(120% 80% at 50% 0%, var(--tuner-ink-card), var(--tuner-ink) 70%);
  box-shadow: 0 20px 44px rgb(26 22 18 / 0.25);
  color: var(--tuner-cream);
  font-family: 'Inter Tight', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
  box-sizing: border-box;
}

.tuner *,
.tuner *::before,
.tuner *::after {
  box-sizing: border-box;
}

.tuner button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

/* Host pages often style p and select; keep ours as designed. */
.tuner p {
  max-width: none;
  margin: 0;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
  text-align: center;
}

.tuner-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tuner[data-state='close'] { --mood: var(--tuner-cream); }
.tuner[data-state='in-tune'] { --mood: var(--tuner-good); }
.tuner[data-state='idle'],
.tuner[data-state=''] { --mood: var(--tuner-muted); }

/* ---- Tuning menu and headstock ---- */

.tuner-top {
  display: flex;
  min-height: 34px;
}

.tuner.has-headstock .tuner-top {
  padding-right: 104px;
}

.tuner-tuning {
  min-width: 0;
}

.tuner .tuner-tuning select {
  max-width: 100%;
  padding: 8px 32px 8px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--tuner-faint)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23fbf7ee' stroke-opacity='.6' stroke-width='1.6'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5'/%3E%3C/svg%3E")
    no-repeat right 12px center;
  color: var(--tuner-cream);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  appearance: none;
  cursor: pointer;
}

.tuner .tuner-tuning select option {
  color: #1a1612;
}

.tuner-headstock {
  position: absolute;
  top: 6px;
  right: 10px;
  width: 104px;
  overflow: visible;
}

.tuner:not(.has-headstock) .tuner-headstock {
  display: none;
}

.tuner-headstock .head { stroke: rgb(251 247 238 / 0.22); stroke-width: 0.8; }
.tuner-headstock .nut { fill: #efe6d0; }
.tuner-headstock .fret { stroke: rgb(251 247 238 / 0.3); stroke-width: 0.8; }
.tuner-headstock .string { stroke: rgb(251 247 238 / 0.5); stroke-width: 0.7; }
.tuner-headstock .string.is-active { stroke: var(--tuner-accent); stroke-width: 1.2; }
.tuner-headstock .bushing { fill: #2a2119; stroke: rgb(251 247 238 / 0.18); stroke-width: 0.6; }
.tuner-headstock .post { fill: #cfc5ae; }
.tuner-headstock .shaft { fill: #9a907e; }
.tuner-headstock .key { fill: #e9e0cc; transition: fill 0.2s; }
.tuner-headstock .peg.is-tuned .key { fill: var(--tuner-good); }
.tuner-headstock .peg.is-active .key { fill: var(--tuner-accent); filter: drop-shadow(0 0 3px var(--tuner-accent)); }
.tuner[data-state='in-tune'] .tuner-headstock .peg.is-active .key { fill: var(--tuner-good); filter: drop-shadow(0 0 3px var(--tuner-good)); }
.tuner[data-state='in-tune'] .tuner-headstock .string.is-active { stroke: var(--tuner-good); }

/* ---- Gauge ---- */

.tuner-dial {
  position: relative;
  max-width: 300px;
  margin: 14px auto 0;
}

.tuner-gauge {
  display: block;
  width: 100%;
  overflow: visible;
}

.tuner-arc { fill: none; stroke: rgb(255 255 255 / 0.12); stroke-width: 2; }
.tuner-tick { stroke: rgb(255 255 255 / 0.28); stroke-width: 2; stroke-linecap: round; }
.tuner-zone { fill: none; stroke: var(--tuner-accent); stroke-width: 8; stroke-linecap: round; transition: stroke 0.2s; }
.tuner[data-state='in-tune'] .tuner-zone { stroke: var(--tuner-good); }

.tuner-needle {
  transform-box: view-box;
  transform-origin: 150px 160px;
  transition: transform 0.12s linear, opacity 0.2s;
}
.tuner-needle line { stroke: var(--tuner-accent); stroke-width: 3; stroke-linecap: round; transition: stroke 0.2s; }
.tuner-needle circle { fill: var(--tuner-accent); transition: fill 0.2s; }
.tuner[data-state='in-tune'] .tuner-needle line { stroke: var(--tuner-good); }
.tuner[data-state='in-tune'] .tuner-needle circle { fill: var(--tuner-good); }
.tuner[data-state='idle'] .tuner-needle,
.tuner[data-state=''] .tuner-needle { opacity: 0.25; }

.tuner-note {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4px;
  font-size: 76px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  transition: color 0.2s, text-shadow 0.3s, opacity 0.2s;
}
.tuner-accidental { font-size: 0.5em; vertical-align: 0.7em; }
.tuner[data-state='in-tune'] .tuner-note { color: var(--tuner-good); text-shadow: 0 0 28px rgb(127 208 140 / 0.45); }
.tuner.is-held .tuner-note,
.tuner.is-held .tuner-needle { opacity: 0.45; }

.tuner-readout {
  display: flex;
  justify-content: space-between;
  margin: 10px 8px 0;
  font-size: 13px;
  color: var(--tuner-muted);
  font-variant-numeric: tabular-nums;
}

.tuner .tuner-hint {
  margin-top: 6px;
  font-size: 18px;
  font-weight: 700;
  color: var(--mood);
  transition: color 0.2s;
}

/* ---- Strings ---- */

.tuner-strings {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.tuner .tuner-string {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--tuner-faint);
  font-size: 16px;
  font-weight: 700;
  transition: background-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.tuner-string sub { font-size: 10px; opacity: 0.55; vertical-align: baseline; }
.tuner .tuner-string:hover { background: rgb(255 255 255 / 0.12); }
.tuner .tuner-string.is-tuned { box-shadow: inset 0 0 0 2px var(--tuner-good); }
.tuner .tuner-string.is-locked { box-shadow: inset 0 0 0 2px var(--tuner-accent); }
.tuner .tuner-string.is-active { background: var(--tuner-accent); color: var(--tuner-ink); }
.tuner.is-chromatic .tuner-string { opacity: 0.5; }

.tuner .tuner-help {
  margin-top: 10px;
  font-size: 12px;
  color: var(--tuner-muted);
}

/* ---- Footer ---- */

.tuner-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 18px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgb(255 255 255 / 0.08);
  font-size: 12px;
  color: var(--tuner-muted);
}

.tuner-a4 {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.tuner .tuner-a4 button {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--tuner-faint);
  line-height: 1;
}

.tuner-a4 output {
  min-width: 2em;
  color: var(--tuner-cream);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.tuner-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.tuner-toggle input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--tuner-accent);
}

.tuner .tuner-stop {
  text-decoration: underline;
  text-underline-offset: 3px;
  color: var(--tuner-muted);
}

/* ---- Start ---- */

.tuner-start {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 24px;
  border-radius: inherit;
  background: rgb(26 22 18 / 0.88);
}

.tuner-start[hidden] {
  display: none;
}

.tuner .tuner-mic {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  margin-bottom: 18px;
  border-radius: 50%;
  background: var(--tuner-accent);
  color: var(--tuner-ink);
  box-shadow:
    0 0 0 10px rgb(240 180 41 / 0.22),
    0 0 0 22px rgb(240 180 41 / 0.1);
  transition: transform 0.15s;
}
.tuner .tuner-mic:hover { transform: scale(1.04); }
.tuner .tuner-mic:disabled { opacity: 0.6; cursor: progress; }
.tuner-mic svg { width: 28px; height: 28px; }
.tuner-start b { font-size: 17px; }
.tuner-start small { font-size: 13px; color: var(--tuner-muted); }

.tuner .tuner-error {
  max-width: 300px;
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgb(220 38 38 / 0.15);
  color: #fca5a5;
  font-size: 13px;
}

@media (max-width: 420px) {
  .tuner { padding-left: 14px; padding-right: 14px; }
  .tuner-headstock { width: 88px; right: 6px; }
  .tuner .tuner-string { width: 40px; height: 40px; }
  .tuner.has-headstock .tuner-top { padding-right: 88px; }
}
