/* Guided tour stage (LAT-90, tour runtime V4) - overlay chrome.
 *
 * SHIPS DARK: no page links this stylesheet yet; the WP4 wiring commit
 * adds the hub include alongside tour-stage.js and flips the dark pin in
 * tests/test_tour_stage_units.py.
 *
 * Z-BAND: 9500. The stage is a single body-child OUTSIDE design.css
 * stacking contexts. Registry as of this file: design.css tops out at
 * 101 (toasts); the legacy tour widget mounts at 10000 during the
 * coexistence window and is mutually excluded via the server tour
 * block's stage field (red-team fix #1, enforced at WP4); WP8 deletes it.
 *
 * Every color/typography value reuses design.css brand tokens - this
 * file is loaded after design.css on the hub, never standalone.
 */

#lattice-tour-stage {
    /* Exported geometry: the JS callout clamp and the caption offset
       both read --stage-bar-h. Keep the bar's height changes HERE. */
    --stage-bar-h: 56px;
    --lts-curtain-ms: 450ms; /* keep in sync with TIMING.CURTAIN_BEAT_MS */

    position: fixed;
    inset: 0;
    z-index: 9500;
    font-family: var(--sans);
    color: var(--ink);
}

/* ── Backdrop: dim + blur the host hub underneath ─────────────────── */

#lattice-tour-stage .lts-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(45, 26, 16, 0.55); /* --ink at 55% */
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

/* ── Stage bar: brand · progress dots · Skip (visible in EVERY state) */

#lattice-tour-stage .lts-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--stage-bar-h) + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 16px 0 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
}

#lattice-tour-stage .lts-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
}

#lattice-tour-stage .lts-progress {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 0;
}

#lattice-tour-stage .lts-dots {
    display: flex;
    gap: 6px;
}

#lattice-tour-stage .lts-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: background 200ms var(--ease);
}

#lattice-tour-stage .lts-dot.is-done { background: var(--accent-deep); }
#lattice-tour-stage .lts-dot.is-current {
    background: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

#lattice-tour-stage .lts-progress-text {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
}

#lattice-tour-stage .lts-skip {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 6px 14px;
    font: inherit;
    font-size: 14px;
    color: var(--ink-soft);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

#lattice-tour-stage .lts-skip:hover {
    border-color: var(--border-strong);
    background: var(--surface-3);
}

/* ── Framed viewport: the stage's OWN scroller (iOS shim) ─────────── */

/* overflow:auto is load-bearing: WKWebView expands an iframe to its
   content height, so THIS wrapper scrolls, not the frame. That makes
   wrap scroll a spotlight reposition driver and puts wrap scroll
   offsets in the overlay geometry math (red-team fix #2). */
#lattice-tour-stage .lts-frame-wrap {
    position: absolute;
    top: calc(var(--stage-bar-h) + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    bottom: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--canvas);
}

/* NO transform on the frame, ever: the spotlight composes
   frameRect + elementRect with plain offsets and any scale silently
   breaks the math (red-team fix #2; device-qa asserts this at WP5). */
#lattice-tour-stage .lts-frame {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: var(--canvas);
}

/* ── Spotlight overlay: strips + ring + callout, parent-rendered ──── */

#lattice-tour-stage .lts-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none; /* visuals only; gating = iframe inert */
}

#lattice-tour-stage .lts-strip {
    position: absolute;
    background: rgba(45, 26, 16, 0.45);
}

/* Per-cue interactive:true - strips take the clicks so only the hole
   geometry passes through to the (then non-inert) frame. */
#lattice-tour-stage .lts-overlay.is-interactive .lts-strip {
    pointer-events: auto;
}

#lattice-tour-stage .lts-ring {
    position: absolute;
    border: 2px solid var(--accent);
    border-radius: 10px;
    box-shadow: 0 0 0 4px var(--accent-soft), 0 4px 18px rgba(0, 0, 0, 0.25);
    transition: left 240ms var(--ease), top 240ms var(--ease),
                width 240ms var(--ease), height 240ms var(--ease);
}

#lattice-tour-stage .lts-callout {
    position: absolute;
    max-width: 320px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    font-size: 14px;
    line-height: 1.45;
}

/* ── Curtain: between-stop beat + Begin/Resume, error, end cards ──── */

#lattice-tour-stage .lts-curtain {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--canvas);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--lts-curtain-ms) var(--ease),
                visibility 0s linear var(--lts-curtain-ms);
}

#lattice-tour-stage .lts-curtain.is-up {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--lts-curtain-ms) var(--ease);
}

#lattice-tour-stage .lts-curtain-card {
    max-width: 420px;
    margin: 16px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
    text-align: center;
}

#lattice-tour-stage .lts-curtain-card .lts-card-title {
    font-family: var(--serif);
    font-size: 20px;
    margin: 0 0 8px;
    color: var(--ink);
}

#lattice-tour-stage .lts-curtain-card .lts-card-body {
    font-size: 14px;
    color: var(--ink-soft);
    margin: 0 0 16px;
}

#lattice-tour-stage .lts-curtain-card button {
    min-height: 44px; /* tap target */
    padding: 10px 22px;
    margin: 4px;
    font: inherit;
    font-size: 15px;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--ink);
}

#lattice-tour-stage .lts-curtain-card button.lts-primary {
    background: var(--accent);
    border-color: var(--accent-deep);
    color: #fff;
}

#lattice-tour-stage .lts-curtain-card button.lts-primary:hover {
    background: var(--accent-deep);
}

/* ── Post-tour debrief: the in-stage Q&A panel (END_CARD, WP7) ─────────
 * The end card becomes a chat panel: the briefed tutor opens, the learner
 * asks about the walkthrough, "Start learning" finishes to the hub. Wider
 * + left-aligned + a scrolling message log, unlike the centered cards. */

#lattice-tour-stage .lts-curtain-card.lts-debrief {
    max-width: 560px;
    width: calc(100vw - 32px);
    text-align: left;
    display: flex;
    flex-direction: column;
    max-height: min(80vh, 640px);
    padding: 20px;
}

#lattice-tour-stage .lts-debrief .lts-card-title {
    text-align: left;
    margin: 0 0 12px;
}

#lattice-tour-stage .lts-debrief-log {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 120px;
    padding-right: 4px;
    margin-bottom: 14px;
}

#lattice-tour-stage .lts-msg {
    max-width: 85%;
    padding: 9px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#lattice-tour-stage .lts-msg.is-tutor {
    align-self: flex-start;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--ink);
    border-bottom-left-radius: 4px;
}

#lattice-tour-stage .lts-msg.is-user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

#lattice-tour-stage .lts-msg.is-pending {
    color: var(--muted);
    font-style: italic;
}

/* Surface links the tutor drops into a debrief reply ("hop into Speak"). */
#lattice-tour-stage .lts-msg .lts-debrief-link {
    color: var(--accent-deep);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

#lattice-tour-stage .lts-msg.is-user .lts-debrief-link {
    color: #fff;
}

#lattice-tour-stage .lts-debrief-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

#lattice-tour-stage .lts-debrief-text {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 44px;
    padding: 10px 14px;
    font: inherit;
    font-size: 15px;
    color: var(--ink);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-sizing: border-box;
}

#lattice-tour-stage .lts-debrief-text:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

#lattice-tour-stage .lts-curtain-card.lts-debrief button.lts-debrief-send {
    flex: 0 0 auto;
    margin: 0;
    padding: 10px 18px;
}

#lattice-tour-stage .lts-curtain-card.lts-debrief button.lts-debrief-send:disabled {
    opacity: 0.5;
    cursor: default;
}

#lattice-tour-stage .lts-curtain-card.lts-debrief button.lts-debrief-done {
    align-self: center;
    margin: 0;
}

/* ── Caption card: bottom, above the home indicator; resume target ── */

#lattice-tour-stage .lts-caption {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
    max-width: min(560px, calc(100vw - 32px));
    padding: 12px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
    font-size: 15px;
    line-height: 1.5;
    text-align: center;
    /* Doubles as the tap-to-resume target after visibility pause. */
    cursor: default;
}

#lattice-tour-stage .lts-caption.is-resume-gate {
    cursor: pointer;
    border-color: var(--accent);
}

#lattice-tour-stage .lts-caption:empty { display: none; }

/* The one audio element renders no UI. */
#lattice-tour-stage audio { display: none; }

/* ── Small screens ────────────────────────────────────────────────── */

@media (max-width: 640px) {
    #lattice-tour-stage { --stage-bar-h: 48px; }
    #lattice-tour-stage .lts-progress-text { display: none; }
    #lattice-tour-stage .lts-callout { max-width: calc(100vw - 48px); }
}

/* ── Reduced motion ───────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    #lattice-tour-stage .lts-curtain,
    #lattice-tour-stage .lts-ring,
    #lattice-tour-stage .lts-dot {
        transition: none;
    }
}
