:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --card: rgba(255, 255, 255, 0.96);
  --text: #152033;
  --muted: #68758a;
  --line: #dce3ee;
  --primary: #0b63ce;
  --primary-dark: #084faa;
  --primary-soft: #eaf3ff;
  --success: #147a48;
  --danger: #b42318;
  --shadow: 0 12px 34px rgba(25, 47, 79, 0.10);
  --radius: 22px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 14% -4%, rgba(11, 99, 206, 0.12), transparent 32%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font: inherit; }
button { touch-action: manipulation; }

.app-shell {
  width: min(100%, 620px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(26px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 4px 18px;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(27px, 7vw, 36px); letter-spacing: -0.035em; }
h2 { margin-bottom: 8px; font-size: clamp(23px, 6vw, 30px); letter-spacing: -0.025em; }
.eyebrow { margin-bottom: 4px; color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.muted { color: var(--muted); line-height: 1.55; }
.center { text-align: center; }
.hidden { display: none !important; }

.local-badge, .status-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  border: 1px solid #cce7d8;
  border-radius: 999px;
  background: #edf9f2;
  color: var(--success);
  padding: 8px 11px;
  font-size: 12px;
  font-weight: 750;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #20a260; box-shadow: 0 0 0 4px rgba(32, 162, 96, 0.12); }

.card {
  border: 1px solid rgba(205, 216, 232, 0.9);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.hero-card { padding: 32px 22px 24px; text-align: center; }
.hero-icon {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  margin: 0 auto 20px;
  border-radius: 24px;
  background: linear-gradient(145deg, #edf5ff, #dfeeff);
  color: var(--primary);
}
.hero-icon svg { width: 48px; height: 48px; }
.privacy-note { margin: 18px 0 0; color: #7a8798; font-size: 12px; line-height: 1.45; }

.button {
  min-height: 48px;
  border: 0;
  border-radius: 15px;
  padding: 12px 17px;
  font-weight: 760;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease, background .12s ease;
}
.button:active { transform: scale(.985); }
.button:disabled { opacity: .56; cursor: default; }
.button.primary { background: var(--primary); color: #fff; box-shadow: 0 9px 22px rgba(11, 99, 206, .24); }
.button.primary:active { background: var(--primary-dark); }
.button.secondary { border: 1px solid #cbd8ea; background: #fff; color: #2c405f; }
.button.text-button { background: transparent; color: var(--primary); box-shadow: none; }
.button.large { width: 100%; min-height: 58px; font-size: 17px; }
.button.small { min-height: 40px; padding: 8px 10px; }
.button.full { width: 100%; margin-top: 10px; }
.hero-card .button.primary { margin-top: 12px; }

#processingView, #errorView { padding: 34px 22px; text-align: center; }
.spinner {
  width: 48px;
  height: 48px;
  margin: 0 auto 20px;
  border: 4px solid #dceafb;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 4px 4px 10px; }
.preview-frame { padding: 10px; overflow: hidden; }
#resultImage {
  display: block;
  width: 100%;
  height: auto;
  max-height: 64dvh;
  object-fit: contain;
  border-radius: 14px;
  background: repeating-conic-gradient(#eef1f5 0 25%, #fff 0 50%) 50% / 16px 16px;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
  -webkit-user-drag: auto;
}
.long-press-tip {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 10px 2px 0;
  padding: 12px 14px;
  border: 1px solid #cbd8ea;
  border-radius: 15px;
  background: #f8fbff;
  color: #2c405f;
}
.long-press-tip .press-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 20px;
  font-weight: 850;
}
.long-press-tip strong { display: block; font-size: 14px; }
.long-press-tip p { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.result-meta.compact { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-top: 12px; overflow: hidden; box-shadow: none; }
.result-meta > div { display: flex; flex-direction: column; gap: 3px; padding: 13px 14px; background: #fff; }
.result-meta > div:first-child { border-right: 1px solid var(--line); }
.result-meta span { color: var(--muted); font-size: 12px; }
.result-meta strong { font-size: 14px; }
.sticky-action { margin-top: 14px; }
.secondary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
#resultMessage { margin: 12px 4px 0; font-size: 12px; }

.editor-card { padding: 8px; overflow: hidden; }
.editor-stage { position: relative; width: 100%; overflow: hidden; border-radius: 16px; background: #111; touch-action: none; user-select: none; }
.editor-stage img { display: block; width: 100%; height: auto; pointer-events: none; }
.crop-shade { position: absolute; background: rgba(0, 0, 0, .55); pointer-events: none; }
.crop-rect { position: absolute; border: 2px solid #35a1ff; box-shadow: 0 0 0 1px rgba(255,255,255,.85) inset; cursor: move; }
.handle { position: absolute; display: block; width: 24px; height: 24px; }
.handle::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: #fff; border: 2px solid #1689ed; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.handle.n { left: 50%; top: -12px; transform: translateX(-50%); }
.handle.s { left: 50%; bottom: -12px; transform: translateX(-50%); }
.handle.e { top: 50%; right: -12px; transform: translateY(-50%); }
.handle.w { top: 50%; left: -12px; transform: translateY(-50%); }
.handle.nw { left: -12px; top: -12px; }
.handle.ne { right: -12px; top: -12px; }
.handle.se { right: -12px; bottom: -12px; }
.handle.sw { left: -12px; bottom: -12px; }

.fine-controls { margin-top: 12px; padding: 0 15px; box-shadow: none; }
.fine-controls summary { padding: 15px 0; font-weight: 740; cursor: pointer; }
.nudge-grid { display: grid; gap: 10px; padding: 0 0 15px; }
.nudge-row { display: grid; grid-template-columns: 58px repeat(4, 1fr); gap: 6px; align-items: center; }
.nudge-row > span { color: var(--muted); font-size: 13px; }
.nudge-row button { min-height: 38px; border: 1px solid #d4deeb; border-radius: 10px; background: #f8fbff; color: #284461; font-size: 12px; font-weight: 700; }

.banner { margin-bottom: 12px; padding: 12px 14px; border-radius: 14px; font-size: 14px; font-weight: 700; }
.banner.success { border: 1px solid #b9e2ca; background: #ebf8f0; color: var(--success); }
.error-icon { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto 18px; border-radius: 50%; background: #fff0ee; color: var(--danger); font-size: 25px; font-weight: 900; }
#errorView .button { width: 100%; margin-top: 10px; }

footer { display: flex; justify-content: space-between; gap: 12px; padding: 22px 4px 0; color: #8994a4; font-size: 11px; }

@media (min-width: 700px) {
  .app-shell { padding-left: 22px; padding-right: 22px; }
  .hero-card { padding: 42px 34px 30px; }
}

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