:root {
  --canvas: #f3f5f7;
  --surface: #ffffff;
  --surface-subtle: #f7f8fa;
  --surface-strong: #e9edf1;
  --text: #171a1f;
  --muted: #69717d;
  --muted-strong: #4c5562;
  --line: #dce1e6;
  --line-strong: #c8d0d8;
  --primary: #18794e;
  --primary-hover: #11643f;
  --primary-soft: #e8f4ed;
  --info: #2463a6;
  --info-soft: #eaf2fb;
  --warning: #a95b10;
  --warning-soft: #fff3e4;
  --danger: #b42318;
  --danger-soft: #fef0ee;
  --camera: #080b0e;
  --camera-raised: #11161b;
  --camera-text: #f7f9fb;
  --shadow: 0 16px 44px rgba(20, 28, 36, 0.09);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html {
  min-width: 320px;
  color-scheme: light;
  background: var(--canvas);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  color: var(--text);
  font-family: var(--font);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  outline: none;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(36, 99, 166, 0.3);
  outline-offset: 2px;
}

svg {
  display: block;
}

/* Mode picker */
.landing-page {
  background: var(--canvas);
}

.launch-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 24px max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.launch-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.app-identity {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #ffffff;
  background: #1e252c;
  box-shadow: 0 7px 18px rgba(23, 26, 31, 0.16);
}

.app-mark svg {
  width: 23px;
  height: 23px;
}

.app-name,
.app-meta {
  margin: 0;
}

.app-name {
  font-size: 15px;
  line-height: 1.35;
  font-weight: 720;
}

.app-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.privacy-chip {
  min-height: 30px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid #c9dfd2;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 650;
}

.privacy-chip svg {
  width: 15px;
  height: 15px;
}

.mode-picker {
  width: 100%;
  margin: auto 0;
  padding: clamp(52px, 10vh, 92px) 0;
}

.mode-heading {
  margin-bottom: 24px;
}

.section-label {
  margin: 0 0 7px;
  color: var(--primary);
  font-size: 13px;
  line-height: 1.4;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(32px, 8vw, 42px);
  line-height: 1.14;
  font-weight: 760;
}

.brand-promises {
  margin-top: 14px;
  display: grid;
  gap: 5px;
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.55;
  font-weight: 600;
}

.brand-promises p {
  margin: 0;
}

.mode-list {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mode-option {
  min-height: 96px;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 22px;
  align-items: center;
  gap: 15px;
  padding: 18px;
  color: var(--text);
  text-decoration: none;
  transition: background-color 180ms ease;
}

.mode-option + .mode-option {
  border-top: 1px solid var(--line);
}

.mode-option:hover {
  background: var(--surface-subtle);
}

.mode-option:active {
  background: var(--surface-strong);
}

.mode-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
}

.mode-icon svg {
  width: 25px;
  height: 25px;
}

.mode-icon-camera {
  color: var(--primary);
  background: var(--primary-soft);
}

.mode-icon-screen {
  color: var(--info);
  background: var(--info-soft);
}

.mode-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mode-copy strong {
  font-size: 17px;
  line-height: 1.35;
  font-weight: 720;
}

.mode-copy span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.mode-arrow {
  width: 20px;
  height: 20px;
  color: #8a939f;
  transition: color 180ms ease, transform 180ms ease;
}

.mode-option:hover .mode-arrow {
  color: var(--text);
  transform: translateX(2px);
}

.home-link {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--muted-strong);
  background: transparent;
  font-size: 14px;
  line-height: 1.4;
  font-weight: 650;
  text-decoration: none;
  transition: color 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.home-link svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.home-link:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.home-link:active {
  background: #dceee4;
}

.usage-guide {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.usage-guide-heading {
  display: flex;
  align-items: center;
  gap: 9px;
}

.usage-guide-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--info);
  background: var(--info-soft);
}

.usage-guide-icon svg {
  width: 17px;
  height: 17px;
}

.usage-guide h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.4;
  font-weight: 720;
}

.usage-guide-content {
  margin-top: 12px;
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.8;
  white-space: pre-line;
}

.launch-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

/* Scanner */
.scanner-page {
  background: var(--canvas);
}

.scanner-shell {
  width: min(100%, 1180px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
}

.app-bar {
  min-height: 64px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  background: var(--surface-subtle);
  transition: color 180ms ease, background-color 180ms ease;
}

.icon-button:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

.icon-button svg {
  width: 21px;
  height: 21px;
}

.app-bar-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.app-bar-title strong {
  overflow: hidden;
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
  font-weight: 720;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.app-bar-title span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.scanner-layout {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 18px;
  align-items: start;
}

.capture-panel {
  min-width: 0;
}

.scanner-frame {
  position: relative;
  width: 100%;
  max-height: min(70svh, 650px);
  aspect-ratio: 4 / 3;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #242b32;
  border-radius: 8px;
  color: var(--camera-text);
  background: var(--camera);
  box-shadow: 0 14px 34px rgba(8, 11, 14, 0.18);
}

.screen-frame {
  aspect-ratio: 16 / 10;
}

.scanner-frame video {
  position: relative;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  background: var(--camera);
}

.screen-frame video {
  object-fit: contain;
}

.scanner-placeholder {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: #8d99a5;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.scanner-placeholder svg {
  width: 42px;
  height: 42px;
}

.scanner-placeholder span {
  font-size: 13px;
  font-weight: 600;
}

.scanner-frame.is-scanning .scanner-placeholder {
  opacity: 0;
  visibility: hidden;
}

.scan-mask {
  pointer-events: none;
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: min(62%, 320px);
  aspect-ratio: 1;
  border: 2px solid rgba(255, 255, 255, 0.76);
  border-radius: 8px;
  box-shadow: 0 0 0 999px rgba(3, 6, 8, 0.24);
  transform: translate(-50%, -50%);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.scan-mask::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  top: 8px;
  height: 2px;
  display: none;
  border-radius: 2px;
  background: #4ade80;
  box-shadow: 0 0 10px rgba(74, 222, 128, 0.72);
}

.scanner-frame.is-scanning .scan-mask::after {
  display: block;
  animation: scan-line 2.2s ease-in-out infinite;
}

.scanner-frame.has-update .scan-mask {
  border-color: #4ade80;
  box-shadow: 0 0 0 999px rgba(3, 6, 8, 0.2), 0 0 0 4px rgba(74, 222, 128, 0.2);
}

.scanner-hud {
  position: absolute;
  z-index: 4;
  inset: 12px 12px auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.camera-state,
.preview-index {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 6px 9px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(8, 11, 14, 0.76);
  backdrop-filter: blur(10px);
  font-size: 12px;
  line-height: 1.3;
  font-weight: 650;
}

.camera-state {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.camera-state::before {
  content: "";
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  margin-right: 7px;
  border-radius: 50%;
  background: #89939e;
}

.scanner-frame.is-scanning .camera-state::before {
  background: #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.16);
}

.preview-index {
  flex: 0 0 auto;
  color: #ffffff;
  background: rgba(36, 99, 166, 0.84);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
}

.scan-update-flash {
  pointer-events: none;
  position: absolute;
  z-index: 3;
  inset: 0;
  opacity: 0;
  border: 3px solid rgba(74, 222, 128, 0.88);
}

.scan-update-flash.is-visible {
  animation: update-flash 900ms ease-out;
}

.controls {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

button {
  min-width: 0;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #ffffff;
  background: var(--primary);
  font-size: 14px;
  line-height: 1.4;
  font-weight: 700;
  cursor: pointer;
  transition: color 180ms ease, background-color 180ms ease, border-color 180ms ease, opacity 180ms ease;
}

button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

button:hover:not(:disabled) {
  background: var(--primary-hover);
}

button.secondary {
  border-color: var(--line-strong);
  color: var(--text);
  background: var(--surface);
}

button.secondary:hover:not(:disabled) {
  background: var(--surface-strong);
}

button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.capture-note {
  margin: 12px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.capture-note svg {
  width: 15px;
  height: 15px;
  color: var(--primary);
}

.result-panel {
  position: sticky;
  top: max(20px, env(safe-area-inset-top));
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 10px 26px rgba(20, 28, 36, 0.06);
}

.result-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.result-kicker {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  font-weight: 650;
}

.result-heading h2 {
  margin: 0;
  color: var(--text);
  font-size: 24px;
  line-height: 1.2;
  font-weight: 760;
}

.result-time {
  padding-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
}

.update-notice {
  margin: 14px 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted-strong);
  background: var(--surface-subtle);
  font-size: 13px;
  line-height: 1.45;
  font-weight: 650;
}

.result-preview {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.result-preview-body {
  padding: 0 0 12px;
}

.result-preview-body[hidden] {
  display: none !important;
}

label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  font-weight: 600;
}

textarea {
  width: 100%;
  min-height: 112px;
  resize: vertical;
  display: block;
  padding: 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
  color: var(--text);
  background: var(--surface-subtle);
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  word-break: break-all;
}

textarea:focus {
  border-color: var(--info);
}

.status {
  min-height: 40px;
  margin: 13px 0;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.status[data-type="success"] {
  color: var(--primary);
}

.status[data-type="warning"] {
  color: var(--warning);
}

.status[data-type="error"] {
  color: var(--danger);
}

.result-column > #copyBtn {
  width: 100%;
}

@keyframes scan-line {
  0%, 100% { top: 8px; opacity: 0.5; }
  50% { top: calc(100% - 10px); opacity: 1; }
}

@keyframes update-flash {
  0% { opacity: 0; }
  18% { opacity: 1; }
  100% { opacity: 0; }
}

@media (max-width: 820px) {
  .scanner-shell {
    width: min(100%, 620px);
  }

  .scanner-layout {
    grid-template-columns: 1fr;
  }

  .result-panel {
    position: static;
  }
}

@media (max-width: 640px) {
  .launch-shell {
    padding-right: 18px;
    padding-left: 18px;
  }

  .privacy-chip {
    padding-inline: 7px;
  }

  .brand-promises {
    font-size: 13px;
  }

  .usage-guide {
    margin-top: 22px;
    padding-top: 18px;
  }

  .usage-guide-content {
    font-size: 13px;
    line-height: 1.75;
  }

  .scanner-page {
    background: var(--surface);
  }

  .scanner-shell {
    width: 100%;
    padding: 0 0 max(8px, env(safe-area-inset-bottom));
    background: var(--surface);
  }

  .app-bar {
    position: relative;
    z-index: 6;
    min-height: 60px;
    padding: max(8px, env(safe-area-inset-top)) 12px 8px;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
  }

  .scanner-layout {
    margin-top: 0;
    gap: 0;
  }

  .capture-panel {
    padding-bottom: 12px;
    background: var(--camera);
  }

  .scanner-frame {
    width: 100%;
    max-height: 56svh;
    aspect-ratio: 4 / 5;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .screen-frame {
    max-height: 48svh;
    aspect-ratio: 16 / 10;
  }

  .scan-mask {
    width: min(68%, 280px);
  }

  .controls {
    margin: 12px 12px 0;
  }

  .capture-panel button.secondary {
    border-color: #343c44;
    color: #eef2f5;
    background: var(--camera-raised);
  }

  .capture-panel button.secondary:hover:not(:disabled) {
    background: #1a2128;
  }

  .capture-note {
    color: #a7b0b9;
  }

  .capture-note svg {
    color: #4ade80;
  }

  .result-panel {
    padding: 18px 16px max(18px, env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}

@media (max-width: 390px) {
  .launch-header {
    align-items: flex-start;
    gap: 10px;
  }

  .app-identity {
    flex: 1 1 auto;
  }

  .app-identity > div {
    min-width: 0;
  }

  .app-name {
    font-size: 14px;
    overflow-wrap: anywhere;
  }

  .privacy-chip {
    font-size: 11px;
  }

  .mode-option {
    grid-template-columns: 44px minmax(0, 1fr) 20px;
    gap: 12px;
    padding: 15px;
  }

  .mode-icon {
    width: 44px;
    height: 44px;
  }

  .version-badge {
    max-width: 78px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .scanner-hud {
    inset: 9px 9px auto;
  }

  .camera-state {
    max-width: 58%;
  }

  .controls {
    gap: 8px;
  }

  button {
    padding-inline: 10px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .scanner-shell {
    width: min(100%, 980px);
    padding: 8px;
  }

  .app-bar {
    min-height: 52px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .scanner-layout {
    margin-top: 8px;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 36vw);
    gap: 8px;
  }

  .capture-panel {
    padding: 0;
    background: transparent;
  }

  .scanner-frame,
  .screen-frame {
    max-height: calc(100svh - 122px);
    aspect-ratio: 16 / 9;
    border: 1px solid #242b32;
    border-radius: 8px;
  }

  .controls {
    margin: 7px 0 0;
  }

  .capture-note {
    display: none;
  }

  .result-panel {
    max-height: calc(100svh - 70px);
    overflow-y: auto;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }
}

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