/* ZURU Fuggler × Детский мир — demo mini app.
   Kraft-paper look per customer mockups: kraft bg, paper cells, pink/black accents,
   round red "ПОЙМАН" stamps. No frameworks. */

:root {
  --kraft: #c9b48c;
  --kraft-dark: #b49d74;
  --paper: #eee4cb;
  --paper-warm: #e6d8b8;
  --ink: #221d16;
  --pink: #e73278;
  --red: #c9163f;
  --green: #7cc400;
  --green-dark: #5e9900;
  --shadow: rgba(40, 28, 10, .35);
  --radius: 10px;
  --font-ui: 'Rubik', system-ui, -apple-system, sans-serif;
  --font-hand: 'Caveat', 'Comic Sans MS', cursive;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(ellipse at 30% 10%, rgba(255,255,255,.18), transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgba(60,40,10,.22), transparent 55%),
    var(--kraft);
  background-attachment: fixed;
  min-height: 100vh;
  padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)); /* room for tabbar + gesture bar */
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 2px 8px var(--shadow);
}
.topbar-title { display: flex; flex-direction: column; line-height: 1.1; }
.brand { font-weight: 900; letter-spacing: .08em; font-size: 15px; }
.sub { font-size: 11px; opacity: .75; letter-spacing: .04em; }
.mode-btn {
  font-family: var(--font-ui); font-weight: 700; font-size: 10px; letter-spacing: .06em;
  color: #fff; background: var(--pink); border: none; border-radius: 6px;
  padding: 7px 10px; cursor: pointer;
}
.mode-btn.admin { background: var(--green-dark); }

/* mode switching: live (Telegram, real API) vs demo (browser, mock) */
.demo-badge {
  display: none; background: var(--pink); color: #fff;
  font-size: 10px; font-weight: 900; letter-spacing: .08em;
  padding: 3px 8px; border-radius: 6px; margin-right: 8px; align-self: center;
}
body.demo .demo-badge { display: inline-block; }
body.live .demo-only { display: none; }

/* gate shown when opened outside Telegram */
body.gated .topbar, body.gated #app, body.gated .tabbar { display: none; }
.gate { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 22px; }
.gate.hidden { display: none; }
.gate-box {
  background: var(--paper-warm); border: 2px solid var(--ink); border-radius: 12px;
  box-shadow: 4px 5px 0 var(--shadow); padding: 22px 18px; max-width: 380px; text-align: center;
}
.gate-box h3 { font-size: 19px; font-weight: 900; margin: 10px 0 8px; }
.gate-box p { font-size: 14px; line-height: 1.5; margin-bottom: 16px; }
.gate-box .btn { display: block; text-decoration: none; color: var(--ink); }

.consent-row {
  display: flex; gap: 8px; align-items: flex-start; text-align: left;
  font-size: 12.5px; line-height: 1.35; margin: 10px 0 6px;
}
.consent-row input { margin-top: 2px; flex: 0 0 auto; }

.check-status {
  display: inline-block; margin-top: 6px; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 6px; background: #e6dcbf;
}
.check-status.pending { background: #f4e6b6; }
.check-status.rejected { background: #f6dfd9; color: var(--red); }

/* ---------- support screen ---------- */
.support-form {
  background: var(--paper-warm); border: 2px solid rgba(34,29,22,.5); border-radius: var(--radius);
  box-shadow: 3px 4px 0 var(--shadow); padding: 14px; margin-bottom: 16px;
}
.sf-label { display: block; font-size: 12px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; opacity: .7; margin: 4px 0 6px; }
.sf-kinds { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.sf-kinds .chip { font-size: 12px; }
.support-form textarea {
  width: 100%; border: 1.5px solid var(--ink); border-radius: 8px; padding: 10px;
  font-family: var(--font-ui); font-size: 14px; background: var(--paper); resize: vertical;
}
.sf-file-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 4px; flex-wrap: wrap; }
.sf-file-row .btn { margin-top: 0; }
.sf-file-name { font-size: 12px; opacity: .75; }
.sub-title { font-size: 15px; font-weight: 900; text-transform: uppercase;
  letter-spacing: .04em; margin: 4px 0 10px; }

.support-list { display: flex; flex-direction: column; gap: 10px; }
.support-item {
  background: var(--paper); border: 1.5px solid rgba(34,29,22,.35);
  border-radius: 8px; padding: 10px 12px;
}
.support-item.resolved { border-color: var(--green-dark); background: #eef5dd; }
.support-item.rejected { border-color: rgba(201,22,63,.6); }
.si-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.si-kind { font-weight: 700; font-size: 13px; }
.si-status { font-size: 11px; font-weight: 700; opacity: .8; white-space: nowrap; }
.si-msg { font-size: 13px; line-height: 1.45; margin: 6px 0 4px; white-space: pre-wrap; }
.si-clip { font-size: 11px; opacity: .7; margin-left: 6px; white-space: nowrap; }
.si-date { font-size: 11px; opacity: .6; }
.si-answer {
  margin-top: 8px; padding: 8px 10px; border-radius: 6px;
  background: #fff8e2; border: 1px solid rgba(34,29,22,.25);
  font-size: 13px; line-height: 1.45; white-space: pre-wrap;
}

/* ---------- screens ---------- */
/* bottom padding must live on the content box (body has height:100%, so its own
   padding does not push overflowing content above the fixed tabbar) */
#app { max-width: 480px; margin: 0 auto; padding: 14px 12px calc(110px + env(safe-area-inset-bottom, 0px)); }
.screen { display: none; animation: fadein .18s ease; }
.screen.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.screen-title {
  font-weight: 900; text-transform: uppercase; letter-spacing: .05em;
  font-size: 20px; margin: 4px 0 12px;
}

/* ---------- passport card ---------- */
.passport {
  background: var(--paper-warm);
  border: 2px solid rgba(34,29,22,.55);
  border-radius: var(--radius);
  box-shadow: 3px 4px 0 var(--shadow);
  padding: 14px 12px 16px;
  position: relative;
}
.passport::before { /* paper clip decor */
  content: "🖇"; position: absolute; top: -12px; right: 16px; font-size: 22px;
  transform: rotate(12deg);
}
.passport-head { text-align: center; margin-bottom: 10px; }
.wanted-tag {
  display: inline-block; background: var(--pink); color: #fff;
  font-weight: 900; font-size: 11px; letter-spacing: .12em;
  padding: 4px 10px; transform: rotate(-2deg); margin-bottom: 6px;
}
.passport-head h1 {
  font-size: 18px; font-weight: 900; text-transform: uppercase;
  letter-spacing: .04em; line-height: 1.25;
}

.card-picker { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0; }
.chip {
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink);
  font-family: var(--font-ui); font-weight: 700; font-size: 12px;
  border-radius: 999px; padding: 5px 12px; cursor: pointer;
}
.chip.active { background: var(--ink); color: #fff; }
.chip .chip-note { font-weight: 400; opacity: .7; }

.card-meta {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; margin: 4px 2px 10px;
}
.card-meta .card-id { font-weight: 700; letter-spacing: .04em; }
.card-meta .card-count { font-family: var(--font-hand); font-size: 18px; }

/* character grid: 8 cells (5 small, 2 big, 1 superboss) */
.char-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.cell {
  position: relative; aspect-ratio: 3 / 3.8;
  background: var(--paper);
  border: 1.5px dashed rgba(231,50,120,.75);
  border-radius: 6px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  overflow: hidden; padding-top: 10px;
}
.cell:nth-child(odd) { transform: rotate(-.6deg); }
.cell:nth-child(even) { transform: rotate(.5deg); }
.cell.tier-big { border-style: solid; border-width: 2px; background: #f2e6c4; }
.cell.tier-superboss {
  border: 2.5px solid var(--ink); background: #efdfb4;
  box-shadow: inset 0 0 0 2px rgba(231,50,120,.5);
}
.cell .num {
  position: absolute; top: 3px; left: 4px;
  background: var(--ink); color: #fff; font-size: 8px; font-weight: 700;
  padding: 1px 4px; letter-spacing: .05em;
}
.cell .cell-th {
  position: absolute; top: 3px; right: 4px;
  font-size: 8px; font-weight: 900; color: var(--ink); opacity: .65; letter-spacing: .02em;
}
.cell .placeholder {
  font-size: 7.5px; font-weight: 700; letter-spacing: .04em; color: var(--pink);
  text-align: center; text-transform: uppercase; opacity: .85; line-height: 1.5;
  padding: 0 3px;
}
.cell .placeholder::first-line { font-size: 17px; }
.cell.tier-superboss .placeholder { color: var(--ink); }

/* character photos in cells */
.cell.has-img { padding-top: 0; }
.cell .num, .cell .cell-th { z-index: 3; }
.cell.has-img .cell-th {
  background: rgba(238,228,203,.9); padding: 1px 4px; border-radius: 3px; opacity: 1;
}
.char-img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; z-index: 1;
}
.char-img.locked { filter: grayscale(1) contrast(.8); opacity: .3; }
.lock-q {
  position: relative; z-index: 2; font-weight: 900; font-size: 30px;
  color: var(--ink); opacity: .5;
}
.stamp-over {
  position: absolute; z-index: 2; width: 62%; left: 19%; bottom: 5%;
  background: rgba(238,228,203,.35);
}
.cell { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.grid-hint { text-align: center; font-size: 11px; opacity: .55; margin-top: 8px; }

/* ---------- character dossier ---------- */
.dossier-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.file-tag {
  background: var(--ink); color: #fff; font-weight: 900; font-size: 11px;
  letter-spacing: .1em; padding: 5px 9px;
}
.dossier-status {
  font-weight: 900; font-size: 12px; letter-spacing: .06em;
  padding: 4px 9px; border: 2px solid; transform: rotate(2deg);
}
.dossier-status.caught { color: var(--red); border-color: var(--red); }
.dossier-status.wanted { color: var(--ink); border-color: var(--ink); border-style: dashed; }
.dossier-photo {
  position: relative; width: 68%; margin: 0 auto 12px; aspect-ratio: 3 / 4;
  border: 2px solid var(--ink); border-radius: 8px; overflow: hidden;
  box-shadow: 3px 4px 0 var(--shadow); background: var(--paper);
}
.dossier-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dossier-photo.locked img { filter: grayscale(1) contrast(.85); opacity: .45; }
.dossier-photo .stamp-over { width: 68%; left: 16%; bottom: 7%; }
.wanted-plate {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(-8deg);
  border: 2.5px dashed var(--ink); color: var(--ink); font-weight: 900;
  font-size: 15px; letter-spacing: .12em; padding: 6px 12px; white-space: nowrap;
  background: rgba(238,228,203,.8);
}
#dossier-box h3 { margin: 2px 0 2px; }
.tier-line { font-size: 12px; opacity: .65; margin-bottom: 10px; }
.dossier-traits {
  text-align: left; background: var(--paper);
  border: 1.5px dashed rgba(34,29,22,.4); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 10px;
}
.traits-title {
  font-weight: 900; font-size: 11px; letter-spacing: .06em;
  text-transform: uppercase; margin-bottom: 6px;
}
.dossier-traits ul { list-style: none; margin: 0; padding: 0; }
.dossier-traits li { font-size: 13.5px; line-height: 1.65; }
.redact {
  background: var(--ink); color: transparent; border-radius: 2px;
  padding: 0 3px; user-select: none;
}
#dossier-box .status-line { text-align: left; margin-bottom: 12px; }

/* the ПОЙМАН stamp */
.stamp {
  width: 86%; aspect-ratio: 1; border-radius: 50%;
  border: 2.5px solid var(--red);
  box-shadow: inset 0 0 0 1.5px var(--red);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--red); transform: rotate(-14deg);
  animation: stamp-in .3s cubic-bezier(.2, 2.2, .5, 1);
  background:
    radial-gradient(circle at 32% 28%, rgba(201,22,63,.12), transparent 55%),
    radial-gradient(circle at 70% 74%, rgba(201,22,63,.10), transparent 50%);
}
.cell:nth-child(3n) .stamp { transform: rotate(9deg); }
.cell:nth-child(4n) .stamp { transform: rotate(-5deg); }
.stamp .t1 { font-weight: 900; font-size: 11px; letter-spacing: .04em; }
.stamp .t2 { font-size: 6px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
@keyframes stamp-in { from { transform: scale(2.2) rotate(-30deg); opacity: 0; } }

/* card status block */
.card-status { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.status-line {
  background: var(--paper); border: 1.5px solid rgba(34,29,22,.35);
  border-radius: 8px; padding: 9px 10px; font-size: 13px; line-height: 1.35;
}
.status-line.ok { border-color: var(--green-dark); background: #e8f3cf; }
.status-line.done { border-color: var(--ink); background: #ddd3bb; }
.status-line b { font-weight: 700; }
.progressbar {
  height: 8px; background: rgba(34,29,22,.15); border-radius: 999px; overflow: hidden; margin-top: 6px;
}
.progressbar > div { height: 100%; background: var(--pink); border-radius: 999px; transition: width .4s ease; }

/* ---------- buttons ---------- */
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.btn {
  font-family: var(--font-ui); font-weight: 700; font-size: 14px;
  border: 2px solid var(--ink); border-radius: 10px;
  padding: 12px 14px; cursor: pointer; width: 100%;
  box-shadow: 2px 3px 0 var(--shadow);
  transition: transform .06s ease;
}
.btn:active { transform: translate(1px, 2px); box-shadow: none; }
.btn-primary { background: var(--green); color: var(--ink); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: none; border-style: dashed; }
.btn-small { font-size: 12px; padding: 8px 10px; width: auto; margin-top: 10px; }
.btn-inline { width: 100%; margin-top: 8px; font-size: 13px; padding: 10px 12px; }
.btn-mini {
  width: auto; font-size: 11px; padding: 5px 9px; margin-top: 7px;
  box-shadow: none; border-width: 1.5px;
}
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- checks screen ---------- */
.checks-summary {
  background: var(--paper-warm); border: 2px solid rgba(34,29,22,.5); border-radius: var(--radius);
  box-shadow: 3px 4px 0 var(--shadow); padding: 12px; font-size: 13px; margin-bottom: 12px;
}
.checks-summary .big { font-size: 22px; font-weight: 900; }
.checks-list { display: flex; flex-direction: column; gap: 8px; }
.check-item {
  background: var(--paper); border: 1.5px solid rgba(34,29,22,.35); border-radius: 8px;
  padding: 10px 12px; font-size: 12px; line-height: 1.45;
}
.check-item .row1 { display: flex; justify-content: space-between; font-weight: 700; font-size: 13px; }
.check-item .stamps-gain { color: var(--red); font-weight: 900; }
.check-item .muted { opacity: .65; }
.check-item.refunded { opacity: .55; }
.check-item.refunded .row1 { text-decoration: line-through; }
.check-item.refunded .stamps-gain { text-decoration: none; }
.empty-note { text-align: center; opacity: .6; font-size: 13px; padding: 30px 10px; }

/* ---------- info screen ---------- */
.paper-note {
  background: var(--paper-warm); border: 2px solid rgba(34,29,22,.5); border-radius: var(--radius);
  box-shadow: 3px 4px 0 var(--shadow); padding: 14px; font-size: 14px; line-height: 1.5;
  margin-bottom: 12px;
}
.paper-note p + p { margin-top: 8px; }
.rule-step { display: flex; gap: 10px; margin-bottom: 10px; align-items: flex-start; }
.rule-step .n {
  flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--pink); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 13px;
}
.rule-step .txt { font-size: 13.5px; line-height: 1.45; padding-top: 3px; }
.dates-note { font-size: 12px; opacity: .7; margin: 8px 0 4px; }

/* ---------- admin screen ---------- */
.admin-local { margin-top: 14px; }
.admin-result { margin-top: 14px; }
.admin-card {
  background: var(--paper-warm); border: 2px solid rgba(34,29,22,.5); border-radius: var(--radius);
  box-shadow: 3px 4px 0 var(--shadow); padding: 14px;
}
.admin-card h4 { font-size: 15px; margin-bottom: 8px; letter-spacing: .03em; }
.admin-row { display: flex; justify-content: space-between; font-size: 13.5px; padding: 5px 0; border-bottom: 1px dashed rgba(34,29,22,.25); }
.admin-row:last-of-type { border-bottom: none; }
.verdict { margin-top: 10px; border-radius: 8px; padding: 10px 12px; font-size: 14px; font-weight: 700; }
.verdict.ok { background: #e8f3cf; border: 2px solid var(--green-dark); }
.verdict.no { background: #f6dfd9; border: 2px solid var(--red); color: var(--red); }
.verdict.done { background: #ddd3bb; border: 2px solid var(--ink); }
.issued-stamp {
  margin: 12px auto 2px; width: 130px; height: 130px; border-radius: 50%;
  border: 3px solid var(--red); box-shadow: inset 0 0 0 2px var(--red);
  color: var(--red); display: flex; flex-direction: column; align-items: center; justify-content: center;
  transform: rotate(-12deg); animation: stamp-in .35s cubic-bezier(.2, 2.2, .5, 1);
  font-weight: 900; font-size: 18px; letter-spacing: .05em;
}
.issued-stamp small { font-size: 9px; letter-spacing: .1em; font-weight: 700; }

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--ink);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 8px var(--shadow);
}
.tab {
  flex: 1; background: none; border: none; color: rgba(255,255,255,.6);
  font-family: var(--font-ui); font-size: 17px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 0;
  border-radius: 8px;
}
.tab span { font-size: 9.5px; font-weight: 700; letter-spacing: .04em; }
.tab.active { color: #fff; background: rgba(231,50,120,.25); }
.tabbar.hidden { display: none; }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 14, 6, .6); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--paper-warm); border: 2px solid var(--ink); border-radius: 12px;
  box-shadow: 4px 5px 0 rgba(0,0,0,.4);
  width: 100%; max-width: 400px; max-height: 86vh; overflow-y: auto;
  padding: 18px 16px; text-align: center;
}
.modal-box h3 { font-size: 17px; font-weight: 900; letter-spacing: .02em; margin-bottom: 10px; }
.hint { font-size: 12px; opacity: .65; margin: 6px 0; line-height: 1.4; }

.video-wrap { position: relative; border-radius: 10px; overflow: hidden; background: #000; margin: 10px 0; }
#scanner-video { width: 100%; display: block; max-height: 46vh; object-fit: cover; }
.video-frame {
  position: absolute; inset: 12%; border: 2px solid rgba(124,196,0,.9); border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.25); pointer-events: none;
}
.scanner-error { color: var(--red); font-size: 13px; font-weight: 700; margin: 8px 0; }
.manual-input { text-align: left; margin: 10px 0; font-size: 13px; }
.manual-input summary { cursor: pointer; font-weight: 700; opacity: .75; }
.manual-input textarea {
  width: 100%; margin-top: 8px; border: 1.5px solid var(--ink); border-radius: 8px;
  padding: 8px; font-family: monospace; font-size: 11px; background: var(--paper);
}

/* delivery form + admin shipping */
.form-fields { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.form-fields input, .form-fields textarea {
  width: 100%; border: 1.5px solid var(--ink); border-radius: 8px;
  padding: 10px; font-family: var(--font-ui); font-size: 14px; background: var(--paper);
}
.ship-form { display: flex; gap: 8px; margin-top: 10px; align-items: stretch; }
.ship-form .track-input {
  flex: 1; border: 1.5px solid var(--ink); border-radius: 8px;
  padding: 8px 10px; font-family: monospace; font-size: 13px; background: var(--paper);
}
.ship-form .btn { margin-top: 0; }
.admin-card + .admin-card, #admin-list .admin-card { margin-top: 10px; }
.muted-line { font-weight: 400; opacity: .7; font-size: 12px; }

/* result modal */
.result-emoji { font-size: 44px; margin-bottom: 6px; }
.result-sums { text-align: left; font-size: 13.5px; margin: 10px 0; }
.result-sums .admin-row b { font-weight: 900; }
.gain-line { font-size: 17px; font-weight: 900; color: var(--red); margin: 8px 0; }

/* onboarding */
.onboarding-steps { text-align: left; margin: 12px 0 16px; padding-left: 0; list-style: none; }
.onboarding-steps li { display: flex; gap: 10px; margin-bottom: 10px; font-size: 13.5px; line-height: 1.45; }
.onboarding-steps .n {
  flex: 0 0 24px; height: 24px; border-radius: 50%; background: var(--pink); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 12px;
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%);
  background: var(--ink); color: #fff; font-size: 13px; font-weight: 500;
  padding: 10px 16px; border-radius: 999px; z-index: 60; max-width: 88vw;
  box-shadow: 0 4px 14px rgba(0,0,0,.4); text-align: center;
  animation: fadein .2s ease;
}
.toast.hidden { display: none; }
