/* ── Custom styles beyond Tailwind ── */
body {
    font-family: "Inter", system-ui, sans-serif;
}

/* Bottom nav — slightly larger center button */
.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 0;
    flex: 1;
    cursor: pointer;
    transition: color 0.15s;
}
.nav-btn.active {
    color: #6366f1;
}
.nav-btn-scan {
    margin-top: -12px;
}
.nav-btn-scan .scan-circle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #6366f1;
    color: #fff;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

/* Page transitions */
.page {
    display: none;
}
.page.active {
    display: flex;
}

/* Collection grid tiles */
.col-tile {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
}

/* Fanned card preview stack inside collection tiles */
.col-preview-stack {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.col-preview-card {
    position: absolute;
    width: 56px;
    height: 78px;
    border-radius: 6px;
    overflow: hidden;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.col-preview-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.col-preview-placeholder {
    font-size: 1.5rem;
    color: #9ca3af;
}
.col-tile-add {
    border: 2px dashed #d1d5db;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 16px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s;
}
.col-tile-add:hover {
    border-color: #6366f1;
    color: #6366f1;
}

/* Grid mode — square tiles */
.col-tile-grid {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    padding: 8px;
}
.col-tile-grid:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}
.col-tile-add-grid {
    border: 2px dashed #d1d5db;
    aspect-ratio: 1;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
}
.col-tile-add-grid:hover {
    border-color: #6366f1;
    color: #6366f1;
}
body.dark-mode .col-tile-grid {
    background: #1f2937 !important;
    border-color: #374151 !important;
}
body.dark-mode .col-tile-grid:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Card grid */
.card-grid-item {
    break-inside: avoid;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.15s;
}
.card-grid-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

/* Camera viewfinder — full screen on mobile */
#page-scan.active {
    position: fixed;
    inset: 0;
    z-index: 10;
    padding: 0;
}
body:has(#page-scan.active) nav {
    display: none;
}

/* Card viewfinder corners */
.viewfinder-box {
    position: absolute;
    width: 95%;
    aspect-ratio: 2.5 / 3.5;
}
.vf-corner {
    position: absolute;
    width: 28px;
    height: 28px;
    border-color: rgba(255, 255, 255, 0.85);
    border-style: solid;
}
.vf-tl {
    top: 0;
    left: 0;
    border-width: 3px 0 0 3px;
    border-radius: 6px 0 0 0;
}
.vf-tr {
    top: 0;
    right: 0;
    border-width: 3px 3px 0 0;
    border-radius: 0 6px 0 0;
}
.vf-bl {
    bottom: 0;
    left: 0;
    border-width: 0 0 3px 3px;
    border-radius: 0 0 0 6px;
}
.vf-br {
    bottom: 0;
    right: 0;
    border-width: 0 3px 3px 0;
    border-radius: 0 0 6px 0;
}

/* Camera viewfinder */
#camera-view {
    display: none;
}
#camera-view.active {
    display: flex;
}
.capture-btn {
    position: absolute;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 4px solid #fff;
    background: rgba(255, 255, 255, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.capture-btn-inner {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #fff;
}

/* Floating save button */
#save-btn {
    display: none;
    position: fixed;
    bottom: 80px;
    right: 16px;
    z-index: 40;
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 80px;
    left: 0;
    right: 0;
    z-index: 50;
    pointer-events: none;
}
.toast {
    background: #1f2937;
    color: #f9fafb;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    animation: toast-in 0.25s ease-out;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal {
    background: #fff;
    border-radius: 16px;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

/* Scan results */
.scan-image-thumb {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
}

/* Loading spinner */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #e5e7eb;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Star rating */
.star {
    cursor: pointer;
    font-size: 20px;
}
.star:hover,
.star.active {
    color: #f59e0b;
}

/* Image grid in card detail */
.img-toggle {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}
.img-toggle button {
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid #d1d5db;
    background: #fff;
    transition: all 0.15s;
}
.img-toggle button.active {
    background: #6366f1;
    color: #fff;
    border-color: #6366f1;
}

/* Scrollable cards list with masonry effect */
#cards-list {
    column-count: 2;
    column-gap: 12px;
}
#cards-list > * {
    break-inside: avoid;
    margin-bottom: 12px;
}
@media (min-width: 640px) {
    #cards-list {
        column-count: 3;
    }
}

/* ── Dark Mode ── */
body.dark-mode {
    background: #111827;
    color: #e5e7eb;
}
body.dark-mode #main-content {
    background: #111827;
}

/* Page wrappers */
body.dark-mode .page {
    background: #111827;
}

/* Headings */
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3 {
    color: #f3f4f6;
}
body.dark-mode .text-gray-900 {
    color: #f3f4f6 !important;
}
body.dark-mode .text-gray-700 {
    color: #d1d5db !important;
}
body.dark-mode .text-gray-600 {
    color: #9ca3af !important;
}
body.dark-mode .text-gray-500 {
    color: #9ca3af !important;
}
body.dark-mode .text-gray-400 {
    color: #6b7280 !important;
}
body.dark-mode .text-red-600 {
    color: #f87171 !important;
}

/* Backgrounds */
body.dark-mode .bg-gray-50 {
    background: #111827 !important;
}
body.dark-mode .bg-gray-100 {
    background: #1f2937 !important;
}
body.dark-mode .bg-white {
    background: #1f2937 !important;
}
body.dark-mode .bg-red-50 {
    background: #3b1a1a !important;
}

/* Borders */
body.dark-mode .border-gray-100 {
    border-color: #374151 !important;
}
body.dark-mode .border-gray-200 {
    border-color: #374151 !important;
}
body.dark-mode .border-red-100 {
    border-color: #7f1d1d !important;
}

/* Collection tiles */
body.dark-mode .col-tile {
    background: #1f2937 !important;
    border-color: #374151 !important;
}
body.dark-mode .col-tile:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
body.dark-mode .col-tile div[style*="color:#111827"] {
    color: #f3f4f6 !important;
}
body.dark-mode .col-tile-grid div[style*="color:#111827"] {
    color: #f3f4f6 !important;
}
body.dark-mode .col-tile-add {
    border-color: #4b5563;
}
body.dark-mode .col-tile-add:hover {
    border-color: #6366f1;
}
body.dark-mode .col-preview-card {
    background: #374151;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Card grid items */
body.dark-mode .card-grid-item {
    background: #1f2937 !important;
    border-color: #374151 !important;
}

/* Bottom nav */
body.dark-mode nav {
    background: #1f2937 !important;
    border-top-color: #374151 !important;
}
body.dark-mode nav .nav-btn {
    color: #9ca3af;
}
body.dark-mode nav .nav-btn.active {
    color: #818cf8;
}

/* Inputs */
body.dark-mode input,
body.dark-mode textarea,
body.dark-mode select {
    background: #374151 !important;
    color: #e5e7eb !important;
    border-color: #4b5563 !important;
}
body.dark-mode input::placeholder,
body.dark-mode textarea::placeholder {
    color: #6b7280;
}

/* Buttons */
body.dark-mode .bg-indigo-600 {
    background: #4f46e5 !important;
}
body.dark-mode .bg-indigo-600:hover {
    background: #4338ca !important;
}
body.dark-mode .bg-gray-100 {
    background: #374151 !important;
}
body.dark-mode .bg-gray-100:hover {
    background: #4b5563 !important;
}
body.dark-mode button.text-gray-700 {
    color: #e5e7eb !important;
}

/* Modal */
body.dark-mode .modal {
    background: #1f2937;
}
body.dark-mode .modal .bg-white {
    background: #1f2937 !important;
}
body.dark-mode .modal-overlay {
    background: rgba(0, 0, 0, 0.7);
}

/* Debug log */
body.dark-mode #debug-log {
    color: #9ca3af !important;
}

/* Toast */
body.dark-mode .toast {
    background: #374151;
    color: #f3f4f6;
}

/* Nav scan circle */
body.dark-mode .scan-circle {
    background: #4f46e5;
}

/* Collection detail back button etc */
body.dark-mode .text-indigo-600 {
    color: #818cf8 !important;
}

/* Rarity / badge colors remained unchanged for consistency */

/* Dark mode toggle knob */
body.dark-mode #dark-mode-toggle {
    background-color: #4f46e5 !important;
}
body.dark-mode #dark-mode-knob {
    transform: translateX(20px);
}

/* Collection count badge */
body.dark-mode .bg-gray-100.px-3.py-1 {
    background: #374151 !important;
    color: #9ca3af !important;
}

/* Modal select */
body.dark-mode select option {
    background: #1f2937;
    color: #e5e7eb;
}
