/* ─── Demo Guidance Layer ───────────────────────────────────────
 *
 * Activates only when state.demoModuleId is set. All elements live
 * inside #demoTourRoot (declared in index.php) so they survive the
 * #viewToggleBar innerHTML wipes that happen on every renderTopBar.
 *
 * Phase 1 ships only the persistent panel + collapsed badge.
 * Phase 2 will add the spotlight backdrop + cutout + callout card.
 *
 * Uses theme custom properties so dark mode works without a second
 * rule set. See css/theme-variables.css for the palette.
 */

#demoTourRoot {
    /* Demo-specific accent colors. Chosen to contrast hard with the
     * app's teal primary so "demo mode" reads as deliberate guidance,
     * not ambient UI. Amber works in both light and dark themes. */
    --demo-accent: #F59E0B;
    --demo-accent-strong: #D97706;
    --demo-accent-soft: rgba(245, 158, 11, 0.18);
    --demo-accent-glow: rgba(245, 158, 11, 0.55);
    --demo-on-accent: #1E2030;
}

/* ─── Persistent panel ────────────────────────────────────────── */

.demo-guide {
    position: fixed;
    /* Stack above the floating Help + Beta Feedback FABs (both at
     * bottom ~20px, heights 44-48px). 80px clears the FAB row with a
     * small gap so the expanded panel never covers them. */
    bottom: 80px;
    right: 1.25rem;
    z-index: 9400;
    width: 320px;
    max-width: calc(100vw - 2.5rem);
    background: var(--bg-surface, #ffffff);
    color: var(--charcoal, #1E2030);
    border: 2px solid var(--demo-accent);
    border-radius: 12px;
    box-shadow: 0 0 0 4px var(--demo-accent-soft),
                0 14px 40px rgba(0, 0, 0, 0.22),
                0 4px 12px rgba(0, 0, 0, 0.10);
    font-family: 'Open Sans', system-ui, sans-serif;
    overflow: visible;
    animation: demoGuideEnter 220ms ease-out;
}

/* Speech-bubble tail pointing down toward the Clarity FAB so the panel
 * reads as something Clarity is saying. The outer triangle matches the
 * panel border; the inner triangle, nudged 2px up, paints the fill so
 * the tail looks like a continuation of the bordered bubble. */
.demo-guide::before,
.demo-guide::after {
    content: '';
    position: absolute;
    right: 18px;
    width: 0;
    height: 0;
    pointer-events: none;
}
.demo-guide::before {
    bottom: -14px;
    border-left: 14px solid transparent;
    border-right: 14px solid transparent;
    border-top: 14px solid var(--demo-accent);
}
.demo-guide::after {
    bottom: -10px;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 12px solid var(--bg-surface, #ffffff);
}

@keyframes demoGuideEnter {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.demo-guide-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0.85rem;
    background: var(--demo-accent);
    border-bottom: 1px solid var(--demo-accent-strong);
}

.demo-guide-pill {
    display: inline-block;
    padding: 0.18rem 0.5rem;
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    color: var(--on-brand);
    background: var(--bg-panel);
    border-radius: 4px;
    text-transform: uppercase;
}

.demo-guide-title {
    flex: 1;
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--demo-on-accent);
    line-height: 1.2;
}

.demo-guide-collapse-btn,
.demo-guide-help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: rgba(255, 255, 255, 0.35);
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    color: var(--demo-on-accent);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.demo-guide-help-btn {
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.9rem;
    font-weight: 800;
}

.demo-guide-collapse-btn:hover,
.demo-guide-collapse-btn:focus,
.demo-guide-help-btn:hover,
.demo-guide-help-btn:focus {
    background: var(--on-brand);
    color: var(--demo-on-accent);
    border-color: var(--demo-accent-strong);
    outline: none;
}

.demo-guide-body {
    padding: 0.75rem 0.85rem 0.85rem;
}

.demo-guide-copy {
    margin: 0;
    font-size: 0.84rem;
    line-height: 1.45;
    color: var(--charcoal, #1E2030);
}

.demo-guide-next {
    margin-top: 0.75rem;
}

.demo-guide-next-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.8rem;
    background: var(--demo-accent);
    color: var(--demo-on-accent);
    border: none;
    border-radius: 8px;
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4);
    transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease;
}

.demo-guide-next-btn:hover,
.demo-guide-next-btn:focus {
    filter: brightness(1.05);
    outline: none;
}

.demo-guide-next-btn:active {
    transform: translateY(1px);
}

.demo-guide-next-arrow {
    font-size: 0.95rem;
    line-height: 1;
}

/* ─── Collapsed badge ─────────────────────────────────────────── */
/* Sits to the left of the Beta Feedback FAB (right:80px, 48px wide), so
 * this lands at right:140px to keep a 12px gap and form a single FAB row
 * across Help / Beta Feedback / Demo Guide. */

.demo-guide-badge {
    position: fixed;
    bottom: 20px;
    right: 140px;
    z-index: 9400;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    padding: 0;
    background: var(--demo-accent);
    color: var(--demo-on-accent);
    border: 2px solid var(--on-brand);
    border-radius: 50%;
    box-shadow: 0 0 0 3px var(--demo-accent-soft),
                0 6px 18px rgba(0, 0, 0, 0.22);
    font-family: 'Montserrat', system-ui, sans-serif;
    font-weight: 800;
    cursor: pointer;
    transition: filter 120ms ease, transform 80ms ease;
    animation: demoGuideEnter 220ms ease-out, demoBadgePulse 2400ms ease-in-out 600ms infinite;
}

@keyframes demoBadgePulse {
    0%, 100% { box-shadow: 0 0 0 3px var(--demo-accent-soft), 0 6px 18px rgba(0, 0, 0, 0.22); }
    50%      { box-shadow: 0 0 0 10px rgba(245, 158, 11, 0), 0 6px 18px rgba(0, 0, 0, 0.22); }
}

.demo-guide-badge:hover,
.demo-guide-badge:focus {
    filter: brightness(1.05);
    outline: none;
    transform: scale(1.08);
}

.demo-guide-badge:active {
    transform: scale(0.95);
}

.demo-guide-badge-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    font-size: 1rem;
    font-weight: 800;
    color: var(--demo-on-accent);
    line-height: 1;
}

/* When the demo guide is mounted, recolor the Clarity FAB so its ring
 * matches the demo accent and visually anchors the speech-bubble tail. */
body:has(#demoGuidePanel) .floating-help-btn,
body:has(#demoGuideBadge) .floating-help-btn {
    background: var(--demo-accent);
}

/* ─── Mobile breakpoint ───────────────────────────────────────── */
/* Phone (≤600px) has a 5-tab bottom bar at #mobileBottomBar. Lift the
 * panel and badge above it so neither clips. The bar is roughly 56px tall
 * with safe-area padding. */

@media (max-width: 600px) {
    /* On phone, the FAB row sits at bottom:72px above the 5-tab bottom
     * bar. Help is at right:14px (44px wide), Beta Feedback at right:70px
     * (44px wide), so the Demo Guide badge slots in at right:126px to
     * extend the row leftward. The expanded panel still lifts above the
     * row to avoid covering the buttons. */
    .demo-guide-badge {
        bottom: 72px;
        right: 126px;
        width: 44px;
        height: 44px;
    }
    .demo-guide {
        bottom: calc(130px + env(safe-area-inset-bottom, 0px));
        right: 0.75rem;
        width: calc(100vw - 1.5rem);
        max-width: 360px;
    }
}

/* ─── Spotlight tour (Phase 2) ────────────────────────────────── */
/* The backdrop covers the viewport and intercepts clicks so the tour
 * is modal. The cutout uses an oversized box-shadow trick to "punch a
 * hole" around the highlighted element without needing SVG masking.
 * The callout card is positioned by JS based on the cutout's bbox. */

.demo-spotlight-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9500;
    pointer-events: none;
    /* No dim -- site stays fully visible during the tour. */
}

/* no-cutout steps (welcome/end): still no dim, callout floats over live UI */
.demo-spotlight-backdrop.no-cutout {
    background: none;
}

.demo-spotlight-cutout {
    position: fixed;
    /* Must sit above app chrome (top bar 200, rail 150, panels 50)
     * so the amber ring renders on top of the highlighted element. */
    z-index: 9550;
    border-radius: 10px;
    pointer-events: none;
    /* Amber ring only -- no viewport-wide dim shadow. */
    box-shadow:
        0 0 0 4px var(--demo-accent-soft),
        0 0 24px 6px var(--demo-accent-glow);
    transition: top 220ms ease, left 220ms ease, width 220ms ease, height 220ms ease;
    outline: 3px solid var(--demo-accent);
    outline-offset: 4px;
    animation: demoSpotlightPulse 1800ms ease-in-out 400ms infinite;
}

@keyframes demoSpotlightPulse {
    0%, 100% {
        box-shadow:
            0 0 0 4px var(--demo-accent-soft),
            0 0 24px 6px var(--demo-accent-glow);
    }
    50% {
        box-shadow:
            0 0 0 10px rgba(245, 158, 11, 0.08),
            0 0 40px 10px var(--demo-accent-glow);
    }
}

.demo-spotlight-callout {
    position: fixed;
    z-index: 9600;
    width: 360px;
    max-width: calc(100vw - 2rem);
    background: var(--bg-surface, #ffffff);
    color: var(--charcoal, #1E2030);
    border: 2px solid var(--demo-accent);
    border-radius: 12px;
    box-shadow: 0 0 0 4px var(--demo-accent-soft),
                0 18px 50px rgba(0, 0, 0, 0.4),
                0 4px 12px rgba(0, 0, 0, 0.2);
    font-family: 'Open Sans', system-ui, sans-serif;
    overflow: hidden;
    animation: demoSpotlightFade 200ms ease-out;
}

/* Centered welcome / end variant when there is no anchor. */
.demo-spotlight-callout.centered {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 420px;
}

.demo-spotlight-header {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.7rem 0.95rem;
    background: var(--demo-accent);
    border-bottom: 1px solid var(--demo-accent-strong);
}

.demo-spotlight-step {
    padding: 0.2rem 0.55rem;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border-radius: 4px;
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    white-space: nowrap;
}

.demo-spotlight-title {
    flex: 1;
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--demo-on-accent);
    line-height: 1.2;
}

.demo-spotlight-skip-btn {
    padding: 0.28rem 0.6rem;
    background: rgba(255, 255, 255, 0.35);
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    color: var(--demo-on-accent);
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.demo-spotlight-skip-btn:hover,
.demo-spotlight-skip-btn:focus {
    background: var(--on-brand);
    color: var(--demo-on-accent);
    border-color: var(--demo-accent-strong);
    outline: none;
}

.demo-spotlight-body {
    padding: 0.85rem 0.95rem 0.95rem;
}

.demo-spotlight-copy {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--charcoal, #1E2030);
}

.demo-spotlight-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-top: 0.95rem;
}

.demo-spotlight-progress {
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.7rem;
    color: var(--slate, #3D4355);
}

.demo-spotlight-button-group {
    display: flex;
    gap: 0.4rem;
}

.demo-spotlight-btn {
    padding: 0.5rem 0.95rem;
    background: var(--demo-accent);
    color: var(--demo-on-accent);
    border: none;
    border-radius: 8px;
    font-family: 'Montserrat', system-ui, sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.45);
    transition: filter 120ms ease, transform 80ms ease, box-shadow 120ms ease;
}

.demo-spotlight-btn:hover,
.demo-spotlight-btn:focus {
    filter: brightness(1.05);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.55);
    outline: none;
}

.demo-spotlight-btn:active {
    transform: translateY(1px);
}

.demo-spotlight-btn.secondary {
    background: transparent;
    color: var(--charcoal, #1E2030);
    border: 1px solid var(--border-medium, rgba(0, 0, 0, 0.18));
    box-shadow: none;
}

.demo-spotlight-btn.secondary:hover,
.demo-spotlight-btn.secondary:focus {
    background: var(--demo-accent-soft);
    border-color: var(--demo-accent);
    box-shadow: none;
}

/* On phone, the callout takes nearly the full width and sits in the
 * lower half so the cutout (when on a rail/tab) stays visible. */
@media (max-width: 600px) {
    .demo-spotlight-callout {
        width: calc(100vw - 1.5rem);
        max-width: none;
    }
}
