/* ==========================================================================
   Paddy Prompt Studio — shared string-instrument tuner (ukulele, bass)
   A generalised copy of the guitar tuner styles. Layers on /blog/style.css
   (same dark indigo/cyan palette and type scale). Pads and the string diagram
   are generated by string-tuner.js, so the grid adapts to 4, 5 or 6 strings.
   ========================================================================== */

:root {
  --good: #34d399;      /* within ±5 cents */
  --near: #fcd34d;      /* within ±20 cents */
  --off:  #fb7185;      /* further out */
}

/* ------------------------------------------------------------ Tuner shell */
.tuner {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid var(--border); border-radius: 22px;
  padding: 1.25rem; margin: 0.5rem 0 1rem;
  box-shadow: 0 30px 70px -40px rgba(99, 102, 241, 0.6);
}

/* Controls row */
.tuner-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem;
  padding-bottom: 1rem; border-bottom: 1px solid var(--border-soft);
}
.control {
  display: inline-flex; align-items: center; gap: 0.45rem;
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.35rem 0.55rem;
}
.control > .lbl {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.62rem;
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-dim); font-weight: 700;
}
.control select {
  font: inherit; font-size: 0.9rem; font-weight: 600; color: var(--text);
  background: #07080d; border: 1px solid var(--border); border-radius: 9px;
  padding: 0.4rem 0.5rem; max-width: 15rem;
}
.control .step {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  width: 1.8rem; height: 1.8rem; border-radius: 8px; line-height: 1;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border);
  color: var(--text); font-size: 1rem; font-weight: 700;
}
.control .step:hover { background: rgba(129, 140, 248, 0.22); }
.control .a4-val {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 700;
  font-size: 0.9rem; min-width: 4.4rem; text-align: center; color: #c7d2fe;
}

.mic-btn {
  display: inline-flex; align-items: center; gap: 0.5rem; cursor: pointer;
  margin-left: auto; padding: 0.6rem 1.15rem; border: 0; border-radius: 12px;
  font: inherit; font-size: 0.95rem; font-weight: 700;
  background: linear-gradient(135deg, #818cf8, #22d3ee); color: #0b0620;
}
.mic-btn:hover { filter: brightness(1.08); }
.mic-btn[data-state="listening"] { background: rgba(52, 211, 153, 0.16); color: #6ee7b7; border: 1px solid rgba(52, 211, 153, 0.45); }
.mic-btn .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: currentColor; }
.mic-btn[data-state="listening"] .dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.tuner-status {
  margin: 0.85rem 0 0; font-size: 0.88rem; color: var(--text-muted); min-height: 1.3em;
}
.tuner-status.err { color: #fca5a5; font-weight: 600; }

/* ------------------------------------------------------------ Dial + note */
.dial-area {
  display: grid; gap: 0.5rem; justify-items: center;
  padding: 1.1rem 0 0.25rem;
}
.dial { width: 100%; max-width: 30rem; display: block; }
/* The needle pivots around the dial centre in user-space units, and both the
   needle and the "in tune" arc take their colour from `color` so the JS only
   has to swap one class (is-good / is-near / is-off). */
.dial .needle {
  transform-box: view-box; transform-origin: 200px 200px;
  transition: transform 90ms linear;
  color: var(--indigo-strong);
}
.dial .zone { color: var(--good); transition: opacity 200ms ease; }
.dial .zone.dim { opacity: 0.3; }
@media (prefers-reduced-motion: reduce) { .dial .needle { transition: none; } }

.note-read { text-align: center; margin-top: -0.35rem; }
.note-read .note {
  font-family: "Space Grotesk", "Inter", sans-serif; font-weight: 800;
  font-size: clamp(3.2rem, 13vw, 4.6rem); line-height: 1; color: #fff;
  letter-spacing: -0.03em; display: inline-flex; align-items: flex-start;
}
.note-read .note .oct { font-size: 0.34em; font-weight: 700; color: var(--indigo); margin-left: 0.15em; padding-top: 0.35em; }
.note-read .verdict {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-weight: 700;
  font-size: 0.82rem; letter-spacing: 0.18em; text-transform: uppercase;
  margin: 0.35rem 0 0; color: var(--text-dim); min-height: 1.3em;
}
.note-read .hz {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.82rem; color: var(--text-dim); margin: 0.15rem 0 0;
}
.is-good { color: var(--good) !important; }
.is-near { color: var(--near) !important; }
.is-off  { color: var(--off)  !important; }

/* ------------------------------------------- String / tuning-peg diagram */
.headstock { width: 100%; max-width: 30rem; margin: 0.6rem auto 0; display: block; }
.headstock .str-line, .headstock .peg-ring { transition: stroke 200ms ease, opacity 200ms ease; }
.headstock .str-row .str-line { stroke: rgba(232, 236, 244, 0.30); }
.headstock .str-row .peg-ring { stroke: rgba(232, 236, 244, 0.28); fill: #07080d; }
.headstock .str-row .str-label { fill: var(--text-dim); }
.headstock .str-row[data-active="true"] .str-line { stroke: var(--good); }
.headstock .str-row[data-active="true"] .peg-ring { stroke: var(--good); fill: rgba(52, 211, 153, 0.18); }
.headstock .str-row[data-active="true"] .str-label { fill: #6ee7b7; }

/* ------------------------------------------------------------ String pads */
.strings {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.5rem;
  margin-top: 1.1rem;
}
.strings[data-n="5"] { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.strings[data-n="6"] { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.string-pad { min-height: 44px; }
.string-pad {
  position: relative; cursor: pointer; font: inherit; text-align: center;
  display: grid; gap: 0.1rem; padding: 0.7rem 0.25rem 0.6rem;
  background: rgba(255, 255, 255, 0.03); border: 1px solid var(--border);
  border-radius: 14px; color: var(--text); transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.string-pad:hover { border-color: rgba(129, 140, 248, 0.5); background: rgba(99, 102, 241, 0.10); }
.string-pad:active { transform: translateY(1px); }
.string-pad .num {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.6rem;
  letter-spacing: 0.1em; color: var(--text-dim); font-weight: 700;
}
.string-pad .pad-note { font-family: "Space Grotesk", "Inter", sans-serif; font-weight: 800; font-size: 1.32rem; line-height: 1.1; }
.string-pad .pad-hz { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.6rem; color: var(--text-dim); }
.string-pad[aria-current="true"] { border-color: rgba(129, 140, 248, 0.75); background: rgba(99, 102, 241, 0.16); }
.string-pad[data-tuned="true"] { border-color: rgba(52, 211, 153, 0.55); background: rgba(52, 211, 153, 0.12); }
.string-pad[data-tuned="true"] .pad-note { color: var(--good); }
.string-pad[data-playing="true"] { border-color: rgba(103, 232, 249, 0.75); box-shadow: 0 0 0 1px rgba(103, 232, 249, 0.35) inset; }
.string-pad .tick {
  position: absolute; top: 0.3rem; right: 0.4rem; font-size: 0.72rem; color: var(--good);
  opacity: 0; transition: opacity 0.2s ease;
}
.string-pad[data-tuned="true"] .tick { opacity: 1; }

.tuner-hint {
  margin: 0.9rem 0 0; text-align: center; font-size: 0.85rem; color: var(--text-dim);
}
.tuner-hint kbd {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.78rem;
  background: rgba(129, 140, 248, 0.14); border: 1px solid var(--border-soft);
  border-radius: 5px; padding: 0.05em 0.35em; color: #c7d2fe;
}

/* ------------------------------------------------------------ Mode toggle */
.seg { display: inline-flex; background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 12px; padding: 0.22rem; gap: 0.15rem; }
.seg button {
  min-height: 2.2rem;
  font: inherit; font-size: 0.82rem; font-weight: 700; cursor: pointer;
  border: 0; border-radius: 9px; padding: 0.4rem 0.7rem;
  background: transparent; color: var(--text-muted);
}
.seg button[aria-pressed="true"] { background: rgba(99, 102, 241, 0.22); color: #fff; }

/* ------------------------------------------------------------ Prose tables */
.table-wrap { overflow-x: auto; margin: 0 0 1.5rem; border: 1px solid var(--border); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
table.data caption { text-align: left; padding: 0.85rem 1rem 0.2rem; color: var(--text-dim); font-size: 0.82rem; }
table.data th, table.data td { padding: 0.6rem 1rem; text-align: left; border-bottom: 1px solid var(--border-soft); }
table.data thead th {
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.68rem;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--indigo); font-weight: 700;
  background: rgba(255, 255, 255, 0.03);
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.mono, table.data th.mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: 0.85rem; color: #a5f3fc; }
table.data tbody tr:hover { background: rgba(129, 140, 248, 0.05); }

/* ------------------------------------------------------------ Responsive */
@media (max-width: 640px) {
  .tuner { padding: 0.9rem; border-radius: 18px; }
  .mic-btn { margin-left: 0; width: 100%; justify-content: center; }
  .tuner-controls { gap: 0.5rem; }
  .control select { max-width: 11rem; }
  .strings[data-n="6"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .strings[data-n="5"] { gap: 0.35rem; }
  .strings[data-n="5"] .string-pad .pad-note { font-size: 1.12rem; }
  .strings[data-n="5"] .string-pad .pad-hz { font-size: 0.55rem; }
  .tuner-extras .extra-btn { flex: 1 1 auto; justify-content: center; }
}

/* ------------------------------------------------- Extras row (per page) */
.tuner-extras {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem;
  margin-top: 0.9rem;
}
.extra-btn {
  display: inline-flex; align-items: center; gap: 0.45rem; cursor: pointer;
  min-height: 44px; padding: 0.5rem 0.95rem; border-radius: 12px;
  font: inherit; font-size: 0.88rem; font-weight: 700; color: var(--text);
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border);
}
.extra-btn:hover { background: rgba(129, 140, 248, 0.16); border-color: rgba(129, 140, 248, 0.5); }
.extra-btn[aria-pressed="true"] { background: rgba(34, 211, 238, 0.14); border-color: rgba(103, 232, 249, 0.6); color: #a5f3fc; }
.extra-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.extra-btn .ico { font-size: 1rem; line-height: 1; }

/* ------------------------------------------- "All strings in tune" glow */
.tuner.is-celebrating { animation: tuned-glow 1.6s ease-out 1; }
.tuner.is-celebrating .string-pad[data-tuned="true"] { animation: pad-pop 0.6s ease-out 1; }
@keyframes tuned-glow {
  0%   { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.0), 0 30px 70px -40px rgba(99, 102, 241, 0.6); }
  25%  { box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.45), 0 0 60px 6px rgba(52, 211, 153, 0.25); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.0), 0 30px 70px -40px rgba(99, 102, 241, 0.6); }
}
@keyframes pad-pop { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .mic-btn[data-state="listening"] .dot { animation: none; }
  .tuner.is-celebrating, .tuner.is-celebrating .string-pad[data-tuned="true"] { animation: none; }
  .tuner.is-celebrating { border-color: rgba(52, 211, 153, 0.6); }
  .string-pad, .headstock .str-line, .headstock .peg-ring { transition: none; }
}

/* ------------------------------------------- Suno snippet copy button */
.code-block .label .copy-btn {
  margin-left: auto; cursor: pointer; min-height: 2rem; padding: 0.25rem 0.7rem;
  font: inherit; font-size: 0.68rem; letter-spacing: 0.1em; color: #c7d2fe;
  background: rgba(129, 140, 248, 0.14); border: 1px solid var(--border); border-radius: 8px;
}
.code-block .label .copy-btn:hover { background: rgba(129, 140, 248, 0.28); }
.snippet-actions { margin: -0.6rem 0 1.4rem; }
