/* Hand Reaction (touch) — mobile-only, landscape, two zones */

@media (min-width: 769px) {
    #deskReactionSelectStack {
        display: none !important;
    }
}

body.hand-reaction-touch-active {
    touch-action: manipulation;
    overscroll-behavior: none;
}

body.hand-reaction-touch-active .app-wrapper,
body.hand-reaction-touch-active .app-header {
    visibility: hidden;
    pointer-events: none;
}

#deskReactionRoot {
    position: fixed;
    inset: 0;
    z-index: 12000;
    background: var(--dark-bg);
    color: var(--text-primary);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
}

#deskReactionRoot[hidden] {
    display: none !important;
}

/* ── Play: fullscreen left | right (landscape) ── */
.desk-reaction-play {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 100%;
    min-height: 0;
    z-index: 1;
    touch-action: none;
}

.desk-reaction-play[hidden] {
    display: none !important;
}

.desk-reaction-panel {
    flex: 1 1 50%;
    width: 50%;
    height: 100%;
    display: block;
    border: none;
    margin: 0;
    padding: 0;
    background: var(--dark-bg-card);
    box-shadow: inset 0 0 0 1px rgba(0, 217, 255, 0.12);
    transition: background 0.07s ease, box-shadow 0.07s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    cursor: pointer;
}

.desk-reaction-panel--left {
    border-right: 2px solid rgba(0, 217, 255, 0.28);
    background: linear-gradient(180deg, #111827 0%, #0d1422 100%);
}

.desk-reaction-panel--right {
    background: linear-gradient(180deg, #141c2c 0%, #101828 100%);
}

#deskReactionRoot.desk-reaction--waiting .desk-reaction-panel {
    box-shadow: inset 0 0 0 1px rgba(0, 217, 255, 0.22);
    animation: handReactionZoneIdle 1.4s ease-in-out infinite;
}

#deskReactionRoot.desk-reaction--waiting .desk-reaction-panel--right {
    animation-delay: 0.18s;
}

@keyframes handReactionZoneIdle {
    0%, 100% { opacity: 0.82; }
    50% { opacity: 1; }
}

.desk-reaction-panel--lit {
    background: linear-gradient(160deg, var(--primary-cyan) 0%, var(--electric-blue) 100%);
    box-shadow:
        inset 0 0 0 2px rgba(255, 255, 255, 0.35),
        0 0 42px var(--glow-cyan);
}

.desk-reaction-panel--flash-ok {
    background: linear-gradient(160deg, var(--success) 0%, var(--primary-cyan-dark) 100%) !important;
    box-shadow: 0 0 36px rgba(0, 230, 118, 0.45) !important;
}

.desk-reaction-panel--flash-bad {
    background: linear-gradient(160deg, var(--error) 0%, #c62828 100%) !important;
    box-shadow: 0 0 28px rgba(255, 82, 82, 0.4) !important;
}

/* Portrait during live test → rotate prompt */
.desk-reaction-rotate {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(10, 14, 26, 0.94);
    text-align: center;
}

.desk-reaction-rotate[hidden] {
    display: none !important;
}

.desk-reaction-rotate__card {
    width: min(320px, 100%);
    padding: 1.25rem 1.1rem;
    border-radius: var(--r-lg);
    border: 1px solid rgba(0, 217, 255, 0.35);
    background: var(--dark-bg-card);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
}

.desk-reaction-rotate__icon {
    font-size: 2rem;
    color: var(--primary-cyan);
    margin-bottom: 0.65rem;
}

.desk-reaction-rotate__title {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-primary);
}

.desk-reaction-rotate__lead {
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--text-secondary);
}

/* ── Setup / summary overlays (app theme) ── */
.desk-reaction-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: rgba(4, 8, 18, 0.78);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow: auto;
}

.desk-reaction-overlay[hidden] {
    display: none !important;
}

.desk-reaction-overlay__card {
    width: min(360px, 100%);
    padding: 16px 16px 14px;
    border-radius: var(--r-lg);
    border: 1px solid rgba(0, 217, 255, 0.32);
    background: rgba(10, 14, 26, 0.97);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
}

.desk-reaction-overlay__step {
    display: block;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(0, 217, 255, 0.88);
    margin-bottom: 6px;
}

.desk-reaction-overlay__title {
    margin: 0 0 6px;
    font-size: 1.08rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.25;
}

.desk-reaction-overlay__lead {
    margin: 0 0 12px;
    font-size: 0.78rem;
    line-height: 1.4;
    color: var(--text-secondary);
}

.desk-reaction-setup__fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
}

.desk-reaction-setup__field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 8px 10px;
    border-radius: var(--r-md);
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(0, 0, 0, 0.22);
}

.desk-reaction-setup__field label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.desk-reaction-setup__field input {
    width: 100%;
    box-sizing: border-box;
    border: none;
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--mono);
    padding: 0.5rem 0.55rem;
    text-align: center;
}

.desk-reaction-btn {
    appearance: none;
    width: 100%;
    border: none;
    border-radius: var(--r-md);
    padding: 0.82rem 1rem;
    font-size: 0.92rem;
    font-weight: 800;
    font-family: var(--font);
    cursor: pointer;
    transition: transform 0.12s var(--ease), opacity 0.12s var(--ease);
}

.desk-reaction-btn:active {
    transform: scale(0.98);
}

.desk-reaction-btn--primary {
    background: linear-gradient(135deg, var(--primary-cyan), var(--electric-blue));
    color: #041018;
    box-shadow: 0 4px 18px var(--glow-cyan);
}

.desk-reaction-btn--ghost {
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.desk-reaction-summary__stats {
    margin: 0 0 10px;
    font-size: 0.72rem;
    line-height: 1.45;
    text-align: center;
    color: var(--text-secondary);
    font-family: var(--mono);
}

.desk-reaction-summary__metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin: 0 0 10px;
}

.desk-reaction-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    min-width: 0;
}

.desk-reaction-metric--wide {
    grid-column: span 2;
}

.desk-reaction-metric__label {
    font-size: 0.55rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.desk-reaction-metric__val {
    font-family: var(--mono);
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.1;
}

.desk-reaction-metric__val--accent {
    color: var(--primary-cyan);
}

.desk-reaction-summary__actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.desk-reaction-summary__actions .desk-reaction-btn--primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
}

.desk-reaction-summary__actions .desk-reaction-btn--primary i {
    font-size: 0.95rem;
    opacity: 0.92;
}

.desk-reaction-summary__actions .desk-reaction-btn--ghost {
    margin-top: 0;
}

.desk-reaction-summary__list {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-height: 38vh;
    overflow: auto;
    margin-bottom: 12px;
}

.desk-reaction-summary-row {
    display: grid;
    grid-template-columns: 2rem 1fr 5.5rem;
    gap: 0.5rem;
    align-items: center;
    padding: 0.45rem 0.55rem;
    border-radius: var(--r-sm);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    font-size: 0.8rem;
}

.desk-reaction-summary-row__rt {
    text-align: right;
    font-family: var(--mono);
    color: var(--primary-cyan);
}

.desk-reaction-summary-row__rt.is-ok {
    color: var(--success);
}

.desk-reaction-summary-row__rt.is-bad {
    color: var(--error);
}

/* Test picker visibility — mobile only (styling lives in styles.css) */
html.hand-reaction-fullscreen-html {
    overflow: hidden;
    touch-action: manipulation;
    overscroll-behavior: none;
}

html.hand-reaction-fullscreen-html,
body.hand-reaction-fullscreen {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden !important;
    overscroll-behavior: none;
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

@supports (-webkit-touch-callout: none) {
    html.hand-reaction-fullscreen-html {
        position: fixed;
        inset: 0;
        width: 100% !important;
        height: 100% !important;
        max-width: 100%;
        max-height: 100%;
    }

    body.hand-reaction-fullscreen {
        position: fixed;
        inset: 0;
        width: 100% !important;
        height: 100% !important;
        max-width: 100%;
        max-height: 100%;
    }
}

html.hand-reaction-fullscreen-html::after,
body.hand-reaction-fullscreen::after {
    display: none !important;
}

body.hand-reaction-fullscreen #deskReactionRoot {
    position: fixed;
    inset: 0;
    margin: 0;
    padding: 0;
    max-width: none;
    max-height: none;
    z-index: 2147483000;
    box-sizing: border-box;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    touch-action: manipulation;
}

body.hand-reaction-fullscreen:fullscreen #deskReactionRoot,
body.hand-reaction-fullscreen #deskReactionRoot:fullscreen,
html.hand-reaction-fullscreen-html:fullscreen #deskReactionRoot {
    width: 100% !important;
    height: 100% !important;
    inset: 0 !important;
}

/* Countdown overlay */
.desk-reaction-countdown {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 50% 40%, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.82));
    pointer-events: none;
}

.desk-reaction-countdown[hidden] {
    display: none !important;
}

.desk-reaction-countdown__num {
    font-family: var(--mono);
    font-size: clamp(4rem, 18vw, 7rem);
    font-weight: 900;
    color: #fff;
    text-shadow:
        0 0 30px rgba(0, 0, 0, 0.9),
        0 0 48px var(--glow-cyan);
    animation: handReactionCountdownPulse 0.9s ease-in-out infinite;
}

.desk-reaction-countdown__num--ready {
    font-size: clamp(2.2rem, 10vw, 3.6rem);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Debug: reaction timer at stimulus T0 (gray live → green frozen on touch) */
.desk-reaction-debug-timer {
    position: absolute;
    top: max(8px, env(safe-area-inset-top, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 6;
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem 0.4rem;
    border-radius: 10px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
    background: rgba(10, 14, 26, 0.88);
    border: 2px solid rgba(148, 163, 184, 0.55);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    backdrop-filter: none;
}

.desk-reaction-debug-timer[hidden] {
    display: none !important;
}

.desk-reaction-debug-timer__val {
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1;
    min-width: 4.2ch;
    text-align: right;
}

.desk-reaction-debug-timer__unit {
    font-size: 0.7rem;
    font-weight: 700;
    opacity: 0.75;
}

.desk-reaction-debug-timer--live {
    border-color: rgba(148, 163, 184, 0.75);
}

.desk-reaction-debug-timer--live .desk-reaction-debug-timer__val,
.desk-reaction-debug-timer--live .desk-reaction-debug-timer__unit {
    color: #94a3b8;
}

.desk-reaction-debug-timer--frozen-ok {
    border-color: rgba(0, 230, 118, 0.85);
    box-shadow: 0 0 22px rgba(0, 230, 118, 0.28);
}

.desk-reaction-debug-timer--frozen-ok .desk-reaction-debug-timer__val,
.desk-reaction-debug-timer--frozen-ok .desk-reaction-debug-timer__unit {
    color: var(--success);
}

.desk-reaction-debug-timer--frozen-bad {
    border-color: rgba(255, 140, 74, 0.85);
}

.desk-reaction-debug-timer--frozen-bad .desk-reaction-debug-timer__val {
    font-size: 0.95rem;
    letter-spacing: 0.06em;
    color: #ff8c4a;
}

.desk-reaction-debug-timer--frozen-bad .desk-reaction-debug-timer__unit {
    display: none;
}

#deskReactionRoot.desk-reaction--playing .desk-reaction-debug-timer--live {
    animation: handReactionDebugTimerPulse 0.9s ease-in-out infinite;
}

@keyframes handReactionDebugTimerPulse {
    0%, 100% { opacity: 0.92; }
    50% { opacity: 1; }
}

@keyframes handReactionCountdownPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.06); opacity: 0.92; }
}

#deskReactionRoot.desk-reaction--countdown .desk-reaction-panel {
    animation: none;
    opacity: 0.65;
}

/* Per-trial feedback */
.desk-reaction-trial-feedback {
    position: absolute;
    left: 50%;
    bottom: max(14px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 9;
    width: min(92vw, 420px);
    pointer-events: none;
}

.desk-reaction-trial-feedback[hidden] {
    display: none !important;
}

.desk-reaction-trial-feedback__card {
    padding: 10px 14px 11px;
    border-radius: var(--r-md);
    border: 1px solid rgba(0, 217, 255, 0.35);
    background: rgba(10, 14, 26, 0.92);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    text-align: center;
}

.desk-reaction-trial-feedback__result {
    margin: 0 0 4px;
    font-family: var(--mono);
    font-size: clamp(1.35rem, 5vw, 1.85rem);
    font-weight: 800;
    color: var(--text-primary);
}

.desk-reaction-trial-feedback__result--ok {
    color: var(--success);
}

.desk-reaction-trial-feedback__result--bad {
    color: var(--error);
}

.desk-reaction-trial-feedback__remaining {
    margin: 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

#deskReactionRoot.desk-reaction--playing .desk-reaction-overlay {
    display: none !important;
}

#deskReactionRoot.desk-reaction--playing .desk-reaction-play {
    display: flex !important;
    visibility: visible !important;
}

#deskReactionRoot.desk-reaction--playing .desk-reaction-play[hidden] {
    display: flex !important;
}

@media (orientation: portrait) {
    #deskReactionRoot.desk-reaction--playing .desk-reaction-play {
        display: none !important;
    }

    #deskReactionRoot.desk-reaction--playing .desk-reaction-rotate {
        display: flex !important;
    }
}

@media (orientation: landscape) {
    #deskReactionRoot.desk-reaction--playing .desk-reaction-rotate {
        display: none !important;
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-overlay {
        display: flex !important;
        align-items: stretch;
        justify-content: center;
        padding:
            max(8px, env(safe-area-inset-top))
            max(10px, env(safe-area-inset-right))
            max(8px, env(safe-area-inset-bottom))
            max(10px, env(safe-area-inset-left));
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-summary__card {
        width: min(94vw, 720px);
        max-height: min(92dvh, 100%);
        display: flex;
        flex-direction: column;
        padding: 12px 14px 10px;
        overflow: hidden;
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-overlay__title {
        font-size: 0.95rem;
        margin-bottom: 4px;
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-summary__metrics {
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 5px;
        margin-bottom: 8px;
        flex: 0 0 auto;
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-metric--wide {
        grid-column: span 1;
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-metric__val {
        font-size: 0.74rem;
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-summary__list {
        flex: 1 1 auto;
        min-height: 0;
        max-height: none;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 4px;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 8px;
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-summary-row {
        grid-template-columns: 1.6rem 1fr 4.2rem;
        padding: 0.35rem 0.45rem;
        font-size: 0.72rem;
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-summary__actions {
        flex: 0 0 auto;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 8px;
    }

    #deskReactionRoot.desk-reaction--summary .desk-reaction-summary__actions .desk-reaction-btn--primary {
        grid-column: 1 / -1;
    }
}
