/* AR-Puzzle Player polish.
 *
 * Inherits from ThinkLab brand surface:
 *   --tl-navy / --tl-navy-light / --tl-navy-dark  (background tiers)
 *   --tl-orange / --tl-orange-hover / --tl-orange-light (accent)
 *   --tl-white / --tl-gray-100 / --tl-gray-200    (text / surfaces)
 *   --tl-transition                                (default ease)
 *   --tl-primary / --tl-secondary                  (tenant-overridden hooks)
 *
 * Button classes .tl-btn / .tl-btn-primary / .tl-btn-secondary are reused
 * verbatim from /css/thinklab.css — this file ONLY adds player-specific
 * layout + state transitions, never re-skins the buttons.
 */

.arp {
    --arp-card-bg:        rgba(255, 255, 255, 0.04);
    --arp-card-border:    rgba(255, 255, 255, 0.08);
    --arp-card-shadow:    0 12px 32px rgba(0, 0, 0, 0.45);
    --arp-glow-accent:    rgba(245, 166, 35, 0.35);

    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 0.75rem 0.75rem calc(1rem + env(safe-area-inset-bottom));
    color: var(--tl-white);
    background: linear-gradient(180deg, var(--tl-navy-dark) 0%, var(--tl-navy) 100%);
}

.arp-shell {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    flex: 1 1 auto;
}

/* Header -------------------------------------------------------------- */
.arp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
}
.arp-title {
    margin: 0;
    font-size: 1.15rem;
    line-height: 1.2;
    font-weight: 700;
    color: var(--tl-white);
}
.arp-subtitle {
    margin: 0.15rem 0 0;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.6);
}

/* Progress pill ------------------------------------------------------- */
.arp-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.85rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--tl-white);
    transition: background 200ms ease, color 200ms ease, transform 200ms ease;
}
.arp-pill .arp-pill-num {
    color: var(--tl-orange);
}
.arp-pill.is-pulse {
    transform: scale(1.06);
    background: rgba(245, 166, 35, 0.18);
}

/* Preview banner ------------------------------------------------------ */
.arp-preview-pill {
    align-self: flex-start;
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-size: 0.78rem;
    background: rgba(245, 166, 35, 0.14);
    border: 1px solid rgba(245, 166, 35, 0.4);
    color: var(--tl-orange-light);
}

/* Stage --------------------------------------------------------------- */
.arp-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #000;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--arp-card-border);
    box-shadow: var(--arp-card-shadow);
}
.arp-stage video,
.arp-stage canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
}
.arp-stage canvas { pointer-events: none; }
.arp-stage.is-idle::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 50% 50%, rgba(245,166,35,0.08) 0%, transparent 60%),
        repeating-linear-gradient(45deg, rgba(255,255,255,0.02) 0 12px, transparent 12px 24px);
    pointer-events: none;
}

/* Feedback line ------------------------------------------------------- */
.arp-feedback {
    min-height: 1.8rem;
    text-align: center;
    font-size: 0.92rem;
    color: rgba(255, 255, 255, 0.78);
    transition: color 200ms ease;
}
.arp-feedback[data-kind="error"]   { color: #ff8a8a; }
.arp-feedback[data-kind="success"] { color: #8ce29e; }

/* Action bar ---------------------------------------------------------- */
.arp-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}
.arp-actions .tl-btn {
    /* The ThinkLab default .tl-btn is event-screen-sized (1rem 2.5rem).
       Player surface is smaller — tighten the padding without re-skinning. */
    padding: 0.7rem 1.4rem;
    font-size: 1rem;
    border-radius: 999px;
}
.arp-actions .tl-btn-secondary {
    background: rgba(255, 255, 255, 0.06);
}
/* Armed-state pulse: engine writes [data-armed-id="<int>"] on #arpSubmitBtn
   whenever the locally-expected next marker is currently visible. CSS does
   the rest — no JS animation loop. */
.arp-actions .tl-btn-primary:not([disabled])[data-armed-id]:not([data-armed-id=""]) {
    animation: arp-pulse 1.4s ease-in-out infinite;
    box-shadow: 0 0 0 0 var(--arp-glow-accent), 0 8px 24px rgba(245, 166, 35, 0.25);
}
@keyframes arp-pulse {
    0%   { transform: scale(1);    box-shadow: 0 0 0 0    var(--arp-glow-accent); }
    50%  { transform: scale(1.025); box-shadow: 0 0 0 12px rgba(245,166,35,0); }
    100% { transform: scale(1);    box-shadow: 0 0 0 0    rgba(245,166,35,0); }
}

/* Inline error card (slides in from above the action bar) ------------ */
.arp-error-card {
    display: none;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.75rem 0.9rem;
    border-radius: 12px;
    background: rgba(255, 90, 90, 0.12);
    border: 1px solid rgba(255, 90, 90, 0.45);
    color: #ffdada;
    font-size: 0.9rem;
    transform: translateY(-12px);
    opacity: 0;
    transition: transform 250ms ease, opacity 250ms ease;
    cursor: pointer;
}
.arp-error-card.is-visible {
    display: flex;
    transform: translateY(0);
    opacity: 1;
}
.arp-error-card .arp-error-dismiss {
    margin-left: auto;
    background: none;
    border: none;
    color: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}

/* Success overlay ----------------------------------------------------- */
.arp-success {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1500;
    background: rgba(10, 16, 28, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 220ms ease;
}
.arp-success.is-visible {
    display: flex;
    opacity: 1;
}
.arp-success-card {
    background: linear-gradient(180deg, var(--tl-navy-light), var(--tl-navy));
    border: 1px solid var(--tl-orange);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.55), 0 0 0 8px rgba(245, 166, 35, 0.12);
    border-radius: 18px;
    padding: 1.5rem 1.4rem 1.25rem;
    max-width: 360px;
    width: 100%;
    text-align: center;
    transform: scale(0.92);
    transition: transform 380ms cubic-bezier(0.18, 0.89, 0.32, 1.28);
}
.arp-success.is-visible .arp-success-card { transform: scale(1); }
.arp-success-icon {
    font-size: 2.5rem;
    color: var(--tl-orange);
    line-height: 1;
    margin-bottom: 0.4rem;
}
.arp-success-title {
    margin: 0 0 0.3rem;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--tl-white);
}
.arp-success-sub {
    margin: 0 0 1.1rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
}
.arp-success-time {
    display: inline-block;
    margin-bottom: 1rem;
    padding: 0.35rem 0.85rem;
    border-radius: 999px;
    background: rgba(245, 166, 35, 0.15);
    color: var(--tl-orange-light);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Desktop tightening: cap the shell so the layout doesn't sprawl. */
@media (min-width: 900px) {
    .arp-shell { max-width: 640px; }
    .arp { padding-top: 2rem; }
}

/* Reduced motion: keep state changes legible, skip springs + pulses. */
@media (prefers-reduced-motion: reduce) {
    .arp-pill,
    .arp-feedback,
    .arp-error-card,
    .arp-success,
    .arp-success-card {
        transition-duration: 120ms !important;
    }
    .arp-actions .tl-btn-primary[data-armed-id]:not([data-armed-id=""]) {
        animation: none !important;
        box-shadow: 0 8px 24px rgba(245, 166, 35, 0.25);
    }
    .arp-success-card {
        transform: scale(1) !important;
    }
}
