:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --text: #1c1f24;
    --muted: #646b75;
    --border: #d9dde3;
    --accent: #2563eb;
    --accent-text: #ffffff;
    --ok: #15803d;
    --warn: #b45309;
    --error: #b91c1c;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121418;
        --card: #1c1f25;
        --text: #e7e9ec;
        --muted: #9aa1ab;
        --border: #343943;
        --accent: #3b82f6;
        --ok: #4ade80;
        --warn: #fbbf24;
        --error: #f87171;
    }
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 {
    margin: 0 0 .5rem;
    font-size: 1.6rem;
}

button,
select {
    font: inherit;
    padding: .6rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: .5rem;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
}

button:disabled {
    opacity: .5;
    cursor: default;
}

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    min-width: 8rem;
}

.muted {
    color: var(--muted);
    font-size: .9rem;
}

.ok {
    color: var(--ok);
}

.warn {
    color: var(--warn);
}

.error {
    color: var(--error);
}

.result {
    display: block;
    padding: .75rem 1rem;
    border: 1px solid var(--border);
    border-radius: .5rem;
    background: var(--bg);
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
    min-height: 3rem;
}

/* --- desktop page --- */

.card {
    max-width: 32rem;
    margin: 3rem auto;
    padding: 2rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    text-align: center;
}

.card .result {
    text-align: left;
    margin: 1rem 0 .75rem;
}

.lead {
    color: var(--muted);
    margin: 0 0 1.5rem;
}

.qr {
    width: min(280px, 100%);
    margin: 0 auto 1rem;
}

.qr svg {
    display: block;
    width: 100%;
    height: auto;
    border-radius: .5rem;
}

.link {
    display: block;
    color: var(--muted);
    font-size: .8rem;
    overflow-wrap: anywhere;
}

.actions {
    display: flex;
    gap: .75rem;
    justify-content: center;
    margin-top: 1.25rem;
}

@media (max-width: 34rem) {
    .card {
        margin: 1rem;
        padding: 1.5rem 1rem;
    }
}

/* --- scanner page: the camera fills the screen, everything else floats over it --- */

.scan-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    /* The global body min-height: 100vh would win over height, and on mobile 100vh is the
       viewport with the toolbar hidden - the bottom strip ended up under the screen edge. */
    min-height: 0;
    overflow: hidden;
    background: #000;
    color: #fff;
}

/* Not display: none - some browsers won't render <use> references into a hidden sprite. */
.sprite {
    position: absolute;
    width: 0;
    height: 0;
}

.scan svg {
    width: 1.5rem;
    height: 1.5rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.scan video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* The OCR region; scan.js crops whatever video lies under this box. */
.frame {
    position: absolute;
    left: 8%;
    width: 84%;
    top: 41%;
    height: 18%;
    border: 2px solid rgba(255, 255, 255, .85);
    border-radius: .75rem;
    box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .3);
    pointer-events: none;
}

.camera-msg {
    position: absolute;
    inset: 0;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    font-size: 1.1rem;
}

.bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: max(.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 1.5rem max(1rem, env(safe-area-inset-left));
    background: linear-gradient(rgba(0, 0, 0, .65), transparent);
}

.bar h1 {
    margin: 0;
    font-size: 1.2rem;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}

.modes {
    display: flex;
    gap: .25rem;
    padding: .25rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, .45);
    backdrop-filter: blur(8px);
}

.modes button {
    display: grid;
    place-items: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #fff;
}

.modes button svg {
    width: 1.3rem;
    height: 1.3rem;
}

.modes button[aria-pressed="true"] {
    background: #fff;
    color: #000;
}

.panel {
    position: absolute;
    left: max(.75rem, env(safe-area-inset-left));
    right: max(.75rem, env(safe-area-inset-right));
    bottom: calc(.75rem + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
}

.hint {
    margin: 0;
    padding: .3rem .8rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, .65);
    font-size: .85rem;
    text-align: center;
}

.hint.warn {
    color: #fbbf24;
}

.hint.error {
    color: #f87171;
}

.hint.ok {
    color: #4ade80;
}

.readout {
    align-self: stretch;
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .4rem .4rem .4rem .9rem;
    border-radius: 1.75rem;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(8px);
}

.kind {
    flex: none;
    opacity: .9;
}

.value {
    flex: 1;
    min-width: 0;
    font-family: ui-monospace, "SF Mono", Consolas, monospace;
    font-size: .95rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
}

.value:empty::before {
    content: attr(data-placeholder);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: rgba(255, 255, 255, .65);
}

.send {
    flex: none;
    display: grid;
    place-items: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
}

.send svg {
    width: 1.35rem;
    height: 1.35rem;
    margin: .1rem .15rem 0 0;
}

.send:disabled {
    background: rgba(255, 255, 255, .2);
    opacity: 1;
}
