:root {
  color-scheme: light dark;
  --background: #eef2f3;
  --foreground: #17212b;
  --surface: #ffffff;
  --border: #dce3e6;
  --muted: #64717b;
  --green: #218866;
  --blue: #236fa1;
  --red: #c84444;
  --amber: #b77718;
  --frame: #f6f8f9;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #11171b;
    --foreground: #edf2f4;
    --surface: #1a2228;
    --border: #344047;
    --muted: #9aa8b1;
    --green: #52b28d;
    --blue: #65addb;
    --red: #ef8585;
    --amber: #e4ad57;
    --frame: #131b20;
  }
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; background: var(--background); }
body { min-height: 100%; margin: 0; background: var(--background); color: var(--foreground); font-family: "Segoe UI", "Microsoft YaHei", sans-serif; letter-spacing: 0; }
button, input { font: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }

.scan-shell { width: min(980px, calc(100% - 32px)); min-height: 100vh; min-height: 100svh; margin: 0 auto; display: flex; flex-direction: column; }
.scan-header { min-height: 72px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); }
.scan-brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; color: #fff; background: #236fa1; border-radius: 6px; font-weight: 700; }
.scan-brand strong { font-size: 17px; font-weight: 650; }
.status-tag { min-width: 64px; padding: 4px 9px; border: 1px solid var(--border); border-radius: 4px; color: var(--muted); text-align: center; font-size: 12px; line-height: 1.4; }
.status-tag.active, .status-tag.processing { color: var(--blue); border-color: color-mix(in srgb, var(--blue), transparent 55%); background: color-mix(in srgb, var(--blue), transparent 90%); }
.status-tag.success { color: var(--green); border-color: color-mix(in srgb, var(--green), transparent 55%); background: color-mix(in srgb, var(--green), transparent 90%); }
.status-tag.warning { color: var(--amber); border-color: color-mix(in srgb, var(--amber), transparent 55%); background: color-mix(in srgb, var(--amber), transparent 90%); }
.status-tag.error { color: var(--red); border-color: color-mix(in srgb, var(--red), transparent 55%); background: color-mix(in srgb, var(--red), transparent 90%); }

.scan-workspace { flex: 1; display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(270px, .72fr); align-items: center; padding: 32px 0; }
.scan-stage { height: 548px; display: grid; grid-template-rows: 300px 76px 52px; justify-items: center; align-content: center; gap: 14px; padding: 32px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px 0 0 7px; }
.scan-frame { position: relative; width: 300px; max-width: 100%; aspect-ratio: 1; display: grid; place-items: center; overflow: hidden; color: var(--muted); border: 1px solid #aab6bc; border-radius: 6px; background: var(--frame); }
.scan-frame.camera-active { border-color: var(--blue); }
.scan-frame video { width: 100%; height: 100%; object-fit: cover; background: #101416; }
.frame-placeholder { display: grid; justify-items: center; gap: 14px; font-size: 14px; color: var(--muted); }
.frame-symbol { width: 44px; height: 44px; border: 3px solid currentColor; border-radius: 4px; position: relative; }
.frame-symbol::before, .frame-symbol::after { content: ""; position: absolute; background: currentColor; }
.frame-symbol::before { width: 20px; height: 3px; left: 9px; top: 18px; }
.frame-symbol::after { width: 3px; height: 20px; left: 18px; top: 9px; }
.state-symbol { width: 58px; height: 58px; border: 4px solid currentColor; border-radius: 50%; position: relative; }
.state-symbol.success { color: var(--green); }
.state-symbol.success::after { content: ""; position: absolute; width: 26px; height: 13px; left: 12px; top: 15px; border-left: 4px solid currentColor; border-bottom: 4px solid currentColor; transform: rotate(-45deg); }
.state-symbol.error, .state-symbol.warning { color: var(--red); }
.state-symbol.warning { color: var(--amber); }
.state-symbol.error::before, .state-symbol.error::after, .state-symbol.warning::before, .state-symbol.warning::after { content: ""; position: absolute; width: 30px; height: 4px; left: 10px; top: 23px; background: currentColor; }
.state-symbol.error::before, .state-symbol.warning::before { transform: rotate(45deg); }
.state-symbol.error::after, .state-symbol.warning::after { transform: rotate(-45deg); }
.loading-indicator { width: 44px; height: 44px; border: 4px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scan-corners { position: absolute; inset: 28px; border: 2px solid rgb(255 255 255 / 75%); border-radius: 4px; box-shadow: 0 0 0 999px rgb(0 0 0 / 14%); pointer-events: none; }
.stage-copy { min-width: 0; align-self: center; text-align: center; }
.stage-copy h1 { margin: 0 0 7px; font-size: 23px; line-height: 1.3; }
.stage-copy p { max-width: 460px; margin: 0; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.scan-actions { min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.button { min-width: 124px; min-height: 42px; padding: 8px 18px; color: var(--foreground); background: var(--surface); border: 1px solid var(--border); border-radius: 5px; cursor: pointer; }
.button:hover { border-color: var(--blue); color: var(--blue); }
.button:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue), transparent 65%); outline-offset: 2px; }
.button.primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.button:disabled { opacity: .55; cursor: not-allowed; }
.file-input { position: fixed; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dialog-backdrop { position: fixed; z-index: 10; inset: 0; display: grid; place-items: center; padding: 24px; background: rgb(23 33 43 / 52%); }
.confirm-dialog { width: min(100%, 400px); padding: 24px; color: var(--foreground); background: var(--surface); border: 1px solid var(--border); border-radius: 7px; box-shadow: 0 18px 48px rgb(0 0 0 / 22%); }
.confirm-dialog h2 { margin: 0; font-size: 19px; line-height: 1.4; }
.confirm-dialog p { margin: 10px 0 22px; color: var(--muted); line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

.scan-status { height: 548px; padding: 36px 26px; border: 1px solid var(--border); border-left: 0; border-radius: 0 7px 7px 0; background: color-mix(in srgb, var(--surface), var(--background) 18%); }
.scan-status > span { color: var(--muted); font-size: 13px; }
.scan-status > strong { display: block; margin: 8px 0 32px; font-size: 21px; line-height: 1.35; }
.status-line { min-height: 58px; display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); }
.status-line i { width: 8px; height: 8px; border-radius: 50%; background: #9ba7ad; }
.status-line small { color: var(--muted); }
.status-line.done i { background: var(--green); }
.status-line.current i { background: var(--blue); box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue), transparent 82%); }
.status-line.stopped i { background: var(--red); }
.security-note { display: flex; align-items: center; gap: 8px; margin-top: 28px; color: var(--muted); font-size: 13px; }
.shield { width: 13px; height: 15px; display: inline-block; border: 2px solid currentColor; border-radius: 6px 6px 8px 8px; }
.expiry-line { margin-top: 10px; color: var(--muted); font-size: 12px; }
.debug-panel { margin: 0 0 14px; padding: 10px 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 5px; background: color-mix(in srgb, var(--surface), var(--background) 12%); font-size: 12px; }
.debug-panel summary { color: var(--foreground); cursor: pointer; font-weight: 650; }
.debug-panel pre { max-height: 240px; margin: 10px 0 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.scan-shell footer { min-height: 54px; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.scan-shell footer > span { display: inline-flex; align-items: center; gap: 7px; }

@media (max-width: 720px) {
  .scan-shell { width: min(100% - 24px, 560px); }
  .scan-header { min-height: 64px; }
  .scan-workspace { grid-template-columns: 1fr; align-content: center; padding: 18px 0; }
  .scan-stage { height: auto; min-height: 500px; grid-template-rows: minmax(240px, 62vw) 76px auto; padding: 22px 18px; border-radius: 7px 7px 0 0; }
  .scan-frame { width: min(100%, 300px); }
  .scan-status { height: auto; min-height: 310px; padding: 26px 22px; border-left: 1px solid var(--border); border-top: 0; border-radius: 0 0 7px 7px; }
  .scan-status > strong { margin-bottom: 18px; }
  .scan-actions { width: 100%; min-height: 108px; flex-direction: column; }
  .scan-actions button { width: 100%; }
  .dialog-backdrop { align-items: end; padding: 12px; }
  .confirm-dialog { width: 100%; padding: 22px 18px; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .button { width: 100%; }
  .security-note { margin-top: 20px; }
}

@media (max-height: 700px) and (min-width: 721px) {
  .scan-stage, .scan-status { height: 500px; }
  .scan-stage { grid-template-rows: 260px 72px 52px; padding: 24px; }
  .scan-frame { width: 260px; }
}

@media (prefers-reduced-motion: reduce) {
  .loading-indicator { animation-duration: 1.6s; }
}
