/* ==========================================================================
   Virtual Glasses Try-On — button + modal styles for the Zid product page.
   Namespaced under .tryon-* to avoid collisions with theme CSS.
   ========================================================================== */

/* --- Trigger button on the product page -------------------------------- */
.btn-try-on {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 10px;
    padding: 12px 18px;
    border: 1px solid var(--primary-color);
    border-radius: 6px;
    --btn-drift: var(--primary-color);
    background-color: transparent;
    color: var(--primary-color);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
    cursor: pointer;
    transition: background-position .9s cubic-bezier(.22, 1, .36, 1), color .4s ease, opacity .2s ease;
}

/* The fill itself is the theme's button drift (custom.css). */
.btn-try-on:hover,
.btn-try-on:focus-visible {
    color: var(--text-color-primary-bg, #fff);
}

.btn-try-on:disabled {
    opacity: .55;
    cursor: not-allowed;
}

.btn-try-on .tryon-icon {
    flex: 0 0 auto;
    display: block;
    width: 20px;
    height: 20px;
}

/* --- Modal shell ---------------------------------------------------------
   Two looks (theme editor: tryon_style). Every colour is a token on the root,
   so the dark look and merchant overrides are one block each. */
.tryon-root[hidden] {
    /* Beats the display:flex below; the [hidden] attribute alone loses to it. */
    display: none !important;
}

body.tryon-open {
    overflow: hidden;
}

.tryon-root {
    --tryon-accent: #FFC20E;
    --tryon-accent-soft: #FFF6DA;
    --tryon-bg: #FBF8F1;
    --tryon-surface: #fff;
    --tryon-surface-2: #f4f4f2;
    --tryon-ink: #111;
    --tryon-muted: #6b6b6b;
    --tryon-line: #e6e6e6;
    --tryon-cta-bg: #111;
    --tryon-cta-text: #fff;
    --tryon-cta-bub: var(--tryon-accent);
    --tryon-cta-bub-ink: #111;
    --tryon-alt-bg: #fff;
    --tryon-alt-hover: var(--tryon-accent-soft);
    --tryon-radius: 14px;
    position: fixed;
    inset: 0;
    z-index: 99990;
    display: flex;
    align-items: stretch;
    justify-content: center;
    background: rgba(0, 0, 0, .72);
}

.tryon-root--dark {
    --tryon-bg: #0d0d0d;
    --tryon-surface: #161616;
    --tryon-surface-2: #242424;
    --tryon-ink: #f3f3f3;
    --tryon-muted: #a3a3a3;
    --tryon-line: #2c2c2c;
    --tryon-cta-bg: var(--tryon-accent);
    --tryon-cta-text: #111;
    --tryon-cta-bub: #111;
    --tryon-cta-bub-ink: var(--tryon-accent);
    --tryon-alt-bg: transparent;
    --tryon-alt-hover: rgba(255, 194, 14, .08);
}

.tryon-panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: var(--tryon-bg);
    color: var(--tryon-ink);
    outline: none;
    overflow: hidden;
}

/* Phones: full screen. Anything wider: one fixed-size dialog in the centre,
   the same fit on a tablet and a large monitor. */
@media (min-width: 480px) {
    .tryon-root {
        align-items: center;
        padding: 24px;
    }

    .tryon-panel {
        width: var(--tryon-dialog-w, 420px);
        height: min(92vh, var(--tryon-dialog-h, 780px));
        border-radius: 20px;
        box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
    }
}

/* Icons: line drawings from the lens panel set. */
.tryon-ic {
    display: inline-flex;
    flex: none;
    width: 20px;
    height: 20px;
}

.tryon-ic svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* --- Header ---------------------------------------------------------------- */
.tryon-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top));
    background: var(--tryon-surface);
    border-bottom: 1px solid var(--tryon-line);
}

.tryon-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: var(--tryon-ink);
}

.tryon-close {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--tryon-surface-2);
    color: var(--tryon-ink);
    cursor: pointer;
    transition: background-color .18s ease, color .18s ease;
}

.tryon-close .tryon-ic {
    width: 18px;
    height: 18px;
}

/* --- Stage (video + glasses overlay) ------------------------------------- */
.tryon-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    margin: 12px 12px 0;
    border-radius: 18px;
    background: #000;
    overflow: hidden;
}

.tryon-stage video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    /* Mirror the front camera for a natural selfie view. */
    transform: scaleX(-1);
}

/* Glasses overlay. One canvas covering the stage: the frame front is a bitmap
   but the temple arms are drawn per frame toward the tracked ears, so this
   cannot be a CSS-transformed <img>. z-index 1 keeps it above the video and
   below the face guide (2), the status and photo button (3/4) and the
   error/capture layers (5/6). */
.tryon-glasses-layer,
.tryon-lens-layer {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

/* Face guideline shown while no face is locked. */
.tryon-face-guide {
    position: absolute;
    top: 46%;
    left: 50%;
    width: 58%;
    height: 62%;
    border: 2px dashed rgba(255, 255, 255, .7);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 2;
}

.tryon-face-guide.is-hidden {
    display: none;
}

/* Status / tip over the bottom of the camera. */
.tryon-status {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0;
    padding: 9px 12px;
    border-radius: 12px;
    background: rgba(0, 0, 0, .58);
    color: #fff;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
    backdrop-filter: blur(3px);
}

.tryon-status.is-hidden {
    display: none;
}

.tryon-status .tryon-spinner {
    flex: none;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: var(--tryon-accent);
    border-radius: 50%;
    animation: tryon-spin .8s linear infinite;
}

@keyframes tryon-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Save-a-photo icon on the camera. Hidden while the tip is showing, which is
   exactly when it is disabled (no face). */
.tryon-shot {
    position: absolute;
    bottom: 12px;
    inset-inline-end: 12px;
    z-index: 4;
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .92);
    color: #111;
    cursor: pointer;
    transition: background-color .18s ease, transform .18s ease, opacity .18s ease;
}

.tryon-shot[disabled] {
    opacity: 0;
    pointer-events: none;
}

/* --- Footer: product card + buy buttons ----------------------------------- */
.tryon-footer {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.tryon-product {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--tryon-line);
    border-radius: var(--tryon-radius);
    background: var(--tryon-surface);
}

.tryon-product-thumb {
    display: grid;
    place-items: center;
    flex: none;
    width: 46px;
    height: 34px;
    border-radius: 8px;
    background: var(--tryon-surface-2);
    color: var(--tryon-ink);
}

.tryon-product-info {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.tryon-product-name {
    overflow: hidden;
    font-size: 14px;
    color: var(--tryon-ink);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tryon-price {
    flex: none;
    font-size: 15px;
    font-weight: 800;
    color: var(--tryon-ink);
}

.tryon-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tryon-swatches[hidden] {
    display: none;
}

.tryon-swatch {
    width: 20px;
    height: 20px;
    padding: 0;
    border: 2px solid var(--tryon-surface);
    border-radius: 50%;
    background: var(--tryon-swatch, #ccc);
    box-shadow: 0 0 0 1px var(--tryon-line);
    cursor: pointer;
    transition: box-shadow .18s ease;
}

.tryon-swatch.is-active {
    box-shadow: 0 0 0 2px var(--tryon-ink);
}

/* Lens colour with no known colour (a brand name): its name as a chip. */
.tryon-swatch--text {
    width: auto;
    height: 24px;
    padding-inline: 10px;
    border-radius: 12px;
    background: var(--tryon-surface);
    color: var(--tryon-ink);
    font-size: 12px;
    line-height: 20px;
    white-space: nowrap;
}

.tryon-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tryon-cta,
.tryon-alt {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 56px;
    padding: 9px 12px;
    border-radius: var(--tryon-radius);
    font-family: inherit;
    text-align: start;
    cursor: pointer;
    transition: background-position .9s cubic-bezier(.22, 1, .36, 1), border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

.tryon-cta {
    --btn-drift: var(--tryon-cta-bg);
    border: 2px solid var(--tryon-cta-bg);
    background-color: var(--tryon-cta-bg);
    color: var(--tryon-cta-text);
}

/* Drifts from its own surface to the soft accent, not to a dark fill. */
.tryon-alt {
    --btn-drift: var(--tryon-alt-hover);
    --btn-drift-from: var(--tryon-alt-bg);
    --btn-drift-tone: var(--btn-drift);
    --btn-drift-stop: 62%;
    border: 1.5px solid var(--tryon-line);
    background-color: var(--tryon-alt-bg);
    color: var(--tryon-ink);
}

.tryon-action-bub {
    display: grid;
    place-items: center;
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    transition: background-color .18s ease, color .18s ease, transform .18s ease;
}

.tryon-cta .tryon-action-bub {
    background: var(--tryon-cta-bub);
    color: var(--tryon-cta-bub-ink);
}

.tryon-alt .tryon-action-bub {
    background: var(--tryon-surface-2);
    color: var(--tryon-ink);
}

.tryon-action-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
    line-height: 1.35;
}

.tryon-action-text b {
    font-size: 15px;
}

.tryon-action-text small {
    font-size: 12px;
    opacity: .75;
}

.tryon-action-go {
    transition: transform .18s ease;
}

/* The arrow drawing points left: flip it to point forward in LTR. */
html:not([dir="rtl"]) .tryon-action-go {
    transform: scaleX(-1);
}

.tryon-cta[disabled],
.tryon-alt[disabled] {
    opacity: .4;
    cursor: not-allowed;
}

.tryon-cta:focus-visible,
.tryon-alt:focus-visible,
.tryon-close:focus-visible,
.tryon-shot:focus-visible,
.tryon-swatch:focus-visible {
    outline: 3px solid var(--tryon-accent);
    outline-offset: 2px;
}

@media (hover: hover) {
    .tryon-cta:not([disabled]):hover {
        box-shadow: 0 8px 18px rgba(0, 0, 0, .22);
        transform: translateY(-1px);
    }

    .tryon-cta:not([disabled]):hover .tryon-action-bub {
        transform: rotate(-12deg);
    }

    .tryon-cta:not([disabled]):hover .tryon-action-go {
        transform: translateX(-4px);
    }

    html:not([dir="rtl"]) .tryon-cta:not([disabled]):hover .tryon-action-go {
        transform: scaleX(-1) translateX(-4px);
    }

    .tryon-alt:not([disabled]):hover {
        border-color: var(--tryon-accent);
    }

    .tryon-alt:not([disabled]):hover .tryon-action-bub,
    .tryon-close:hover,
    .tryon-shot:hover {
        background: var(--tryon-accent);
        color: #111;
    }

    .tryon-shot:hover {
        transform: scale(1.06);
    }

    .tryon-swatch:hover {
        box-shadow: 0 0 0 2px var(--tryon-accent);
    }
}

.tryon-privacy {
    margin: 0;
    color: var(--tryon-muted);
    font-size: 12px;
    text-align: center;
}

/* Error card and photo preview buttons. */
.tryon-btn {
    min-height: 44px;
    padding: 10px 22px;
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 10px;
    --btn-drift: rgba(255, 255, 255, .14);
    --btn-drift-from: transparent;
    --btn-drift-tone: var(--btn-drift);
    --btn-drift-stop: 62%;
    background-color: transparent;
    color: #fff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background-position .9s cubic-bezier(.22, 1, .36, 1), color .18s ease;
}

.tryon-btn--primary {
    --btn-drift: var(--tryon-accent);
    --btn-drift-from: var(--btn-drift);
    --btn-drift-tone: color-mix(in srgb, var(--btn-drift) 72%, #fff);
    --btn-drift-stop: 70%;
    border-color: var(--tryon-accent);
    background-color: var(--tryon-accent);
    color: #111;
}

.tryon-btn:focus-visible {
    outline: 3px solid var(--tryon-accent);
    outline-offset: 2px;
}

.tryon-btn[disabled] {
    opacity: .55;
    cursor: not-allowed;
}

/* --- Error card ------------------------------------------------------------- */
.tryon-error {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 24px;
    background: rgba(0, 0, 0, .9);
    text-align: center;
}

.tryon-error.is-hidden {
    display: none;
}

.tryon-error-title {
    margin: 0;
    font-size: 17px;
    font-weight: 700;
    color: #fff;
}

.tryon-error p {
    max-width: 420px;
    margin: 0;
    color: rgba(255, 255, 255, .85);
    font-size: 14px;
    line-height: 1.6;
}

.tryon-error-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 6px;
}

/* --- Capture preview -------------------------------------------------------- */
.tryon-capture {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    background: #000;
}

.tryon-capture.is-hidden {
    display: none;
}

.tryon-capture-holder {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tryon-capture img,
.tryon-capture canvas {
    max-width: 100%;
    max-height: 100%;
}

.tryon-capture .tryon-privacy {
    color: rgba(255, 255, 255, .7);
}

.tryon-capture-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 12px 14px;
}

/* --- Accessibility / motion ------------------------------------------------- */
.tryon-controls[hidden] {
    display: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .tryon-status .tryon-spinner {
        animation-duration: 2s;
    }

    .tryon-root,
    .tryon-panel {
        animation: none !important;
    }

    .tryon-cta,
    .tryon-alt,
    .tryon-action-bub,
    .tryon-action-go,
    .tryon-shot {
        transition: none;
    }

    .tryon-cta:not([disabled]):hover,
    .tryon-cta:not([disabled]):hover .tryon-action-bub,
    .tryon-shot:hover {
        transform: none;
    }
}

/* RTL: nothing direction-specific is required because layout is flex-based,
   but keep mirrors/symmetric paddings explicit for safety. */
.rtl .tryon-stage video {
    transform: scaleX(-1);
}

/* --- Diagnostics chip (only when ?tryon=debug / VITRIN_TRYON.debug) ------- */
.tryon-debug {
    position: fixed;
    left: 12px;
    bottom: 12px;
    z-index: 100010;
    max-width: 280px;
    background: rgba(10, 10, 10, .88);
    color: #e8e8e8;
    border: 1px solid rgba(255, 255, 255, .25);
    border-radius: 8px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    line-height: 1.5;
    overflow: hidden;
    pointer-events: auto;
}

.tryon-debug-header {
    padding: 4px 10px;
    background: rgba(255, 255, 255, .12);
    font-weight: 700;
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
}

.tryon-debug-body {
    padding: 6px 10px 8px;
    max-height: 40vh;
    overflow: auto;
}

.tryon-debug-row {
    display: flex;
    gap: 8px;
}

.tryon-debug-key {
    flex: 0 0 auto;
    color: #9fd0ff;
}

.tryon-debug-value {
    word-break: break-all;
}