/* ---- The Tuner (docs/product/tuner-tool-decisions.md) ----
   Listen to one string at a time and say, in words, whether to tune up or down. In the Tools
   panel the card is the title (with the tune's tuning), then the strings to tap or, while it
   listens, the note and a slim needle, and the mic button; the words under them. On the stage
   the header row hides and the body has the whole tool (_SessionTuner.cshtml).
   No red and no green: off is plain ink, far off is a warm orange needle, in tune is teal.
   Kept beside session.css, in the same layer, so the tool's styles stay in one place. */
@layer components {
  /* The tuning fork, in its card, the toolbar and the closed panel, draws with the tool
     icons' stroke rule in session.css; its tint is --av-tool-tuner-* in tokens.css. */
  .av-session-panel-open--tuner svg,
  .av-session-strip__mic {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* ---- The needle, in all three sizes ---- */
  .av-tuner__meter {
    position: relative;
    display: block;
    height: 52px;
  }

  /* The baseline, and a tick every 10 cents with the middle one darker. */
  .av-tuner__meter::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 2px;
    margin-top: -1px;
    background: rgba(15, 23, 42, 0.18);
  }

  .av-tuner__ticks {
    position: absolute;
    inset: 30% 0;
    background:
      linear-gradient(rgba(15, 23, 42, 0.55), rgba(15, 23, 42, 0.55)) 50% 0 / 2px 100% no-repeat,
      repeating-linear-gradient(to right, rgba(15, 23, 42, 0.22) 0 2px, transparent 2px 10%);
    background-position: 50% 0, -1px 0;
  }

  .av-tuner__zone {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 46%;
    width: 8%;
    border-radius: 6px;
    background: rgba(53, 171, 178, 0.16);
    transition: background-color 0.15s ease;
  }

  .av-tuner__needle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 6px;
    margin-left: -3px;
    border-radius: 3px;
    background: var(--av-ink);
    opacity: 0.15;
    transition: left 0.12s ease-out, background-color 0.15s ease;
  }

  [data-heard="true"] .av-tuner__needle {
    opacity: 1;
  }

  [data-far="true"] .av-tuner__needle {
    background: #c26a00;
  }

  [data-in-tune="true"] .av-tuner__needle,
  .av-session-strip--tuner[data-in-tune="true"] .av-tuner__needle {
    background: #176269;
  }

  [data-in-tune="true"] .av-tuner__zone,
  .av-session-strip--tuner[data-in-tune="true"] .av-tuner__zone {
    background: #8ac3c6;
  }

  /* What changed since the last item's tuning. */
  .av-tuner__notice {
    margin: 0;
    padding: 7px 10px;
    border-radius: 6px;
    background: #eaf5f5;
    font-size: 13px;
    line-height: 1.4;
  }

  .av-tuner__notice[hidden] {
    display: none;
  }

  /* A string: tap it to hear its note. Ghost, as it repeats in a row; the one being heard
     is ringed, a tuned one gets a tick, a retuned one says what standard has there. */
  .av-tuner__string {
    position: relative;
    min-height: 56px;
    padding: 4px 2px;
    border: 2px solid rgba(15, 23, 42, 0.14);
    border-radius: var(--av-btn-radius);
    background: transparent;
    color: var(--av-ink);
    cursor: pointer;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    line-height: 1;
  }

  .av-tuner__string:hover {
    background: rgba(53, 171, 178, 0.12);
  }

  .av-tuner__string:focus-visible {
    outline: 3px solid var(--av-accent);
    outline-offset: 2px;
  }

  .av-tuner__string b {
    font-size: 18px;
  }

  .av-tuner__string span {
    font-size: 11px;
    color: #4f5868;
  }

  .av-tuner__string--changed span {
    color: #176269;
  }

  .av-tuner__string[aria-current="true"] {
    background: #e6f4f5;
    border-color: var(--av-accent);
  }

  /* !important: Font Awesome's unlayered .fas sets display, which beats any layered rule. */
  .av-tuner__tick {
    display: none !important;
    position: absolute;
    top: 4px;
    right: 4px;
    font-size: 10px;
    color: #176269;
  }

  .av-tuner__string--tuned .av-tuner__tick {
    display: block !important;
  }

  /* ---- In the Tools panel ---- */
  .av-tuner__small {
    display: none;
  }

  .av-session-sidebar .av-tuner__small {
    order: 10;
    flex: 1 1 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
  }

  .av-session-sidebar .av-tool--tuner .av-tool__head {
    flex-wrap: wrap;
    row-gap: 8px;
    padding-bottom: 12px;
    border-bottom: 0;
  }

  .av-session-sidebar .av-tool--tuner .av-tool__body {
    display: none;
  }

  .av-tuner__small-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .av-tuner__small-strings {
    flex: 1 1 auto;
    display: flex;
    gap: 2px;
    min-width: 0;
  }

  .av-tuner__small-strings .av-tuner__string {
    flex: 1 1 0;
    min-width: 28px;
    min-height: 34px;
    border-color: transparent;
  }

  .av-tuner__small-strings .av-tuner__string b {
    font-size: 14px;
  }

  .av-tuner__small-strings .av-tuner__string span {
    display: none;
  }

  .av-tuner__small-reading {
    display: none;
    flex: 1 1 auto;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }

  .av-tuner__small-reading b {
    flex: none;
    width: 30px;
    font-size: 22px;
    text-align: center;
  }

  .av-tool--tuner[data-in-tune="true"] .av-tuner__small-reading b {
    color: #176269;
  }

  .av-tuner__meter--small {
    flex: 1 1 auto;
    height: 22px;
    border-radius: 4px;
    background: #f1f4f6;
  }

  .av-tuner__meter--small::before {
    display: none;
  }

  .av-tuner__meter--small .av-tuner__needle {
    top: 1px;
    bottom: 1px;
    width: 4px;
    margin-left: -2px;
  }

  .av-tool--tuner[data-listening="true"] .av-tuner__small-strings {
    display: none;
  }

  .av-tool--tuner[data-listening="true"] .av-tuner__small-reading {
    display: flex;
  }

  .av-tuner__small-toggle {
    flex: none;
    width: 36px;
    height: 34px;
    padding: 0 !important;
    display: grid;
    place-items: center;
  }

  /* Listening: the mic button turns into a dark Stop, like the Recorder's. */
  .av-tool--tuner[data-listening="true"] [data-tuner="toggle"] {
    background: var(--av-ink) !important;
    border-color: #141a26 !important;
    color: #f4f7fb !important;
  }

  .av-tuner__small-words {
    margin: 0;
    font-size: 13px;
    color: #4f5868;
  }

  .av-tool--tuner[data-heard="true"] .av-tuner__small-words {
    color: var(--av-ink);
  }

  .av-tool--tuner[data-in-tune="true"] .av-tuner__small-words {
    color: #176269;
    font-weight: 700;
  }

  /* ---- The whole tool, on the stage ---- */
  .av-tuner {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .av-tuner__top {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
  }

  /* "Guitar in Drop D": the instrument and tuning drop-downs, one choice with the Theory
     Map, so they look like its own instrument drop-down, a size up for the stage. */
  .av-tuner__pick {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  .av-tuner__select {
    min-height: 40px;
    padding: 4px 8px !important;
    font-size: 16px !important;
    color: var(--av-ink);
    background-color: var(--av-card);
    border: 2px solid rgba(15, 23, 42, 0.28);
    border-radius: var(--av-btn-radius);
    box-shadow: 2px 2px 0 rgba(15, 23, 42, 0.1);
    cursor: pointer;
  }

  .av-tuner__select:hover {
    background-color: #e3f1f2;
  }

  .av-tuner__select:focus-visible {
    outline: 3px solid var(--av-ghost-focus);
    outline-offset: 1px;
  }

  .av-tuner__select[hidden],
  .av-tuner__in[hidden] {
    display: none;
  }

  .av-tuner__in {
    font-size: 15px;
    color: #4f5868;
  }

  .av-tuner__from {
    margin: 0;
    font-size: 13px;
    color: #4f5868;
  }

  .av-tuner__top .av-session-switch[hidden] {
    display: none;
  }

  /* "Tune to": the optional narrowing, at the foot under a hairline, after the note and
     Listen (decision 33). Any note shows only the switch; Strings adds the rest. */
  .av-tuner__limit {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid rgba(15, 23, 42, 0.1);
  }

  .av-tuner__limit [data-tuner-strings-only][hidden] {
    display: none;
  }

  .av-tuner__readout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-radius: 12px;
    background: #f6f9fa;
    transition: background-color 0.2s ease;
  }

  .av-tool--tuner[data-in-tune="true"] .av-tuner__readout {
    background: #e6f4f5;
  }

  .av-tuner__note {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    min-height: 92px;
    line-height: 1;
  }

  .av-tuner__note strong {
    font-size: 84px;
    color: rgba(15, 23, 42, 0.3);
    transition: color 0.15s ease;
  }

  .av-tool--tuner[data-heard="true"] .av-tuner__note strong {
    color: var(--av-ink);
  }

  .av-tool--tuner[data-in-tune="true"] .av-tuner__note strong {
    color: #176269;
  }

  .av-tuner__note span {
    font-size: 24px;
    color: #4f5868;
  }

  .av-tuner__target {
    min-height: 18px;
    font-size: 14px;
    color: #4f5868;
  }

  .av-tuner__scale {
    width: 100%;
    max-width: 560px;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .av-tuner__ends {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #4f5868;
  }

  .av-tuner__cents {
    font-family: 'Roboto Mono', ui-monospace, monospace;
  }

  .av-tuner__words {
    min-height: 24px;
    font-size: 20px;
    text-align: center;
    color: #4f5868;
  }

  .av-tool--tuner[data-heard="true"] .av-tuner__words {
    color: var(--av-ink);
  }

  .av-tool--tuner[data-in-tune="true"] .av-tuner__words {
    color: #176269;
  }

  .av-tuner__listen {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
  }

  .av-tuner__toggle {
    min-width: 150px;
    min-height: 42px;
  }

  .av-tuner__mic {
    flex: 1 1 220px;
    font-size: 13px;
    line-height: 1.4;
    color: #4f5868;
  }

  .av-tuner__blocked {
    margin: 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: #fdf2dc;
    font-size: 14px;
    line-height: 1.45;
  }

  .av-tuner__blocked[hidden],
  .av-tuner__field[hidden] {
    display: none;
  }

  .av-tuner__field {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .av-tuner__label {
    font-size: 14px;
    color: #4f5868;
  }

  /* Every string in one row, sharing the width (six at most): a phone fits six at 44px. */
  .av-tuner__strings {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 6px;
    max-width: 520px;
  }

  /* ---- The closed panel's mark for a listening tuner ---- */
  .av-session-panel-open--tuner {
    flex: none;
    min-height: 0;
    padding: 10px 0 !important;
    gap: 4px !important;
    color: var(--av-tool-tuner-ink);
  }

  .av-session-panel-open--tuner b {
    font-size: 16px;
    font-weight: 700;
  }

  .av-session-panel-open__listen {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #176269;
    animation: av-tuner-listen 1.6s ease-in-out infinite;
  }

  .av-session-panel-open__tuned[hidden] {
    display: none !important;   /* the same .fas display, unlayered */
  }

  @keyframes av-tuner-listen {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
  }

  /* ---- Phones ---- */
  @media (max-width: 767.98px) {
    .av-tuner__readout {
      padding: 14px 12px;
    }

    .av-tuner__note {
      min-height: 84px;
    }

    .av-tuner__note strong {
      font-size: 76px;
    }

    .av-tuner__meter {
      height: 46px;
    }

    .av-tuner__toggle {
      flex: 1 1 100%;
      min-height: 48px;
    }

    .av-tuner__top .av-session-switch {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      width: 100%;
    }

    .av-tuner__top .av-session-switch > button {
      min-height: 44px;
    }

    .av-tuner__strings {
      max-width: none;
    }

    .av-tuner__string {
      min-height: 58px;
    }

    /* The tuner's row in the now-playing strip: Stop, the note, a slim needle, the words. */
    .av-session-strip__stop--tuner {
      animation: none !important;
    }

    .av-session-strip__mic {
      flex: none;
      color: #8ac3c6;
    }

    .av-session-strip__note {
      flex: none;
      width: 26px;
      font-size: 20px;
      text-align: center;
    }

    .av-session-strip--tuner[data-in-tune="true"] .av-session-strip__note {
      color: #8ac3c6;
    }

    .av-session-strip__tuner {
      flex: 1 1 auto;
      min-width: 0;
      display: flex;
      flex-direction: column;
      gap: 4px;
    }

    .av-tuner__meter--strip {
      height: 12px;
      border-radius: 3px;
      background: rgba(255, 255, 255, 0.12);
    }

    .av-tuner__meter--strip::before {
      display: none;
    }

    .av-tuner__meter--strip .av-tuner__needle {
      top: -2px;
      bottom: -2px;
      width: 4px;
      margin-left: -2px;
      background: #fff;
      opacity: 1;
    }

    .av-session-strip__words {
      font-size: 12px;
      color: #cfd6e4;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .av-tuner__needle {
      transition: none;
    }

    .av-session-panel-open__listen {
      animation: none;
    }
  }

  /* ---- The Tuner alone on the stage: centred, as the Metronome is (c47c2a7) ----
     The stage card fills the window, and the tool used to sit in a full-width column pinned
     to the top, with its words, Listen and the strings hugging the left edge and the rest of
     the card blank. Alone on the stage it is one centred column, the whole group centred top
     to bottom, and tight enough to fit a 1440x900 window without the card scrolling: the
     instrument and tuning beside the Strings / Any note switch, the readout, Listen beside
     its microphone line, the strings. A split, the Tools panel and phones keep the layout
     above. */
  @media (min-width: 992px) {
    .av-session-stage:not(.av-session-stage--split) > [data-tool="tuner"] .av-tool__body {
      justify-content: safe center;
      padding: 10px 24px;
    }

    .av-session-stage:not(.av-session-stage--split) > [data-tool="tuner"] .av-tuner {
      width: 100%;
      max-width: 640px;
      margin-inline: auto;
      gap: 10px;
    }

    .av-session-stage:not(.av-session-stage--split) > [data-tool="tuner"] :is(.av-tuner__top, .av-tuner__listen) {
      flex-wrap: nowrap;
      justify-content: center;
    }

    .av-session-stage:not(.av-session-stage--split) > [data-tool="tuner"] :is(.av-tuner__pick, .av-tuner__mic) {
      flex: 0 1 auto;
    }

    .av-session-stage:not(.av-session-stage--split) > [data-tool="tuner"] .av-tuner__from {
      margin-top: -4px;
      text-align: center;
    }

    .av-session-stage:not(.av-session-stage--split) > [data-tool="tuner"] .av-tuner__readout {
      gap: 6px;
      padding: 10px 20px;
    }

    /* The note keeps its 84px size; only the box it sits in is trimmed to the glyph. */
    .av-session-stage:not(.av-session-stage--split) > [data-tool="tuner"] .av-tuner__note {
      min-height: 80px;
    }

    .av-session-stage:not(.av-session-stage--split) > [data-tool="tuner"] .av-tuner__field {
      align-items: center;
    }

    .av-session-stage:not(.av-session-stage--split) > [data-tool="tuner"] .av-tuner__strings {
      width: 100%;
    }
  }
}
