/* === Custom Properties === */
:root {
    --color-bg: #faf9f7;
    --color-surface: #ffffff;
    --color-text: #2c2c2c;
    --color-text-muted: #6b6b6b;
    --color-border: #e0ddd8;
    --color-accent: #8b4513;
    --color-accent-light: #d4a574;
    --color-accent-bg: #f5ede4;
    --color-hover: #f0ebe4;
    --color-tag: #e8e2d8;
    --color-tag-text: #5a4a3a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.15);
    --radius: 6px;
    --radius-lg: 12px;
    --gap: 16px;
    --max-width: 1400px;
    --header-height: 64px;
    --filter-width: 280px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-serif: Georgia, "Times New Roman", serif;
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
    min-height: 100vh;
}
a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
img { max-width: 100%; display: block; }
.hidden { display: none !important; }

/* === Header === */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    height: var(--header-height);
}
.header-inner {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 var(--gap);
    height: 100%;
    display: flex;
    align-items: center;
    gap: 24px;
}
.logo {
    flex-shrink: 0;
    color: var(--color-text);
}
.logo:hover { text-decoration: none; }
.logo h1 {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}
.logo .subtitle {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.search-bar {
    flex: 1;
    max-width: 500px;
    position: relative;
}
.search-bar input {
    width: 100%;
    padding: 8px 16px;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    font-size: 0.9rem;
    background: var(--color-bg);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.search-bar input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(139,69,19,0.1);
}
.search-suggest {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    margin-top: 4px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 200;
}
.search-suggest-item {
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}
.search-suggest-item:hover { background: var(--color-hover); }
.search-suggest-item img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}
.object-count {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

/* === Loading === */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    color: var(--color-text-muted);
}
.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    background: var(--color-surface);
    font-size: 0.85rem;
    color: var(--color-text);
    transition: all 0.2s;
}
.btn:hover { background: var(--color-hover); }
.btn-primary {
    background: var(--color-accent);
    color: white;
    border-color: var(--color-accent);
}
.btn-primary:hover { background: #7a3b10; }
.btn-small { padding: 4px 12px; font-size: 0.8rem; }
.btn-large { padding: 12px 32px; font-size: 1rem; }

/* === Overview === */
.view {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 24px var(--gap) 60px;
}
.overview-intro { text-align: center; margin-bottom: 40px; }
.intro-text {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    color: var(--color-text-muted);
    max-width: 700px;
    margin: 0 auto;
}
.overview-structure h2,
.overview-sparklines h2,
.overview-discover h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--color-text);
}

/* A. Mosaic Strip */
.overview-mosaic {
    display: flex;
    flex-wrap: wrap;
    overflow: hidden;
    max-height: 96px;
    margin-bottom: 32px;
    border-radius: var(--radius-lg);
    opacity: 0.9;
}
.overview-mosaic img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    flex-shrink: 0;
}

/* B. Donut + Stats */
.overview-structure { margin-bottom: 48px; }
.structure-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 40px;
    align-items: start;
}
.donut-container { position: relative; }
.donut-svg { width: 100%; max-width: 300px; display: block; margin: 0 auto; }
.donut-segment {
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
    transform-origin: 150px 150px;
}
.donut-segment:hover { filter: brightness(1.1); }
.donut-legend { margin-top: 20px; }
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    cursor: pointer;
    font-size: 0.82rem;
    transition: opacity 0.2s;
}
.legend-item:hover { color: var(--color-accent); }
.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.legend-label { flex: 1; }
.legend-count { color: var(--color-text-muted); font-size: 0.75rem; }
.legend-pct { color: var(--color-text-muted); font-size: 0.72rem; margin-left: 4px; }

/* Stats Panel */
.donut-stats {
    padding: 24px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    min-height: 200px;
}
.stats-header { margin-bottom: 16px; }
.stats-label {
    display: block;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
    font-family: var(--font-serif);
    transition: all 0.2s;
}
.stats-count {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}
.stats-samples {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.stats-thumb { cursor: pointer; }
.stats-thumb img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius);
    transition: transform 0.2s;
}
.stats-thumb:hover img { transform: scale(1.05); }
.stats-thumb-title {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* C. Sparklines */
.overview-sparklines { margin-bottom: 48px; }
.sparkline-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--gap);
}
.sparkline-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    transition: box-shadow 0.2s;
}
.sparkline-card:hover { box-shadow: var(--shadow-sm); }
.sparkline-label {
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--color-text);
}
.sparkline-svg { width: 100%; height: auto; display: block; }
.sparkline-bar, .sparkline-bubble { cursor: pointer; }
.sparkline-bar-fill { transition: opacity 0.2s, fill 0.2s; }
.sparkline-bubble-fill { transition: opacity 0.2s, fill 0.2s; }
.sparkline-bar:hover .sparkline-bar-fill { fill: var(--color-accent) !important; }
.sparkline-bubble:hover .sparkline-bubble-fill { fill: var(--color-accent) !important; opacity: 0.9 !important; }

/* D. Discover Cards */
.overview-discover { margin-bottom: 40px; }
.discover-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--gap);
}
.discover-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.discover-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}
.discover-image {
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: var(--color-bg);
}
.discover-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}
.discover-card:hover .discover-image img { transform: scale(1.05); }
.discover-info { padding: 14px 16px; }
.discover-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.7rem;
    color: white;
    margin-bottom: 8px;
}
.discover-title {
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--font-serif);
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.discover-date, .discover-creator {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* E. CTA */
.overview-cta-section { text-align: center; padding: 20px 0; }

/* === Grid View === */
#view-grid { max-width: var(--max-width); }
.grid-layout {
    display: grid;
    grid-template-columns: var(--filter-width) 1fr;
    gap: 24px;
    align-items: start;
}

/* Filter Panel */
.filter-panel {
    position: sticky;
    top: calc(var(--header-height) + 16px);
    max-height: calc(100vh - var(--header-height) - 32px);
    overflow-y: auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 16px;
}
.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.filter-header h3 { font-size: 0.95rem; }
.filter-group { margin-bottom: 20px; }
.filter-group-title {
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.filter-group-title::after {
    content: "▾";
    font-size: 0.7rem;
    color: var(--color-text-muted);
}
.filter-group.collapsed .filter-group-title::after { content: "▸"; }
.filter-group.collapsed .filter-options { display: none; }
.filter-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 0.82rem;
    cursor: pointer;
    color: var(--color-text);
}
.filter-option:hover { color: var(--color-accent); }
.filter-option input[type="checkbox"] { accent-color: var(--color-accent); }
.filter-option .count {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--color-text-muted);
}

/* Active Filters */
.grid-toolbar {
    margin-bottom: 16px;
}
.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--color-accent-bg);
    color: var(--color-tag-text);
    border-radius: 12px;
    font-size: 0.78rem;
}
.filter-tag .remove {
    cursor: pointer;
    font-weight: bold;
    margin-left: 2px;
    opacity: 0.6;
}
.filter-tag .remove:hover { opacity: 1; }
.grid-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.82rem;
    color: var(--color-text-muted);
}
.sort-select {
    padding: 4px 8px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.82rem;
    background: var(--color-surface);
}

/* Object Grid */
.object-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}
.object-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    content-visibility: auto;
    contain-intrinsic-size: 0 260px;
}
.object-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}
.card-image {
    width: 100%;
    aspect-ratio: 1;
    background: var(--color-bg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.card-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-border);
    font-size: 2rem;
}
.card-info { padding: 8px 10px; }
.card-title {
    font-size: 0.78rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 4px;
}
.card-meta {
    font-size: 0.7rem;
    color: var(--color-text-muted);
}
.grid-footer { text-align: center; padding: 24px 0; }

/* === Detail Modal === */
.modal {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
}
.modal-content {
    position: relative;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    width: 90vw;
    max-width: 1000px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    position: sticky;
    top: 0;
    background: var(--color-surface);
    display: flex;
    justify-content: flex-end;
    padding: 12px 16px 0;
    z-index: 1;
}
.btn-close {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--color-bg);
    border-radius: 50%;
    font-size: 1.3rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.btn-close:hover { background: var(--color-border); }

.detail-body { padding: 0 24px 32px; }
.detail-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
    margin-bottom: 32px;
}
.detail-image {
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--color-bg);
}
.detail-image img {
    width: 100%;
    cursor: zoom-in;
}
.detail-meta h2 {
    font-size: 1.3rem;
    font-family: var(--font-serif);
    margin-bottom: 16px;
    line-height: 1.3;
}
.meta-table {
    width: 100%;
    font-size: 0.85rem;
    border-collapse: collapse;
}
.meta-table tr { border-bottom: 1px solid var(--color-border); }
.meta-table td { padding: 8px 0; vertical-align: top; }
.meta-table td:first-child {
    font-weight: 600;
    color: var(--color-text-muted);
    width: 120px;
    padding-right: 12px;
    white-space: nowrap;
}
.detail-description {
    font-size: 0.9rem;
    line-height: 1.6;
    margin-top: 16px;
    color: var(--color-text-muted);
}
.detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}
.tag {
    padding: 3px 10px;
    background: var(--color-tag);
    color: var(--color-tag-text);
    border-radius: 12px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}
.tag:hover { background: var(--color-accent-bg); }
.detail-links {
    margin-top: 16px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.detail-related { margin-top: 32px; }
.detail-related h3 {
    font-size: 0.95rem;
    margin-bottom: 12px;
}
.related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
}
.related-card {
    aspect-ratio: 1;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    background: var(--color-bg);
}
.related-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* === Mobile Filter Toggle === */
.btn-filter-toggle {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 90;
    padding: 10px 18px;
    background: var(--color-accent);
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 0.85rem;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 6px;
}
.btn-filter-toggle svg { flex-shrink: 0; }

/* === Responsive === */
@media (max-width: 1024px) {
    .grid-layout {
        grid-template-columns: 1fr;
    }
    .filter-panel {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        width: 300px;
        border-radius: 0;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.3s;
        border-right: 1px solid var(--color-border);
    }
    .filter-panel.open {
        transform: translateX(0);
    }
    .btn-filter-toggle.visible { display: flex; }
}

@media (max-width: 768px) {
    .header-inner { gap: 12px; }
    .logo h1 { font-size: 0.95rem; }
    .logo .subtitle { display: none; }
    .search-bar { max-width: none; }
    .structure-layout { grid-template-columns: 1fr; }
    .donut-svg { max-width: 240px; }
    .sparkline-row { grid-template-columns: 1fr 1fr; }
    .discover-cards { grid-template-columns: 1fr; }
    .object-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
    .detail-layout { grid-template-columns: 1fr; }
    .modal-content { width: 95vw; max-height: 95vh; }
}
