/* Blind test (/blindtests and /blindtests/:id): the site's printed sleeve, laid on a green page.
 * Only the page background changes; everything else is the site's vocabulary (paper slips, ink rules, solid drops). */

/* The panels open and close with the hidden attribute. */
.blindtest [hidden] { display: none !important; }

@layer pages {
  /* The green: --ok darkened with a touch of ink; the global paper grain stays on top of it. */
  html:has(.blindtest), body:has(.blindtest) { background: color-mix(in srgb, var(--ok) 82%, var(--ink)); }
  body:has(.blindtest) .site-footer { background: var(--paper); }

  .blindtest { color: var(--paper); }
  .blindtest h1 small { border-color: currentColor; }
  .blindtest h1 a:hover { background: var(--paper); color: var(--ink); }
  /* Paper slips on the green: back to ink. */
  .blindtest :is(.acl-totals, .acl-filter label:not([data-active]), .bt-choice, .bt-panel, .bt-reveal, .bt-roulette-box, .bt-suggestions) { color: var(--ink); }

  /* --- Setup ------------------------------------------------------------------------------------------ */
  .bt-head .lede { margin: 0; }
  .bt-form { display: grid; gap: 0.4rem; max-width: 56rem; }
  .bt-form fieldset { border-color: color-mix(in srgb, var(--paper) 70%, transparent); }

  .bt-difficulty { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 1.2rem; padding-top: 1.8rem; }
  .bt-choice {
    position: relative;
    display: grid;
    gap: 0.4rem;
    margin: 0;
    padding: 0.9rem 1rem 0.9rem;
    border: var(--rule);
    background: var(--paper-lift);
    box-shadow: var(--drop);
    text-transform: none;
    letter-spacing: 0;
    rotate: -0.6deg;
    cursor: pointer;
    transition: rotate 160ms var(--ease-snap), translate 160ms var(--ease-snap), box-shadow 160ms var(--ease-snap);
  }
  .bt-choice:nth-of-type(2n) { rotate: 0.5deg; }
  .bt-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
  .bt-choice-name { font: 400 1.8rem/1 var(--font-display); text-transform: uppercase; letter-spacing: 0.03em; }
  .bt-choice-reward { font: 600 1rem/1.2 var(--font-mono); }
  .bt-choice-reward small { font-size: 0.72rem; opacity: 0.75; }
  .bt-choice-pitch { font: 500 0.9rem/1.35 var(--font-body); opacity: 0.85; }
  .bt-choice:hover { translate: -2px -2px; box-shadow: var(--drop-lg); }
  .bt-choice:has(input:checked) { border-width: 3px; background: var(--paper); box-shadow: 5px 5px 0 var(--stamp); rotate: 0deg; }
  .bt-choice[data-difficulty="hard"] .bt-choice-reward { color: var(--stamp); }
  .bt-choice:has(input:focus-visible) { outline: 3px solid var(--stamp); outline-offset: 3px; }

  .bt-genres .acl-filter small { margin-left: 0.25em; font: 600 0.68rem/1 var(--font-mono); opacity: 0.75; }

  .bt-launch { display: grid; justify-items: start; gap: 0.7rem; margin-top: 0.6rem; }
  .bt-eligible { font: 600 0.95rem/1.3 var(--font-mono); letter-spacing: 0.04em; }
  .bt-eligible[data-none] { padding: 0.2rem 0.5rem 0.1rem; background: var(--stamp); rotate: -1deg; }
  .bt-hint { font: 500 0.85rem/1.4 var(--font-body); opacity: 0.85; }

  .bt-today {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.8rem;
    margin-top: 2.2rem;
    padding-top: 0.8rem;
    border-top: 2px dashed color-mix(in srgb, var(--paper) 70%, transparent);
    font: 600 0.72rem/1 var(--font-mono);
    letter-spacing: 0.12em;
    text-transform: uppercase;
  }
  .bt-today b { font: 400 1.3rem/1 var(--font-display); letter-spacing: 0.03em; }
  .bt-today meter { width: min(14rem, 100%); height: 0.8rem; border: var(--rule); background: var(--paper); }
  .bt-today meter::-webkit-meter-bar { border: 0; border-radius: 0; background: var(--paper); height: 100%; }
  .bt-today meter::-webkit-meter-optimum-value,
  .bt-today meter::-webkit-meter-suboptimum-value,
  .bt-today meter::-webkit-meter-even-less-good-value { background: var(--stamp); }
  .bt-today meter::-moz-meter-bar { background: var(--stamp); }

  /* The roulette: a paper slip over the dimmed page, a reel of radios under a red needle. */
  .bt-roulette {
    position: fixed;
    inset: 0;
    z-index: 96;
    display: grid;
    place-items: center;
    padding: var(--gutter);
    background: color-mix(in srgb, var(--ink) 78%, transparent);
  }
  .bt-roulette-box {
    width: min(46rem, 100%);
    display: grid;
    gap: 1rem;
    justify-items: center;
    padding: 1.4rem 1.2rem 1.2rem;
    border: var(--rule-thick);
    background: var(--paper-lift);
    box-shadow: var(--drop-lg);
    rotate: -0.6deg;
    text-align: center;
  }
  .bt-reel {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-block: var(--rule-thick);
    background: var(--paper);
    mask-image: linear-gradient(90deg, transparent, black 14%, black 86%, transparent);
  }
  .bt-reel-strip { display: flex; width: max-content; will-change: transform; }
  .bt-reel-item {
    flex: none;
    width: 176px;
    display: grid;
    gap: 0.3rem;
    padding: 1rem 0.7rem 0.9rem;
    border-right: 1px dashed var(--ink-soft);
    text-align: center;
  }
  .bt-reel-item b { font: 400 1.15rem/1.05 var(--font-display); text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bt-reel-item span { font: 600 0.7rem/1 var(--font-mono); opacity: 0.75; }
  .bt-reel-needle { position: absolute; top: 0; bottom: 0; left: 50%; width: 4px; translate: -50% 0; background: var(--stamp); }
  .bt-roulette-status { min-height: 1.5em; font: 600 0.9rem/1.4 var(--font-mono); }
  .bt-roulette[data-state="failed"] .bt-roulette-status { color: var(--stamp); }
  .bt-roulette[data-state="failed"] .bt-reel { opacity: 0.5; }
  .bt-roulette[data-state="landed"] .bt-reel-item[data-landed] { background: var(--ink); color: var(--paper); }

  /* --- The game --------------------------------------------------------------------------------------- */
  .bt-play-head h1 a { text-decoration: none; }
  /* A lower head than the other pages: the TV and the answer have to fit under it. The score goes to the right. */
  .bt-play-head { gap: 0.5rem; margin-bottom: 1rem; }
  .bt-play-head h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); }
  @media (min-width: 760px) {
    .bt-play-head { grid-template-columns: minmax(0, 1fr) auto; align-items: end; column-gap: 1.5rem; }
    .bt-play-head > :not(.bt-score) { grid-column: 1; }
    .bt-play-head > .bt-score { grid-column: 2; grid-row: 1 / span 2; align-self: end; }
  }
  .bt-play-head .genre-stamps > li { background: var(--paper); color: var(--ink); }

  /* The TV, the answer and the reveal under it: low enough that the answer stays in view while the 30 s run. */
  .bt-stage { display: grid; gap: 1rem; max-width: 46rem; }
  .bt-screen { position: relative; display: grid; grid-template-columns: minmax(0, 1fr); isolation: isolate; }
  .bt-screen > * { grid-area: 1 / 1; }

  /* The radio's TV, standing on the page (the dock's look, larger); its screen is the player. */
  .bt-tv {
    position: relative;
    z-index: 0;
    height: clamp(15rem, 36vw, 19.5rem);
    filter: drop-shadow(5px 6px 0 color-mix(in srgb, var(--ink) 55%, transparent));
  }
  /* Before the TV takes the screen, and without WebGL: the screen alone in an ink frame (≥ 200 px). */
  .bt-tv > .bt-tv-screen { position: absolute; inset: 0; margin: auto; width: min(100%, 26rem); height: max(200px, 82%); visibility: hidden; }
  .bt-tv[data-flat] { filter: none; }
  .bt-tv[data-flat] > .bt-tv-screen { visibility: visible; border: 10px solid var(--ink); border-radius: 14px; box-shadow: var(--drop); }

  /* The one YouTube player: blurred (and a little scaled so the blur has no edges) until the reveal. */
  .bt-frame-host { position: absolute; inset: 0; filter: blur(28px); scale: 1.18; transition: filter 900ms var(--ease-snap), scale 900ms var(--ease-snap); }
  .bt-frame { width: 100%; height: 100%; border: 0; display: block; }
  .blindtest:is([data-state="reveal"], [data-state="done"]) .bt-frame-host { filter: none; scale: 1; }

  /* The slips over the screen. */
  .bt-panel { position: relative; z-index: 3; align-self: center; justify-self: center; margin: 1.2rem; text-align: center; }
  .bt-ready, .bt-done {
    display: grid;
    gap: 0.8rem;
    justify-items: center;
    max-width: 32rem;
    padding: 1.2rem 1.3rem 1.3rem;
    border: var(--rule-thick);
    background: var(--paper-lift);
    box-shadow: 5px 5px 0 var(--stamp);
    rotate: -1deg;
  }
  .bt-ready p, .bt-done p { margin: 0; }
  .bt-panel-title { font: 400 clamp(2.4rem, 8vw, 4rem)/0.95 var(--font-display); text-transform: uppercase; filter: url(#ink-bleed); }
  .bt-done-actions { display: flex; flex-wrap: wrap; gap: 0.8rem; justify-content: center; }

  /* The reveal: a paper slip under the TV, the video sharp on its screen. */
  .bt-reveal {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1rem;
    border: var(--rule-thick);
    background: var(--paper-lift);
    box-shadow: var(--drop);
    rotate: -0.4deg;
  }
  .bt-cover { flex: none; width: clamp(4.5rem, 16vw, 7rem); height: auto; aspect-ratio: 1; object-fit: cover; border: var(--rule); box-shadow: var(--drop); rotate: -2deg; }
  .bt-reveal-text { min-width: 0; display: grid; gap: 0.35rem; }
  .bt-reveal-text p { margin: 0; }
  .bt-verdict {
    justify-self: start;
    padding: 0.15em 0.45em 0.05em;
    border: 0.12em solid currentColor;
    outline: 0.05em solid currentColor;
    outline-offset: 0.12em;
    color: var(--stamp);
    font: 400 clamp(1.2rem, 3.6vw, 1.7rem)/1 var(--font-display);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    rotate: -4deg;
    mix-blend-mode: multiply;
    -webkit-mask: var(--wear) 0 0 / 160px;
    mask: var(--wear) 0 0 / 160px;
  }
  .blindtest[data-verdict="found"] .bt-verdict { color: var(--ok); }
  .bt-reveal-title { font: 400 clamp(1.4rem, 4.5vw, 2.1rem)/1 var(--font-display); text-transform: uppercase; overflow-wrap: anywhere; }
  .bt-reveal-title a { text-decoration: none; }
  .bt-reveal-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font: 500 0.92rem/1.3 var(--font-body); }
  .bt-reveal-meta .tier { font-size: 0.8rem; }
  .bt-reveal-note { font: 500 0.75rem/1.4 var(--font-mono); letter-spacing: 0.04em; opacity: 0.85; }

  /* The equaliser and the clock, while a sound plays. */
  .bt-eq {
    z-index: 3;
    align-self: end;
    justify-self: start;
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 2.4rem;
    margin: 1rem;
    padding: 0.35rem;
    background: var(--paper);
    border: var(--rule);
    opacity: 0;
    transition: opacity 300ms;
  }
  .bt-eq span { width: 5px; height: 100%; background: var(--ink); transform-origin: bottom; scale: 1 0.25; }
  .bt-clock {
    --left: 1;
    z-index: 3;
    align-self: start;
    justify-self: end;
    position: relative;
    width: clamp(4.2rem, 12vw, 5.6rem);
    aspect-ratio: 1;
    margin: 1rem;
    display: grid;
    place-items: center;
    border: var(--rule);
    border-radius: 50%;
    background: var(--paper);
    color: var(--ink);
    box-shadow: var(--drop);
    opacity: 0;
    transition: opacity 300ms;
  }
  .bt-clock svg { position: absolute; inset: 0; width: 100%; height: 100%; rotate: -90deg; }
  .bt-clock circle { fill: none; stroke-width: 10; }
  .bt-clock-track { stroke: var(--ink-faint); }
  .bt-clock-ring { stroke: var(--ink); stroke-dasharray: 100; stroke-dashoffset: calc(100 - var(--left) * 100); }
  .bt-clock b { position: relative; font: 400 clamp(1.4rem, 4vw, 2rem)/1 var(--font-display); }
  .bt-clock[data-hurry] .bt-clock-ring { stroke: var(--stamp); }
  .bt-clock[data-hurry] b { color: var(--stamp); }
  .blindtest:is([data-state="listening"], [data-state="loading"], [data-state="sending"]) .bt-clock { opacity: 1; }
  .blindtest[data-state="listening"] .bt-eq { opacity: 1; }
  .blindtest:is([data-state="ready"], [data-state="done"]) .bt-clock { display: none; }

  /* The answer, under the screen. */
  .bt-answer { display: grid; gap: 0.8rem; }
  .bt-guess-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.7rem; }
  .bt-guess-label { flex-basis: 100%; margin: 0; }
  .bt-combo { position: relative; flex: 1 1 18rem; min-width: 0; }
  .bt-combo input { width: 100%; min-height: 3.1rem; font-size: 1.15rem; box-shadow: var(--drop); }
  .bt-answer-actions { display: flex; gap: 0.7rem; }
  .bt-answer-actions .btn { min-height: 3.1rem; }
  .bt-suggestions {
    position: absolute;
    z-index: 20;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 18rem;
    overflow-y: auto;
    border: var(--rule-thick);
    background: var(--paper-lift);
    box-shadow: var(--drop-lg);
  }
  .bt-suggestions li { padding: 0.55rem 0.8rem; cursor: pointer; border-bottom: 1px dashed var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bt-suggestions li:last-child { border-bottom: 0; }
  .bt-suggestions li b { font-weight: 700; }
  .bt-suggestions li span { opacity: 0.75; }
  .bt-suggestions li:hover, .bt-suggestions li[aria-selected="true"] { background: var(--ink); color: var(--paper); }
  .bt-next { justify-self: start; }
  .bt-message { min-height: 1.4em; font: 600 0.85rem/1.4 var(--font-mono); }

  @media (max-width: 600px) {
    .bt-reveal { flex-direction: column; align-items: flex-start; }
    .bt-answer-actions { flex: 1 1 100%; }
    .bt-answer-actions .btn { flex: 1; }
    .bt-start { width: 100%; }
    .bt-choice { rotate: 0deg; }
  }
}

@layer fx {
  .blindtest[data-state="listening"] .bt-eq span { animation: bt-eq 0.9s ease-in-out infinite alternate; }
  .bt-eq span:nth-child(2n) { animation-duration: 0.62s !important; }
  .bt-eq span:nth-child(3n) { animation-duration: 0.77s !important; animation-delay: -0.3s !important; }
  .bt-eq span:nth-child(4n + 1) { animation-duration: 0.53s !important; animation-delay: -0.2s !important; }

  .bt-reveal:not([hidden]) { animation: drop-in 380ms var(--ease-snap) both; }
  .bt-reveal:not([hidden]) .bt-verdict { animation: stamp-slam 360ms var(--ease-snap) 120ms backwards; }
  .bt-ready:not([hidden]), .bt-done:not([hidden]) { animation: pop-in 320ms var(--ease-pop) backwards; }
  .bt-screen[data-shake] { animation: shake 380ms var(--ease-snap) both; }
  .bt-roulette:not([hidden]) .bt-roulette-box { animation: pop-in 260ms var(--ease-pop) backwards; }
  .bt-roulette[data-state="landed"] .bt-reel-item[data-landed] { animation: bt-land 500ms var(--ease-pop) both; }

  /* "Trouvé": the big stamp in green, printed on a paper slip so it reads on the green page (red says "missed"). */
  .fx-stamp[data-tone="ok"] { color: var(--ok); background: var(--paper); mix-blend-mode: normal; }

  /* Paper confetti, in the palette. */
  .bt-confetti { position: absolute; z-index: 5; inset: 0; display: grid; place-items: center; pointer-events: none; }
  .bt-confetti i {
    grid-area: 1 / 1;
    width: 9px;
    height: 14px;
    background: var(--paper);
    animation: bt-burst 1.3s cubic-bezier(0.12, 0.8, 0.3, 1) var(--d) both;
  }
  .bt-confetti i[data-hue="1"] { background: var(--stamp); }
  .bt-confetti i[data-hue="2"] { background: var(--paper-white); border-radius: 50%; width: 10px; height: 10px; }

  @keyframes bt-eq { 0% { scale: 1 0.2; } 100% { scale: 1 1; } }
  @keyframes bt-burst {
    0% { opacity: 1; translate: 0 0; rotate: 0deg; }
    100% { opacity: 0; translate: var(--x) calc(var(--y) + 120px); rotate: var(--r); }
  }
  @keyframes bt-land { 0% { scale: 1; } 50% { scale: 1.12; } 100% { scale: 1.04; } }

  @media (prefers-reduced-motion: reduce) {
    .blindtest *, .blindtest *::before, .blindtest *::after { animation: none !important; transition-duration: 1ms !important; }
    .blindtest[data-state="listening"] .bt-eq span { scale: 1 0.6; }
  }
}
