/* Tutorial System */
.tutorial-trigger-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    background: transparent;
    color: var(--primary-text-color);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    margin-right: 8px;
    flex-shrink: 0;
}

.tutorial-trigger-btn:hover {
    background: var(--primary-color);
    color: var(--primary-contrast);
}

#calibration-modal .modal-body {
    position: relative;
}

.tutorial-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    pointer-events: none;
}

.tutorial-overlay.active {
    display: block;
    pointer-events: auto;
}

.tutorial-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    transition: clip-path 0.3s ease;
}

.tutorial-ring {
    position: absolute;
    border: 2px solid var(--primary-color);
    border-radius: 6px;
    pointer-events: none;
    transition: all 0.3s ease;
    animation: tutorial-pulse 2s infinite;
}

@keyframes tutorial-pulse {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary-color) 60%, transparent); }
    50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--primary-color) 0%, transparent); }
}

.tutorial-tooltip {
    position: absolute;
    width: 260px;
    background: var(--card-bg);
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--shadow-color);
    z-index: 102;
    pointer-events: auto;
    animation: tutorial-tooltip-in 0.25s ease-out;
}

@keyframes tutorial-tooltip-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.tutorial-tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
}

.tutorial-step-counter {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary-text-color);
}

.tutorial-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
    padding: 0;
    line-height: 1;
}

.tutorial-close-btn:hover {
    color: var(--text-color);
    background: rgba(128, 128, 128, 0.15);
}

.tutorial-tooltip-text {
    margin: 0;
    padding: 12px;
    line-height: 1.5;
    color: var(--text-color);
    font-size: 0.9rem;
}

.tutorial-tooltip-nav {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
}

.tutorial-prev-btn,
.tutorial-next-btn {
    flex: 1;
    padding: 6px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: opacity 0.2s;
}

.tutorial-prev-btn {
    background: var(--border-color);
    color: var(--text-color);
}

.tutorial-next-btn {
    background: var(--primary-color);
    color: var(--primary-contrast);
}

.tutorial-prev-btn:hover:not(:disabled),
.tutorial-next-btn:hover:not(:disabled) {
    opacity: 0.85;
}

.tutorial-prev-btn:disabled,
.tutorial-next-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.tutorial-target {
    position: relative;
    z-index: 101 !important;
}

/* Fixed (viewport-level) tutorial overlay for device cards */
.tutorial-overlay-fixed {
    position: fixed;
    z-index: var(--z-tutorial);
}

.tutorial-overlay-fixed .tutorial-backdrop {
    position: fixed;
}

.tutorial-overlay-fixed .tutorial-ring {
    position: fixed;
}

.tutorial-overlay-fixed .tutorial-tooltip {
    position: absolute;
    z-index: var(--z-tutorial-tooltip);
    animation: none;
    opacity: 1;
}

/* target z-index for fixed overlay is set inline via JS (target is outside overlay DOM) */


/* ──────────────────────────────────────────────────────────────────────
   v2 "Signal Bench" — opt-in via .tutorial-v2 on the overlay root.
   Keeps the legacy ring+tooltip CSS untouched so unmigrated tours keep
   working. Aligns with the lux/instrument language used elsewhere in
   the UI (hairlines, JetBrains Mono labels, --ch-signal accent).
   ────────────────────────────────────────────────────────────────────── */

/* Backdrop: dimmer page + a hint of grain so the cutout reads as an
   instrument viewfinder instead of a flat hole-punch. */
.tutorial-overlay.tutorial-v2 .tutorial-backdrop {
    background:
        repeating-linear-gradient(
            0deg,
            rgba(255, 255, 255, 0.018) 0px,
            rgba(255, 255, 255, 0.018) 1px,
            transparent 1px,
            transparent 3px
        ),
        radial-gradient(
            1400px 900px at 50% 35%,
            rgba(0, 0, 0, 0.78) 0%,
            rgba(0, 0, 0, 0.92) 100%
        );
    transition: clip-path 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

[data-theme="light"] .tutorial-overlay.tutorial-v2 .tutorial-backdrop {
    background:
        repeating-linear-gradient(
            0deg,
            rgba(0, 0, 0, 0.02) 0px,
            rgba(0, 0, 0, 0.02) 1px,
            transparent 1px,
            transparent 3px
        ),
        radial-gradient(
            1400px 900px at 50% 35%,
            rgba(20, 24, 30, 0.55) 0%,
            rgba(20, 24, 30, 0.72) 100%
        );
}

/* Ring becomes a hairline + signal-glow frame; the prominent visual is
   the 4 corner brackets layered on top. */
.tutorial-overlay.tutorial-v2 .tutorial-ring {
    border: 1px dashed color-mix(in srgb, var(--ch-signal) 38%, transparent);
    border-radius: 2px;
    animation: none;
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--ch-signal) 14%, transparent),
        0 0 22px color-mix(in srgb, var(--ch-signal) 28%, transparent),
        inset 0 0 0 1px color-mix(in srgb, var(--ch-signal) 6%, transparent);
    transition:
        left 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        top 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        width 0.28s cubic-bezier(0.22, 1, 0.36, 1),
        height 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.tutorial-overlay.tutorial-v2 .tutorial-reticle-corner {
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid var(--ch-signal);
    pointer-events: none;
    filter: drop-shadow(0 0 6px color-mix(in srgb, var(--ch-signal) 55%, transparent));
}
.tutorial-overlay.tutorial-v2 .tutorial-reticle-corner.tl {
    top: -2px; left: -2px;
    border-right: none; border-bottom: none;
}
.tutorial-overlay.tutorial-v2 .tutorial-reticle-corner.tr {
    top: -2px; right: -2px;
    border-left: none; border-bottom: none;
}
.tutorial-overlay.tutorial-v2 .tutorial-reticle-corner.bl {
    bottom: -2px; left: -2px;
    border-right: none; border-top: none;
}
.tutorial-overlay.tutorial-v2 .tutorial-reticle-corner.br {
    bottom: -2px; right: -2px;
    border-left: none; border-top: none;
}

/* Animate corner draw-in on each step change (ring already eases its
   bounds; this adds a snappy "lock" on top). */
.tutorial-overlay.tutorial-v2.step-changed .tutorial-reticle-corner {
    animation: tutorial-corner-lock 0.26s cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes tutorial-corner-lock {
    0%   { opacity: 0; transform: scale(2.4); }
    60%  { opacity: 1; transform: scale(0.85); }
    100% { opacity: 1; transform: scale(1); }
}

/* Patch cable — connects reticle to tooltip. Animated dash-offset reads
   as transmission flowing toward the tooltip. Absolute by default for
   modal-mode overlays; viewport-fixed for tour overlays via the
   .tutorial-overlay-fixed class. */
.tutorial-overlay.tutorial-v2 .tutorial-cable {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 101;
    overflow: visible;
}
.tutorial-overlay-fixed.tutorial-v2 .tutorial-cable {
    position: fixed;
}
.tutorial-overlay.tutorial-v2 .tutorial-cable line {
    stroke: var(--ch-signal);
    stroke-width: 1.25;
    stroke-dasharray: 4 5;
    stroke-linecap: round;
    fill: none;
    opacity: 0.7;
    filter: drop-shadow(0 0 4px color-mix(in srgb, var(--ch-signal) 50%, transparent));
    animation: tutorial-cable-flow 1.4s linear infinite;
    transition: all 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes tutorial-cable-flow {
    from { stroke-dashoffset: 0; }
    to   { stroke-dashoffset: -18; }
}

/* Tooltip — instrument readout: square corners, hairline border,
   inner ring, lux shadow. */
.tutorial-overlay.tutorial-v2 .tutorial-tooltip {
    width: 296px;
    background: var(--card-bg);
    border: 1px solid var(--lux-line-bold);
    border-radius: 2px;
    box-shadow:
        0 0 0 1px var(--lux-bg-2),
        var(--lux-shadow-rack, 0 8px 24px rgba(0, 0, 0, 0.5)),
        0 0 32px color-mix(in srgb, var(--ch-signal) 12%, transparent);
    animation: tutorial-tooltip-v2-in 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    overflow: hidden;
    position: relative;
}
.tutorial-overlay.tutorial-v2 .tutorial-tooltip::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--ch-signal) 20%,
        var(--ch-signal) 80%,
        transparent 100%
    );
    opacity: 0.85;
}
@keyframes tutorial-tooltip-v2-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tutorial-overlay.tutorial-v2 .tutorial-tooltip-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px 8px;
    border-bottom: 1px solid var(--lux-line);
}
.tutorial-overlay.tutorial-v2 .tutorial-tooltip-eyebrow {
    flex: 1;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.14em;
    color: var(--ch-signal);
    text-transform: uppercase;
}
.tutorial-overlay.tutorial-v2 .tutorial-step-counter {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.06em;
    color: var(--lux-ink-dim);
    font-variant-numeric: tabular-nums;
}
.tutorial-tooltip-breadcrumb {
    display: none;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--lux-ink-mute, var(--text-muted));
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tutorial-tooltip-breadcrumb.is-visible {
    display: inline-block;
}
.tutorial-tooltip-breadcrumb.is-visible + .tutorial-step-counter::before {
    content: '· ';
    color: var(--lux-ink-mute, var(--text-muted));
    margin-right: 4px;
}
.tutorial-overlay.tutorial-v2 .tutorial-close-btn {
    color: var(--lux-ink-mute);
    border-radius: 2px;
}
.tutorial-overlay.tutorial-v2 .tutorial-close-btn:hover {
    color: var(--lux-ink);
    background: var(--lux-bg-2);
}

/* Segmented progress pips — one slot per step. */
.tutorial-overlay.tutorial-v2 .tutorial-pips {
    display: flex;
    gap: 3px;
    padding: 10px 12px 4px;
}
.tutorial-overlay.tutorial-v2 .tutorial-pip {
    flex: 1;
    height: 3px;
    background: var(--lux-line);
    border-radius: 1px;
    transition: background 0.2s ease, box-shadow 0.2s ease;
}
.tutorial-overlay.tutorial-v2 .tutorial-pip.done {
    background: color-mix(in srgb, var(--ch-signal) 60%, var(--lux-line));
}
.tutorial-overlay.tutorial-v2 .tutorial-pip.active {
    background: var(--ch-signal);
    box-shadow: 0 0 8px color-mix(in srgb, var(--ch-signal) 60%, transparent);
}

.tutorial-overlay.tutorial-v2 .tutorial-tooltip-text {
    margin: 0;
    padding: 8px 14px 14px;
    line-height: 1.55;
    color: var(--lux-ink);
    font-size: 13.5px;
    font-weight: 400;
    letter-spacing: 0.005em;
}

.tutorial-overlay.tutorial-v2 .tutorial-tooltip-nav {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--lux-line);
}
.tutorial-overlay.tutorial-v2 .tutorial-prev-btn,
.tutorial-overlay.tutorial-v2 .tutorial-next-btn {
    flex: 1;
    padding: 7px 10px;
    border: 1px solid var(--lux-line-bold);
    border-radius: 2px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.tutorial-overlay.tutorial-v2 .tutorial-prev-btn {
    background: transparent;
    color: var(--lux-ink-dim);
}
.tutorial-overlay.tutorial-v2 .tutorial-prev-btn:hover:not(:disabled) {
    color: var(--lux-ink);
    border-color: var(--lux-ink-mute);
    background: var(--lux-bg-2);
}
.tutorial-overlay.tutorial-v2 .tutorial-next-btn {
    background: var(--ch-signal);
    color: var(--primary-contrast, #000);
    border-color: var(--ch-signal);
}
.tutorial-overlay.tutorial-v2 .tutorial-next-btn:hover:not(:disabled) {
    box-shadow: 0 0 16px color-mix(in srgb, var(--ch-signal) 50%, transparent);
    filter: brightness(1.06);
}
.tutorial-overlay.tutorial-v2 .tutorial-prev-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Keyboard hint chip — surfaces existing arrow/Esc bindings. */
.tutorial-overlay.tutorial-v2 .tutorial-keyhint {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px 10px;
    border-top: 1px solid var(--lux-line);
    background: var(--lux-bg-1);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 9.5px;
    font-weight: 500;
    letter-spacing: 0.1em;
    color: var(--lux-ink-mute);
    text-transform: uppercase;
}
.tutorial-overlay.tutorial-v2 .tutorial-keyhint kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    background: var(--lux-bg-3);
    border: 1px solid var(--lux-line-bold);
    border-radius: 2px;
    font: inherit;
    font-size: 10px;
    color: var(--lux-ink-dim);
}
.tutorial-overlay.tutorial-v2 .tutorial-keyhint span {
    margin-right: 6px;
}
.tutorial-overlay.tutorial-v2 .tutorial-keyhint span:last-child {
    margin-right: 0;
}

/* Mobile — collapse cable, dock tooltip to bottom of viewport. */
@media (max-width: 640px) {
    .tutorial-overlay.tutorial-v2 .tutorial-cable { display: none; }
    .tutorial-overlay.tutorial-v2 .tutorial-tooltip {
        width: calc(100vw - 24px);
        max-width: 360px;
    }
    .tutorial-overlay.tutorial-v2 .tutorial-keyhint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .tutorial-overlay.tutorial-v2 .tutorial-cable line { animation: none; }
    .tutorial-overlay.tutorial-v2 .tutorial-tooltip { animation: none; }
    .tutorial-overlay.tutorial-v2.step-changed .tutorial-reticle-corner { animation: none; }
    .tutorial-overlay.tutorial-v2 .tutorial-ring { transition: none; }
}
