:root {
    color-scheme: light;
    --ink: #0f172a;
    --muted-ink: #64748b;
    --surface: #ffffff;
    --canvas: #f8fafc;
    --soft: #f1f5f9;
    --border: #e2e8f0;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --success: #15803d;
    --danger: #b91c1c;
    --radius-xl: 24px;
    --radius-lg: 18px;
    --shadow: 0 18px 48px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); }

body {
    margin: 0;
    min-width: 320px;
    min-height: 100vh;
    min-height: 100dvh;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 0%, rgba(37, 99, 235, .09), transparent 28rem),
        var(--canvas);
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    overscroll-behavior-y: contain;
    -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button, label[for] { touch-action: manipulation; }

.app-shell {
    width: min(100% - 32px, 680px);
    margin: 0 auto;
    padding: max(28px, env(safe-area-inset-top)) 0 max(36px, env(safe-area-inset-bottom));
}

.page-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 8px 4px 24px;
}

.brand-mark {
    display: grid;
    flex: 0 0 52px;
    width: 52px;
    height: 52px;
    place-items: center;
    color: #fff;
    background: var(--ink);
    border-radius: 16px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .16);
}

.brand-mark svg { width: 28px; height: 28px; }
.eyebrow, .section-kicker { margin: 0 0 3px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(25px, 7vw, 34px); line-height: 1.18; letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: 19px; line-height: 1.3; letter-spacing: -.02em; }
.subtitle { margin-bottom: 0; color: var(--muted-ink); font-size: 14px; }

.scanner-card {
    padding: 20px;
    background: rgba(255, 255, 255, .94);
    border: 1px solid rgba(226, 232, 240, .9);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.section-heading, .history-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}
.section-heading.compact { margin-bottom: 12px; }

.camera-state {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 30px;
    padding: 5px 10px;
    color: #475569;
    background: var(--soft);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.camera-state span { width: 7px; height: 7px; background: #94a3b8; border-radius: 50%; }
.camera-state.active { color: #166534; background: #dcfce7; }
.camera-state.active span { background: #22c55e; box-shadow: 0 0 0 4px rgba(34, 197, 94, .13); }
.scanner-indicators { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.sound-toggle { display: inline-flex; min-height: 44px; align-items: center; gap: 5px; padding: 7px 10px; color: #1d4ed8; background: #dbeafe; border: 0; border-radius: 999px; font-size: 11px; font-weight: 750; cursor: pointer; transition: color .18s ease, background-color .18s ease; }
.sound-toggle:hover { background: #bfdbfe; }
.sound-toggle svg { width: 15px; height: 15px; }
.sound-toggle .sound-off-icon { display: none; }
.sound-toggle.is-muted { color: #64748b; background: var(--soft); }
.sound-toggle.is-muted .sound-on-icon { display: none; }
.sound-toggle.is-muted .sound-off-icon { display: block; }

.batch-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    padding: 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 15px;
}
.batch-summary { display: flex; min-width: 0; align-items: center; gap: 10px; }
.batch-icon { display: grid; flex: 0 0 38px; width: 38px; height: 38px; place-items: center; color: #1d4ed8; background: #dbeafe; border-radius: 11px; }
.batch-icon svg { width: 21px; height: 21px; }
.batch-summary small, .batch-summary strong, .batch-summary span { display: block; }
.batch-summary small { color: #64748b; font-size: 10px; font-weight: 750; }
.batch-summary strong { overflow: hidden; color: #1e3a8a; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.batch-summary span { color: #64748b; font-size: 11px; }
.batch-summary b { color: #1e3a8a; }
.batch-complete-button { flex: 0 0 auto; min-height: 40px; padding: 8px 11px; color: #fff; background: #1d4ed8; border: 0; border-radius: 10px; font-size: 12px; font-weight: 750; cursor: pointer; transition: background-color .18s ease, opacity .18s ease; }
.batch-complete-button:hover:not(:disabled) { background: #1e40af; }
.batch-complete-button:disabled { cursor: not-allowed; opacity: .45; }

.batch-form { margin: -2px 0 14px; padding: 13px; background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 8px 22px rgba(15, 23, 42, .06); }
.batch-form.is-hidden { display: none; }
.batch-form > label { display: block; color: #1e293b; font-size: 13px; font-weight: 800; }
.batch-form > p { margin: 2px 0 10px; color: var(--muted-ink); font-size: 11px; }
.batch-form-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; }
.batch-form input { min-width: 0; min-height: 44px; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 11px; outline: none; }
.batch-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.batch-form .button { min-height: 44px; padding: 9px 12px; font-size: 12px; }

.scanner-viewport {
    position: relative;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    color: #94a3b8;
    background: #0f172a;
    border-radius: var(--radius-lg);
}

#camera { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .25s ease; }
#camera.visible { opacity: 1; }

.scanner-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 24px;
    text-align: center;
    background: linear-gradient(145deg, #172033, #0f172a);
}
.scanner-placeholder.hidden { display: none; }
.scanner-placeholder svg { width: 52px; height: 52px; margin-bottom: 14px; color: #cbd5e1; }
.scanner-placeholder p { margin-bottom: 3px; color: #fff; font-weight: 700; }
.scanner-placeholder span { font-size: 13px; }

.scan-frame { position: absolute; inset: 18%; pointer-events: none; opacity: .45; }
.scan-frame i { position: absolute; width: 26px; height: 26px; border-color: #fff; border-style: solid; }
.scan-frame i:nth-child(1) { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 8px 0 0; }
.scan-frame i:nth-child(2) { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 8px 0 0; }
.scan-frame i:nth-child(3) { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 8px; }
.scan-frame i:nth-child(4) { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 0 8px; }
.scan-frame b { display: none; position: absolute; top: 0; right: 6px; left: 6px; height: 2px; background: #60a5fa; border-radius: 2px; box-shadow: 0 0 12px #3b82f6; animation: scan 2.4s ease-in-out infinite; }
.scanner-viewport.is-scanning .scan-frame { opacity: 1; }
.scanner-viewport.is-scanning .scan-frame b { display: block; }

@keyframes scan { 0%, 100% { transform: translateY(0); opacity: .45; } 50% { transform: translateY(calc(64vw - 86px)); opacity: 1; } }

.status-box {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-height: 48px;
    margin-top: 14px;
    padding: 12px 14px;
    color: #334155;
    background: var(--soft);
    border: 1px solid transparent;
    border-radius: 14px;
    font-size: 14px;
}
.status-box svg { flex: 0 0 20px; width: 20px; height: 20px; margin-top: 1px; }
.status-box.success { color: #166534; background: #f0fdf4; border-color: #bbf7d0; }
.status-box.error { color: #991b1b; background: #fef2f2; border-color: #fecaca; }

.scanner-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.button {
    display: inline-flex;
    min-height: 48px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 11px 15px;
    border: 1px solid transparent;
    border-radius: 14px;
    font-weight: 750;
    line-height: 1.2;
    cursor: pointer;
    transition: transform .18s ease, background-color .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.button svg { width: 20px; height: 20px; }
.button:active { transform: scale(.98); }
.button:focus-visible, input:focus-visible { outline: 3px solid rgba(37, 99, 235, .28); outline-offset: 2px; }
.button:disabled { cursor: not-allowed; opacity: .58; box-shadow: none; transform: none; }
.button-primary { color: #fff; background: var(--accent); box-shadow: 0 8px 18px rgba(37, 99, 235, .22); }
.button-primary:hover { background: var(--accent-dark); }
.button-secondary { color: #1e293b; background: #fff; border-color: var(--border); }
.button-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.button-dark { color: #fff; background: var(--ink); }
.button-dark:hover { background: #1e293b; }

.history-section { margin-top: 30px; }
.history-heading { padding: 0 4px; }
.total-badge { padding: 6px 10px; color: #475569; background: var(--soft); border-radius: 999px; font-size: 12px; }
.total-badge strong { color: var(--ink); font-size: 14px; }
.history-list { display: grid; gap: 10px; }
.history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 15px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 4px 18px rgba(15, 23, 42, .035);
}
.history-main { min-width: 0; }
.history-domain { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; font-size: 14px; font-weight: 800; }
.history-domain svg { width: 17px; height: 17px; color: var(--accent); }
.history-url { display: block; overflow: hidden; color: var(--muted-ink); font-size: 12px; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.history-url:hover { color: var(--accent); text-decoration: underline; }
.history-meta { margin-top: 7px; color: #94a3b8; font-size: 11px; }
.copy-button { width: 44px; height: 44px; padding: 0; color: #475569; background: var(--soft); border: 0; border-radius: 12px; cursor: pointer; transition: background .18s ease, color .18s ease; }
.copy-button:hover { color: var(--accent); background: #dbeafe; }
.copy-button svg { width: 19px; height: 19px; vertical-align: middle; }

.empty-state { padding: 38px 20px; color: var(--muted-ink); text-align: center; background: rgba(255, 255, 255, .65); border: 1px dashed #cbd5e1; border-radius: 18px; }
.empty-state svg { width: 36px; height: 36px; margin-bottom: 8px; color: #94a3b8; }
.empty-state p { margin-bottom: 2px; color: #334155; font-weight: 700; }
.empty-state span { font-size: 13px; }

footer { padding: 26px 0 0; color: #94a3b8; font-size: 12px; text-align: center; }
.toast { position: fixed; z-index: 20; right: 16px; bottom: max(20px, env(safe-area-inset-bottom)); left: 16px; max-width: 480px; margin: auto; padding: 12px 16px; color: #fff; background: #0f172a; border-radius: 13px; box-shadow: 0 14px 40px rgba(15, 23, 42, .24); font-size: 14px; text-align: center; transform: translateY(24px); opacity: 0; visibility: hidden; transition: opacity .2s ease, transform .2s ease, visibility .2s; }
.toast.show { transform: translateY(0); opacity: 1; visibility: visible; }
.visually-hidden { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

@media (min-width: 700px) {
    .app-shell { padding-top: 48px; }
    .scanner-card { padding: 24px; }
    @keyframes scan { 0%, 100% { transform: translateY(0); opacity: .45; } 50% { transform: translateY(330px); opacity: 1; } }
}

@media (max-width: 480px) {
    .app-shell { width: min(100% - 20px, 680px); }
    .page-header { gap: 12px; padding-bottom: 20px; }
    .brand-mark { flex-basis: 46px; width: 46px; height: 46px; border-radius: 14px; }
    .brand-mark svg { width: 25px; height: 25px; }
    .scanner-card { padding: 14px; border-radius: 20px; }
    .section-heading { align-items: flex-start; }
    .scanner-indicators { max-width: 132px; }
    .camera-state { min-height: 34px; }
    .scanner-actions { grid-template-columns: 1fr; }
    .batch-panel { align-items: stretch; flex-direction: column; }
    .batch-complete-button { width: 100%; min-height: 44px; }
    .batch-form-row { grid-template-columns: 1fr 1fr; }
    .batch-form-row input { grid-column: 1 / -1; }
}

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