/* =========================================================
   SETUP WIZARD (core shell)
   Full-screen first run. Tokens only; light theme; Manrope.
   Shared pieces the screens reuse: .sw-narrow, .sw-field, .sw-lab, .sw-txt,
   .sw-help, .sw-note, .sw-chips/.sw-chip, .sw-opts/.sw-opt, .sw-card, .sw-key, .sw-spin.
========================================================= */

body.setup-open { overflow: hidden; }

.setup-wizard {
    position: fixed;
    inset: 0;
    z-index: 960;
    background: var(--bg);
    color: var(--text);
    font-family: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    /* an edge that reads on the pale ground, built from app tokens */
    --sw-edge: color-mix(in srgb, var(--text-3) 38%, var(--border-strong));
}

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

.setup-wizard :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.setup-wizard .sw-title:focus-visible { outline: none; }

/* quiet dotted ground, so the page behind never competes */
.setup-wizard::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: radial-gradient(circle, var(--border-strong) 1.1px, transparent 1.5px);
    background-size: 24px 24px;
    opacity: .5;
}

.sw-shell {
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.sw-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ---------- top bar and progress ---------- */

.sw-top {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 14px max(16px, 3vw);
}

.sw-mark {
    width: 26px;
    height: 24px;
    flex: none;
    background: var(--primary);
    -webkit-mask: var(--emblem-mask-image) center / contain no-repeat;
    mask: var(--emblem-mask-image) center / contain no-repeat;
}

.sw-progress {
    flex: 1;
    display: flex;
    gap: 20px;
    max-width: 760px;
    margin: 0 auto;
    min-width: 0;
}

.sw-phase { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.sw-phase b { font-size: 12px; font-weight: 700; color: var(--text-3); white-space: nowrap; }
.sw-phase.is-cur b { color: var(--primary); }

.sw-dashes { display: flex; gap: 4px; }

.sw-dashes i {
    flex: 1;
    height: 3px;
    border-radius: 2px;
    background: var(--border-strong);
    position: relative;
    overflow: hidden;
}

.sw-dashes i::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--primary);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform .7s cubic-bezier(.2, .8, .2, 1);
}

.sw-dashes i.is-done::after { transform: scaleX(1); }
.sw-dashes i.is-skip::after { transform: scaleX(1); background: var(--primary-soft); }

/* the current dash is part-filled and carries a moving highlight */
.sw-dashes i.is-cur::after {
    transform: scaleX(.55);
    background: linear-gradient(90deg, var(--primary), var(--primary-2), var(--primary));
    background-size: 200% 100%;
    animation: sw-flow 1.6s linear infinite;
}

/* ---------- main column ---------- */

/* Short screens sit in the middle of the space; tall ones scroll from the top. */
.sw-main { flex: 1; overflow: auto; display: flex; padding: 4px max(16px, 3vw) 170px; }
.sw-col { width: 100%; max-width: 1040px; margin: auto; }

.sw-hd { display: flex; gap: 30px; align-items: center; margin: 30px 0 26px; }

.sw-pali {
    position: relative;
    width: 76px;
    height: 76px;
    flex: none;
    background: var(--mascot-image) center / contain no-repeat;
}

.sw-pali::before,
.sw-pali::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
}

.sw-pali::before { inset: -8px; border: 2px dashed var(--primary-2); transition: opacity .4s; }
.sw-pali::after { inset: -4px; border: 2px solid var(--primary); }
.sw-pali.is-working::before { opacity: .65; animation: sw-rot 7s linear infinite; }
.sw-pali.is-working::after { animation: sw-ping 1.9s ease-out infinite; }
.sw-pali.is-working { animation: sw-bob 1.1s ease-in-out infinite; }
.sw-pali.is-happy { animation: sw-hop .7s ease 2; }

.sw-title {
    font-size: clamp(26px, 3.6vw, 38px);
    line-height: 1.12;
    font-weight: 800;
    letter-spacing: -.025em;
    text-wrap: balance;
    outline: none;
}

.sw-word { display: inline-block; animation: sw-wordin .6s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i) * 45ms + 60ms); }
.sw-sub { margin-top: 6px; max-width: 62ch; font-size: 16px; line-height: 1.45; color: var(--text-2); }
.sw-stage { max-width: 1040px; }
.sw-narrow { max-width: 640px; }

/* ---------- status pill and details ---------- */

.sw-pill-slot { margin-top: 6px; }
.sw-pill-slot:not(:empty) { margin-bottom: 18px; }
.sw-pillwrap { position: relative; display: inline-block; }

.sw-pill {
    position: relative;
    display: inline-flex;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.sw-pill-icon { display: grid; place-items: center; padding: 0 14px; color: var(--text-3); }
.sw-pill.is-done .sw-pill-icon { color: var(--success); }
.sw-pill.is-fail .sw-pill-icon { color: var(--danger); }
.sw-pill-text { padding: 9px 14px 9px 0; }
.sw-pill-text b { display: block; font-size: 14px; font-weight: 700; }
.sw-pill-text small { font-size: 12.5px; color: var(--text-3); }

.sw-pill > button {
    padding: 0 16px;
    border: 0;
    border-left: 1px solid var(--border);
    background: none;
    font: 700 13px "Manrope", system-ui, sans-serif;
    color: var(--text);
    cursor: pointer;
}

.sw-pill > button:hover { background: var(--surface-soft); }

/* a soft sweep while the read is really running */
.sw-pill.is-run::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(100deg, transparent 30%, rgba(0, 113, 219, .10) 50%, transparent 70%);
    background-size: 200% 100%;
    animation: sw-sweep 1.8s linear infinite;
}

.sw-ring {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: conic-gradient(var(--primary) calc(var(--p) * 1%), var(--border-strong) 0);
    -webkit-mask: radial-gradient(circle, transparent 6.5px, #000 7.5px);
    mask: radial-gradient(circle, transparent 6.5px, #000 7.5px);
}

.sw-drawer {
    position: absolute;
    z-index: 20;
    top: calc(100% + 8px);
    left: 0;
    width: min(460px, calc(100vw - 32px));
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 6px 6px 12px;
    animation: sw-rise .3s cubic-bezier(.2, .8, .2, 1) both;
}

.sw-drawer h3 { display: flex; justify-content: space-between; gap: 8px; padding: 10px 12px; font-size: 14px; font-weight: 700; }
.sw-drawer h3 span { color: var(--text-3); font-weight: 600; }
.sw-drawer-note { padding: 2px 12px 8px; font-size: 13.5px; line-height: 1.45; color: var(--text-2); }
.sw-drawer > .btn { margin: 6px 12px 0 auto; display: flex; }

.sw-trk { display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; padding: 10px 12px; border-radius: var(--radius-md); align-items: start; }
.sw-trk.is-running { background: var(--primary-soft-2); }
.sw-trk-icon { margin-top: 2px; display: grid; place-items: center; color: var(--text-3); }
.sw-trk.is-done .sw-trk-icon { color: var(--success); }
.sw-trk b { font-size: 14px; font-weight: 700; }
.sw-trk small { display: block; font-size: 12.5px; line-height: 1.4; color: var(--text-3); }
.sw-trk-state { font-size: 12.5px; font-weight: 600; color: var(--text-3); white-space: nowrap; }
.sw-trk.is-done .sw-trk-state { color: var(--success); }
.sw-trk.is-failed .sw-trk-icon, .sw-trk.is-failed .sw-trk-state { color: var(--danger); }

/* ---------- footer ---------- */

.sw-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 40px max(16px, 3vw) 18px;
    background: linear-gradient(to top, var(--bg) 60%, rgba(247, 250, 253, 0));
    pointer-events: none;
}

.sw-bar-in { max-width: 1040px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 12px; pointer-events: auto; }
.sw-nav-r { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-left: auto; }
.sw-hint { font-size: 13px; color: var(--text-3); }
.setup-wizard .btn { min-height: 44px; padding: 0 22px; font-size: 14px; font-weight: 700; }
.setup-wizard .btn-ghost { color: var(--text-2); }
.setup-wizard .btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

/* ---------- splash, redirect, toast ---------- */

.sw-splash {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: var(--bg);
    display: grid;
    place-items: center;
    cursor: pointer;
}

.sw-splash-in { display: flex; flex-direction: column; align-items: center; gap: 14px; animation: sw-rise .7s cubic-bezier(.2, .8, .2, 1) both; }
.sw-splash-in b { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.sw-splash-in small { font-size: 14px; color: var(--text-3); }

.sw-splash-pali {
    position: relative;
    width: 120px;
    height: 120px;
    display: grid;
    place-items: center;
}

.sw-splash-pali i { position: absolute; inset: 0; background: var(--mascot-image) center / contain no-repeat; animation: sw-bob 1.1s ease-in-out infinite; }
.sw-splash-pali span { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--primary); opacity: 0; animation: sw-ping 1.6s ease-out infinite; }
.sw-splash-pali span:nth-child(2) { animation-delay: .8s; }

.sw-bootbar { width: 180px; height: 3px; border-radius: 2px; background: var(--border-strong); overflow: hidden; }
.sw-bootbar i { display: block; height: 100%; background: var(--primary); transform: scaleX(0); transform-origin: left; animation: sw-bootfill 2s cubic-bezier(.3, .6, .2, 1) forwards; }

.sw-redirect { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; background: var(--overlay); }

.sw-redirect > div {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 26px 30px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    font-size: 16px;
    font-weight: 700;
    max-width: min(360px, calc(100vw - 32px));
}

.sw-redirect small { font-size: 13px; font-weight: 500; color: var(--text-3); }

.sw-toast {
    position: absolute;
    left: 50%;
    bottom: 90px;
    z-index: 7;
    transform: translateX(-50%) translateY(20px);
    opacity: 0;
    pointer-events: none;
    background: var(--text);
    color: #fff;
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    max-width: calc(100vw - 32px);
    transition: opacity .3s, transform .3s;
}

.sw-toast.is-on { opacity: 1; transform: translateX(-50%); }

/* ---------- shared pieces for the screens ---------- */

.sw-spin { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: sw-rot .8s linear infinite; }

.sw-field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.sw-lab { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.sw-help { font-size: 13px; color: var(--text-3); }

.sw-txt {
    width: 100%;
    font: 500 17px "Manrope", system-ui, sans-serif;
    color: var(--text);
    background: var(--surface);
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 13px 14px;
    outline: none;
    transition: border-color .16s, box-shadow .16s;
}

.sw-txt:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft-2); }
.sw-txt:disabled { background: var(--surface-soft); color: var(--text-3); }

.sw-note { border-radius: var(--radius-md); padding: 12px 14px; margin-bottom: 14px; font-size: 14px; line-height: 1.45; background: var(--primary-soft-2); }
.sw-note.is-warn { background: var(--warning-soft); }
.sw-note.is-bad { background: var(--danger-soft); }

.sw-chips { display: flex; flex-wrap: wrap; gap: 8px; }

.sw-chip {
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: 600 13.5px "Manrope", system-ui, sans-serif;
    cursor: pointer;
    transition: background .16s, border-color .16s;
}

.sw-chip:hover { background: var(--surface-soft); }
.sw-chip.is-on { background: var(--primary); border-color: var(--primary); color: #fff; }

.sw-key {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-3);
    background: var(--surface-soft);
}

.sw-opts { display: grid; gap: 12px; }

.sw-opt {
    position: relative;
    text-align: left;
    background: var(--surface);
    border: 1.5px solid var(--sw-edge);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font: inherit;
    color: inherit;
    cursor: pointer;
    transition: border-color .16s, background .16s, box-shadow .16s;
}

.sw-opt:hover { border-color: var(--primary-2); background: var(--surface-soft); }
.sw-opt.is-on { border-color: var(--primary); background: var(--primary-soft-2); box-shadow: 0 0 0 3px var(--primary-soft-2); }
.sw-opt > .sw-key { position: absolute; top: 12px; right: 12px; }

.sw-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow-sm); min-width: 0; }

/* ---------- motion ---------- */

@keyframes sw-rot { to { transform: rotate(360deg); } }
@keyframes sw-ping { from { transform: scale(.85); opacity: .55; } to { transform: scale(1.7); opacity: 0; } }
@keyframes sw-bob { 50% { transform: translateY(-4px); } }
@keyframes sw-hop { 40% { transform: translateY(-12px) scale(1.04); } }
@keyframes sw-flow { to { background-position: -200% 0; } }
@keyframes sw-sweep { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes sw-rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes sw-wordin { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } to { opacity: 1; transform: none; filter: blur(0); } }
@keyframes sw-bootfill { to { transform: scaleX(1); } }

/* ---------- smaller screens ---------- */

@media (max-width: 900px) {
    .sw-hd { flex-direction: column; align-items: flex-start; gap: 10px; }
    .sw-pali { width: 60px; height: 60px; margin: 8px 0 6px 8px; }
    .sw-pill-slot { margin-top: 12px; }
    .sw-phase b { font-size: 11px; }
}

@media (max-width: 700px) {
    .sw-top { flex-wrap: wrap; gap: 10px 14px; }
    .sw-progress { order: 3; flex: 1 1 100%; max-width: none; }
    .sw-exit { margin-left: auto; }
    .sw-bar-in { flex-wrap: wrap; }
    .sw-nav-r { width: 100%; justify-content: space-between; }
    .sw-nav-r .btn-primary { flex: 1; }
    .sw-pill { max-width: 100%; }
    .sw-phase:not(.is-cur) b { visibility: hidden; }
}

@media (prefers-reduced-motion: reduce) {
    .setup-wizard *,
    .setup-wizard *::before,
    .setup-wizard *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* No page paints while we find out whether setup applies. */
body.setup-checking .app { visibility: hidden; }
