* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #0a0a0a;
    --surface: #161616;
    --surface2: #222;
    --border: #333;
    --text: #e8e8e8;
    --text-dim: #888;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --radius: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-text-size-adjust: 100%;
}

/* --- Auth view --- */

#auth-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 2rem;
}

#auth-view h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
#auth-view p { color: var(--text-dim); margin-bottom: 2rem; }

/* --- App shell --- */

#app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

header h1 { font-size: 1.1rem; font-weight: 600; }

nav {
    display: flex;
    background: var(--surface);
    border-top: 1px solid var(--border);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
}

nav button {
    flex: 1;
    padding: 0.75rem;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.8rem;
    cursor: pointer;
    transition: color 0.2s;
}

nav button.active { color: var(--accent); }
nav button:hover { color: var(--text); }

.view {
    flex: 1;
    padding: 1rem;
    padding-bottom: 5rem; /* space for nav */
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.hidden { display: none !important; }

/* --- Buttons --- */

.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
}

.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

/* --- Scan view --- */

.scan-controls {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 1rem;
}

.capture-btn {
    position: relative;
    overflow: hidden;
}

.capture-btn input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.scan-controls select {
    padding: 0.6rem;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.status {
    padding: 0.5rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.status.uploading { background: var(--surface2); color: var(--accent); }
.status.success { background: #052e16; color: var(--success); }
.status.error { background: #450a0a; color: var(--danger); }

/* --- Gallery --- */

.gallery-controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    align-items: center;
}

.gallery-controls select {
    padding: 0.6rem;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    flex: 1;
}

#gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
}

.scan-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.scan-card img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    display: block;
}

.scan-info {
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.scan-name {
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scan-date { font-size: 0.7rem; color: var(--text-dim); }

.scan-actions {
    padding: 0.5rem;
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    border-top: 1px solid var(--border);
}

/* --- Books --- */

.book-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.book-info { display: flex; flex-direction: column; gap: 0.25rem; }
.book-info span { font-size: 0.85rem; color: var(--text-dim); }

.book-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

/* --- Error toast --- */

#error-toast {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    z-index: 100;
    font-size: 0.9rem;
    max-width: 90%;
}

.empty { color: var(--text-dim); text-align: center; padding: 2rem; }

/* Desktop adjustments */
@media (min-width: 768px) {
    #gallery { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
    nav { position: static; border-top: none; border-bottom: 1px solid var(--border); }
    .view { padding-bottom: 1rem; }
}
