/*
 * Jade QR PIN Unlock (jadefw.blockstream.com/pinqr), dark rebrand:
 * index.html (landing) and qrpin.html (built from shell_minimal.html).
 * Source: Figma "QR PIN Unlock" section + designer handoff.
 *
 * qrpin.html is a single layout; which parts are visible is driven by
 * <body data-state="..."> (setState() in js/jadeqr.js). Every element that
 * belongs to a screen carries data-for="state1 state2 ...".
 */

/* ---- Fonts (self-hosted, latin subset; SIL OFL, see fonts/*-OFL.txt) ----- */
/* Manrope is a variable font: one file covers weights 400 and 500 */
@font-face {
    font-family: Manrope;
    font-style: normal;
    font-weight: 400 500;
    font-display: swap;
    src: url("../fonts/manrope-latin.woff2") format("woff2");
}

@font-face {
    font-family: "JetBrains Mono";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/jetbrains-mono-latin-400.woff2") format("woff2");
}

/* ---- Tokens (Blockstream Design System, Color = Dark) ------------------ */
:root {
    --color-bg-canvas: #121e29;
    --color-text-primary: #fff;
    --color-text-secondary: #c5d0dd;
    --color-action-primary: #0066cd;
    --color-action-primary-text: #fff;
    --color-bg-glass: rgba(255, 255, 255, 0.08);
    --color-border-default: #3e4246;
    --color-border-strong: #747b82;
    --color-border-outline: #fff;
    --color-card-border: rgba(70, 109, 134, 0.6);
    --color-scrim: rgba(8, 20, 31, 0.8);

    --font-family-content: Manrope, system-ui, sans-serif;
    --font-family-ui: "JetBrains Mono", ui-monospace, monospace;

    --size-h1: 56px;
    --size-h2: 32px;
    --size-h4: 20px;
    --size-p1: 22px;
    --size-p2: 18px;
    --size-p3: 16px;
    --size-p4: 14px;
    --size-ui1: 16px;

    --button-padding-x: 40px;
    --button-padding-y: 17px;
}

@media (max-width: 1180px) {
    :root {
        --size-h1: 44px;
        --size-p1: 20px;
    }
}

@media (max-width: 900px) {
    :root {
        --size-h1: 32px;
        --size-h2: 26px;
        --size-p1: 18px;
        --size-p2: 16px;
    }
}

/* ---- Base --------------------------------------------------------------- */
* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background: var(--color-bg-canvas);
    color: var(--color-text-primary);
    font-family: var(--font-family-content);
    -webkit-font-smoothing: antialiased;
}

[hidden],
.hidden {
    display: none !important;
}

main {
    min-height: 100vh;
    overflow-x: clip;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 80px 24px;
}

.layout {
    width: 100%;
    max-width: 1280px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 40px;
}

.copy {
    flex: 0 1 600px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.logo {
    align-self: flex-start;
}

.logo img {
    display: block;
    width: 200px;
    height: auto;
}

.logo:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 4px;
}

h1 {
    margin: 0;
    font-weight: 500;
    font-size: var(--size-h1);
    line-height: 1.4;
    letter-spacing: -0.01em;
}

h1 em {
    font-style: normal;
    color: var(--color-action-primary);
}

.sub {
    margin: 0;
    font-size: var(--size-p1);
    line-height: 1.55;
    color: var(--color-text-secondary);
}

/* Phosphor Light icons, inline SVG (fill: currentColor) */
.ico {
    flex: 0 0 auto;
    display: block;
    width: 20px;
    height: 20px;
}

/* ---- Back link (above the H1) ------------------------------------------- */
.controls {
    align-items: center;
}

.back {
    all: unset;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-size: 16px;
    line-height: 1.4;
    color: var(--color-text-primary);
}

.back .ico {
    width: 16px;
    height: 16px;
}

.back:hover {
    text-decoration: underline;
}

.back:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 4px;
}

/* ---- Landing points ----------------------------------------------------- */
.points {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.points li {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    font-size: var(--size-p2);
    line-height: 1.55;
    color: var(--color-text-secondary);
}

.points .ico {
    flex: 0 0 24px;
    width: 24px;
    height: 24px;
    margin-top: 2px;
    color: var(--color-action-primary);
}

/* ---- Actions row (Figma "CTA") ------------------------------------------ */
.actions {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding-top: 16px;
}

.actions:not([data-for]) {
    display: flex;
}

.row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.btn {
    appearance: none;
    border: 0;
    border-radius: 0;
    min-height: 56px;
    padding: var(--button-padding-y) var(--button-padding-x);
    font: 400 var(--size-ui1) / 1.4 var(--font-family-ui);
    color: var(--color-action-primary-text);
    background: var(--color-action-primary);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    transition: filter 0.15s ease, opacity 0.15s ease;
}

.btn:hover {
    filter: brightness(1.12);
}

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

.btn.outline {
    background: var(--color-bg-glass);
    box-shadow: inset 0 0 0 1px var(--color-border-outline);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}

.btn[disabled] {
    opacity: 0.4;
    cursor: not-allowed;
    filter: none;
}

/* Help line under the QR screens' button row */
.help {
    margin: 0;
    font-size: var(--size-p3);
    line-height: 1.55;
    color: var(--color-text-secondary);
}

.help .ico {
    display: inline-block;
    vertical-align: -4px;
    margin: 0 2px;
    color: var(--color-text-primary);
}

.link {
    font-weight: 500;
    font-size: 16px;
    line-height: 1.4;
    color: var(--color-text-primary);
    text-decoration: none;
}

.link:hover {
    text-decoration: underline;
}

.link:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 4px;
}

/* ---- Art column ---------------------------------------------------------- */
.art {
    position: relative;
    flex: 0 1 640px;
    min-width: 0;
    aspect-ratio: 640 / 600;
}

.slot {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* animated state art: <object> so the SVG's own script runs */
.slot object,
.slot object > img {
    display: block;
    width: 100%;
    height: 100%;
}

/* Landing art: Jade Plus render (467.9 x 330.5) centred on the rings
   (40px right of the art-box centre), rings at 10% */
.slot .rings {
    position: absolute;
    left: 56.25%;
    top: 50%;
    width: 118.25%;
    transform: translate(-50%, -50%);
    opacity: 0.1;
    pointer-events: none;
    user-select: none;
}

.slot .render {
    position: absolute;
    left: 56.25%;
    top: 50%;
    width: 73.11%;
    transform: translate(-50%, -50%);
}

/* ---- Screen switching (qrpin.html) -------------------------------------- */
.state {
    display: flex;
    flex-direction: column;
    gap: 24px;
    animation: state-in 0.28s ease both;
}

[data-for] {
    display: none;
}

body[data-state="start"] [data-for~="start"],
body[data-state="stepOne"] [data-for~="stepOne"],
body[data-state="stepTwo"] [data-for~="stepTwo"],
body[data-state="stepThree"] [data-for~="stepThree"],
body[data-state="stepFour"] [data-for~="stepFour"],
body[data-state="final"] [data-for~="final"],
body[data-state="error"] [data-for~="error"] {
    display: flex;
}

@keyframes state-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* ---- Camera module (Scan QR on Jade) ------------------------------------ */
.cam {
    width: 75%;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* 4:3 feed; the <video> covers the placeholder once the camera plays */
.feed {
    position: relative;
    aspect-ratio: 4 / 3;
    background: var(--color-bg-canvas);
    border: 1px solid var(--color-border-default);
    overflow: hidden;
}

.feed .ph {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: var(--size-p4);
    line-height: 1.55;
    color: var(--color-text-secondary);
}

.feed .ph .ico {
    width: 40px;
    height: 40px;
}

.feed video {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* qr-scanner's overlay (.scan-region-highlight, positioned by the library
   over the real scan region): drawn as four 2px corners in the accent
   colour instead of the library's own rounded yellow frame */
.feed .scan-region-highlight {
    z-index: 1;
    --corner: 16.667%;
    --c: linear-gradient(var(--color-action-primary), var(--color-action-primary));
    background:
        var(--c) left top / var(--corner) 2px no-repeat,
        var(--c) left top / 2px var(--corner) no-repeat,
        var(--c) right top / var(--corner) 2px no-repeat,
        var(--c) right top / 2px var(--corner) no-repeat,
        var(--c) left bottom / var(--corner) 2px no-repeat,
        var(--c) left bottom / 2px var(--corner) no-repeat,
        var(--c) right bottom / var(--corner) 2px no-repeat,
        var(--c) right bottom / 2px var(--corner) no-repeat;
}

.feed .scan-region-highlight-svg {
    display: none;
}

.feed .code-outline-highlight {
    stroke: var(--color-action-primary) !important;
    stroke-width: 3px !important;
}

/* Scanning progress: label row (ui/UI1), 10 above a 4px track */
.prog {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.prog .lbl {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font: 400 var(--size-ui1) / 1.4 var(--font-family-ui);
    color: var(--color-text-secondary);
}

#progressbar {
    appearance: none;
    -webkit-appearance: none;
    display: block;
    width: 100%;
    height: 4px;
    margin: 0;
    border: 0;
    background: var(--color-border-default);
    color: var(--color-action-primary);
}

#progressbar::-webkit-progress-bar {
    background: var(--color-border-default);
}

#progressbar::-webkit-progress-value {
    background: var(--color-action-primary);
}

#progressbar::-moz-progress-bar {
    background: var(--color-action-primary);
}

/* "Change camera selection" (body/label) */
.camsel {
    all: unset;
    cursor: pointer;
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-size: 16px;
    line-height: 1.4;
    color: var(--color-text-primary);
}

.camsel .caret {
    width: 16px;
    height: 16px;
}

.camsel:hover {
    text-decoration: underline;
}

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

/* ---- QR tile (Scan QR with Jade): 400 x 400, 24 quiet zone -------------- */
#qrcode {
    width: 62.5%;
    aspect-ratio: 1;
    padding: 24px;
    background: #fff;
    justify-content: center;
    align-items: center;
}

#qrcode > canvas,
#qrcode > img {
    width: 100%;
    height: 100%;
}

/* ---- Modals --------------------------------------------------------------- */
.backdrop {
    position: fixed;
    inset: 0;
    background: var(--color-scrim);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 5;
}

.modal {
    width: 640px;
    max-width: 100%;
    max-height: 100%;
    overflow-y: auto;
    background: var(--color-bg-canvas);
    border: 1px solid var(--color-card-border);
    padding: 48px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.modal h2 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    font-weight: 500;
    font-size: var(--size-h2);
    line-height: 1.4;
    letter-spacing: -0.01em;
}

.modal h2 .ico {
    width: 32px;
    height: 32px;
}

.modal p {
    margin: 0;
    font-size: var(--size-p3);
    line-height: 1.55;
    color: var(--color-text-secondary);
}

.modal .row {
    gap: 16px;
}

/* 2a Select Camera */
.modal-camera {
    width: 560px;
}

.cams {
    display: flex;
    flex-direction: column;
}

.camopt {
    all: unset;
    box-sizing: border-box;
    position: relative;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-bottom: 1px solid var(--color-border-default);
    font-weight: 500;
    font-size: var(--size-h4);
    line-height: 1.4;
    letter-spacing: -0.01em;
}

/* clicks always land on the row itself (setPreferredCamera reads
   e.target.dataset.optionId) */
.camopt > * {
    pointer-events: none;
}

.camopt:first-child {
    border-top: 1px solid var(--color-border-default);
}

.camopt:hover {
    background: rgba(255, 255, 255, 0.04);
}

.camopt[aria-checked="true"] {
    background: var(--color-bg-glass);
}

.camopt[aria-checked="true"]::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--color-action-primary);
}

.camopt:focus-visible {
    outline: 2px solid #fff;
    outline-offset: -2px;
}

.camopt .box {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    box-shadow: inset 0 0 0 1.5px var(--color-border-strong);
    display: grid;
    place-items: center;
}

.camopt[aria-checked="true"] .box {
    box-shadow: inset 0 0 0 1.5px var(--color-action-primary);
}

.camopt[aria-checked="true"] .box::after {
    content: "";
    width: 10px;
    height: 10px;
    background: var(--color-action-primary);
}

.camopt .name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ui/eyebrow; the design asks for JetBrains Mono 500, only 400 is hosted */
.camopt .tag {
    font: 400 16px / 1.4 var(--font-family-ui);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

.modal .info {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.modal .info .ico {
    flex: 0 0 20px;
    margin-top: 2px;
    color: var(--color-text-secondary);
}

/* 2b Enable Camera: 440 wide, everything centred */
.modal-perm {
    width: 440px;
    align-items: center;
    text-align: center;
}

.modal-perm .big {
    width: 40px;
    height: 40px;
    color: var(--color-text-primary);
}

.modal .x {
    all: unset;
    cursor: pointer;
    align-self: flex-end;
    width: 24px;
    height: 24px;
    display: grid;
    place-items: center;
    color: var(--color-text-primary);
}

.modal .x .ico {
    width: 24px;
    height: 24px;
}

.modal .x:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* 2c Custom Blind Oracle: checkbox rows */
.checks {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.check {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: var(--size-p3);
    line-height: 1.55;
    cursor: pointer;
    word-break: break-all;
}

.check + .check {
    border-top: 1px solid var(--color-border-default);
    padding-top: 16px;
}

.check input {
    appearance: none;
    -webkit-appearance: none;
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    margin: 0;
    border: 1.5px solid var(--color-border-strong);
    border-radius: 0;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.check input:checked {
    background: var(--color-action-primary);
    border-color: var(--color-action-primary);
}

.check input:checked::after {
    content: "";
    width: 10px;
    height: 6px;
    border: solid #fff;
    border-width: 0 0 2px 2px;
    transform: translate(0, -1px) rotate(-45deg);
}

.check input:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ---- Small screens: art stacks above the copy --------------------------- */
@media (max-width: 900px) {
    main {
        align-items: flex-start;
        padding: 40px 16px 120px;
    }

    .layout {
        flex-direction: column-reverse;
        gap: 24px;
    }

    .art {
        width: 100%;
        max-width: 480px;
        flex: 0 0 auto;
        margin: 0 auto;
    }

    /* camera module and QR tile span the column */
    body[data-state="stepOne"] .art,
    body[data-state="stepTwo"] .art,
    body[data-state="stepThree"] .art,
    body[data-state="stepFour"] .art {
        aspect-ratio: auto;
    }

    body[data-state="stepOne"] .slot,
    body[data-state="stepTwo"] .slot,
    body[data-state="stepThree"] .slot,
    body[data-state="stepFour"] .slot {
        position: static;
    }

    .cam,
    #qrcode {
        width: 100%;
    }

    .copy {
        width: 100%;
        flex: 0 0 auto;
    }

    .logo img {
        width: 160px;
    }

    .btn {
        width: 100%;
        justify-content: center;
        text-align: center;
        --button-padding-x: 16px;
    }

    .actions {
        align-items: stretch;
    }

    .row {
        width: 100%;
    }

    .modal {
        padding: 30px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .state {
        animation: none;
    }
}
