:root {
    --bg: #0b0e17;
    --bg-elevated: #131829;
    --bg-card: #171d33;
    --border: #262e4a;
    --text: #eef1fb;
    --text-dim: #9aa3c4;
    --accent: #7c5cff;
    --accent-2: #37e0d6;
    --accent-warn: #ff5c7a;
    --radius: 14px;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
    font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

main {
    display: block;
}

a { color: var(--accent-2); }

.topnav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 28px;
    background: linear-gradient(to bottom, rgba(11,14,23,0.85), rgba(11,14,23,0));
    pointer-events: none;
}
.topnav a { pointer-events: auto; }

.brand {
    font-weight: 600;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
    text-decoration: none;
    color: var(--text-dim);
    transition: color 0.15s ease;
}
.brand:hover { color: var(--text); }

.topnav-links { display: flex; gap: 22px; }
.topnav-links a {
    text-decoration: none;
    color: var(--text-dim);
    font-size: 0.92rem;
    font-weight: 500;
    transition: color 0.15s ease;
}
.topnav-links a:hover { color: var(--text); }

/* ---------- Landing / blob scene ---------- */

.hero {
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 20%, #171f3a 0%, var(--bg) 70%);
}

#blob-canvas {
    position: absolute;
    inset: 0;
    display: block;
    touch-action: none;
}

.hero-heading {
    position: absolute;
    top: 14%;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    pointer-events: none;
    z-index: 5;
    width: 100%;
    padding: 0 20px;
}
.hero-heading h1 {
    font-size: clamp(1.8rem, 5vw, 3rem);
    margin: 0 0 8px;
    letter-spacing: -0.02em;
}
.hero-heading p {
    margin: 0;
    color: var(--text-dim);
    font-size: clamp(0.9rem, 2vw, 1.05rem);
}

.blob-caption {
    position: absolute;
    left: 50%;
    bottom: 12%;
    transform: translate(-50%, 12px);
    z-index: 6;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.blob-caption.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}
.blob-caption .title {
    font-size: 1.15rem;
    font-weight: 600;
    margin: 0 0 4px;
}
.blob-caption .hint {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin: 0;
}

.hero-fade {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.45s ease;
}
.hero-fade.active {
    opacity: 1;
    pointer-events: auto;
}

.hero-touch-hint {
    position: absolute;
    bottom: 4%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.78rem;
    color: var(--text-dim);
    z-index: 5;
    opacity: 0.7;
}

/* ---------- Generic page shell ---------- */

.page {
    max-width: 720px;
    margin: 0 auto;
    padding: 110px 24px 60px;
    min-height: 100vh;
}

.page h1 {
    font-size: clamp(1.6rem, 4vw, 2.1rem);
    margin: 0 0 6px;
    letter-spacing: -0.02em;
}
.page .subtitle {
    color: var(--text-dim);
    margin: 0 0 32px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
}

/* ---------- Tabs ---------- */

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 22px;
    background: var(--bg-elevated);
    padding: 6px;
    border-radius: 999px;
    border: 1px solid var(--border);
}
.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-dim);
    padding: 10px 16px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 0.92rem;
    font-weight: 600;
    transition: all 0.15s ease;
}
.tab-btn.active {
    background: linear-gradient(135deg, var(--accent), #5a3fd1);
    color: #fff;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Form elements ---------- */

textarea, input[type="text"] {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    padding: 14px;
    font-size: 0.98rem;
    font-family: inherit;
    resize: vertical;
    min-height: 140px;
}
textarea:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}

.char-count {
    text-align: right;
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-top: 6px;
}

.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone.dragover {
    border-color: var(--accent);
    background: rgba(124, 92, 255, 0.08);
}
.dropzone p { margin: 6px 0; color: var(--text-dim); }
.dropzone .filename {
    color: var(--text);
    font-weight: 600;
    word-break: break-all;
}
.dropzone input[type="file"] { display: none; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 10px;
    padding: 13px 22px;
    font-size: 0.96rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease, opacity 0.15s ease;
    text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
    background: linear-gradient(135deg, var(--accent), #5a3fd1);
    color: #fff;
    width: 100%;
    margin-top: 18px;
}
.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.btn-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 140px; }

/* ---------- Alerts / status ---------- */

.alert {
    padding: 12px 16px;
    border-radius: 10px;
    font-size: 0.9rem;
    margin-bottom: 18px;
}
.alert-error { background: rgba(255, 92, 122, 0.12); color: #ff8fa3; border: 1px solid rgba(255,92,122,0.3); }
.alert-info { background: rgba(55, 224, 214, 0.1); color: var(--accent-2); border: 1px solid rgba(55,224,214,0.25); }

.hidden { display: none !important; }

/* ---------- Result / QR display ---------- */

.result-card {
    text-align: center;
}
.result-card canvas {
    background: #fff;
    border-radius: 10px;
    padding: 16px;
    max-width: 100%;
}
.result-url {
    margin-top: 16px;
    font-size: 0.82rem;
    color: var(--text-dim);
    word-break: break-all;
    background: var(--bg-elevated);
    padding: 10px 14px;
    border-radius: 8px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- View page ---------- */

.view-text {
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--bg-elevated);
    border-radius: 10px;
    padding: 18px;
    font-size: 1rem;
    line-height: 1.55;
    max-height: 55vh;
    overflow-y: auto;
}

.view-image img {
    max-width: 100%;
    border-radius: 10px;
    display: block;
    margin: 0 auto 18px;
}

.file-meta {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px;
    background: var(--bg-elevated);
    border-radius: 10px;
    margin-bottom: 18px;
}
.file-icon {
    font-size: 2rem;
}
.file-meta .name { font-weight: 600; word-break: break-all; }
.file-meta .size { color: var(--text-dim); font-size: 0.85rem; }

.meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-top: 18px;
}

/* ---------- Scan page ---------- */

.scan-modes {
    display: flex;
    gap: 8px;
    margin-bottom: 22px;
}

#reader-viewport {
    border-radius: var(--radius);
    overflow: hidden;
    background: #000;
    min-height: 260px;
}

.scan-result {
    margin-top: 20px;
}
.scan-result .decoded {
    word-break: break-all;
    background: var(--bg-elevated);
    padding: 14px;
    border-radius: 10px;
    font-size: 0.9rem;
    margin-bottom: 14px;
}

/* ---------- 404 ---------- */

.not-found {
    text-align: center;
    padding: 80px 20px;
}
.not-found h1 { font-size: 4rem; margin: 0; color: var(--accent); }

@media (max-width: 640px) {
    .page { padding-top: 90px; }
    .card { padding: 20px; }
}
