/* ============================================================
   Aperture — QR Scanner
   A precision optical-instrument console.
   Signature: a live finder-pattern lock-on driven by real
   jsQR corner coordinates.
   ============================================================ */

:root {
    --bg:        #0B0D12;   /* page, deep ink                       */
    --stage:     #06070A;   /* scanner viewport surround (darkest)  */
    --panel:     #14171F;   /* raised panels                        */
    --panel-2:   #1B1F2A;   /* inset wells                          */
    --line:      rgba(255, 255, 255, 0.09);
    --line-strong: rgba(255, 255, 255, 0.16);
    --text:      #ECEEF3;
    --muted:     #878D9C;
    --signal:    #5B8CFF;   /* scanning — electric beam blue        */
    --signal-soft: rgba(91, 140, 255, 0.16);
    --lock:      #45E3B0;   /* locked — confirmed mint              */
    --lock-soft: rgba(69, 227, 176, 0.16);

    --r-lg: 22px;
    --r-md: 13px;
    --r-sm: 9px;

    --display: "Space Grotesk", system-ui, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", monospace;
    --ui: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    background:
        radial-gradient(120% 80% at 50% -10%, #161a24 0%, var(--bg) 55%) fixed;
    color: var(--text);
    font-family: var(--ui);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.app {
    width: min(560px, 100%);
    margin: 0 auto;
    min-height: 100dvh;
    padding: clamp(14px, 4vw, 26px);
    padding-top: max(clamp(14px, 4vw, 26px), env(safe-area-inset-top));
    padding-bottom: max(clamp(14px, 4vw, 26px), env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: clamp(14px, 3vw, 20px);
}

/* ---------- top bar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 9px;
}

.brand__mark {
    align-self: center;
    width: 18px;
    height: 18px;
    border-radius: 5px;
    border: 2.5px solid var(--text);
    position: relative;
    flex: none;
}
.brand__mark::after {
    content: "";
    position: absolute;
    inset: 3px;
    border-radius: 1px;
    background: var(--signal);
}

.brand__name {
    font-family: var(--display);
    font-weight: 700;
    font-size: 19px;
    letter-spacing: -0.01em;
}

.brand__tag {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: 0.22em;
    color: var(--muted);
    align-self: center;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.12em;
    color: var(--muted);
    white-space: nowrap;
}
.status__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    box-shadow: 0 0 0 0 transparent;
}
.status[data-state="scanning"] { color: var(--signal); border-color: var(--signal-soft); }
.status[data-state="scanning"] .status__dot {
    background: var(--signal);
    animation: pulse 1.4s ease-in-out infinite;
}
.status[data-state="locked"] { color: var(--lock); border-color: var(--lock-soft); }
.status[data-state="locked"] .status__dot { background: var(--lock); }
.status[data-state="error"] { color: #ff8a8a; border-color: rgba(255,138,138,.25); }
.status[data-state="error"] .status__dot { background: #ff8a8a; }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--signal-soft); }
    50%      { box-shadow: 0 0 0 5px transparent; }
}

/* ---------- scanner stage ---------- */
.stage { display: flex; }

.viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: var(--r-lg);
    overflow: hidden;
    background: var(--stage);
    border: 1px solid var(--line);
    box-shadow:
        0 1px 0 rgba(255,255,255,.04) inset,
        0 30px 70px -40px rgba(0,0,0,.9);
}

#qr-video,
.overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
#qr-video {
    object-fit: cover;
    background: var(--stage);
}
.overlay { pointer-events: none; }

/* finder-pattern reticle */
.reticle {
    position: absolute;
    inset: 11%;
    pointer-events: none;
}
.reticle__corner {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 3px solid var(--signal);
    transition: border-color .25s ease;
}
.reticle__corner--tl { top: 0; left: 0; border-right: 0; border-bottom: 0; border-top-left-radius: 8px; }
.reticle__corner--tr { top: 0; right: 0; border-left: 0; border-bottom: 0; border-top-right-radius: 8px; }
.reticle__corner--bl { bottom: 0; left: 0; border-right: 0; border-top: 0; border-bottom-left-radius: 8px; }
.reticle__corner--br { bottom: 0; right: 0; border-left: 0; border-top: 0; border-bottom-right-radius: 8px; }

.reticle__beam {
    position: absolute;
    left: 6%;
    right: 6%;
    top: 0;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(90deg, transparent, var(--signal), transparent);
    box-shadow: 0 0 14px 1px var(--signal-soft);
    animation: sweep 2.6s cubic-bezier(.5,0,.5,1) infinite;
}
@keyframes sweep {
    0%, 100% { transform: translateY(0); opacity: .35; }
    50%      { transform: translateY(calc(100% - 2px)); opacity: 1; }
}

/* locked state hides the searching chrome */
.viewport.is-locked .reticle__corner { border-color: var(--lock); }
.viewport.is-locked .reticle__beam { animation: none; opacity: 0; }
.viewport.is-locked .viewport__hint { opacity: 0; }

.viewport__hint {
    position: absolute;
    left: 0; right: 0;
    bottom: 16px;
    text-align: center;
    font-size: 12.5px;
    color: rgba(255,255,255,.78);
    text-shadow: 0 1px 8px rgba(0,0,0,.8);
    transition: opacity .25s ease;
    padding: 0 16px;
}

/* permission / error overlay */
.permission[hidden] { display: none; }
.permission {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px;
    text-align: center;
    background: rgba(6,7,10,.92);
    backdrop-filter: blur(2px);
}
.permission__title { font-family: var(--display); font-weight: 500; font-size: 17px; margin: 0; }
.permission__body { margin: 0; color: var(--muted); font-size: 13px; max-width: 30ch; line-height: 1.55; }
.permission .btn { margin-top: 6px; }

/* ---------- readout ---------- */
.readout {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 16px 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.readout__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.readout__label {
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--muted);
}
.readout__kind {
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.12em;
    color: var(--lock);
    opacity: 0;
    transition: opacity .2s ease;
}
.readout__kind.is-on { opacity: 1; }

.readout__value {
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1.55;
    color: var(--muted);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 13px 14px;
    min-height: 52px;
    display: flex;
    align-items: center;
    word-break: break-all;
    transition: color .2s ease, border-color .2s ease;
}
.readout__value.has-value {
    color: var(--text);
    border-color: var(--line-strong);
}

.readout__actions {
    display: flex;
    gap: 9px;
}

/* ---------- buttons ---------- */
.btn {
    font-family: var(--ui);
    font-size: 13.5px;
    font-weight: 500;
    border-radius: var(--r-sm);
    padding: 11px 16px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .16s ease, border-color .16s ease, transform .06s ease, opacity .16s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }

.btn--primary {
    background: var(--signal);
    color: #07101f;
    font-weight: 700;
}
.btn--primary:hover:not([disabled]) { background: #74a0ff; }

.btn--ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--line-strong);
}

/* the actions row lays its buttons out side by side */
.readout__actions .btn { flex: 1; }
.btn--ghost:hover:not([disabled]) { background: rgba(255,255,255,.05); }
.btn--ghost.is-copied { color: var(--lock); border-color: var(--lock-soft); }

/* ---------- footer ---------- */
.footer {
    margin-top: auto;
    text-align: center;
    padding-top: 4px;
}
.footer__meta {
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: 0.06em;
    color: var(--muted);
    opacity: .8;
}

/* ---------- a11y / motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .reticle__beam { animation: none; opacity: .6; top: 50%; }
    .status__dot { animation: none !important; }
    .btn:active { transform: none; }
}

@media (max-width: 380px) {
    .brand__tag { display: none; }
    .reticle__corner { width: 24px; height: 24px; }
}
