/* ===================================================================
   /touchscreen-test - the coverage surface.

   Cells light only when touchscreen-test.js marks them from real
   pointer events. The ink canvas sits on top and draws the strokes;
   neither takes input of its own - the surface does, with
   touch-action:none so the browser never claims the drag for scrolling.
   Scoped under .tsc.
   =================================================================== */

.tsc {
    --tsc-accent: #3d8bff;
    --tsc-cyan: #22d3ee;
    --tsc-ok: #34f5a6;
    --tsc-ink: #10162b;
    --tsc-muted: #5b6275;
    --tsc-line: #e4e7ef;

    margin: 18px auto 24px;
    padding: 0;
    max-width: 1100px;
    border-radius: 28px;
    background: #fff;
    border: 1px solid var(--tsc-line);
    box-shadow: 0 30px 60px -32px rgb(16 22 43 / 45%);
    overflow: hidden;
    text-align: left;
    color: var(--tsc-ink);
    font-family: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.tsc *, .tsc *::before, .tsc *::after { box-sizing: border-box; }
.tsc button { font: inherit; }
.tsc svg { display: block; }
.tsc :where(p, dl, dd) { margin: 0; }

.tsc-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 ---------- */

.tsc-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;
}
.tsc-detected { display: flex; align-items: center; gap: 8px; font-size: .9rem; font-weight: 500; min-width: 0; }
.tsc-detected svg { flex: none; width: 18px; height: 18px; color: var(--tsc-cyan); }

.tsc-density { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: rgb(255 255 255 / 8%); }
.tsc-density 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;
}
.tsc-density button:hover { color: #fff; }
.tsc-density button[aria-checked="true"] { background: #fff; color: var(--tsc-ink); }
.tsc-density button:focus-visible { outline: 3px solid var(--tsc-cyan); outline-offset: 2px; }

/* ---------- stage + surface ---------- */

.tsc-stage {
    position: relative;
    padding: clamp(12px, 2.4vw, 26px);
    background:
        radial-gradient(60% 80% at 50% 120%, rgb(61 139 255 / 26%), transparent 70%),
        linear-gradient(180deg, #10162b 0%, #1a2142 100%);
}

.tsc-surface {
    position: relative;
    height: clamp(320px, 52vw, 560px);
    border-radius: 20px;
    overflow: hidden;
    background: #0b1022;
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 8%), 0 20px 40px -24px rgb(0 0 0 / 70%);
    touch-action: none;
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    cursor: crosshair;
}
.tsc-surface:focus-visible { outline: 3px solid var(--tsc-cyan); outline-offset: 3px; }

.tsc-grid {
    position: absolute; inset: 0;
    display: grid;
    grid-template-columns: repeat(var(--cols, 12), minmax(0, 1fr));
    grid-template-rows: repeat(var(--rows, 8), minmax(0, 1fr));
    gap: 2px; padding: 2px;
}
.tsc-cell {
    border-radius: 6px;
    background: rgb(255 255 255 / 4.5%);
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / 5%);
    transition: background-color .5s ease, box-shadow .5s ease;
}
.tsc-cell.is-hit {
    background: linear-gradient(160deg, rgb(52 245 166 / 34%), rgb(34 211 238 / 22%));
    box-shadow: inset 0 0 0 1px rgb(52 245 166 / 40%);
    animation: tsc-light .6s ease-out;
}
@keyframes tsc-light {
    0% { background: rgb(120 200 255 / 85%); box-shadow: 0 0 18px 4px rgb(34 211 238 / 70%), inset 0 0 0 1px #fff; }
    100% { }
}

/* Missed cells after "Show missed cells" */
.tsc.is-revealed .tsc-cell:not(.is-hit) {
    background: rgb(255 95 109 / 22%);
    box-shadow: inset 0 0 0 1px rgb(255 95 109 / 65%);
    animation: tsc-missed 1.2s ease-in-out infinite;
}
@keyframes tsc-missed { 50% { background: rgb(255 95 109 / 48%); box-shadow: inset 0 0 0 2px #ff5f6d, 0 0 14px rgb(255 95 109 / 55%); } }

.tsc-ink { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.tsc-hover {
    position: absolute; left: 0; top: 0; width: 26px; height: 26px; margin: -13px 0 0 -13px;
    border-radius: 50%; border: 2px dashed #c4b5fd; opacity: 0; pointer-events: none;
    transition: opacity .15s ease;
}
.tsc-hover.is-on { opacity: 1; }

.tsc-start {
    position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 18px 22px; border-radius: 20px;
    background: rgb(16 22 43 / 72%); color: #e8ecfb; font-weight: 600; font-size: .95rem; text-align: center;
    box-shadow: 0 16px 34px -14px rgb(0 0 0 / 70%);
    pointer-events: none;
    transition: opacity .3s ease;
}
.tsc-start-icon { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 50%; background: rgb(34 211 238 / 16%); color: var(--tsc-cyan); animation: tsc-swipe 2.2s ease-in-out infinite; }
.tsc-start-icon svg { width: 30px; height: 30px; }
@keyframes tsc-swipe { 0%, 100% { transform: translateX(-14px); } 50% { transform: translateX(14px); } }
.tsc.has-input .tsc-start { opacity: 0; }

.tsc.is-complete .tsc-surface { box-shadow: inset 0 0 0 2px var(--tsc-ok), 0 0 40px -6px rgb(52 245 166 / 55%); }

/* ---------- full screen ---------- */

.tsc-exit {
    display: none;
    position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); z-index: 3;
    align-items: center; gap: 8px;
    min-width: 48px; min-height: 48px; padding: 0 14px 0 12px;
    border: 1px solid rgb(255 255 255 / 25%); border-radius: 999px; cursor: pointer;
    background: rgb(16 22 43 / 82%); color: #fff; font-weight: 700;
    box-shadow: 0 10px 24px -10px rgb(0 0 0 / 70%);
}
.tsc-exit.is-left { right: auto; left: max(12px, env(safe-area-inset-left)); }
.tsc-exit svg { width: 20px; height: 20px; }
.tsc-exit:focus-visible { outline: 3px solid var(--tsc-cyan); outline-offset: 2px; }

.tsc.is-full .tsc-stage {
    position: fixed; inset: 0; z-index: 2147483000;
    padding: 0; border-radius: 0;
}
.tsc.is-full .tsc-surface { height: 100%; border-radius: 0; }
.tsc.is-full .tsc-exit { display: inline-flex; }

/* ---------- panel ---------- */

.tsc-panel {
    display: grid;
    grid-template-columns: auto minmax(0, 1.4fr) auto;
    grid-template-areas: "score readout counts" "actions actions actions";
    gap: 18px 26px; align-items: center;
    padding: 22px clamp(16px, 3vw, 32px) 6px;
}
.tsc-score { grid-area: score; display: flex; align-items: center; gap: 14px; }
.tsc-ring { position: relative; width: 84px; height: 84px; flex: none; }
.tsc-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.tsc-ring circle { fill: none; stroke-width: 3.2; }
.tsc-ring-track { stroke: #e3e7f1; }
.tsc-ring-bar { stroke: var(--tsc-accent); stroke-linecap: round; stroke-dasharray: 100 100; stroke-dashoffset: calc(100 - var(--p)); transition: stroke-dashoffset .25s ease, stroke .3s ease; }
.tsc.is-complete .tsc-ring-bar { stroke: #16a34a; }
.tsc-ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tsc-ring.is-pop { animation: tsc-pop .5s ease; }
@keyframes tsc-pop { 40% { transform: scale(1.12); } }
.tsc-score-text strong { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.tsc-score-text span { display: block; font-size: .8rem; color: var(--tsc-muted); }
.tsc-score-text .tsc-edge { margin-top: 4px; }
.tsc-edge b { color: var(--tsc-ink); font-variant-numeric: tabular-nums; }

.tsc-readout { grid-area: readout; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 16px; padding: 12px 16px; border-radius: 16px; background: #f6f8fc; border: 1px solid var(--tsc-line); min-width: 0; }
.tsc-readout div { min-width: 0; }
.tsc-readout dt { font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--tsc-muted); }
.tsc-readout dd { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .86rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tsc-readout dd.is-muted { color: #9aa1b2; font-weight: 500; }

.tsc-counts { grid-area: counts; display: flex; gap: 10px; }
.tsc-count { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px; font-size: .72rem; color: var(--tsc-muted); text-align: center; }
.tsc-count-big { display: grid; place-items: center; width: 50px; height: 50px; border-radius: 50%; background: #fff; border: 1px solid var(--tsc-line); box-shadow: 0 4px 10px -8px rgb(16 22 43 / 45%); font-size: 1.25rem; font-weight: 800; color: var(--tsc-ink); font-variant-numeric: tabular-nums; }
.tsc-count-big.is-pop { animation: tsc-pop .4s ease; border-color: var(--tsc-accent); }

.tsc-actions { grid-area: actions; display: flex; flex-wrap: wrap; gap: 8px; }
.tsc-btn {
    display: inline-flex; align-items: center; gap: 8px;
    min-height: 44px; padding: 0 16px; border-radius: 12px; cursor: pointer;
    border: 1px solid var(--tsc-line); background: #fff; color: var(--tsc-ink); font-weight: 600; font-size: .9rem;
    box-shadow: 0 4px 10px -8px rgb(16 22 43 / 45%);
    transition: background-color .15s ease, transform .1s ease;
}
.tsc-btn:hover { background: #f4f7ff; }
.tsc-btn:active { transform: translateY(1px); }
.tsc-btn:focus-visible { outline: 3px solid var(--tsc-accent); outline-offset: 2px; }
.tsc-btn svg { width: 18px; height: 18px; }
.tsc-btn--primary { border-color: transparent; color: #fff; background: linear-gradient(180deg, #5b9dff, var(--tsc-accent)); box-shadow: 0 10px 20px -10px rgb(61 139 255 / 80%); }
.tsc-btn--primary:hover { background: linear-gradient(180deg, #6aa9ff, #3480f5); }
.tsc-btn[aria-pressed="true"] { background: #fff1f2; border-color: #fecdd3; color: #be123c; }

.tsc-status {
    margin: 16px clamp(16px, 3vw, 32px) 0; padding: 12px 16px;
    border-radius: 14px; background: #f4f7ff; border: 1px solid #dce6fb;
    font-weight: 600; color: #1d3a7a;
}
.tsc-status.is-warn { background: #fff8eb; border-color: #fde2b0; color: #8a4b08; }
.tsc-status.is-ok { background: #ecfdf3; border-color: #bbf7d0; color: #166534; }
.tsc-note { margin: 10px clamp(16px, 3vw, 32px) 22px; font-size: .88rem; color: var(--tsc-muted); }

/* ---------- responsive ---------- */

@media (max-width: 991.98px) {
    .tsc-panel { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "score counts" "readout readout" "actions actions"; }
    .tsc-counts { justify-content: flex-end; }
}
@media (max-width: 575.98px) {
    .tsc { border-radius: 22px; margin-inline: -4px; }
    .tsc-topbar { padding: 12px 14px; }
    .tsc-density { width: 100%; }
    .tsc-density button { flex: 1; padding: 6px 4px; }
    .tsc-stage { padding: 10px; }
    .tsc-surface { height: min(70vh, 520px); border-radius: 16px; }
    .tsc-panel { grid-template-columns: 1fr; grid-template-areas: "score" "counts" "readout" "actions"; gap: 14px; }
    .tsc-ring { width: 72px; height: 72px; }
    .tsc-counts { justify-content: space-between; }
    .tsc-readout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tsc-actions .tsc-btn { flex: 1 1 auto; justify-content: center; }
}
@media (pointer: coarse) {
    .tsc-density button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    .tsc *, .tsc *::before, .tsc *::after { animation: none !important; transition: none !important; }
}
