:root {
    --bg: #f3f5f7;
    --surface: #ffffff;
    --text: #14202b;
    --muted: #5d6b78;
    --line: #e2e7ec;
    --brand: #1f6fd1;
    --brand-ink: #ffffff;
    --price: #2c8a1e;
    --promo-bg: #fff4e5;
    --promo-line: #f5b25b;
    --promo-ink: #9a4b00;
    --danger: #b42318;
    --radius: 14px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1418;
        --surface: #172026;
        --text: #e8eef2;
        --muted: #9aa8b3;
        --line: #26323a;
        --brand: #3d8bf0;
        --price: #5cc84a;
        --promo-bg: #2a1f10;
        --promo-line: #a8691f;
        --promo-ink: #ffc477;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
    /* Logo has a white background, so the header stays white in both themes. */
    background: #ffffff;
    color: #14202b;
    border-bottom: 3px solid #1f6fd1;
    box-shadow: 0 1px 6px rgba(0, 0, 0, .08);
}

.logo { height: 76px; width: auto; display: block; flex-shrink: 0; }

.header-text { min-width: 0; text-align: right; }

.brand { font-weight: 700; font-size: 1.05rem; color: #1f6fd1; letter-spacing: .2px; }

.store {
    font-size: .88rem;
    color: #5d6b78;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 600px) {
    .logo { height: 92px; }
}

.app {
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
}

/* Scanner */
.scanner-wrap { display: flex; flex-direction: column; gap: 10px; }

.reader {
    width: 100%;
    overflow: hidden;
    border-radius: var(--radius);
    background: #000;
    min-height: 220px;
}

.reader video { display: block; width: 100% !important; height: auto !important; object-fit: cover; }

.hint { margin: 0; text-align: center; color: var(--muted); font-size: .95rem; }

/* States */
.message { text-align: center; }
.message p { margin: 6px 0 12px; line-height: 1.45; }
.message .icon { font-size: 2rem; }

.loading { display: flex; align-items: center; justify-content: center; gap: 12px; }
.loading p { margin: 0; color: var(--muted); }

.spinner {
    width: 22px; height: 22px;
    border: 3px solid var(--line);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Result */
.result-head h1 { margin: 0; font-size: 1.3rem; line-height: 1.3; word-break: break-word; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.result-head p { margin: 4px 0 0; }

.price-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin: 16px 0 6px;
    padding-top: 14px;
    border-top: 1px dashed var(--line);
}

.price-label { color: var(--muted); font-weight: 600; }

.price {
    font-size: clamp(2rem, 9vw, 2.6rem);
    font-weight: 800;
    color: var(--price);
    font-variant-numeric: tabular-nums;
}

.price.na { font-size: 1.3rem; color: var(--danger); }

.promos { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.promos:empty { display: none; }

.promo {
    background: var(--promo-bg);
    border: 1px solid var(--promo-line);
    border-radius: 12px;
    padding: 12px 14px;
}

.promo-badge {
    display: inline-block;
    font-size: .7rem;
    font-weight: 800;
    letter-spacing: .8px;
    color: var(--promo-ink);
    border: 1px solid var(--promo-line);
    border-radius: 999px;
    padding: 1px 8px;
    margin-bottom: 6px;
}

.promo-title { font-size: 1.15rem; font-weight: 700; color: var(--promo-ink); }
.promo-details { margin-top: 4px; font-size: .88rem; color: var(--text); line-height: 1.4; }
.promo-details:empty { display: none; }

/* Controls */
.btn {
    appearance: none;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    border-radius: 12px;
    padding: 12px 16px;
    min-height: 48px;
    cursor: pointer;
}

.btn-primary { width: 100%; background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-size: 1.05rem; }
.btn:active { transform: translateY(1px); }

.manual { display: flex; gap: 8px; }

.manual input {
    flex: 1;
    min-width: 0;
    font: inherit;
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 12px 14px;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
}

.manual input:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
