/*
 * W1Network Pro — Auto-Reading / Teleprompter Toolbar Styles
 *
 * Covers:
 *  - Fixed toolbar (bottom of viewport on desktop, top-sticky on mobile)
 *  - Play / Pause button
 *  - Speed selector (Slow / Medium / Fast)
 *  - Progress bar (thin strip at top of the toolbar)
 *  - Content wrapper fade-overlay at top edge (visual teleprompter feel)
 *  - Responsive breakpoints for all screen sizes
 *  - Dark / Light mode support (inherits from theme variables)
 *  - Reduced-motion support (disables smooth scroll animation)
 *  - Print: toolbar hidden, content shown normally
 *
 * @package W1Network_Pro
 * @since   5.1.0
 */

/* ==========================================================================
   CSS Custom Properties (can be overridden per-theme)
   ========================================================================== */

:root {
    /* Toolbar */
    --ar-toolbar-bg:          rgba(18, 18, 18, 0.96);
    --ar-toolbar-border:      rgba(255, 255, 255, 0.08);
    --ar-toolbar-radius:      16px;
    --ar-toolbar-shadow:      0 -4px 32px rgba(0, 0, 0, 0.45),
                              0 2px 8px  rgba(0, 0, 0, 0.3);
    --ar-toolbar-height:      58px;
    --ar-toolbar-z:           900;   /* Below site header (z:1000) */
    --ar-toolbar-padding:     0 16px;

    /* Buttons */
    --ar-btn-radius:          50px;
    --ar-btn-gap:             8px;

    /* Play button */
    --ar-play-bg:             linear-gradient(135deg, #ff0050 0%, #e6004a 100%);
    --ar-play-color:          #ffffff;
    --ar-play-shadow:         0 3px 14px rgba(255, 0, 80, 0.4);

    /* Speed buttons */
    --ar-speed-bg:            rgba(255, 255, 255, 0.07);
    --ar-speed-color:         #b3b3b3;
    --ar-speed-border:        1px solid rgba(255, 255, 255, 0.1);
    --ar-speed-active-bg:     rgba(255, 0, 80, 0.18);
    --ar-speed-active-color:  #ff0050;
    --ar-speed-active-border: 1px solid rgba(255, 0, 80, 0.45);

    /* Progress bar */
    --ar-progress-h:          3px;
    --ar-progress-track:      rgba(255, 255, 255, 0.08);
    --ar-progress-fill:       linear-gradient(90deg, #ff0050 0%, #ff4d8e 100%);

    /* Fade overlay */
    --ar-fade-height:         80px;
}

/* Light mode overrides */
body.light-mode {
    --ar-toolbar-bg:          rgba(255, 255, 255, 0.97);
    --ar-toolbar-border:      rgba(0, 0, 0, 0.09);
    --ar-toolbar-shadow:      0 -4px 32px rgba(0, 0, 0, 0.1),
                              0 2px 8px  rgba(0, 0, 0, 0.05);
    --ar-speed-bg:            rgba(0, 0, 0, 0.05);
    --ar-speed-color:         #555;
    --ar-speed-border:        1px solid rgba(0, 0, 0, 0.1);
    --ar-speed-active-bg:     rgba(255, 0, 80, 0.09);
    --ar-progress-track:      rgba(0, 0, 0, 0.08);
}

/* ==========================================================================
   Toolbar Container
   Fixed to the bottom of the viewport on desktop.
   On mobile it floats as a pill near the bottom.
   ========================================================================== */

#ar-toolbar {
    /* Hidden until JS initialises (prevents flash) */
    opacity: 0;
    pointer-events: none;

    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--ar-toolbar-z);

    display: flex;
    align-items: center;
    gap: var(--ar-btn-gap);

    height: var(--ar-toolbar-height);
    padding: var(--ar-toolbar-padding);
    padding-top: 0;                /* progress bar sits above */

    background: var(--ar-toolbar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--ar-toolbar-border);
    border-radius: var(--ar-toolbar-radius);
    box-shadow: var(--ar-toolbar-shadow);

    /* Smooth entry animation */
    transition: opacity 0.3s ease, transform 0.3s ease;

    /* Minimum touch target width */
    min-width: 280px;
    max-width: calc(100vw - 32px);
    white-space: nowrap;
}

/* Reveal once JS is ready */
#ar-toolbar.ar-toolbar--ready {
    opacity: 1;
    pointer-events: auto;
}

/* ==========================================================================
   Progress Bar — sits at the top edge of the toolbar
   ========================================================================== */

.ar-progress-track {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--ar-progress-h);
    background: var(--ar-progress-track);
    border-radius: var(--ar-toolbar-radius) var(--ar-toolbar-radius) 0 0;
    overflow: hidden;
}

.ar-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--ar-progress-fill);
    border-radius: inherit;
    /* Smooth progress fill transition */
    transition: width 0.25s linear;
}

/* Screen-reader only label for progress */
.ar-progress-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Toolbar Label (the "Auto Read" text badge)
   ========================================================================== */

.ar-toolbar-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ar-speed-color);
    padding: 0 4px 0 2px;
    flex-shrink: 0;
    user-select: none;
}

.ar-toolbar-label svg {
    color: #ff0050;
    flex-shrink: 0;
    animation: ar-pulse 2s ease-in-out infinite;
}

/* Only pulse when auto-scrolling is active */
#ar-toolbar:not(.ar-is-playing) .ar-toolbar-label svg {
    animation: none;
    opacity: 0.4;
}

@keyframes ar-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.6; transform: scale(0.9); }
}

/* ==========================================================================
   Divider
   ========================================================================== */

.ar-divider {
    width: 1px;
    height: 22px;
    background: var(--ar-toolbar-border);
    flex-shrink: 0;
    margin: 0 2px;
}

/* ==========================================================================
   Play / Pause Button
   ========================================================================== */

.ar-play-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;

    padding: 8px 18px;
    height: 38px;

    background: var(--ar-play-bg);
    color: var(--ar-play-color);
    border: none;
    border-radius: var(--ar-btn-radius);
    font-size: 0.82rem;
    font-weight: 700;
    font-family: inherit;
    letter-spacing: 0.02em;
    cursor: pointer;
    flex-shrink: 0;

    box-shadow: var(--ar-play-shadow);
    transition: opacity 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.ar-play-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(255, 0, 80, 0.5);
}

.ar-play-btn:active {
    transform: translateY(0) scale(0.97);
}

.ar-play-btn:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

.ar-play-btn svg {
    flex-shrink: 0;
    pointer-events: none;
}

.ar-btn-label {
    line-height: 1;
}

/* ==========================================================================
   Speed Buttons
   ========================================================================== */

.ar-speed-group {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.ar-speed-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--ar-speed-color);
    margin-right: 2px;
    opacity: 0.7;
    user-select: none;
}

.ar-speed-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    height: 30px;
    padding: 0 11px;
    min-width: 44px;        /* WCAG minimum touch target */

    background: var(--ar-speed-bg);
    color: var(--ar-speed-color);
    border: var(--ar-speed-border);
    border-radius: var(--ar-btn-radius);
    font-size: 0.72rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    flex-shrink: 0;

    transition: background 0.15s ease, color 0.15s ease,
                border-color 0.15s ease, transform 0.12s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.ar-speed-btn:hover {
    background: rgba(255, 0, 80, 0.1);
    color: #ff0050;
    border-color: rgba(255, 0, 80, 0.3);
}

.ar-speed-btn:active {
    transform: scale(0.95);
}

.ar-speed-btn:focus-visible {
    outline: 3px solid var(--ar-speed-active-color);
    outline-offset: 2px;
}

/* Active speed state */
.ar-speed-btn--active {
    background: var(--ar-speed-active-bg)  !important;
    color:      var(--ar-speed-active-color) !important;
    border:     var(--ar-speed-active-border) !important;
}

/* ==========================================================================
   "Playing" state — add subtle glow ring to toolbar
   ========================================================================== */

#ar-toolbar.ar-is-playing {
    border-color: rgba(255, 0, 80, 0.22);
    box-shadow: var(--ar-toolbar-shadow),
                0 0 0 1px rgba(255, 0, 80, 0.14);
}

/* ==========================================================================
   Top Fade Overlay — the "teleprompter" fading edge effect.
   A gradient mask at the top of the content that fades text out,
   reinforcing the sense that content is scrolling INTO view.
   ========================================================================== */

.ar-content-wrapper {
    position: relative;
}

.ar-content-wrapper::before {
    content: '';
    position: fixed;
    top: 64px;      /* Height of the fixed site header */
    left: 0;
    right: 0;
    height: var(--ar-fade-height);
    /* Fade from theme background to transparent */
    background: linear-gradient(
        to bottom,
        var(--bg-0, #000000) 0%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 500;
    opacity: 0;
    transition: opacity 0.4s ease;
}

/* Show the fade overlay only while auto-scroll is active */
.ar-content-wrapper.ar-scrolling::before {
    opacity: 1;
}

/* ==========================================================================
   Keyboard Shortcut Tooltip (shown on desktop, hidden on touch)
   ========================================================================== */

.ar-shortcuts-hint {
    font-size: 0.66rem;
    color: var(--ar-speed-color);
    opacity: 0.55;
    letter-spacing: 0.03em;
    white-space: nowrap;
    user-select: none;
    flex-shrink: 0;
    padding-left: 4px;
}

.ar-shortcuts-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    font-size: 0.65rem;
    font-family: inherit;
    color: #999;
}

body.light-mode .ar-shortcuts-hint kbd {
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.1);
}

/* Hide shortcuts hint on touch devices */
@media (hover: none) {
    .ar-shortcuts-hint {
        display: none;
    }
}

/* ==========================================================================
   RESPONSIVE — Mobile  (≤ 480px)
   Toolbar shrinks to a compact pill at the bottom.
   ========================================================================== */

@media (max-width: 480px) {
    #ar-toolbar {
        bottom: 16px;
        gap: 6px;
        padding: 0 12px;
        height: 52px;
        min-width: 0;
        max-width: calc(100vw - 24px);
    }

    .ar-shortcuts-hint {
        display: none; /* Hide keyboard hints on small screens */
    }

    .ar-speed-label {
        display: none; /* More room for buttons */
    }

    .ar-play-btn {
        padding: 7px 14px;
        height: 34px;
        font-size: 0.78rem;
    }

    .ar-speed-btn {
        height: 28px;
        padding: 0 8px;
        min-width: 36px;
        font-size: 0.68rem;
    }

    .ar-toolbar-label span:not(.ar-icon) {
        display: none; /* Show only icon on tiny screens */
    }
}

/* ==========================================================================
   RESPONSIVE — Tablet  (481px – 768px)
   ========================================================================== */

@media (min-width: 481px) and (max-width: 768px) {
    #ar-toolbar {
        bottom: 20px;
        gap: 7px;
        padding: 0 14px;
    }

    .ar-shortcuts-hint {
        display: none;
    }
}

/* ==========================================================================
   RESPONSIVE — Large Desktop  (> 1200px)
   Align the toolbar to the content column, not the full viewport.
   ========================================================================== */

@media (min-width: 1200px) {
    #ar-toolbar {
        max-width: 700px;
    }
}

/* ==========================================================================
   Accessibility — Reduced Motion
   When the user has asked for reduced motion, disable the scroll engine
   visually but keep the toolbar controls functional.
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .ar-progress-fill {
        transition: none;
    }

    .ar-toolbar-label svg {
        animation: none;
    }

    .ar-content-wrapper::before {
        display: none;
    }

    /* JS also checks this flag and skips scrolling when set */
}

/* ==========================================================================
   Print — hide the entire toolbar and fade overlay
   ========================================================================== */

@media print {
    #ar-toolbar,
    .ar-content-wrapper::before {
        display: none !important;
    }
}
