:root {
    --bg: #07070c;
    --panel: rgba(22, 22, 30, 0.72);
    --panel-solid: #16161e;
    --text: #ffffff;
    --muted: #9ca3af;
    --accent: #7c5cff;
    --accent2: #fbbf24;
    --border: rgba(255,255,255,0.08);
    --nav-h: 64px;
    --blur: 18px;
    --radius: 18px;
}

/* GLOBAL RESET */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial;
}

body {
    background: radial-gradient(circle at 20% 10%, rgba(124,92,255,0.18), transparent 40%),
                radial-gradient(circle at 80% 80%, rgba(251,191,36,0.10), transparent 45%),
                var(--bg);
    color: var(--text);
    overflow: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: url("https://grainy-gradients.vercel.app/noise.svg");
    opacity: 0.06;
    pointer-events: none;
}

/* APP FRAME */
.app-container {
    height: 100vh;
    max-width: 640px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* ==========================================
   HEADER
   ========================================== */
.app-header {
    padding: 14px 20px;
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    background: rgba(10,10,14,0.6);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex: 0 0 auto;
    box-shadow: 0 0 14px rgba(124,92,255,0.28);
}

.header-text { display: flex; flex-direction: column; }

.header-title {
    font-size: 1.3rem;
    letter-spacing: 0.22em;
    font-weight: 700;
    line-height: 1.1;
}

.header-subtitle {
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.14em;
}

/* ==========================================
   VIEW SYSTEM
   ========================================== */
.view-container {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    padding-bottom: calc(var(--nav-h) + 90px);
}

.app-view {
    display: none;
    opacity: 0;
    transform: translateY(10px);
}

.app-view.active {
    display: block;
    animation: fadeUp 0.35s ease forwards;
    pointer-events: auto;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* TYPOGRAPHY */
h2 { font-size: 1.4rem; margin-bottom: 6px; }
p { color: var(--muted); font-size: 0.92rem; }
.muted { color: var(--muted); }

/* ==========================================
   GLASS CARDS (AI + Source results)
   ========================================== */
.source-card, .ai-card {
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 14px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.source-card:hover {
    transform: translateY(-2px);
    border-color: rgba(124,92,255,0.35);
}

.source-card { border-left: 3px solid var(--accent2); }
.source-title { font-weight: 650; margin-bottom: 4px; }
.source-agency { font-size: 0.7rem; color: var(--muted); letter-spacing: 0.12em; }
.source-meta { font-size: 0.75rem; color: var(--muted); }

/* BADGE */
.badge {
    position: absolute;
    top: 14px;
    right: 14px;
    font-size: 0.6rem;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(124,92,255,0.15);
    color: var(--accent);
    border: 1px solid rgba(124,92,255,0.3);
}

/* AI CARD */
.ai-card { border: 1px solid rgba(124,92,255,0.4); }
.ai-card.speculative { border-color: rgba(251,191,36,0.5); }
.ai-header { font-size: 0.65rem; letter-spacing: 0.18em; color: var(--accent); margin-bottom: 10px; }
.ai-card.speculative .ai-header { color: var(--accent2); }
.ai-content { font-size: 0.95rem; line-height: 1.55; }

/* ==========================================
   ARCHIVE LIST
   ========================================== */
.archive-status { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.06em; margin: 10px 0 16px; }
.archive-status.error-line { color: #ef4444; }
.archive-list { display: flex; flex-direction: column; gap: 10px; }

.archive-row {
    display: flex;
    align-items: stretch;
    gap: 12px;
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 14px 14px 0;
    overflow: hidden;
    position: relative;
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.archive-row:hover {
    transform: translateY(-1px);
    border-color: rgba(124,92,255,0.35);
    background: rgba(124,92,255,0.06);
}

.archive-accent { width: 3px; background: var(--accent2); border-radius: 3px; flex: 0 0 auto; align-self: stretch; }
.archive-body { flex: 1 1 auto; min-width: 0; padding-left: 2px; }
.archive-title { font-weight: 650; font-size: 0.95rem; line-height: 1.32; margin-bottom: 5px; word-break: break-word; }
.archive-agency { font-size: 0.64rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.archive-meta { font-size: 0.72rem; color: var(--muted); margin-top: 4px; }
.archive-badge {
    flex: 0 0 auto; align-self: flex-start; margin-top: 2px; font-size: 0.56rem; letter-spacing: 0.06em;
    padding: 4px 8px; border-radius: 999px; background: rgba(124,92,255,0.15); color: var(--accent);
    border: 1px solid rgba(124,92,255,0.3); white-space: nowrap;
}

/* ==========================================
   DOCUMENT VIEWER
   ========================================== */
.doc-back-btn {
    background: rgba(124,92,255,0.12); color: var(--accent); border: 1px solid rgba(124,92,255,0.3);
    border-radius: 999px; padding: 8px 16px; font-size: 0.85rem; cursor: pointer; margin-bottom: 16px; transition: all 0.2s ease;
}
.doc-back-btn:hover { background: rgba(124,92,255,0.2); }

.document-header {
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border); border-left: 3px solid var(--accent2);
    border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.document-title { font-size: 1.15rem; font-weight: 700; line-height: 1.3; }
.document-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.doc-chip {
    font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; padding: 4px 8px;
    border-radius: 999px; background: rgba(124,92,255,0.15); color: var(--accent); border: 1px solid rgba(124,92,255,0.3);
}
.document-sub { font-size: 0.78rem; color: var(--muted); margin-top: 10px; }
.document-pagecount { font-size: 0.72rem; color: var(--muted); margin-top: 6px; letter-spacing: 0.06em; }
.document-pages { display: flex; flex-direction: column; gap: 14px; }
.doc-loading { text-align: center; color: var(--accent2); padding: 24px 0; animation: pulse 1.4s infinite; }

/* page-unit = outer visible card (border, radius, bg, overflow clip for image corners) */
.page-unit {
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* page-card = inner content area (image + head + transcription); no border/bg of its own */
.page-card {
    background: transparent;
}
.page-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; }
.page-label { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.1em; color: var(--accent); }
.page-count { font-size: 0.62rem; color: var(--muted); }
.page-img-link { display: block; background: #0d0d14; }
.page-img { display: block; width: 100%; height: auto; }
.page-noimg { display: flex; align-items: center; justify-content: center; height: 180px; background: #0d0d14; color: var(--muted); font-size: 0.8rem; }

.page-ocr { border-top: 1px solid var(--border); }
.page-ocr summary {
    cursor: pointer; padding: 10px 12px; font-size: 0.72rem; font-weight: 600;
    letter-spacing: 0.08em; color: var(--accent); list-style: none;
}
.page-ocr summary::-webkit-details-marker { display: none; }
.page-ocr summary::before { content: "▸ "; }
.page-ocr[open] summary::before { content: "▾ "; }
.page-ocr pre {
    margin: 0; padding: 0 12px 14px; white-space: pre-wrap; word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.78rem; line-height: 1.5; color: var(--muted);
}

/* ==========================================
   INFO / LEGAL PAGES
   ========================================== */
.info-body {
    margin-top: 8px;
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border); border-left: 3px solid var(--accent2);
    border-radius: var(--radius); padding: 18px 18px 22px; line-height: 1.6;
}
.info-body h3 { font-size: 0.95rem; margin: 18px 0 6px; color: var(--text); letter-spacing: 0.02em; }
.info-body h3:first-child { margin-top: 0; }
.info-body p { font-size: 0.88rem; color: var(--muted); margin-bottom: 10px; }
.info-body ul { margin: 4px 0 12px 18px; }
.info-body li { font-size: 0.88rem; color: var(--muted); margin-bottom: 6px; }
.info-body a { color: var(--accent); text-decoration: none; }
.info-updated { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }

/* ==========================================
   SETTINGS / HOME MENU
   ========================================== */
.settings-menu { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; }
.settings-item {
    display: flex; align-items: center; padding: 16px 20px;
    background: var(--panel);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border); border-radius: 12px; color: var(--muted);
    text-decoration: none; font-size: 0.9rem; cursor: pointer; transition: all 0.2s ease;
}
.settings-item:hover {
    color: var(--text); border-color: rgba(124,92,255,0.4);
    background: rgba(124,92,255,0.08); transform: translateY(-1px);
}
.settings-item.support-link { border-left: 3px solid var(--accent2); color: var(--text); font-weight: 600; }

/* ==========================================
   CHIPS
   ========================================== */
.chips-container { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.chip {
    border: 1px solid var(--border); background: rgba(255,255,255,0.03);
    padding: 10px 14px; border-radius: 999px; font-size: 0.8rem; color: var(--text);
    transition: all 0.2s ease; cursor: pointer;
}
.chip:hover { transform: translateY(-1px); border-color: rgba(124,92,255,0.4); background: rgba(124,92,255,0.08); }

/* ==========================================
   SEARCH BAR
   ========================================== */
.search-wrapper {
    position: fixed; bottom: var(--nav-h); left: 0; right: 0;
    max-width: 640px; margin: 0 auto; padding: 14px 16px; z-index: 80;
}
.search-box {
    display: flex; align-items: center; background: rgba(22,22,30,0.7);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border); border-radius: 999px; padding: 6px; transition: all 0.2s ease;
}
.search-box:focus-within { border-color: rgba(124,92,255,0.5); box-shadow: 0 0 0 3px rgba(124,92,255,0.12); }
.search-box input { flex: 1; background: transparent; border: none; color: var(--text); padding: 10px 14px; font-size: 0.95rem; }
.search-box input:focus { outline: none; }
.search-box button { width: 40px; height: 40px; border-radius: 50%; border: none; background: rgba(124,92,255,0.15); color: var(--accent); cursor: pointer; }

/* ==========================================
   BOTTOM NAV
   ========================================== */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; max-width: 640px; margin: 0 auto;
    height: var(--nav-h); display: flex; justify-content: space-around; align-items: center;
    background: rgba(10,10,14,0.85);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    border-top: 1px solid var(--border); z-index: 100;
}
.nav-item { display: flex; flex-direction: column; align-items: center; font-size: 0.65rem; color: var(--muted); gap: 4px; transition: all 0.2s ease; cursor: pointer; }
.nav-item svg { width: 20px; height: 20px; }
.nav-item.active { color: var(--accent); transform: translateY(-2px); }
.nav-item.active svg { stroke: var(--accent); filter: drop-shadow(0 0 6px rgba(124,92,255,0.4)); }

/* ==========================================
   LOADING / ERROR
   ========================================== */
.loading { text-align: center; color: var(--accent2); margin: 12px 0; animation: pulse 1.4s infinite; display: none; }
.error { color: #ef4444; font-size: 0.85rem; margin-bottom: 20px; text-align: center; }

@keyframes pulse { 0%,100% { opacity: 0.5; } 50% { opacity: 1; } }

/* ==========================================
   ADSENSE
   Auto ads (anchor + vignette) are enabled via the AdSense dashboard.
   The loader script in <head> powers them — no in-page units needed.
   ========================================== */

/* ==========================================
   PAGE SHARE BUTTON
   ========================================== */
.page-head-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid rgba(124,92,255,0.35);
    background: rgba(124,92,255,0.12);
    color: var(--accent);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.page-share-btn:hover {
    background: rgba(124,92,255,0.25);
    border-color: rgba(124,92,255,0.6);
    transform: scale(1.08);
}

.page-share-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ==========================================
   SHARE TOAST (clipboard fallback on desktop)
   ========================================== */
#share-toast {
    position: fixed;
    bottom: calc(var(--nav-h) + 80px);
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: rgba(124,92,255,0.92);
    color: #fff;
    font-size: 0.85rem;
    padding: 10px 20px;
    border-radius: 999px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 200;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#share-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================
   PAGE SHARE ROW  (below Transcription)
   ========================================== */
.page-share-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px 12px;
    border-top: 1px solid var(--border);
}

.share-row-label {
    font-size: 0.58rem;
    letter-spacing: 0.14em;
    color: var(--muted);
    margin-right: 2px;
    flex-shrink: 0;
}

.share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
    flex-shrink: 0;
    color: #fff;
}
.share-btn:hover  { transform: scale(1.12); }
.share-btn:active { transform: scale(0.96); }
.share-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.share-btn svg { width: 16px; height: 16px; }

/* Platform colours */
.share-fb     { background: #1877F2; }
.share-tw     { background: #000000; }
.share-wa     { background: #25D366; }
.share-native { background: var(--accent); }

/* ==========================================
   SHARE TOAST  (clipboard fallback)
   ========================================== */
#share-toast {
    position: fixed;
    bottom: calc(var(--nav-h) + 80px);
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: rgba(124,92,255,0.92);
    color: #fff;
    font-size: 0.85rem;
    padding: 10px 20px;
    border-radius: 999px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 200;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}
#share-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
