/* =========================================
   COLLECTED — Mosaic Library
   ========================================= */

/* Mosaic grid */
.cl-grid {
    display: grid;
    grid-template-columns: repeat(var(--cl-cols, 4), 1fr);
    grid-auto-rows: var(--cl-row-h, 220px);
    gap: 2px;
    min-height: 100dvh;
    background: #0a0a0a;
    padding-bottom: 90px;
}

.cl-card {
    opacity: 0;
}

.cl-grid.loaded .cl-card {
    animation: fadeIn 0.5s ease forwards;
}
.cl-grid.loaded .cl-card:nth-child(1)  { animation-delay: 0.04s; }
.cl-grid.loaded .cl-card:nth-child(2)  { animation-delay: 0.08s; }
.cl-grid.loaded .cl-card:nth-child(3)  { animation-delay: 0.12s; }
.cl-grid.loaded .cl-card:nth-child(4)  { animation-delay: 0.16s; }
.cl-grid.loaded .cl-card:nth-child(5)  { animation-delay: 0.20s; }
.cl-grid.loaded .cl-card:nth-child(6)  { animation-delay: 0.24s; }
.cl-grid.loaded .cl-card:nth-child(7)  { animation-delay: 0.28s; }
.cl-grid.loaded .cl-card:nth-child(8)  { animation-delay: 0.32s; }
.cl-grid.loaded .cl-card:nth-child(n+9) { animation-delay: 0.36s; }


/* Base card */
.cl-card {
    position: relative;
    display: block;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    background: #111;
    min-height: 0;
    min-width: 0;
}

/* Media fill */
.cl-card-media {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    transition: transform 0.4s ease;
}
.cl-card:hover .cl-card-media { transform: scale(1.04); }

.cl-card-media--icon {
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,0.02);
}
.cl-card-icon {
    font-size: 2em;
    color: rgba(255,255,255,0.12);
    opacity: 1;
}

/* Hover panel — gradient as ::before, info block with left border */
.cl-card-hover {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 0 16px 16px 16px;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.cl-card-hover::before {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 75%;
    background: linear-gradient(to top, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.5) 50%, transparent 100%);
    pointer-events: none;
}
.cl-card:hover .cl-card-hover { opacity: 1; }

/* Info block — left border in type color, no background */
.cl-hover-info {
    position: relative;
    border-left: 1px solid var(--type-color, rgba(255,255,255,0.3));
    padding: 0 0 0 12px;
    max-width: 340px;
}

/* Big title */
.cl-hover-title {
    font-family: var(--font-mono);
    font-size: clamp(0.9rem, 2.5vw, 1.5rem);
    text-transform: uppercase;
    letter-spacing: -0.01em;
    color: #fff;
    line-height: 1.1;
    margin-bottom: 7px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Single compact meta line */
.cl-hover-meta {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255,255,255,0.7);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Note */
.cl-hover-note {
    font-family: var(--font-mono);
    font-size: 0.56rem;
    color: rgba(255,255,255,0.6);
    line-height: 1.55;
    margin-top: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Footer */
.cl-hover-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 9px;
    padding-top: 7px;
    border-top: 1px solid rgba(255,255,255,0.07);
}
.cl-card-connections {
    font-family: var(--font-mono);
    font-size: 0.48rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.55);
    cursor: pointer;
    transition: color 0.15s;
}
.cl-card-connections:hover { color: #fff; }
.cl-hover-open {
    font-family: var(--font-mono);
    font-size: 0.48rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.55);
}

/* ─── Bottom-right toggle button ─── */
.cl-controls-wrapper {
    position: fixed;
    bottom: max(30px, env(safe-area-inset-bottom));
    right: 30px;
    z-index: 9000;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-end;
    gap: 6px;
}

.cl-toggle {
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    border-left: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.55);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: color 0.2s ease, border-color 0.2s ease;
    border-radius: 0;
    pointer-events: auto;
}
.cl-toggle:hover,
.cl-toggle.active {
    color: #fff;
    border-color: rgba(255,255,255,0.5);
}

/* Panel that slides up from the button */
.cl-panel {
    background: rgba(0,0,0,0.75);
    border: none;
    border-left: 1px solid rgba(255,255,255,0.12);
    padding: 16px;
    width: 240px;
    max-height: calc(100dvh - 120px);
    overflow-y: auto;
    display: none;
    flex-direction: column;
    gap: 12px;
    pointer-events: auto;
}
.cl-panel.open { display: flex; }

.cl-panel-title {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.85);
    margin: 0 0 4px;
}
.cl-panel-stats {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    letter-spacing: 0.06em;
    color: rgba(255,255,255,0.45);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.cl-panel-label {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.45);
    margin-bottom: 5px;
}

/* Type filter buttons */
.cl-type-filters { display: flex; gap: 4px; flex-wrap: wrap; }
.cl-type-btn {
    display: flex; align-items: center; gap: 5px;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.55);
    border-radius: 0;
    font-family: var(--font-mono);
    font-size: 0.68rem; cursor: pointer;
    transition: all 0.12s; letter-spacing: 0.06em; text-transform: uppercase;
}
.cl-type-btn:hover { color: rgba(255,255,255,0.7); border-color: rgba(255,255,255,0.18); }
.cl-type-btn.active {
    background: rgba(255,255,255,0.06);
    border-color: var(--type-color, rgba(255,255,255,0.3));
    color: #fff;
}
.cl-count { opacity: 0.4; font-size: 0.85em; }

/* Tag filter */
.cl-tag-filters { display: flex; gap: 4px; flex-wrap: wrap; }
.cl-tag-btn {
    padding: 3px 8px; background: transparent;
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.5); border-radius: 0;
    font-family: var(--font-mono);
    font-size: 0.65rem; cursor: pointer; transition: all 0.12s; letter-spacing: 0.06em;
}
.cl-tag-btn:hover { border-color: rgba(255,255,255,0.2); color: rgba(255,255,255,0.75); }
.cl-tag-btn.active { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.35); color: #fff; }

.cl-empty {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.72rem; opacity: 0.45;
    text-transform: uppercase; letter-spacing: 0.1em;
}

/* Better fallback for cards without thumbnails */
.cl-card-media--icon {
    background: linear-gradient(135deg, rgba(255,255,255,0.03) 0%, rgba(255,255,255,0.01) 100%);
    border: 1px solid rgba(255,255,255,0.04);
}
.cl-card-icon {
    font-size: 2.5em;
    color: rgba(255,255,255,0.12);
    opacity: 1;
    font-style: normal;
}
.cl-card[data-type="note"] .cl-card-media--icon,
.cl-card[data-type="written"] .cl-card-media--icon {
    align-items: flex-start;
    padding: 14px;
}
.cl-card[data-type="note"] .cl-card-icon,
.cl-card[data-type="written"] .cl-card-icon {
    font-size: 0.72em;
    opacity: 0.4;
    line-height: 1.6;
    letter-spacing: 0.02em;
    font-family: var(--font-mono);
    text-transform: none;
}

/* Inline connections — appears inside hover panel on click */
.cl-hover-connections {
    display: none;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.08);
    max-height: 160px;
    overflow-y: auto;
}
.cl-hover-connections.open { display: block; }
.cl-conn-item {
    display: block;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    cursor: pointer;
    color: inherit;
}
.cl-conn-item:hover .cl-conn-title { color: #fff; }
.cl-conn-item:last-child { border-bottom: none; }
.cl-conn-type {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.46rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.5);
    margin-bottom: 2px;
}
.cl-conn-title {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: rgba(255,255,255,0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cl-conn-reason {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.46rem;
    color: rgba(255,255,255,0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}
.cl-conn-loading, .cl-conn-empty {
    font-family: var(--font-mono);
    font-size: 0.5rem;
    color: rgba(255,255,255,0.45);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 4px 0;
}
.cl-card-connections.active { color: rgba(255,255,255,0.65); }

