:root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --text: #0f172a;
    --text-dim: #4b5563;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --ok: #16a34a;
    --ok-bg: #f0fdf4;
    --ok-border: #86efac;
    --warn: #d97706;
    --warn-bg: #fffbeb;
    --warn-border: #fcd34d;
    --muted: #6b7280;
    --muted-bg: #f9fafb;
    --muted-border: #e5e7eb;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0b1220;
        --surface: #111827;
        --text: #f9fafb;
        --text-dim: #cbd5e1;
        --text-muted: #9ca3af;
        --border: #1f2937;
        --border-strong: #334155;
        --primary: #60a5fa;
        --primary-hover: #93c5fd;
        --ok: #22c55e;
        --ok-bg: rgba(34, 197, 94, 0.12);
        --ok-border: rgba(34, 197, 94, 0.35);
        --warn: #f59e0b;
        --warn-bg: rgba(245, 158, 11, 0.12);
        --warn-border: rgba(245, 158, 11, 0.35);
        --muted-bg: rgba(148, 163, 184, 0.08);
        --muted-border: rgba(148, 163, 184, 0.25);
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.4);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, "Noto Sans", sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

.page {
    max-width: 520px;
    margin: 0 auto;
    padding: 32px 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 100vh;
}

/* Brand header */
.brand {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding-top: 12px;
}
.brand-mark {
    width: 48px; height: 48px;
    border-radius: 12px;
    background: var(--primary);
    color: #fff;
    display: grid; place-items: center;
    box-shadow: 0 4px 12px rgba(29, 78, 216, 0.25);
}
.brand h1 {
    font-size: 22px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.01em;
}
.subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

/* Card */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.scanner-wrap {
    width: 100%;
    min-height: 0;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
    margin-bottom: 0;
    transition: min-height 0.2s ease;
}
.scanner-wrap.active { min-height: 260px; margin-bottom: 16px; }
.scanner-wrap video { width: 100% !important; border-radius: 12px; display: block; }

.action-row {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--muted-bg); }
.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border-color: var(--border);
}
.btn-ghost:hover { background: var(--muted-bg); color: var(--text); }

.manual-entry {
    margin-top: 16px;
}
.manual-entry summary {
    cursor: pointer;
    padding: 8px 0;
    font-size: 13px;
    color: var(--text-muted);
    list-style: none;
    user-select: none;
}
.manual-entry summary::before {
    content: "+";
    display: inline-block;
    width: 16px;
    color: var(--text-muted);
    font-weight: bold;
}
.manual-entry[open] summary::before { content: "−"; }

.manual-form {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.manual-form .btn { flex: 0 0 auto; padding-left: 20px; padding-right: 20px; }

.input {
    flex: 1;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}

/* Result states */
.result { animation: slide-in 0.25s ease; }
@keyframes slide-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.state {
    border-radius: 16px;
    padding: 24px 20px;
    text-align: center;
    border: 1px solid;
}
.state-ok {
    background: var(--ok-bg);
    border-color: var(--ok-border);
    color: var(--ok);
}
.state-warn {
    background: var(--warn-bg);
    border-color: var(--warn-border);
    color: var(--warn);
}
.state-muted {
    background: var(--muted-bg);
    border-color: var(--muted-border);
    color: var(--muted);
}
.state-icon {
    width: 64px; height: 64px;
    margin: 0 auto 12px;
    border-radius: 50%;
    background: var(--surface);
    display: grid; place-items: center;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}
.state-title {
    margin: 0 0 6px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}
.state-message {
    margin: 0 0 16px;
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1.5;
}

/* Details dl */
.details {
    margin: 0;
    padding: 16px;
    background: var(--surface);
    border-radius: 10px;
    text-align: left;
    font-size: 13px;
    color: var(--text);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 12px;
    border: 1px solid var(--border);
}
.details dt {
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}
.details dd {
    margin: 0;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12.5px;
}
.details dd.plain { font-family: inherit; font-size: 13px; }

.again {
    margin-top: 16px;
    width: auto;
    flex: 0 0 auto;
    padding-left: 20px;
    padding-right: 20px;
}

.foot {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: auto;
    padding-top: 8px;
}
.foot a { color: var(--text-muted); }