/* The tuner uses the app's theme surfaces and remains a single compact tool. */
#tuner-section { --tune-good: #237653; --tune-line: var(--panel-border); width: min(100%, 900px); }
:root[data-theme='dark'] #tuner-section { --tune-good: #71d4a1; }
.tune-workspace { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; width: 100%; color: var(--ink); }
.tune-stage, .tune-controls { min-width: 0; border: 1px solid var(--tune-line); border-radius: 22px; background: var(--surface-card); padding: 22px; box-shadow: var(--edge-light-soft); }
.tune-stage { display: flex; flex-direction: column; align-items: stretch; justify-content: center; background: radial-gradient(ellipse at 50% 45%, var(--accent-soft), transparent 70%), var(--surface-card); }
.tune-stage-top, .tune-strings-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tune-stage-top { margin-bottom: auto; }
.tune-eyebrow { font: 650 10px/1.3 var(--sans-stack); letter-spacing: .13em; color: var(--muted); }
.tune-input { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.tune-input i { width: 20px; height: 6px; border-radius: 5px; background: var(--tune-line); overflow: hidden; }
.tune-input i::before { content: ''; display: block; height: 100%; width: var(--signal, 0%); background: var(--tune-good); transition: width 100ms; }
.tune-readout { display: flex; align-items: center; justify-content: center; gap: 22px; padding: 24px 0 16px; }
.tune-note-line { display: flex; align-items: baseline; min-height: 96px; }
.tune-note-line > span { font: 500 100px/.95 var(--sans-stack); letter-spacing: -.06em; }
.tune-note-line > sub { font: 500 28px/1 var(--sans-stack); color: var(--muted); bottom: auto; margin-left: 4px; }
.tune-deviation { display: flex; flex-direction: column; gap: 4px; border-left: 1px solid var(--tune-line); padding-left: 20px; min-width: 68px; }
.tune-deviation strong { font: 500 25px/1.1 var(--sans-stack); font-variant-numeric: tabular-nums; min-width: 4ch; text-align: center; }
.tune-deviation > span { font-size: 11px; color: var(--muted); }
.tune-gauge { width: 100%; margin: 4px 0 12px; }
.tune-gauge-labels, .tune-gauge-scale { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 10px; }
.tune-gauge-labels { font-size: 21px; }
.tune-gauge-labels small { font-size: 9px; letter-spacing: .08em; vertical-align: middle; }
.tune-zero { font-size: 11px; color: var(--tune-good); }
.tune-track { position: relative; height: 36px; margin: 7px 5% 6px; background: repeating-linear-gradient(90deg, var(--tune-line) 0 1px, transparent 1px 5%); background-size: 100% 14px; background-repeat: no-repeat; background-position: center; }
.tune-track::after { content: ''; position: absolute; inset: 50% 0 auto; height: 1px; background: var(--tune-line); }
.tune-tolerance { position: absolute; inset: 0 auto 0 47%; width: 6%; background: color-mix(in srgb, var(--tune-good) 14%, transparent); border-radius: 5px; }
.tune-center { position: absolute; inset: 0 auto 0 50%; width: 1px; background: var(--tune-good); }
.tune-pointer { position: absolute; z-index: 1; top: 0; bottom: 0; left: calc(50% + var(--tuner-needle, 0%)); width: 3px; border-radius: 2px; background: var(--accent); transform: translateX(-50%); transition: background-color 180ms ease, box-shadow 180ms ease; }
.tune-pointer::before { content: ''; position: absolute; top: -3px; left: -3px; width: 9px; height: 9px; border-radius: 50%; background: inherit; }
.tune-gauge-scale { margin-inline: 5%; font-variant-numeric: tabular-nums; }
.tune-status { margin: 0; min-height: 36px; display: flex; align-items: center; justify-content: center; color: var(--ink); font-size: 14px; font-weight: 600; line-height: 1.3; text-align: center; }
.tune-frequency { margin: 4px 0 0; text-align: center; font-size: 10px; line-height: 1.4; color: var(--muted); font-variant-numeric: tabular-nums; }
[data-tuner-state='in-tune'] .tune-note-line > span, [data-tuner-state='in-tune'] .tune-status, [data-tuner-state='in-tune'] .tune-deviation strong { color: var(--tune-good); }
[data-tuner-state='in-tune'] .tune-pointer { background: var(--tune-good); box-shadow: 0 0 9px color-mix(in srgb, var(--tune-good) 30%, transparent); }
[data-tuner-state='error'] .tune-status { color: var(--accent); font-size: 12px; }
.tune-controls { display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.tune-settings-row { display: grid; grid-template-columns: minmax(0, 1fr) 72px; gap: 10px; }
.tune-settings-row label, .tune-reference { display: flex; flex-direction: column; gap: 6px; font-size: 11px; font-weight: 600; color: var(--muted); min-width: 0; }
#tuner-section select, #tuner-section input { width: 100%; min-width: 0; height: 44px; padding: 0 10px; color: var(--ink); background-color: var(--surface-card-muted); border: 1px solid var(--tune-line); border-radius: 10px; font: 500 14px var(--sans-stack); box-shadow: none; }
#tuner-section select { padding-right: 25px; }
#tuner-section input { padding: 0 6px; text-align: center; }
#tuner-section button { font-family: var(--sans-stack); cursor: pointer; touch-action: manipulation; box-shadow: none; }
#tuner-section :is(button, input, select):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.tune-auto { border: 1px solid var(--tune-line); color: var(--muted); border-radius: 9px; background: var(--surface-card-muted); font-size: 11px; padding: 0 12px; min-height: 44px; }
.tune-auto[aria-pressed='true'] { color: var(--accent-deep); border-color: var(--accent); background: var(--accent-soft); }
.tune-strings { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.tune-string { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 7px; min-width: 0; min-height: 67px; border: 1px solid var(--tune-line); border-radius: 12px; padding: 7px 0; color: var(--ink); background: var(--surface-card-muted); }
.tune-string small { font-size: 9px; color: var(--muted); }
.tune-string > span { font-size: 21px; font-weight: 550; line-height: 1; }
.tune-string sub { font-size: 9px; margin-left: 1px; bottom: 0; }
.tune-string[aria-pressed='true'] { border-color: var(--accent); background: var(--accent-soft); }
.tune-string.is-detected { outline: 2px solid var(--accent); outline-offset: -2px; }
[data-tuner-state='in-tune'] .tune-string.is-detected { outline-color: var(--tune-good); color: var(--tune-good); }
.tune-hint, .tune-privacy { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.4; text-align: center; }
.tune-hint { min-height: 14px; }
.tune-actions { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 8px; }
#tuner-section .tune-actions button { min-height: 46px; border-radius: 12px; padding: 8px; font-size: 13px; font-weight: 600; }
.tune-listen { background: var(--ink); color: var(--page-bg); border: 1px solid var(--ink); }
.tune-tone { color: var(--ink); background: var(--surface-card-muted); border: 1px solid var(--tune-line); }
#tuner-section [hidden] { display: none; }
.tune-chromatic-hint { grid-column: 1 / -1; margin: 0; min-height: 67px; display: grid; place-content: center; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.6; }
@media (max-width: 700px) and (orientation: portrait) {
  #tuner-section { width: min(100%, 440px); }
  .tune-workspace { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .tune-stage, .tune-controls { padding: 16px; border-radius: 18px; }
  .tune-readout { padding: 18px 0 10px; }
  .tune-controls { gap: 9px; }
  .tune-string { min-height: 59px; }
}
@media (max-height: 760px) and (orientation: portrait) {
  .tune-stage, .tune-controls { padding: 12px; }
  .tune-readout { padding: 8px 0; }
  .tune-note-line { min-height: 68px; }
  .tune-note-line > span { font-size: 72px; }
  .tune-gauge { margin-block: 0 3px; }
  .tune-track { height: 27px; margin-block: 3px; }
  .tune-status { min-height: 30px; font-size: 12px; }
  .tune-controls { gap: 6px; }
  .tune-string { min-height: 48px; gap: 4px; border-radius: 9px; }
  .tune-settings-row label, .tune-reference { gap: 3px; }
}
@media (orientation: landscape) and (max-height: 600px) {
  .tune-workspace { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 10px; }
  .tune-stage, .tune-controls { padding: 12px; border-radius: 16px; }
  .tune-controls { gap: 6px; }
  .tune-readout { padding: 8px 0 4px; }
  .tune-note-line { min-height: 70px; }
  .tune-note-line > span { font-size: 76px; }
  .tune-deviation { padding-left: 12px; min-width: 52px; }
  .tune-track { height: 25px; margin-block: 3px; }
  .tune-gauge { margin-block: 0 4px; }
  .tune-status { min-height: 32px; font-size: 12px; }
  .tune-settings-row label, .tune-reference { gap: 3px; }
  .tune-string { min-height: 45px; gap: 3px; border-radius: 9px; }
  .tune-string > span { font-size: 18px; }
  .tune-strings { gap: 4px; }
  .tune-strings-heading .tune-eyebrow { font-size: 9px; letter-spacing: .06em; }
  .tune-privacy { font-size: 9px; }
}
@media (prefers-reduced-motion: reduce) { .tune-pointer, .tune-input i::before { transition: none; } }
/* Share the string row with Auto when height is scarce. */
@media (max-width: 700px) and (orientation: portrait), (max-height: 600px) and (orientation: landscape) {
  .tune-controls { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-content: center; }
  .tune-settings-row, .tune-hint, .tune-actions, .tune-privacy { grid-column: 1 / -1; }
  .tune-strings-heading { display: contents; }
  .tune-strings-heading .tune-eyebrow { display: none; }
  .tune-auto { padding: 0; min-width: 0; height: 100%; }
  .tune-strings { gap: 4px; }
  .tune-string > span { font-size: 18px; }
  .tune-string sub { font-size: 8px; }
  .tune-controls:has([data-tuner-auto][hidden]) .tune-strings { grid-column: 1 / -1; }
}
@media (max-height: 600px) and (orientation: portrait) {
  .tune-stage, .tune-controls { padding: 9px; }
  .tune-readout { padding: 2px 0; }
  .tune-note-line { min-height: 57px; }
  .tune-note-line > span { font-size: 60px; }
  .tune-note-line > sub { font-size: 22px; }
  .tune-status { min-height: 26px; }
}
body.tuner-active .control-deck, #tuner-section, .tune-workspace { min-width: 0; }
@media (orientation: landscape) and (max-height: 350px) {
  .tune-stage, .tune-controls { padding: 8px; }
  .tune-note-line { min-height: 60px; }
  .tune-note-line > span { font-size: 64px; }
  .tune-status { min-height: 28px; }
  .tune-controls { gap: 4px; }
  .tune-privacy { line-height: 1.2; }
}
@media (max-width: 700px), (max-height: 600px) {
  body:not(.is-native-app).tuner-active .deck-heading { display: none; }
}
@media (max-width: 350px) {
  body.tuner-active :is(.display-shortcut-actions, .app-header-actions, .web-app-shortcut-row) { gap: 4px; }
  body.tuner-active :is(.app-header-actions, .web-app-shortcut-row) button { width: 32px; min-width: 32px; }
}

/* A decaying string's last measurement remains readable, visibly held. */
[data-tuner-state='holding'] .tune-pointer { opacity: .45; }
[data-tuner-state='holding'] .tune-status { color: var(--muted); }

.tune-reference-heading { display: flex; align-items: center; gap: 5px; }
.tune-reference-help { position: relative; flex: none; }
.tune-reference-help summary { position: relative; display: grid; place-items: center; width: 16px; height: 16px; border: 1px solid var(--muted); border-radius: 50%; color: var(--muted); font: 600 10px/1 var(--sans-stack); list-style: none; cursor: pointer; touch-action: manipulation; }
.tune-reference-help summary::-webkit-details-marker { display: none; }
.tune-reference-help summary::after { content: ''; position: absolute; inset: -4px; }
.tune-reference-help summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.tune-reference-help[open] summary { color: var(--accent-deep); border-color: var(--accent); background: var(--accent-soft); }
.tune-reference-explanation { position: absolute; z-index: 20; top: calc(100% + 8px); right: 0; width: min(240px, calc(100vw - 40px)); padding: 12px; border: 1px solid var(--tune-line); border-radius: 12px; background: var(--page-bg); color: var(--ink); box-shadow: var(--shadow); font: 400 12px/1.5 var(--sans-stack); }
