/* ===================================================================
   /refresh-rate-test - the refresh meter.

   Everything that moves here is written by refresh-rate-test.js from
   requestAnimationFrame timestamps: --rrt-fill on the ring is the
   measured rate against the scale, the graph and the motion track are
   canvases redrawn per frame. Scoped under .rrt.
   =================================================================== */

.rrt {
    --rrt-accent: #3d8bff;
    --rrt-accent-2: #22d3ee;
    --rrt-ok: #34f5a6;
    --rrt-late: #ffb547;
    --rrt-drop: #ff5f6d;
    --rrt-ink: #10162b;
    --rrt-muted: #5b6275;
    --rrt-line: #e4e7ef;
    --rrt-fill: 0;

    margin: 18px auto 24px;
    padding: 0; /* WebsiteTemplate gives every <section> 60px of padding */
    max-width: 1080px;
    border-radius: 28px;
    background: #fff;
    border: 1px solid var(--rrt-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(--rrt-ink);
}
.rrt *, .rrt *::before, .rrt *::after { box-sizing: border-box; }
.rrt button { font: inherit; }
.rrt svg { display: block; }
.rrt canvas { display: block; width: 100%; }

.rrt-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 ---------- */

.rrt-topbar {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
    padding: 14px 22px;
    background: linear-gradient(180deg, #151b33, #10162b);
    color: #cdd5ee;
}
.rrt-detected { display: flex; align-items: center; gap: 8px; margin: 0; font-size: .9rem; font-weight: 500; min-width: 0; }
.rrt-detected svg { width: 18px; height: 18px; flex: none; color: var(--rrt-accent-2); }
.rrt-vis {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 5px 12px; border-radius: 999px; background: rgb(255 255 255 / 8%);
    font-size: .78rem; font-weight: 600; color: #dfe5f7;
}
.rrt-vis i { width: 8px; height: 8px; border-radius: 50%; background: var(--rrt-ok); box-shadow: 0 0 8px var(--rrt-ok); }
.rrt[data-state="paused"] .rrt-vis i { background: var(--rrt-late); box-shadow: 0 0 8px var(--rrt-late); }

/* ---------- stage ---------- */

.rrt-stage {
    position: relative;
    display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center;
    gap: clamp(18px, 4vw, 48px);
    padding: clamp(24px, 4vw, 44px) clamp(16px, 4vw, 44px);
    background:
        radial-gradient(50% 80% at 18% 50%, rgb(61 139 255 / 26%), transparent 70%),
        radial-gradient(40% 60% at 85% 20%, rgb(34 211 238 / 10%), transparent 70%),
        linear-gradient(180deg, #10162b 0%, #1a2142 100%);
    color: #dfe5f7;
}

.rrt-meter { position: relative; width: clamp(200px, 26vw, 270px); aspect-ratio: 1; }
.rrt-ring { position: absolute; inset: 0; }
.rrt-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.rrt-ring-track { fill: none; stroke: rgb(255 255 255 / 9%); stroke-width: 12; }
.rrt-ring-bar {
    fill: none; stroke: url(#rrtArc); stroke-width: 12; stroke-linecap: round;
    stroke-dasharray: 100; stroke-dashoffset: calc(100 - var(--rrt-fill) * 100);
    filter: drop-shadow(0 0 6px rgb(34 211 238 / 55%));
    transition: stroke-dashoffset .35s ease;
}
.rrt-ring-pulse { fill: #fff; opacity: 0; }
.rrt.is-live .rrt-ring-pulse { opacity: .95; filter: drop-shadow(0 0 5px #fff); }

.rrt-readout {
    position: absolute; inset: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
    text-align: center;
}
.rrt-hz {
    font-size: clamp(3.6rem, 7vw, 5rem); font-weight: 800; line-height: 1; letter-spacing: -.03em;
    font-variant-numeric: tabular-nums; color: #fff;
    text-shadow: 0 0 28px rgb(61 139 255 / 55%);
}
.rrt-hz.pop { animation: rrt-pop .35s ease; }
@keyframes rrt-pop { 40% { transform: scale(1.08); color: var(--rrt-accent-2); } }
.rrt-hz-unit { margin-top: 2px; font-size: .95rem; font-weight: 700; letter-spacing: .14em; color: var(--rrt-accent-2); }
.rrt-raw { margin-top: 8px; font-size: .8rem; color: #aeb8d6; font-variant-numeric: tabular-nums; }

.rrt-graph-wrap {
    min-width: 0;
    padding: 14px 16px 10px; border-radius: 20px;
    background: rgb(8 11 22 / 55%); border: 1px solid rgb(255 255 255 / 8%);
}
.rrt-graph-head, .rrt-graph-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; align-items: center; }
.rrt-graph-title { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #aeb8d6; }
.rrt-legend { display: inline-flex; align-items: center; gap: 6px; font-size: .74rem; color: #aeb8d6; }
.rrt-legend i { width: 10px; height: 10px; border-radius: 3px; margin-left: 6px; }
.rrt-l-ok { background: var(--rrt-accent-2); }
.rrt-l-late { background: var(--rrt-late); }
.rrt-l-drop { background: var(--rrt-drop); }
.rrt-graph { height: 170px; margin: 10px 0 6px; }
.rrt-graph-foot { font-size: .74rem; color: #8b95b5; font-variant-numeric: tabular-nums; }

/* ---------- motion demo ---------- */

.rrt-motion {
    padding: 16px clamp(16px, 4vw, 44px) 20px;
    background: #0b0f1e;
    border-top: 1px solid rgb(255 255 255 / 6%);
}
.rrt-motion-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 12px; }
.rrt-motion-head .rrt-group-label { color: #aeb8d6; }
.rrt-motion .rrt-segmented { background: rgb(255 255 255 / 6%); border-color: rgb(255 255 255 / 8%); }
.rrt-motion .rrt-segmented button { color: #aeb8d6; min-height: 36px; padding: 0 12px; font-size: .84rem; }
.rrt-motion .rrt-segmented button:hover { color: #fff; }
.rrt-motion .rrt-segmented button[aria-checked="true"] { background: #fff; color: var(--rrt-ink); }
.rrt-track { height: 120px; border-radius: 16px; background: #060913; }
.rrt-motion-note { margin: 10px 0 0; font-size: .82rem; color: #8b95b5; }

/* ---------- panel ---------- */

.rrt-panel { padding: 22px clamp(16px, 4vw, 36px) 26px; }

.rrt-group-label { font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--rrt-muted); }

.rrt-stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.rrt-stat {
    display: flex; flex-direction: column; gap: 2px; min-width: 0;
    padding: 12px 14px; border-radius: 16px; background: #f6f8fc; border: 1px solid var(--rrt-line);
}
.rrt-stat-label { font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--rrt-muted); }
.rrt-stat strong { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rrt-stat-note { font-size: .72rem; color: #7c8397; }
.rrt-stat.is-warn strong { color: #c46a00; }
.rrt-stat.is-bad strong { color: #d23a4b; }

.rrt-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.rrt-segmented { display: inline-flex; flex-wrap: wrap; padding: 4px; gap: 4px; border-radius: 14px; background: #f1f3f8; border: 1px solid var(--rrt-line); }
.rrt-segmented button {
    min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px; cursor: pointer;
    background: transparent; color: var(--rrt-muted); font-weight: 600; white-space: nowrap;
    transition: background-color .15s ease, color .15s ease;
}
.rrt-segmented button[aria-checked="true"] { background: #fff; color: var(--rrt-ink); box-shadow: 0 1px 2px rgb(16 22 43 / 10%), 0 6px 14px -8px rgb(16 22 43 / 35%); }

.rrt-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 42px; padding: 0 18px; border-radius: 12px; cursor: pointer;
    border: 1px solid var(--rrt-line); background: #fff; color: var(--rrt-ink); font-weight: 600;
    transition: transform .12s ease, background-color .15s ease, box-shadow .15s ease;
}
.rrt-btn svg { width: 18px; height: 18px; }
.rrt-btn:hover { background: #f4f7ff; }
.rrt-btn:active { transform: scale(.96); }
.rrt-btn--primary {
    border: 0; color: #fff;
    background: linear-gradient(135deg, #5b9dff, var(--rrt-accent) 55%, #2254c9);
    box-shadow: 0 12px 24px -12px rgb(61 139 255 / 80%);
}
.rrt-btn--primary:hover { background: linear-gradient(135deg, #6aa9ff, #4a94ff 55%, #2a5fd6); }
.rrt-btn--ghost { margin-left: auto; min-height: 36px; background: rgb(255 255 255 / 6%); border-color: rgb(255 255 255 / 12%); color: #dfe5f7; }
.rrt-btn--ghost:hover { background: rgb(255 255 255 / 12%); }
.rrt-i-play { display: none !important; }
.rrt-btn--ghost[aria-pressed="false"] .rrt-i-play { display: block !important; }
.rrt-btn--ghost[aria-pressed="false"] .rrt-i-pause { display: none !important; }

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

.rrt-status {
    margin: 16px 0 0; padding: 12px 16px;
    border-radius: 14px; background: #f4f7ff; border: 1px solid #dce6fb;
    font-weight: 600; color: #1d3a7a;
}
.rrt[data-state="paused"] .rrt-status { background: #fff7eb; border-color: #fde2b8; color: #7a4a06; }
.rrt-honest { margin: 10px 0 0; font-size: .92rem; color: var(--rrt-muted); }
.rrt-honest:empty { display: none; }

.rrt-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; margin-top: 18px; }
.rrt-card { padding: 16px 18px; border-radius: 18px; border: 1px solid var(--rrt-line); background: #fff; min-width: 0; }
.rrt-card h3 { margin: 0 0 10px; font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--rrt-muted); }
.rrt-dl { margin: 0; }
.rrt-dl div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--rrt-line); }
.rrt-dl div:last-child { border-bottom: 0; }
.rrt-dl dt { font-weight: 500; color: var(--rrt-muted); font-size: .9rem; }
.rrt-dl dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; font-size: .9rem; }
.rrt-notes { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.rrt-notes li { font-size: .9rem; color: #454d63; line-height: 1.5; }
.rrt-notes strong { color: var(--rrt-ink); }

/* ---------- responsive ---------- */

@media (max-width: 960px) {
    .rrt-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
    .rrt-stage { grid-template-columns: 1fr; justify-items: center; }
    .rrt-graph-wrap { width: 100%; }
    .rrt-cols { grid-template-columns: 1fr; }
}
@media (max-width: 575.98px) {
    .rrt { border-radius: 22px; margin-inline: -4px; }
    .rrt-topbar { padding: 12px 14px; }
    .rrt-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .rrt-graph { height: 140px; }
    .rrt-track { height: 96px; }
    .rrt-btn--ghost { margin-left: 0; }
    .rrt-motion .rrt-segmented { display: flex; width: 100%; }
    .rrt-motion .rrt-segmented button { flex: 1; padding: 0 4px; font-size: .78rem; }
    .rrt-legend { font-size: .7rem; }
}

@media (pointer: coarse) {
    .rrt-segmented button, .rrt-motion .rrt-segmented button, .rrt-btn, .rrt-btn--ghost { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    .rrt *, .rrt *::before, .rrt *::after { animation: none !important; transition: none !important; }
}
