/* ============================================================
   MetaSnap — visual identity
   Warm paper & ink, one amber accent. An original identity —
   no visual language borrowed from any other product.
   ============================================================ */

:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #efece6;
  --ink: #191613;
  --muted: #7d776c;
  --line: rgba(25, 22, 19, 0.09);
  --accent: #e08a00;
  --accent-soft: rgba(224, 138, 0, 0.14);
  --cta-bg: #191613;
  --cta-fg: #fffdf9;
  --ok: #219653;
  --ok-soft: rgba(33, 150, 83, 0.14);
  --danger: #d14b3d;
  --danger-soft: rgba(209, 75, 61, 0.12);
  --shadow: 0 10px 30px rgba(25, 22, 19, 0.10);
  --radius: 20px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --safe-top: var(--tg-content-safe-area-inset-top, var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)));
  --safe-bottom: var(--tg-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}

.theme-dark {
  --bg: #131110;
  --surface: #1d1a18;
  --surface-2: #262220;
  --ink: #f4f1ea;
  --muted: #a09a8d;
  --line: rgba(244, 241, 234, 0.10);
  --accent: #f2a93b;
  --accent-soft: rgba(242, 169, 59, 0.16);
  --cta-bg: #f4f1ea;
  --cta-fg: #191613;
  --ok: #3fbf7f;
  --ok-soft: rgba(63, 191, 127, 0.16);
  --danger: #e5695c;
  --danger-soft: rgba(229, 105, 92, 0.15);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* The hidden attribute must always win, even over author display rules
   (.screen/.viewer set display:flex, which would otherwise override it). */
[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior-y: none;
  transition: background 0.25s ease, color 0.25s ease;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 20px calc(var(--safe-bottom) + 20px);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 6px;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
}

.mark { width: 27px; height: 27px; }
.mark-tile { fill: var(--cta-bg); }
.mark-ring { stroke: var(--accent); }
.mark-dot { fill: var(--accent); }

.avatar-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  transition: transform 0.15s var(--ease);
}
.avatar-btn:active { transform: scale(0.92); }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Screens ---------- */
.stage { flex: 1; display: flex; flex-direction: column; }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  animation: screenIn 0.3s var(--ease);
}

.screen-center { justify-content: center; align-items: center; gap: 22px; }

@keyframes screenIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Home ---------- */
.hero { text-align: center; padding: 7vh 4px 26px; }

.hero h1 {
  font-size: 31px;
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.14;
}

.hero-sub {
  color: var(--muted);
  font-size: 15px;
  margin-top: 10px;
}

.select-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1.5px dashed var(--line);
  border-radius: 28px;
  padding: 34px 20px 30px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  box-shadow: var(--shadow);
  transition: transform 0.18s var(--ease), border-color 0.18s;
}
.select-zone:active { transform: scale(0.98); border-color: var(--accent); }

.select-zone-art svg { width: 64px; height: 64px; margin-bottom: 8px; }
.sz-tile { fill: var(--surface-2); }
.sz-ring { stroke: var(--accent); }
.sz-dot { fill: var(--accent); }

.select-zone-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.select-zone-hint { font-size: 13px; color: var(--muted); }

.privacy-note {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-top: 18px;
}

.footer-links {
  margin-top: auto;
  padding-top: 26px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}
.footer-links i { font-style: normal; opacity: 0.5; }
.footer-links button {
  background: none;
  border: none;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 2px;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 999px;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding: 16px 22px;
  cursor: pointer;
  width: 100%;
  transition: transform 0.15s var(--ease), opacity 0.15s, background 0.2s;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary {
  background: var(--cta-bg);
  color: var(--cta-fg);
  box-shadow: 0 8px 22px rgba(25, 22, 19, 0.22);
  margin-top: 18px;
}
.theme-dark .btn-primary { box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4); }

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--line);
}

.btn-ghost {
  background: none;
  color: var(--muted);
  font-weight: 600;
}

.btn-star {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- Review / grids ---------- */
.screen-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0 16px;
}
.screen-head h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }

.back-btn {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 17px;
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s var(--ease);
}
.back-btn:active { transform: scale(0.9); }

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  align-content: start;
}

.thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface-2);
  animation: thumbIn 0.25s var(--ease);
}
@keyframes thumbIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.thumb-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-meta {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 8px 6px;
  font-size: 10.5px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

.thumb-add {
  aspect-ratio: 3 / 4;
  border-radius: 14px;
  border: 1.5px dashed var(--line);
  background: none;
  color: var(--muted);
  font-size: 26px;
  cursor: pointer;
  transition: transform 0.15s var(--ease);
}
.thumb-add:active { transform: scale(0.95); }

.thumb-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.thumb.is-failed img { opacity: 0.35; }
.thumb.is-failed .thumb-state {
  background: var(--danger-soft);
  color: var(--danger);
}
.thumb-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.55);
  color: #7ee2a8;
  border-radius: 999px;
  font-size: 11px;
  padding: 3px 7px;
  pointer-events: none;
}

.screen-foot {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.screen-foot .btn-primary { margin-top: 0; }

/* ---------- Progress ---------- */
.ring-wrap { position: relative; width: 150px; height: 150px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-track { fill: none; stroke: var(--surface-2); stroke-width: 9; }
.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 0.35s var(--ease);
}
.ring-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.ring-label strong { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.ring-label span { font-size: 12px; color: var(--muted); }

/* ---------- Result ---------- */
.result-head { text-align: center; padding: 3vh 0 20px; }

.check-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: var(--ok-soft);
  color: var(--ok);
  margin-bottom: 14px;
  animation: pop 0.45s var(--ease);
}
.check-circle svg { width: 30px; height: 30px; }
.check-circle.is-partial { background: var(--accent-soft); color: var(--accent); }

@keyframes pop {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); opacity: 1; }
}

.result-head h2 { font-size: 25px; font-weight: 800; letter-spacing: -0.03em; }
.result-sub { color: var(--muted); font-size: 14px; margin-top: 6px; }

.result-grid .thumb { cursor: pointer; }

/* ---------- Android save fallback (no native File share) ---------- */
/* Telegram for Android: keep images out of the webview's long-press menu —
   its Download / Open-in-browser actions fail for blob: images. Taps still
   reach the parent .thumb / viewer controls. */
body.plat-android .thumb img,
body.plat-android .viewer img { pointer-events: none; }

.browser-note {
  margin: 10px auto 0;
  max-width: 320px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.small { font-size: 12.5px; }

/* Android save chooser: option buttons with a caption */
.option-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  width: 100%;
  margin-top: 10px;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.option-btn:active { transform: scale(0.98); border-color: var(--accent); }
.option-title { font-size: 15.5px; font-weight: 700; }
.option-caption { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.secure-status {
  margin: 10px 0 2px;
  text-align: center;
  font-size: 13px;
  color: var(--text);
}

/* Development diagnostic panel (local only) */
.diag {
  margin-top: 18px;
  padding: 12px;
  border-radius: 14px;
  background: var(--surface-2);
}
.diag pre {
  margin: 0;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: text;
  -webkit-user-select: text;
}
.diag-actions { display: flex; gap: 8px; margin-top: 10px; }
.diag-actions .btn { flex: 1; margin: 0; }
.sheet .privacy-note { margin: 4px 0 12px; }

.support-card {
  margin-top: 26px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}
.support-card p { font-size: 14px; color: var(--muted); }
.support-card p strong { color: var(--ink); font-size: 15px; }
.support-card-actions {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ---------- Viewer ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(10, 9, 8, 0.96);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
}
.viewer img {
  max-width: 100%;
  max-height: 78vh;
  border-radius: 12px;
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-touch-callout: default;
}
.viewer-hint { color: rgba(255, 255, 255, 0.75); font-size: 13.5px; }
.btn-viewer-save {
  background: #f4f1ea;
  color: #191613;
  width: auto;
  padding: 13px 34px;
}
.viewer-close {
  position: absolute;
  top: calc(var(--safe-top) + 14px);
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

/* ---------- Sheets ---------- */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 13, 11, 0.45);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  padding: 10px 22px calc(var(--safe-bottom) + 22px);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.25);
  animation: sheetIn 0.3s var(--ease);
  max-height: 86dvh;
  overflow-y: auto;
}
@keyframes sheetIn {
  from { transform: translateY(40%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-grab {
  width: 38px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 4px auto 16px;
}

.sheet-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-align: center;
  margin-bottom: 8px;
}

.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }

.profile-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 16px;
}
.profile-row h3 { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }

.avatar-lg {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 19px;
  color: var(--muted);
  flex-shrink: 0;
}
.avatar-lg img { width: 100%; height: 100%; object-fit: cover; }

.stat-rows {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 16px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  font-size: 14.5px;
}
.stat-row + .stat-row { border-top: 1.5px solid var(--line); }
.stat-row span { color: var(--muted); }
.stat-row strong { font-weight: 700; }

.sheet-actions { display: flex; flex-direction: column; gap: 8px; }

.tier-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 18px 0 10px;
}
.tier-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 15px 18px;
  font: inherit;
  font-size: 15.5px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.15s var(--ease), border-color 0.15s;
}
.tier-btn:active { transform: scale(0.98); border-color: var(--accent); }
.tier-btn.is-default { border-color: var(--accent); background: var(--accent-soft); }
.tier-btn .stars { color: var(--accent); font-weight: 800; }

.thanks-heart { text-align: center; font-size: 44px; padding: 8px 0 10px; }
.thanks-stars {
  text-align: center;
  font-size: 19px;
  font-weight: 800;
  color: var(--accent);
  margin: 12px 0 18px;
}

.info-body {
  font-size: 14.5px;
  color: var(--ink);
  line-height: 1.6;
  padding-bottom: 18px;
  user-select: text;
  -webkit-user-select: text;
}
.info-body p { margin-bottom: 12px; }
.info-body .muted { font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 26px);
  transform: translateX(-50%);
  z-index: 70;
  background: var(--cta-bg);
  color: var(--cta-fg);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 13.5px;
  font-weight: 600;
  max-width: 88vw;
  text-align: center;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s var(--ease);
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
