/* instrument-tuner/instrument-tuner.css: the Instrument Tuner's layout. Page
 * parts (header, buttons, windows, footer) come from shared/ui/page.css. No
 * panels: the strings (a canvas) run down the middle, the note sits above them
 * and the string circles below. */

.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.tuner {
  position: relative; min-height: 0;
  display: grid; grid-template-rows: auto auto minmax(80px, 1fr) auto auto auto; justify-items: center; align-items: center;
}
/* Computers: the tuner is centred in the window with a capped height, so Listen
   is never at the window's bottom edge (phones keep it under the thumb). */
@media (min-width: 900px) and (hover: hover) and (pointer: fine) {
  .page > main.tuner { flex: 0 1 auto; height: min(580px, calc(100dvh - 180px)); margin-block: auto; }
}

.strings-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tuning-row, .head, .string-btns, .readout, .listen-btn { position: relative; }
.tool-title { white-space: nowrap; overflow: hidden; }
.tool-title.two-lines { white-space: normal; line-height: 1.2; }

/* The instrument and tuning: a slim outlined chip that opens the shared dropdown list. */
.tuning-row { padding: 2px 0 4px; }
.tuning-select { min-width: min(250px, 72vw); font-size: 14px; }
.tuning-select .select-selected {
  justify-content: center; gap: 4px; min-height: 44px; box-sizing: border-box; padding: 6px 16px; border-radius: 999px;
  background: transparent; color: var(--color-text); border-color: color-mix(in srgb, var(--color-text) 45%, transparent);
}
.tuning-select .select-selected:after { color: var(--color-text); opacity: 0.7; }
.tuning-select .select-items { max-height: min(330px, 55dvh); }

/* The note: its name big, the octave small beside it, above the strings. */
.head { display: grid; place-items: center; font-size: clamp(48px, min(17vw, 10dvh), 112px); min-height: 1.06em; width: 100%; }
.note, .prompt { grid-area: 1 / 1; margin: 0; }
.note {
  display: flex; align-items: flex-start; line-height: 1; white-space: nowrap;
  font-family: var(--font-display); font-weight: 800; font-size: var(--note-size, 1em); color: var(--color-text); transition: color 0.25s;
}
.note .acc { width: 0.36em; height: 0.58em; margin: 0.06em 0 0 0.05em; }
.note .oct { font-size: 0.26em; margin: 0.12em 0 0 0.12em; opacity: 0.6; }
.prompt { font-size: 18px; line-height: 1.3; text-align: center; color: var(--color-text); max-width: 20em; }
.tuner.in-tune .note, .tuner.in-tune .say, .tuner.all-tuned .say { color: var(--color-tune); }
/* Monochrome has no accent colour: off the note is grey, in tune it lights up white. */
body[data-theme="bw"] .tuner.has-note:not(.in-tune) :is(.note, .say) { color: var(--color-tune-line); }

/* The strings' area: tapping it starts listening. */
.stage { align-self: stretch; justify-self: stretch; min-height: 0; }
.tuner.idle .stage { cursor: pointer; }

/* The string circles: tap one to stay on it (aria-pressed, a small lock below). */
.string-btns { display: flex; justify-content: center; gap: clamp(6px, 3.2vw, 28px); padding: 6px 0 16px; }
.string-btns:empty { display: none; }
.string-btn {
  position: relative; width: 44px; height: 44px; padding: 0; border-radius: 50%; cursor: pointer; touch-action: manipulation;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid color-mix(in srgb, var(--color-text) 35%, transparent); background: transparent; color: var(--color-text);
  font: 700 17px/1 var(--font-display); transition: background 0.2s ease-out, color 0.2s ease-out, border-color 0.2s ease-out, box-shadow 0.2s ease-out;
}
.string-btn .name { display: inline-flex; align-items: flex-start; }
.string-btn .acc { width: 0.42em; height: 0.68em; margin: -0.05em 0 0 0.04em; }
.string-btn.active { border-color: var(--color-text); box-shadow: inset 0 0 0 1px var(--color-text); }
.string-btn.tuned { background: var(--color-tune); border-color: var(--color-tune); color: var(--bg-page); }
.string-btn.tuned.active { box-shadow: 0 0 0 2px var(--bg-page), 0 0 0 3px var(--color-tune); }
.string-btn .lock { position: absolute; left: 50%; top: calc(100% + 3px); width: 12px; height: 12px; margin-left: -6px; display: none; color: var(--color-text); }
.string-btn[aria-pressed="true"] .lock { display: block; }
.string-btn:focus-visible { outline: 2px solid var(--color-right); outline-offset: 3px; }

.readout { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 2px 0 18px; }
.say { margin: 0; min-height: 1.3em; font-size: 16px; line-height: 1.3; text-align: center; transition: color 0.25s; }

/* The thin line: a notch in the middle, the dot slides ±50 cents. */
.line { position: relative; width: min(260px, 70vw); height: 1px; background: color-mix(in srgb, var(--color-text) 35%, transparent); }
.notch { position: absolute; left: 50%; top: -7px; width: 1px; height: 15px; background: var(--color-text); }
/* The in-tune zone (±5 cents, or ±2 in Hard mode: --tol is set in JS). */
.zone {
  position: absolute; left: calc(50% - var(--tol, 5%)); width: calc(2 * var(--tol, 5%)); top: -1px; height: 3px; border-radius: 2px;
  background: color-mix(in srgb, var(--color-text) 45%, transparent); transition: background 0.25s, left 0.25s, width 0.25s;
}
.tuner.in-tune .zone { background: var(--color-tune); }
.dot {
  position: absolute; left: var(--at, 50%); top: -6px; width: 13px; height: 13px; margin-left: -6.5px; border-radius: 50%;
  background: var(--color-tune-line); opacity: 0; transition: opacity 0.2s, background 0.25s;
}
.tuner.has-note .dot { opacity: 1; }
.tuner.in-tune .dot { background: var(--color-tune); box-shadow: 0 0 12px var(--color-tune); }

/* The main button, at the bottom. */
.listen-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-width: min(260px, 70vw); min-height: 48px; border-radius: var(--radius-control); font-size: 16px;
}
/* The main action is filled; while it runs it turns into an outline. */
.listen-btn.on { background: transparent; color: var(--color-text); border-color: color-mix(in srgb, var(--color-text) 55%, transparent); }
@media (hover: hover) { .listen-btn.on:hover { background: var(--color-hover); color: var(--color-hover-text); } }
.listen-btn svg { width: 20px; height: 20px; flex: none; }
.listen-btn .stop-icon, .listen-btn.on .mic-icon { display: none; }
.listen-btn.on .stop-icon { display: block; }
.mic-msg { max-width: 30em; text-align: center; }

/* Settings: segmented choices. */
.group-label { font-size: 15px; font-weight: 600; }
.seg { display: flex; border: var(--border-width) solid var(--border-panel); border-radius: var(--radius-control); overflow: hidden; }
.seg button {
  flex: 1 1 0; min-width: 0; min-height: 44px; padding: 4px 8px; border: 0; background: var(--color-panel); color: var(--color-btn-text); cursor: pointer;
  font: 600 14px/1.15 var(--font-main); touch-action: manipulation; transition: background 0.15s ease-out, color 0.15s ease-out;
}
.seg button + button { border-left: 1px solid var(--border-panel); }
.seg button[aria-pressed="true"] { background: var(--color-left); color: var(--color-text-pinched); }
.seg button:focus-visible { outline: 2px solid var(--color-right); outline-offset: -3px; }
@media (hover: hover) and (pointer: fine) {
  .seg button:hover:not([aria-pressed="true"]) { background: var(--color-hover); color: var(--color-hover-text); }
  .listen-btn:hover, .tuning-select .select-selected:hover { background: color-mix(in srgb, var(--color-text) 12%, transparent); color: var(--color-text); }
  .string-btn:hover:not(.tuned) { background: color-mix(in srgb, var(--color-text) 12%, transparent); }
}

/* Themes */
body[data-theme="retro"] .note { text-shadow: 0 0 var(--shadow-blur) color-mix(in srgb, currentColor 55%, transparent); }
body[data-theme="y2k"] .note { text-shadow: 0 0 14px color-mix(in srgb, currentColor 55%, transparent); }
body[data-theme="bw"] :is(.seg, .listen-btn, .zone, .tuning-select .select-selected) { border-radius: 0; }

/* Phones: everything on one screen; line heights pinned (theme fonts differ a lot in height). */
/* Very small phones (320 px): six strings still fit without sideways scrolling. */
@media (max-width: 360px) {
  .string-btns { gap: 5px; }
  .string-btn { width: 40px; height: 40px; }
}

@media (max-width: 600px) {
  .readout { gap: 16px; padding-bottom: 14px; }
  .say { font-size: 15px; line-height: 1.25; }
  .prompt { font-size: 16px; line-height: 1.25; }
  .string-btns { padding: 4px 0 15px; }
  .listen-btn { min-height: 46px; margin-bottom: 4px; }
  #about-modal .about-text { line-height: 1.45; }
}
