/* ===================================================================
   /phone-speaker-test

   --lvl (0..1) on each grille is written by phone-speaker-test.js from
   the analyser on the channel mapped to that end of the phone. The
   phone turns with data-orient; its L/R tags and screen stay upright.
   Scoped under .ps.
   =================================================================== */

.ps-lede { max-width: 640px; margin: 4px auto 0; color: #5b6275; }

.ps {
    --ps-accent: #3d8bff;
    --ps-l: #38bdf8;
    --ps-r: #fb7185;
    --ps-ink: #10162b;
    --ps-muted: #5b6275;
    --ps-line: #e4e7ef;
    --ps-volume: 60%;
    --ps-turn: 0deg;

    margin: 18px auto 24px;
    padding: 0;                       /* WebsiteTemplate gives <section> 60px */
    max-width: 980px;
    border-radius: 28px;
    background: #fff;
    border: 1px solid var(--ps-line);
    box-shadow: 0 30px 60px -32px rgb(16 22 43 / 45%);
    overflow: hidden;
    text-align: left;
    font-family: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--ps-ink);
}
.ps *, .ps *::before, .ps *::after { box-sizing: border-box; }
.ps button { font: inherit; }
.ps svg { display: block; }
.ps :where(p) { margin: 0; }
.ps[data-orient="landscape-primary"] { --ps-turn: -90deg; }
.ps[data-orient="landscape-secondary"] { --ps-turn: 90deg; }

.ps-visually-hidden {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- top bar ---------- */

.ps-topbar {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px;
    padding: 14px 20px;
    background: linear-gradient(180deg, #151b33, #10162b);
    color: #cdd5ee;
}
.ps-detected { display: flex; align-items: center; gap: 8px; font-size: .9rem; font-weight: 500; }
.ps-detected svg { width: 18px; height: 18px; color: #22d3ee; flex: none; }
.ps-orients { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: rgb(255 255 255 / 8%); }
.ps-orients button {
    border: 0; border-radius: 999px; padding: 6px 12px; min-height: 32px;
    background: transparent; color: #aeb8d6; font-size: .8rem; font-weight: 600; cursor: pointer; white-space: nowrap;
    transition: background-color .15s ease, color .15s ease;
}
.ps-orients button:hover { color: #fff; }
.ps-orients button[aria-checked="true"] { background: #fff; color: var(--ps-ink); }

/* ---------- stage ---------- */

.ps-stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas: "left phone right" "under under under";
    align-items: center; gap: 8px clamp(8px, 3vw, 32px);
    padding: clamp(18px, 3vw, 30px) clamp(12px, 4vw, 40px) clamp(20px, 3vw, 30px);
    background:
        radial-gradient(40% 55% at 22% 50%, rgb(56 189 248 / calc(6% + var(--glow-l, 0) * 26%)), transparent 70%),
        radial-gradient(40% 55% at 78% 50%, rgb(251 113 133 / calc(6% + var(--glow-r, 0) * 26%)), transparent 70%),
        radial-gradient(60% 60% at 50% 115%, rgb(61 139 255 / 24%), transparent 70%),
        linear-gradient(180deg, #10162b 0%, #1a2142 100%);
    color: #dfe5f7;
}

.ps-side { display: flex; flex-direction: column; gap: 2px; font-size: .85rem; transition: opacity .3s ease; }
.ps-side b { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: #93a0c4; }
.ps-side i { font-style: normal; font-weight: 700; font-size: 1.05rem; }
.ps-side--left { grid-area: left; justify-self: end; text-align: right; }
.ps-side--right { grid-area: right; justify-self: start; }
.ps-side--left i::before { content: "\2190  "; color: var(--ps-l); }
.ps-side--right i::after { content: "  \2192"; color: var(--ps-r); }
.ps[data-orient="portrait"] .ps-side { opacity: 0; }

.ps-holder {
    grid-area: phone; position: relative;
    width: clamp(240px, 44vw, 410px); aspect-ratio: 1;
}

.ps-phone {
    position: absolute; left: 50%; top: 50%;
    width: 47%; aspect-ratio: 1 / 2;
    transform: translate(-50%, -50%) rotate(var(--ps-turn));
    transition: transform .6s cubic-bezier(.3, 1.3, .5, 1);
    filter: drop-shadow(0 26px 30px rgb(0 0 0 / 50%));
}
.ps:not([data-orient="portrait"]) .ps-holder { aspect-ratio: 1 / .62; }
.ps-frame { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- grilles ---------- */

.ps-grille {
    --lvl: 0;
    --side: var(--ps-l);
    position: absolute; left: 22%; right: 22%;
    display: flex; align-items: center; justify-content: center; gap: 6%;
    padding: 0; border: 0; background: none; cursor: pointer; color: #fff; border-radius: 14px;
    -webkit-tap-highlight-color: transparent;
}
.ps-grille[data-ch="right"] { --side: var(--ps-r); }
.ps-grille--top { top: 1.5%; height: 7%; }
.ps-grille--bottom { bottom: 1.2%; height: 7%; left: 14%; right: 14%; }
.ps-grille:focus-visible { outline: 3px solid #22d3ee; outline-offset: 2px; }

.ps-slot {
    position: relative; z-index: 1; width: 64%; height: 22%; border-radius: 99px;
    background: repeating-linear-gradient(90deg, #02030a 0 3px, #2a3150 3px 5px);
    box-shadow: 0 0 0 1.5px #2f3656, 0 0 calc(var(--lvl) * 16px) calc(var(--lvl) * 3px) var(--side);
    transform: scaleY(calc(1 + var(--lvl) * .5));
}
.ps-holes { position: relative; z-index: 1; display: flex; gap: 3px; }
.ps-holes i {
    width: 6px; height: 6px; border-radius: 50%; background: #02030a;
    box-shadow: inset 0 1px 1px rgb(255 255 255 / 12%), 0 0 calc(var(--lvl) * 10px) calc(var(--lvl) * 2px) var(--side);
    transform: scale(calc(1 + var(--lvl) * .45));
}
.ps-holes--mic i { box-shadow: inset 0 1px 1px rgb(255 255 255 / 12%); transform: none; }
.ps-port { position: relative; z-index: 1; width: 20%; height: 32%; border-radius: 99px; background: #02030a; box-shadow: 0 0 0 1.5px #3a4163; }

.ps-halo {
    position: absolute; left: 50%; top: 50%; width: 170%; aspect-ratio: 1; z-index: 0; pointer-events: none;
    border-radius: 50%; background: radial-gradient(circle, var(--side) 0%, transparent 60%);
    opacity: calc(var(--lvl) * .7); transform: translate(-50%, -50%) scale(calc(.5 + var(--lvl) * .6));
}
.ps-waves { position: absolute; left: 50%; top: 50%; width: 0; height: 0; pointer-events: none; }
.ps-waves i {
    position: absolute; left: 0; top: 0; width: 160px; height: 160px; margin: -80px 0 0 -80px;
    border-radius: 50%; border: 2px solid var(--side); opacity: 0; transform: scale(.4);
}
.ps-grille.is-sounding .ps-waves i { animation: ps-ring 1.5s cubic-bezier(.2, .6, .3, 1) infinite; }
.ps-grille.is-sounding .ps-waves i:nth-child(2) { animation-delay: .5s; }
.ps-grille.is-sounding .ps-waves i:nth-child(3) { animation-delay: 1s; }
@keyframes ps-ring { 0% { opacity: calc(.1 + var(--lvl) * .9); transform: scale(.35); } 100% { opacity: 0; transform: scale(1.4); } }

.ps-tag {
    position: absolute; z-index: 3; top: 50%; left: 100%; margin: -13px 0 0 6px;
    display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
    background: var(--side); color: #0b1020; font-size: .78rem; font-weight: 800;
    box-shadow: 0 4px 12px -3px rgb(0 0 0 / 60%);
    transform: rotate(calc(var(--ps-turn) * -1));
    transition: transform .6s cubic-bezier(.3, 1.3, .5, 1), background-color .2s ease;
}
.ps-grille--bottom .ps-tag { left: auto; right: 100%; margin: -13px 6px 0 0; }

/* ---------- screen ---------- */

.ps-screen {
    position: absolute; left: 8%; right: 8%; top: 10%; bottom: 10%;
    display: grid; place-items: center; overflow: hidden; border-radius: 10px;
    pointer-events: none;
}
.ps-screen::before {
    content: ""; position: absolute; inset: 0;
    background: radial-gradient(90% 60% at 50% 30%, rgb(61 139 255 / 18%), transparent 70%);
}
.ps-screen-inner {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
    width: 88%; text-align: center;
    transform: rotate(calc(var(--ps-turn) * -1)); transition: transform .6s cubic-bezier(.3, 1.3, .5, 1);
}
.ps-screen-test { font-size: clamp(.58rem, 1.2vw, .76rem); font-weight: 700; color: #aeb8d6; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.ps-screen-hz { font-size: clamp(1rem, 2.4vw, 1.55rem); font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; line-height: 1.1; white-space: nowrap; }
.ps-bars { display: flex; align-items: flex-end; justify-content: center; gap: 3px; height: 44px; width: 100%; }
.ps-bars i { flex: 0 1 5px; height: calc(4px + var(--b, 0) * 40px); border-radius: 3px; background: linear-gradient(180deg, #22d3ee, #3d8bff); transition: height .06s linear; }
.ps-screen-note { font-size: clamp(.55rem, 1.1vw, .7rem); color: #93a0c4; }

/* ---------- under the phone ---------- */

.ps-under {
    grid-area: under; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 16px;
    width: min(100%, 560px); justify-self: center; margin-top: 6px;
}
.ps-meter { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: .85rem; }
.ps-meter:first-child span:first-child { color: var(--ps-l); }
.ps-meter--right span:last-child { color: var(--ps-r); }
.ps-meter-bar { flex: 1; height: 8px; border-radius: 99px; background: rgb(255 255 255 / 10%); overflow: hidden; }
.ps-meter-fill { display: block; height: 100%; border-radius: inherit; transform: scaleX(0); transform-origin: left center; background: linear-gradient(90deg, #0ea5e9, var(--ps-l)); }
.ps-meter--right .ps-meter-fill { transform-origin: right center; background: linear-gradient(270deg, #e11d48, var(--ps-r)); }

.ps-play {
    position: relative; display: inline-flex; align-items: center; gap: 10px;
    min-height: 56px; padding: 0 26px 0 20px; border: 0; border-radius: 999px; cursor: pointer; color: #fff; font-weight: 700; font-size: 1.05rem;
    background: radial-gradient(circle at 30% 30%, #6aa9ff, var(--ps-accent) 55%, #2254c9);
    box-shadow: 0 16px 34px -12px rgb(61 139 255 / 75%), inset 0 -3px 8px rgb(0 0 0 / 22%), inset 0 2px 6px rgb(255 255 255 / 25%);
    transition: transform .15s ease;
}
.ps-play:hover { transform: translateY(-2px); }
.ps-play:active { transform: scale(.96); }
.ps-play:focus-visible { outline: 3px solid #22d3ee; outline-offset: 4px; }
.ps-play svg { width: 22px; height: 22px; }
.ps-icon-stop, .ps.is-playing .ps-icon-play { display: none !important; }
.ps.is-playing .ps-icon-stop { display: block !important; }
.ps-play-ring { position: absolute; inset: -6px; border-radius: 999px; border: 2px solid rgb(106 169 255 / 55%); opacity: 0; pointer-events: none; }
.ps.is-playing .ps-play-ring { animation: ps-pulse 1.8s ease-out infinite; }
@keyframes ps-pulse { 0% { opacity: .8; transform: scale(.96); } 100% { opacity: 0; transform: scale(1.18); } }

/* ---------- body ---------- */

.ps-body { padding: 18px clamp(14px, 3.5vw, 32px) 24px; display: grid; gap: 16px; }

.ps-orient-hint {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 12px 14px; border-radius: 14px; background: #f0f7ff; border: 1px solid #d5e6fb; color: #1d3a7a; font-size: .9rem; line-height: 1.5;
}
.ps-orient-hint::before {
    content: ""; flex: none; width: 22px; height: 22px; margin-top: 1px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 12a8 8 0 0 1 13.7-5.6M20 12a8 8 0 0 1-13.7 5.6' fill='none' stroke='%233d8bff' stroke-width='2' stroke-linecap='round'/%3E%3Cpath d='M18 3v4h-4M6 21v-4h4' fill='none' stroke='%233d8bff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}

.ps-tests { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.ps-tests button {
    display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: left;
    min-height: 64px; padding: 10px 12px; border-radius: 16px; cursor: pointer;
    border: 1px solid var(--ps-line); background: #fff; color: var(--ps-ink);
    box-shadow: 0 4px 12px -10px rgb(16 22 43 / 45%);
    transition: border-color .15s ease, box-shadow .15s ease, transform .12s ease, background-color .15s ease;
}
.ps-tests button svg { grid-row: 1 / 3; width: 26px; height: 26px; color: var(--ps-accent); }
.ps-tests button b { font-size: .88rem; line-height: 1.2; }
.ps-tests button small { font-size: .74rem; color: var(--ps-muted); }
.ps-tests button:hover { border-color: #bcd3fb; transform: translateY(-1px); }
.ps-tests button[aria-checked="true"] { border-color: var(--ps-accent); background: #f4f8ff; box-shadow: 0 0 0 1px var(--ps-accent), 0 10px 20px -14px rgb(61 139 255 / 80%); }

.ps-detail { min-height: 64px; }
.ps-panel { display: grid; gap: 12px; animation: ps-fade .22s ease; }
.ps-panel[hidden] { display: none; }
@keyframes ps-fade { from { opacity: 0; transform: translateY(4px); } }
.ps-panel p { color: #3c4459; font-size: .95rem; line-height: 1.55; }
.ps-panel p.ps-small, .ps-small { font-size: .84rem; color: var(--ps-muted); line-height: 1.5; }

.ps-segmented { display: inline-flex; flex-wrap: wrap; justify-self: start; padding: 4px; gap: 4px; border-radius: 16px; background: #f1f3f8; border: 1px solid var(--ps-line); }
.ps-segmented button {
    min-height: 40px; padding: 0 16px; border: 0; border-radius: 12px; cursor: pointer;
    background: transparent; color: var(--ps-muted); font-weight: 600; font-size: .9rem;
    transition: background-color .15s ease, color .15s ease;
}
.ps-segmented button[aria-checked="true"] { background: #fff; color: var(--ps-ink); box-shadow: 0 1px 2px rgb(16 22 43 / 10%), 0 6px 14px -8px rgb(16 22 43 / 35%); }

.ps-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ps-chips button {
    min-height: 42px; padding: 0 14px; border-radius: 12px; cursor: pointer;
    border: 1px solid var(--ps-line); background: #fff; color: var(--ps-ink); font-size: .88rem;
    transition: transform .12s ease;
}
.ps-chips button b { font-weight: 700; margin-right: 4px; }
.ps-chips button[aria-checked="true"] { background: linear-gradient(180deg, #5b9dff, var(--ps-accent)); color: #fff; border-color: transparent; box-shadow: 0 8px 18px -8px rgb(61 139 255 / 80%); }
.ps-chips button:active { transform: scale(.95); }

.ps-rise { display: flex; align-items: center; gap: 12px; }
.ps-rise-bar { flex: 1; height: 14px; border-radius: 99px; background: #eef1f7; overflow: hidden; }
.ps-rise-fill { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #22c55e, #eab308 60%, #ef4444); }
.ps-rise-read { min-width: 110px; text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }

.ps-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.ps-btn {
    min-height: 42px; padding: 0 16px; border-radius: 12px; cursor: pointer;
    border: 1px solid var(--ps-line); background: #fff; color: var(--ps-ink); font-weight: 600; font-size: .9rem;
    box-shadow: 0 4px 10px -8px rgb(16 22 43 / 45%);
}
.ps-btn:hover { background: #f4f7ff; }
.ps-result:empty { display: none; }
.ps-panel .ps-result { padding: 12px 14px; border-radius: 14px; background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; font-weight: 600; }
.ps-panel .ps-result.is-ok { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }

.ps-controls { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 18px; align-items: center; padding-top: 14px; border-top: 1px solid var(--ps-line); }
.ps-controls .ps-small { grid-column: 2; }
.ps-label { font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ps-muted); }
.ps-volume { display: flex; align-items: center; gap: 10px; }
.ps-step {
    display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
    border: 1px solid var(--ps-line); background: #fff; color: var(--ps-ink); box-shadow: 0 4px 10px -6px rgb(16 22 43 / 40%);
}
.ps-step svg { width: 18px; height: 18px; }
.ps-step:active { transform: scale(.9); }
.ps-volume input[type="range"] {
    -webkit-appearance: none; appearance: none; flex: 1; min-width: 80px; height: 12px; margin: 0; border-radius: 999px; cursor: pointer;
    background: linear-gradient(90deg, #22d3ee, var(--ps-accent)) 0 / var(--ps-volume) 100% no-repeat, #e3e7f1;
}
.ps-volume input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none; width: 26px; height: 26px; border-radius: 50%;
    background: #fff; border: 3px solid var(--ps-accent); box-shadow: 0 6px 14px -4px rgb(61 139 255 / 70%);
}
.ps-volume input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--ps-accent); }
.ps-volume-value { min-width: 50px; text-align: right; font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.ps-status { padding: 12px 16px; border-radius: 14px; background: #f4f7ff; border: 1px solid #dce6fb; font-weight: 600; color: #1d3a7a; }

.ps-tests button:focus-visible, .ps-segmented button:focus-visible, .ps-chips button:focus-visible, .ps-btn:focus-visible,
.ps-step:focus-visible, .ps-orients button:focus-visible, .ps-volume input:focus-visible { outline: 3px solid var(--ps-accent); outline-offset: 2px; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
    .ps-tests { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 575.98px) {
    .ps { border-radius: 22px; margin-inline: -4px; }
    .ps-topbar { padding: 12px 14px; }
    .ps-orients { width: 100%; }
    .ps-orients button { flex: 1; padding: 6px 4px; font-size: .72rem; white-space: normal; line-height: 1.15; }
    .ps-stage { grid-template-columns: 1fr 1fr; grid-template-areas: "left right" "phone phone" "under under"; }
    .ps-side--left { justify-self: start; text-align: left; }
    .ps-side--right { justify-self: end; text-align: right; }
    .ps[data-orient="portrait"] .ps-side { display: none; }
    .ps-holder { width: min(100%, 290px); justify-self: center; }
    .ps-under { grid-template-columns: 1fr; gap: 10px; }
    .ps-under .ps-play { justify-self: center; grid-row: 1; }
    .ps-meter--right { flex-direction: row-reverse; }
    .ps-meter--right .ps-meter-fill { transform-origin: left center; background: linear-gradient(90deg, #e11d48, var(--ps-r)); }
    .ps-tests { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ps-tests button:last-child { grid-column: 1 / -1; }
    .ps-controls { grid-template-columns: 1fr; }
    .ps-controls .ps-small { grid-column: 1; }
    .ps-segmented { display: flex; justify-self: stretch; }
    .ps-segmented button { flex: 1; padding: 0 6px; }
    .ps-rise-read { min-width: 90px; font-size: .85rem; }
}
@media (pointer: coarse) {
    .ps-segmented button, .ps-chips button, .ps-btn, .ps-orients button { min-height: 44px; }
    .ps-step { width: 44px; height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
    .ps *, .ps *::before, .ps *::after { animation: none !important; transition: none !important; }
}
