/* ---------- Fonts (self-hosted: Gelasio ≈ Georgia, Courier Prime ≈ Courier New, Arimo ≈ Arial) ---------- */
@font-face { font-family: "Gelasio"; src: url(fonts/gelasio-latin-700-normal.woff2) format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Gelasio"; src: url(fonts/gelasio-latin-400-italic.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Gelasio"; src: url(fonts/gelasio-latin-700-italic.woff2) format("woff2"); font-weight: 700; font-style: italic; font-display: swap; }
@font-face { font-family: "Courier Prime"; src: url(fonts/courier-prime-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Courier Prime"; src: url(fonts/courier-prime-latin-700-normal.woff2) format("woff2"); font-weight: 700; font-display: swap; }
@font-face { font-family: "Arimo"; src: url(fonts/arimo-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Arimo"; src: url(fonts/arimo-latin-600-normal.woff2) format("woff2"); font-weight: 600; font-display: swap; }

:root {
  --paper: #f4ecdd; --paper2: #eadfcb; --card: #fbf6ee;
  --text: #2a2320; --muted: #6e655c; --faint: #8e8478; --rule: #cdc1ab;
  --green: #123b30; --green2: #0a241d; --gold: #d4b26a; --pink: #c8186e;
  --c: #c8186e; --ink: #c8186e; --box: #eadfcb;
  --serif: "Gelasio", Georgia, "Times New Roman", serif;
  --mono: "Courier Prime", "Courier New", Courier, monospace;
  --sans: "Arimo", Arial, Helvetica, sans-serif;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--green2); color: var(--text); font-family: var(--sans);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
img { -webkit-user-drag: none; }

/* ---------- Book: one page per screen, swipe sideways ---------- */
.book { position: fixed; inset: 0; display: flex; overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain;
  background: radial-gradient(120% 90% at 50% 0%, #174a3d 0%, #0b261f 60%, #071a15 100%); }
.book::-webkit-scrollbar { display: none; }
.leaf { flex: 0 0 100%; width: 100%; height: 100%; overflow-y: auto; overflow-x: hidden;
  scroll-snap-align: center; scroll-snap-stop: always; overscroll-behavior-y: contain; }

.page { position: relative; min-height: 100%; max-width: 560px; margin: 0 auto;
  padding: calc(20px + var(--st)) 22px calc(100px + var(--sb)); background: var(--paper); }
.paper { background: linear-gradient(90deg, #e3d4b9 0, rgba(227, 212, 185, 0) 22px), var(--paper); }
@media (min-width: 700px) and (min-height: 600px) {
  .page { min-height: calc(100% - 48px); margin: 24px auto; border-radius: 6px 14px 14px 6px;
    padding: 34px 42px 120px; box-shadow: 0 30px 70px -24px rgba(0,0,0,.6), 0 2px 0 rgba(0,0,0,.18); }
  .paper { background: linear-gradient(90deg, #e3d4b9 0, rgba(227, 212, 185, 0) 34px), var(--paper); }
}

/* ---------- Page anatomy (mirrors the printed passport) ---------- */
.pg-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding-bottom: 9px; border-bottom: 1.5px solid var(--c);
  font-family: var(--mono); font-size: 12.5px; letter-spacing: .14em; text-transform: uppercase; }
.pg-head .sec { color: var(--ink); font-weight: 700; }
.pg-head .num { color: var(--faint); letter-spacing: .22em; white-space: nowrap; }
.title { font-family: var(--serif); font-weight: 700; font-size: clamp(28px, 8.6vw, 40px); line-height: 1.08;
  margin: 18px 0 6px; color: var(--text); }
.sub { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 16.5px; margin: 0 0 18px; }

.hero { display: grid; grid-template-columns: 54% 1fr; gap: 14px; align-items: center; margin-bottom: 22px; }
.photo { position: relative; display: block; width: 100%; aspect-ratio: 884 / 764; border-radius: 12px;
  overflow: hidden; background: var(--paper2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam { position: absolute; right: 8px; bottom: 8px; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(244, 236, 221, .93); display: grid; place-items: center; color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,.28); }
.cam svg { width: 18px; height: 18px; }
.photo.mine .cam { background: var(--c); color: #fff; }

.slot { position: relative; justify-self: center; width: min(100%, 190px); aspect-ratio: 1; border-radius: 50%; color: #8a8176; }
.slot .dash { position: absolute; inset: 0; width: 100%; height: 100%; }
.slot .hint { position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: #a69b8b; line-height: 1.5; }
.slot.stamped .hint { display: none; }
.stamp-holder { position: absolute; inset: -5%; pointer-events: none; }
.stamp-svg { width: 100%; height: 100%; display: block; mix-blend-mode: multiply; opacity: .92; transform: rotate(var(--r)); }
.stamp-in { animation: stampIn .45s cubic-bezier(.2, .9, .3, 1.25) both; }
@keyframes stampIn {
  0% { transform: scale(1.9) rotate(var(--r0)); opacity: 0; }
  62% { transform: scale(.93) rotate(var(--r)); opacity: 1; }
  100% { transform: scale(1) rotate(var(--r)); opacity: .92; }
}
.slot.ready::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--c);
  opacity: 0; animation: ready 1.9s ease-out infinite; }
.slot.ready .hint { color: var(--ink); font-weight: 700; }
@keyframes ready { 0% { transform: scale(.92); opacity: .75; } 100% { transform: scale(1.12); opacity: 0; } }
.bump { animation: bump .35s ease; }
@keyframes bump { 0%, 100% { transform: none; } 40% { transform: translateY(2px) scale(.995); } }

.lbl { font-family: var(--mono); font-size: 12.5px; letter-spacing: .16em; color: var(--faint); margin: 0 0 8px; }
.items { margin: 0 0 20px; padding-left: 20px; font-size: 15.5px; line-height: 1.55; }
.para { font-size: 15.5px; line-height: 1.55; margin: 0 0 20px; }
.dyk { background: var(--box); border-radius: 14px; padding: 16px 18px 4px; margin: 0 0 22px; }
.dyk-t { font-family: var(--mono); font-weight: 700; color: var(--ink); font-size: 17px; letter-spacing: .12em;
  text-transform: uppercase; margin-bottom: 8px; }
.dyk p { font-size: 16.5px; line-height: 1.42; margin: 0 0 12px; }
.mis-t { font-family: var(--mono); font-weight: 700; font-size: 15px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 4px; }
.missions { list-style: none; margin: 0 0 22px; padding: 0; }
.mis { position: relative; display: flex; align-items: flex-start; gap: 12px; padding: 9px 0; min-height: 44px;
  cursor: pointer; font-size: 15.5px; line-height: 1.4; }
.mis input { position: absolute; left: 0; top: 10px; width: 24px; height: 24px; opacity: 0; margin: 0; }
.box { flex: 0 0 24px; height: 24px; border: 2px solid var(--c); border-radius: 6px; display: grid; place-items: center;
  transition: background-color .15s ease; }
.box svg { width: 16px; height: 16px; stroke: #fff; stroke-width: 3; fill: none; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: 24; stroke-dashoffset: 24; transition: stroke-dashoffset .25s ease .05s; }
.txt { padding-top: 1px; transition: color .2s; }
.mis input:checked + .box { background: var(--c); }
.mis input:checked + .box svg { stroke-dashoffset: 0; }
.mis input:checked ~ .txt { color: var(--muted); }
.mis input:focus-visible + .box { outline: 2px solid var(--c); outline-offset: 2px; }
.pg-foot { display: flex; justify-content: space-between; border-top: 1px solid #9c9387; padding-top: 9px;
  font-family: var(--mono); font-size: 12.5px; letter-spacing: .16em; color: var(--faint); text-transform: uppercase; }

/* ---------- Holder page ---------- */
.holder-grid { display: grid; grid-template-columns: 42% 1fr; gap: 20px; margin: 4px 0 24px; align-items: start; }
.idphoto { position: relative; width: 100%; aspect-ratio: 3 / 4; border: 2px dashed #8a8176; border-radius: 12px;
  background: var(--paper2); overflow: hidden; display: grid; place-items: center; text-align: center;
  font-family: var(--mono); font-size: 12px; letter-spacing: .16em; color: #8a8176; line-height: 1.6; }
.idphoto small { display: block; font-size: 10px; letter-spacing: .12em; opacity: .8; }
.idphoto img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.idphoto.has { border-style: solid; border-color: transparent; }
.idphoto .cam { display: none; }
.idphoto.has .cam { display: grid; }
.field { margin-bottom: 12px; }
.field label { display: block; font-family: var(--mono); font-size: 11.5px; letter-spacing: .16em; color: var(--faint); text-transform: uppercase; }
.field input { width: 100%; border: 0; border-bottom: 1.5px solid var(--rule); background: transparent; border-radius: 0;
  font: 16px var(--sans); color: var(--text); padding: 4px 0 6px; }
.field input:focus { outline: none; border-bottom-color: var(--pink); }
.field input::placeholder { color: #b3a895; }
.welcome { font-family: var(--serif); font-style: italic; font-weight: 400; color: var(--pink);
  font-size: clamp(40px, 12.5vw, 58px); text-align: center; margin: 6px 0 18px; line-height: 1.1; }
.flag { display: block; width: min(62%, 300px); height: auto; margin: 0 auto 20px; }
.tagline { text-align: center; color: var(--muted); font-size: 16px; margin: 0 0 22px; line-height: 1.4; }
.mode-note { text-align: center; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; color: var(--faint);
  margin: -8px 0 18px; text-transform: uppercase; }
.mode-note:empty { display: none; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 22px; }
.stat { background: var(--card); border: 1px solid #e6dac4; border-radius: 12px; padding: 12px 14px; }
.stat .k { font-family: var(--mono); font-size: 10px; letter-spacing: .06em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--faint); text-transform: uppercase; }
.stat .v { font-family: var(--serif); font-size: 26px; font-weight: 700; margin: 2px 0 8px; }
.stat .v small { font-size: 15px; color: var(--faint); font-weight: 700; }
.bar { height: 6px; border-radius: 3px; background: #eadfcb; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--pink); border-radius: 3px; transition: width .5s ease; }
.stat.m .bar i { background: #378586; }

.mrz { font-family: var(--mono); letter-spacing: .06em; background: var(--card); border-top: 1.5px solid var(--rule);
  border-radius: 4px; padding: 12px 8px; text-align: center; line-height: 1.35; white-space: pre; overflow: hidden;
  font-size: clamp(10px, calc((min(100vw, 560px) - 64px) / 21.4), 19px); }

/* ---------- Closing page ---------- */
.closing .pg-head { justify-content: flex-end; border-bottom-color: var(--pink); }
.bye { font-family: var(--serif); font-style: italic; color: var(--pink); font-size: clamp(40px, 12.5vw, 58px);
  text-align: center; margin: 34px 0 6px; line-height: 1.1; }
.bye-sub { text-align: center; color: var(--muted); font-size: 16px; margin: 0 0 26px; }
.done-msg { text-align: center; font-family: var(--serif); font-style: italic; font-size: 19px; color: var(--text); margin: -6px 0 20px; }
.done-msg:empty { display: none; }

/* ---------- Cover & back cover ---------- */
.cover { color: var(--gold); text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  background: linear-gradient(90deg, var(--green2) 0 14px, rgba(0,0,0,.18) 14px 18px, rgba(0,0,0,0) 18px), var(--green);
  padding-top: calc(56px + var(--st)); padding-bottom: calc(110px + var(--sb)); }
@media (min-width: 700px) and (min-height: 600px) { .cover { padding-top: 64px; } }
.cv-city { font-family: var(--mono); font-size: 15px; letter-spacing: .32em; text-transform: uppercase; }
.cv-title { font-family: var(--serif); font-weight: 700; font-size: clamp(42px, 13vw, 58px); letter-spacing: .03em; margin: 10px 0 12px; line-height: 1; }
.cv-sub { font-family: var(--mono); font-size: 12px; letter-spacing: .55em; text-transform: uppercase; opacity: .9; }
.emblem { position: relative; width: 186px; height: 186px; border-radius: 50%; border: 3px solid var(--gold);
  display: grid; place-content: center; margin: 40px auto; }
.emblem::before { content: ""; position: absolute; inset: -17px; border-radius: 50%; border: 1.5px dashed var(--gold); opacity: .9; }
.emblem b { font-family: var(--serif); font-size: 46px; letter-spacing: .02em; line-height: 1; }
.emblem span { font-family: var(--mono); font-size: 12px; letter-spacing: .32em; margin-top: 12px; opacity: .85; }
.cv-edition { font-family: var(--serif); font-style: italic; font-size: 27px; }
.cv-tag { font-family: var(--sans); font-size: 14px; letter-spacing: .07em; color: #e9e3d2; margin: 10px 0 16px; }
.chip { width: 52px; height: 36px; margin: 0 auto; }
.open-btn { display: inline-flex; align-items: center; gap: 10px; margin-top: 26px; padding: 13px 24px; border-radius: 999px;
  border: 1.5px solid var(--gold); font-family: var(--mono); font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); }
.open-btn:hover, .open-btn:focus-visible { background: rgba(212, 178, 106, .12); outline: none; }
.open-btn span { display: inline-block; animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: none; } 50% { transform: translateX(5px); } }
.back { justify-content: center; gap: 0; }
.back .emblem { width: 150px; height: 150px; margin: 0 auto 70px; }
.back .emblem b { font-size: 36px; }
.found { font-family: var(--serif); font-style: italic; font-size: 21px; line-height: 1.35; max-width: 300px; margin: 0 auto; }
.found-rule { width: 70px; height: 1px; background: var(--gold); opacity: .6; margin: 22px auto; }
.found-es { font-family: var(--mono); font-size: 11.5px; letter-spacing: .2em; text-transform: uppercase; opacity: .75; max-width: 300px; margin: 0 auto; line-height: 1.6; }
.edition { font-family: var(--mono); font-size: 11.5px; letter-spacing: .3em; text-transform: uppercase; opacity: .7; margin-top: 90px; }

/* ---------- Dock ---------- */
.dock { position: fixed; left: 50%; bottom: calc(14px + var(--sb)); transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 4px; padding: 5px; border-radius: 999px; color: var(--paper);
  background: rgba(18, 59, 48, .95); box-shadow: 0 10px 30px rgba(0,0,0,.35), inset 0 0 0 1px rgba(212, 178, 106, .25);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); transition: opacity .25s, transform .25s; }
.dock.hide { opacity: 0; pointer-events: none; transform: translate(-50%, 20px); }
.dock .nav { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-size: 26px; line-height: 1; padding-bottom: 3px; }
.dock .nav:disabled { opacity: .25; cursor: default; }
.where { position: relative; display: flex; align-items: center; gap: 9px; height: 42px; padding: 0 16px; border-radius: 999px;
  background: rgba(255,255,255,.08); font-family: var(--mono); font-size: 13px; letter-spacing: .06em; white-space: nowrap; }
.where .w-sec { opacity: .75; }
.where .w-prog { color: var(--gold); font-weight: 700; }
.where .dot { position: absolute; top: 6px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: transparent; transition: background .3s; }
.dock[data-status="saving"] .dot { background: #e6b34a; }
.dock[data-status="saved"] .dot { background: #5fbf7f; }
.dock[data-status="offline"] .dot, .dock[data-status="retrying"] .dot { background: #e0784a; }
.dock[data-status="error"] .dot { background: #e0484a; }
@media (max-width: 360px) { .where .w-sec { display: none; } }

/* ---------- Sheets, lightbox, toast ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(8, 20, 16, .5); opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 620px; margin: 0 auto; max-height: 88vh; overflow-y: auto;
  background: var(--paper); border-radius: 20px 20px 0 0; padding: 10px 20px calc(20px + var(--sb));
  transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); box-shadow: 0 -10px 40px rgba(0,0,0,.3);
  visibility: hidden; }
.sheet.open { transform: none; visibility: visible; }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: #cfc3ae; margin: 0 auto 12px; }
.sheet h3 { font-family: var(--serif); font-size: 22px; margin: 4px 0 14px; }
.sheet-p { font-size: 15.5px; line-height: 1.45; color: var(--muted); margin: -4px 0 16px; }
.sbtn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 15px 16px; border-radius: 12px; background: var(--card);
  margin-bottom: 8px; font-size: 16px; text-align: left; }
.sbtn svg { width: 20px; height: 20px; flex: 0 0 20px; }
.sbtn.primary { background: var(--green); color: var(--paper); }
.sbtn.danger { color: #b3261e; }
.sbtn.ghost { background: transparent; justify-content: center; color: var(--muted); }

.ix-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.ix-links { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 6px; }
.ix-link { padding: 8px 12px; border-radius: 999px; background: var(--card); font-family: var(--mono); font-size: 12px; letter-spacing: .08em; }
.ix-sec { display: flex; justify-content: space-between; margin: 16px 0 8px; padding-bottom: 6px; border-bottom: 1.5px solid var(--c);
  font-family: var(--mono); font-weight: 700; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink); }
.ix-sec span { color: var(--faint); font-weight: 400; }
.ix-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 12px 6px; }
.ix { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 10.5px; line-height: 1.2; text-align: center; color: var(--muted); }
.ix .c { position: relative; width: 50px; height: 50px; display: grid; place-items: center; font-family: var(--mono); font-size: 13px; color: #8a8176; }
.ix .c .dash { position: absolute; inset: 0; width: 100%; height: 100%; }
.ix .c .mini { position: absolute; inset: -3px; width: 56px; height: 56px; mix-blend-mode: multiply; }
.ix.stamped .c > span { visibility: hidden; }
.ix.ready .c { color: var(--ink); font-weight: 700; }
.ix.ready .c::after { content: ""; position: absolute; top: 1px; right: 1px; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.ix.here .c { outline: 2px solid var(--green); outline-offset: 3px; border-radius: 50%; }
.ix .t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 70px; }
.sync-line { margin: 20px 0 0; padding-top: 12px; border-top: 1px solid #e3d7c1; font-size: 13px; color: var(--faint); line-height: 1.45; }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(5, 12, 10, .94); display: none; place-items: center; padding: 20px; cursor: zoom-out; }
.lightbox.open { display: grid; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(78px + var(--sb)); transform: translate(-50%, 16px); z-index: 60;
  background: #2a2320; color: var(--paper); padding: 11px 16px; border-radius: 12px; font-size: 14px; line-height: 1.4;
  max-width: min(92vw, 420px); width: max-content; text-align: center; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spin { position: absolute; inset: 0; display: none; place-items: center; background: rgba(244, 236, 221, .55); }
.busy .spin { display: grid; }
.spin::after { content: ""; width: 30px; height: 30px; border-radius: 50%; border: 3px solid rgba(0,0,0,.15); border-top-color: var(--c); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

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