:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #121826;
  --muted: #5d6679;
  --line: #e2e7f0;
  --brand: #0f6fff;
  --brand-dark: #0a58d0;
  --brand-soft: #e9f1ff;
  --ok: #12a150;
  --ok-soft: #e7f7ee;
  --warn: #d98a00;
  --warn-soft: #fff5e0;
  --err: #d93a3a;
  --err-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.brand img { border-radius: 8px; }
.stepper { display: flex; gap: 6px; }
.stepper span { display: flex; align-items: center; gap: 6px; color: #9aa3b5; font-size: 13px; padding: 4px 8px; border-radius: 99px; }
.stepper b {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: #e9edf4; color: #8a93a6; font-size: 12px;
}
.stepper i { font-style: normal; }
.stepper span.done b { background: var(--ok); color: #fff; }
.stepper span.done { color: var(--muted); }
.stepper span.active { color: var(--brand-dark); font-weight: 600; background: var(--brand-soft); }
.stepper span.active b { background: var(--brand); color: #fff; }

main { max-width: 1080px; margin: 0 auto; padding: 24px 20px 40px; }
.step { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Step 1 ---------- */
.hero { text-align: center; padding: 24px 0 8px; }
.eyebrow { color: var(--brand); font-weight: 600; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; margin: 0 0 8px; }
.hero h1 { font-size: clamp(30px, 5vw, 46px); line-height: 1.12; margin: 0 0 14px; letter-spacing: -.02em; }
.lead { color: var(--muted); font-size: 17px; max-width: 620px; margin: 0 auto; }
.lead strong { color: var(--text); }

.search-box {
  position: relative; max-width: 620px; margin: 28px auto 8px;
}
.search-box svg { position: absolute; left: 16px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: #8a93a6; }
.search-box input {
  width: 100%; padding: 15px 16px 15px 46px;
  border: 1.5px solid var(--line); border-radius: 12px;
  font: inherit; font-size: 16px; background: #fff;
  box-shadow: var(--shadow); outline: none; transition: border-color .15s;
}
.search-box input:focus { border-color: var(--brand); }

.section-title { font-size: 16px; margin: 30px 0 12px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.doc-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; text-align: left;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.doc-card:hover { border-color: #a8c6ff; box-shadow: var(--shadow); }
.doc-card:active { transform: scale(.99); }
.flag { font-size: 26px; line-height: 1; flex-shrink: 0; width: 32px; text-align: center; }
.doc-card b { display: block; font-size: 14px; }
.doc-card small { color: var(--muted); font-size: 12px; }

.doc-list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.doc-list .country { padding: 8px 14px; background: #f8fafc; font-size: 12px; color: var(--muted); font-weight: 600; border-top: 1px solid var(--line); }
.doc-list .country:first-child { border-top: none; }
.doc-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  width: 100%; padding: 11px 14px; border: none; background: none; text-align: left;
  border-top: 1px solid #f0f3f8; cursor: pointer; color: var(--text);
}
.doc-row:hover { background: var(--brand-soft); }
.doc-row small { color: var(--muted); white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 20px; }

.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 36px; }
.features div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.features b { display: block; margin-bottom: 4px; }
.features span { color: var(--muted); font-size: 14px; }

/* ---------- Step 2 ---------- */
.doc-summary {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.doc-summary .flag { font-size: 32px; }
.doc-summary .info { flex: 1; min-width: 200px; }
.doc-summary b { font-size: 16px; }
.doc-summary .specs { color: var(--muted); font-size: 13px; }
.doc-summary .notes { color: var(--muted); font-size: 12px; margin-top: 2px; }

.doc-warn { flex-basis: 100%; border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; }
.doc-warn p { margin: 0 0 6px; color: #8a5a00; background: var(--warn-soft); border-radius: 8px; padding: 8px 10px; }
.doc-warn a { color: var(--brand); font-weight: 600; text-decoration: none; }

.photo-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.big-btn {
  display: flex; align-items: center; gap: 14px;
  padding: 22px; border-radius: var(--radius);
  border: 1.5px solid var(--line); background: var(--card); color: var(--text);
  cursor: pointer; text-align: left; box-shadow: var(--shadow);
  transition: border-color .15s, transform .1s;
}
.big-btn:hover { border-color: #a8c6ff; }
.big-btn:active { transform: scale(.99); }
.big-btn .ico { font-size: 32px; }
.big-btn b { display: block; font-size: 17px; }
.big-btn small { color: var(--muted); font-size: 13px; }
.big-btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.big-btn.primary small { color: rgba(255,255,255,.85); }

.tips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tip { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.tip .n {
  display: inline-flex; width: 24px; height: 24px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; font-size: 13px;
  align-items: center; justify-content: center; margin-right: 6px;
}
.tip p { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.drop-hint { color: var(--muted); font-size: 13px; text-align: center; margin-top: 18px; }
body.dragover::after {
  content: 'Drop your photo'; position: fixed; top: 10px; left: 10px; right: 10px; bottom: 10px; z-index: 60;
  border: 3px dashed var(--brand); border-radius: 18px; background: rgba(233,241,255,.85);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: var(--brand-dark);
}

/* ---------- Step 3 ---------- */
.check-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.preview-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; display: flex; flex-direction: column; align-items: center;
  box-shadow: var(--shadow);
  position: sticky; top: 80px;
}
.canvas-box { position: relative; line-height: 0; touch-action: none; cursor: grab; box-shadow: 0 4px 20px rgba(16,24,40,.18); }
.canvas-box.dragging { cursor: grabbing; }
#outCanvas { display: block; max-width: 100%; max-height: 56vh; }
.guide { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.preview-meta { color: var(--muted); font-size: 13px; margin: 14px 0 8px; text-align: center; }
.preview-tools { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 99px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: #a8c6ff; }
.hint { color: #98a1b3; font-size: 12px; margin: 10px 0 0; }

.side-col { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 16px; margin: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid #f0f3f8; }
.checklist li:first-child { border-top: none; }
.checklist .st {
  flex-shrink: 0; width: 22px; height: 22px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; margin-top: 1px;
}
.checklist .pass .st { background: var(--ok); }
.checklist .warn .st { background: var(--warn); }
.checklist .fail .st { background: var(--err); }
.checklist .info .st { background: #8a93a6; }
.checklist b { font-size: 14px; font-weight: 600; display: block; }
.checklist small { color: var(--muted); font-size: 13px; display: block; }

details.card summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: '▾'; color: var(--muted); transition: transform .2s; }
details.card[open] summary::after { transform: rotate(180deg); }
details.card[open] summary { margin-bottom: 12px; }
.field { margin-bottom: 10px; }
.field > span { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.bg-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sw {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer;
  box-shadow: inset 0 0 0 2px #fff; padding: 0;
}
.sw.active { border-color: var(--brand); box-shadow: inset 0 0 0 2px #fff, 0 0 0 3px rgba(15,111,255,.2); }
.bg-row input[type=color] { width: 36px; height: 32px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: #fff; }
.slider { display: grid; grid-template-columns: 80px 1fr 44px; align-items: center; gap: 8px; margin: 6px 0; }
.slider span { color: var(--muted); font-size: 13px; }
.slider input { width: 100%; accent-color: var(--brand); }
.slider output { text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.link-btn { background: none; border: none; color: var(--brand); cursor: pointer; padding: 6px 0; font-size: 14px; }

/* ---------- Step 4 ---------- */
.dl-layout { display: grid; grid-template-columns: 300px 1fr; gap: 28px; align-items: start; max-width: 860px; margin: 0 auto; }
.dl-preview { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; text-align: center; box-shadow: var(--shadow); }
.dl-preview img { max-width: 100%; max-height: 340px; box-shadow: 0 4px 16px rgba(16,24,40,.18); }
.dl-preview p { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.dl-title { font-size: 28px; margin: 0 0 16px; letter-spacing: -.01em; }
.option-card {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.option-card b { font-size: 16px; }
.option-card p { color: var(--muted); font-size: 13px; margin: 2px 0 8px; }
.option-card select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); font: inherit; font-size: 13px; background: #fff; }
.dl-note { color: var(--muted); font-size: 13px; min-height: 1em; }
.print-tip { background: var(--brand-soft); border-radius: 10px; padding: 12px 14px; font-size: 13px; color: #2a3a5a; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { border-color: #a8c6ff; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.block { width: 100%; }
.btn.lg { padding: 14px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Footer ---------- */
.foot { text-align: center; color: #8a93a6; font-size: 12px; padding: 10px 20px calc(30px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.foot p { margin: 4px 0; }

/* ---------- Busy overlay ---------- */
.busy { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 70; background: rgba(246,248,251,.86); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 20px; }
.busy-card { background: #fff; border-radius: 16px; padding: 28px 30px; text-align: center; box-shadow: 0 10px 40px rgba(16,24,40,.15); min-width: 280px; }
.busy-card p { margin: 14px 0 10px; font-weight: 600; }
.busy-card small { color: var(--muted); display: block; margin-top: 8px; font-size: 12px; }
.spinner { width: 38px; height: 38px; margin: 0 auto; border-radius: 50%; border: 3px solid #dfe5ef; border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 6px; background: #e5eaf2; border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--brand); transition: width .2s; }

/* ---------- Camera ---------- */
.camera { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 80; background: #000; overflow: hidden; }
/* The video keeps playing underneath (some browsers stop decoding hidden videos);
   what the user sees is #camCanvas on top of it. */
.camera video { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
#camCanvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: block; background: #000; }
.cam-guide {
  position: absolute; left: 50%; top: 50%;
  width: min(92vw, 69vh); height: calc(min(92vw, 69vh) * 4 / 3);
  transform: translate(-50%, -52%);
  pointer-events: none; overflow: visible;
}
.cam-guide #ovalLine { transition: stroke .2s; }
.camera.ready #ovalLine { stroke: #2ee07a; stroke-dasharray: none; stroke-width: 4; }
.cam-top {
  position: absolute; top: 0; left: 0; right: 0;
  padding: calc(14px + env(safe-area-inset-top)) 14px 40px;
  background: linear-gradient(rgba(0,0,0,.6), transparent);
  display: flex; align-items: flex-start; gap: 12px;
}
.cam-status {
  flex: 1; text-align: center; color: #fff; font-weight: 600; font-size: 17px;
  padding: 8px 12px 0 0; text-shadow: 0 1px 4px rgba(0,0,0,.7);
}
.camera.ready .cam-status { color: #5dff9d; }
.cam-icon { width: 40px; height: 40px; border-radius: 50%; border: none; background: rgba(255,255,255,.2); color: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0; }
.cam-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: 40px 20px calc(26px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.65));
  display: flex; align-items: center; justify-content: space-around;
}
.cam-pill { min-width: 86px; height: 40px; padding: 0 14px; border-radius: 99px; border: none; background: rgba(255,255,255,.2); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; }
.cam-pill.on { background: var(--brand); }
.cam-shutter { width: 76px; height: 76px; border-radius: 50%; background: #fff; border: 5px solid rgba(255,255,255,.4); background-clip: padding-box; cursor: pointer; transition: transform .1s; }
.cam-shutter:active { transform: scale(.92); }
.cam-shutter:disabled { opacity: .45; }
.cam-count { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: #fff; font-size: 110px; font-weight: 800; text-shadow: 0 2px 16px rgba(0,0,0,.6); pointer-events: none; }
.camera.flash::after { content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #fff; animation: flash .35s ease-out forwards; }
@keyframes flash { from { opacity: .95; } to { opacity: 0; } }

/* ---------- Save modal ---------- */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 75; background: rgba(10,15,30,.6); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { background: #fff; border-radius: 16px; padding: 18px; width: 100%; max-width: 420px; max-height: 100%; overflow: auto; text-align: center; }
#saveModal { z-index: 90; }
.modal-title { font-weight: 700; font-size: 16px; margin: 0 0 12px; }
.modal-img { background: #f0f3f8; border-radius: 10px; padding: 12px; display: flex; justify-content: center; }
.modal-img img { max-width: 100%; max-height: 52vh; box-shadow: 0 2px 10px rgba(0,0,0,.15); -webkit-touch-callout: default; }
.modal-meta { color: var(--muted); font-size: 12px; margin: 10px 0; }
.modal-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- Payments & orders ---------- */
.price { color: var(--brand-dark); font-weight: 700; margin-left: 4px; }
.price s { color: var(--muted); font-weight: 400; margin-right: 4px; }
.pay-note { font-size: 12px; color: var(--muted); margin: 4px 0 10px; }
.btn.owned { background: var(--ok); border-color: var(--ok); color: #fff; }
.checkout-card { max-width: 520px; text-align: left; padding: 14px; position: relative; }
.checkout-loading {
  position: absolute; left: 0; right: 0; bottom: 0; top: 96px; z-index: 2;
  background: #fff; border-radius: 0 0 16px 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  padding-top: 90px; color: var(--muted); font-size: 14px;
}
.checkout-loading p { margin: 14px 0 0; }
.orders-card { max-width: 480px; text-align: left; }
.checkout-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.checkout-head b { font-size: 17px; }
.cam-icon.dark { background: #eef1f6; color: var(--text); width: 34px; height: 34px; font-size: 15px; }
.test-banner { background: #fff5e0; color: #8a5a00; border-radius: 8px; padding: 8px 10px; font-size: 12px; margin: 0 0 10px; }
.checkout-error { color: var(--err); font-size: 13px; margin: 0; }
.checkout-error:empty { display: none; }
#checkoutMount { min-height: 300px; }
.orders-hint { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.order { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.order b { display: block; font-size: 14px; }
.order small { color: var(--muted); display: block; margin-bottom: 8px; }
.order .btn { padding: 7px 12px; font-size: 13px; margin: 0 6px 6px 0; }
.foot-links { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.foot-links a { color: var(--muted); text-decoration: none; font-size: 13px; }
.foot-links a:hover { color: var(--brand); }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .topbar { padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); }
  .brand span { display: none; }
  .stepper i { display: none; }
  .stepper span.active i { display: inline; }
  main { padding: 16px 14px 30px; }
  .hero { padding-top: 8px; }
  .lead { font-size: 15px; }
  .features, .tips { grid-template-columns: 1fr; }
  .photo-choice { grid-template-columns: 1fr; }
  .doc-grid { grid-template-columns: 1fr 1fr; }
  .doc-card { padding: 10px; gap: 8px; }
  .flag { font-size: 22px; width: 26px; }
  .check-layout { grid-template-columns: 1fr; }
  .preview-card { position: static; padding: 16px; }
  #outCanvas { max-height: 46vh; }
  #toDownload {
    position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 5;
    box-shadow: 0 6px 20px rgba(15,111,255,.35);
  }
  .dl-layout { grid-template-columns: 1fr; }
  .dl-preview img { max-height: 260px; }
  .option-card { flex-direction: column; align-items: stretch; }
  .option-card .btn { width: 100%; }
}
