/* =====================
    DESIGN TOKENS
===================== */
:root {
    --bg-deep:       #0e0f11;
    --bg-surface:    #16181b;
    --bg-card:       #1c1f23;
    --bg-card-hover: #222629;
    --border:        #2e3238;
    --border-glow:   #4a6a9a;
    --accent:        #8fa8c8;
    --accent-bright: #b0cce8;
    --gold:          #d4c5a0;
    --gold-dim:      #9a8c72;
    --text-body:     #a0a8b4;
    --text-dim:      #626a74;
    --text-muted:    #474e58;
    --tag-bg:        #1a2230;
    --tag-border:    #2e4060;
    --tag-text:      #7098c0;
    --dep-bg:        #1a2218;
    --dep-border:    #2e4430;
    --dep-text:      #68986a;
    --radius:        6px;
    --radius-lg:     10px;
}

/* =====================
    RESET & BASE
===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    background-color: var(--bg-deep);
    color: var(--text-body);
    font-family: 'Crimson Pro', Georgia, serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Subtle noise texture overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
    opacity: 0.4;
}

/* =====================
    LAYOUT
===================== */
.page-wrapper {
    position: relative;
    z-index: 1;
    max-width: 92%;
    margin: 0 auto;
    padding: 0 24px 60px;
}

/* =====================
    HEADER
===================== */
.site-header {
    padding: 48px 0 32px;
    text-align: center;
    position: relative;
}

.site-header::after {
    content: '';
    display: block;
    width: 120px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-glow), transparent);
    margin: 20px auto 0;
}

.site-header .logo-icon {
    font-size: 2rem;
    color: var(--accent);
    margin-bottom: 10px;
    display: block;
    opacity: 0.7;
}

.site-title {
    font-family: 'Cinzel', serif;
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.06em;
    text-shadow: 0 0 40px rgba(212, 197, 160, 0.15);
    line-height: 1.1;
}

.site-subtitle {
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-size: 1rem;
    color: var(--text-dim);
    margin-top: 6px;
    letter-spacing: 0.04em;
}

/* =====================
    TOOLBAR
===================== */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-wrap {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-wrap i {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.8rem;
    pointer-events: none;
}

.search-input {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-body);
    font-family: 'Crimson Pro', serif;
    font-size: 1rem;
    padding: 9px 12px 9px 36px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input::placeholder { color: var(--text-muted); font-style: italic; }

.search-input:focus {
    border-color: var(--border-glow);
    box-shadow: 0 0 0 3px rgba(74, 106, 154, 0.15);
}

.result-count {
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    color: var(--text-dim);
    letter-spacing: 0.06em;
    white-space: nowrap;
    padding: 0 4px;
}

/* =====================
    ACTIVE TAGS FILTER
===================== */
.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 14px;
    min-height: 0;
}

.active-filters:empty { display: none; }

.filter-chip {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    padding: 3px 8px 3px 10px;
    background: #1e2e48;
    border: 1px solid #3a5a88;
    border-radius: 20px;
    color: #90b8e0;
    cursor: pointer;
    transition: background 0.15s;
    font-family: 'Crimson Pro', serif;
}

.filter-chip:hover { background: #2a3e5a; }
.filter-chip i { font-size: 0.6rem; opacity: 0.7; }

/* =====================
    GALLERY GRID
===================== */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 10px;
}

/* =====================
    ENTRY CARD
===================== */
.entry-card {
    display: flex;
    flex-direction: row;
    gap: 10px;
    padding: 10px;
    background: linear-gradient(145deg, var(--bg-card), #191c20);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.18s, box-shadow 0.18s, transform 0.12s;
    min-height: 120px;
    max-height: 152px;
    position: relative;
    animation: cardIn 0.3s ease both;
}

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

.entry-card:hover {
    border-color: var(--border-glow);
    box-shadow: 0 4px 20px rgba(60, 100, 160, 0.18);
    transform: translateY(-2px);
}

/* Drag handle */
.entry-card[draggable="true"] { cursor: grab; }
.entry-card[draggable="true"]:active { cursor: grabbing; transform: translateY(0); }

/* Thumbnail */
.entry-card .thumb {
    flex: 0 0 auto;
    width: 108px;
    height: 108px;
    border-radius: var(--radius);
    object-fit: cover;
    align-self: center;
    border: 1px solid #2e3238;
    background: #111315;
}

.entry-card .thumb-placeholder {
    flex: 0 0 108px;
    height: 108px;
    border-radius: var(--radius);
    border: 1px solid #2e3238;
    background: #111315;
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    color: var(--text-muted);
    font-size: 1.5rem;
}

/* Info panel */
.entry-card .info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow: hidden;
}

.entry-card .info hr {
    border: none;
    background: var(--border);
    height: 1px;
    flex-shrink: 0;
    margin: 1px 0;
}

/* Card header row: title/author left, type badge right */
.entry-card .card-header {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    justify-content: space-between;
    min-width: 0;
}

.entry-card .card-header > div {
    flex: 1;
    min-width: 0;
}

.entry-card .card-title {
    font-family: 'Cinzel', serif;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
    letter-spacing: 0.02em;
}

.entry-card .card-author {
    font-size: 0.72rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: color 0.12s;
    text-decoration: none;
    display: block;
}

.entry-card .card-author:hover {
    color: var(--accent-bright);
    text-decoration: underline;
}

/* Type badge - top-right of card info */
.entry-card .type-badge {
    flex-shrink: 0;
    font-size: 0.55rem;
    padding: 2px 6px;
    background: #1a1a2e;
    border: 1px solid #3a3a6a;
    border-radius: 4px;
    color: #8888cc;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    font-family: 'Cinzel', serif;
    letter-spacing: 0.05em;
    text-decoration: none;
    line-height: 1.6;
    align-self: flex-start;
    margin-top: 1px;
}

.entry-card .type-badge:hover {
    background: #252550;
    border-color: #6666bb;
    color: #aaaaee;
}

.entry-card .card-desc {
    font-size: 0.8rem;
    color: var(--text-body);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
}

.entry-card .card-footer {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    overflow: hidden;
}

/* Tags */
.entry-card .tags {
    display: flex;
    gap: 3px;
    overflow: hidden;
    flex: 1;
}

.entry-card .tag {
    font-size: 0.6rem;
    padding: 1px 6px;
    background: var(--tag-bg);
    border: 1px solid var(--tag-border);
    border-radius: 20px;
    color: var(--tag-text);
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    line-height: 1.5;
    flex-shrink: 0;
    font-family: 'Cinzel', serif;
    letter-spacing: 0.04em;
}

.entry-card .tag:hover {
    background: #243550;
    border-color: #5088c0;
    color: var(--accent-bright);
}

/* Only show first 3 tags */
.entry-card .tag:nth-child(n+4) { display: none; }

/* Dep badges */
.entry-card .deps {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
    align-items: center;
}

.entry-card .dep-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    font-size: 0.6rem;
    background: var(--dep-bg);
    border: 1px solid var(--dep-border);
    color: var(--dep-text);
    transition: border-color 0.12s, color 0.12s;
}

.entry-card .dep-badge.system {
    background: #221e2a;
    border-color: #503a68;
    color: #9878c0;
}

.entry-card .dep-badge:hover { border-color: #60a860; color: #90d890; }
.entry-card .dep-badge.system:hover { border-color: #8860b0; color: #c090e8; }

/* =====================
    EMPTY STATE
===================== */
.gallery-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 72px 0;
    color: var(--text-muted);
}

.gallery-empty i { font-size: 2.4rem; opacity: 0.3; }

.gallery-empty p {
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* =====================
    LOADING STATE
===================== */
.gallery-loading {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 72px 0;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border);
    border-top-color: var(--border-glow);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* =====================
    PAGINATION
===================== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 18px 0 4px;
    border-top: 1px solid var(--border);
    margin-top: 16px;
}

.page-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-body);
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    padding: 0;
}

.page-btn:hover:not(:disabled) {
    background: #252a32;
    border-color: var(--border-glow);
    color: var(--accent-bright);
}

.page-btn:disabled { opacity: 0.25; cursor: default; pointer-events: none; }

.page-numbers {
    display: flex;
    gap: 3px;
}

.page-num {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    cursor: pointer;
    font-family: 'Cinzel', serif;
    font-size: 0.7rem;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.page-num:hover { background: #252a32; border-color: var(--border-glow); color: var(--accent-bright); }
.page-num.active {
    background: #1e2e48;
    border-color: var(--border-glow);
    color: var(--gold);
    font-weight: 600;
    cursor: default;
}

.page-ellipsis {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: default;
}

/* =====================
    TOOLTIP
===================== */
.tooltip {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    background: #12151a;
    border: 1px solid #3a4a5a;
    border-radius: var(--radius-lg);
    padding: 12px 14px;
    max-width: 280px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.6);
    font-size: 0.8rem;
    line-height: 1.5;
    opacity: 0;
    transition: opacity 0.15s;
}

.tooltip.visible { opacity: 1; }

.tooltip-title {
    font-family: 'Cinzel', serif;
    font-size: 0.85rem;
    color: var(--gold);
    font-weight: 600;
}

.tooltip-author { font-size: 0.72rem; color: var(--text-dim); margin-top: 1px; }

.tooltip hr {
    border: none;
    background: #2a3240;
    height: 1px;
    margin: 7px 0;
}

.tooltip-meta {
    display: flex;
    gap: 12px;
    font-size: 0.7rem;
    color: #888;
}

.tooltip-meta span { display: flex; align-items: center; gap: 4px; }

.tooltip-desc { color: #b0b8c8; font-size: 0.78rem; }

.tooltip-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-family: 'Cinzel', serif;
}

.tooltip-dep-list { display: flex; flex-wrap: wrap; gap: 4px; }

.tooltip-dep {
    font-size: 0.68rem;
    padding: 2px 8px;
    background: var(--dep-bg);
    border: 1px solid var(--dep-border);
    border-radius: 20px;
    color: var(--dep-text);
}

.tooltip-dep.system {
    background: #221e2a;
    border-color: #503a68;
    color: #9878c0;
}

.tooltip-tag {
    font-size: 0.68rem;
    padding: 2px 8px;
    background: var(--tag-bg);
    border: 1px solid var(--tag-border);
    border-radius: 20px;
    color: var(--tag-text);
    font-family: 'Cinzel', serif;
    letter-spacing: 0.03em;
}

.tooltip-date {
    font-size: 0.64rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 4px;
}

/* =====================
    FOOTER
===================== */
.site-footer {
    text-align: center;
    padding: 24px 0;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-style: italic;
    margin-top: 40px;
}

/* =====================
    RESPONSIVE
===================== */
@media (max-width: 600px) {
    .gallery-grid { grid-template-columns: 1fr; }
    .entry-card .thumb, .entry-card .thumb-placeholder { width: 80px; height: 80px; flex-basis: 80px; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .result-count { text-align: center; }
}

/* =====================
    CONTEXT MENU
===================== */
.ctx-menu {
  position: absolute;
  z-index: 9999;
  min-width: 190px;
  background: #12151a;
  border: 1px solid #3a4a5a;
  border-radius: var(--radius-lg);
  padding: 6px 0 6px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.65);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.96) translateY(-4px);
  transform-origin: top left;
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.ctx-menu--visible {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

.ctx-menu-header {
  padding: 5px 14px 6px;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  color: var(--gold-dim);
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

.ctx-divider {
  border: none;
  border-top: 1px solid #2a3240;
  margin: 0 0 4px;
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 14px;
  background: none;
  border: none;
  color: var(--text-body);
  font-family: 'Crimson Pro', Georgia, serif;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s, color 0.1s;
}

.ctx-item i {
  width: 14px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  flex-shrink: 0;
  transition: color 0.1s;
}

.ctx-item:hover {
  background: #1e2a3a;
  color: var(--accent-bright);
}

.ctx-item:hover i {
  color: var(--accent);
}

.ctx-item--danger { color: var(--text-body); }
.ctx-item--danger:hover { background: #2a1a1a; color: #e08080; }
.ctx-item--danger:hover i { color: #c06060; }

/* =====================
    COPY TOAST
===================== */
.copy-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1a2a1a;
  border: 1px solid var(--dep-border);
  border-radius: 20px;
  padding: 7px 18px;
  font-size: 0.82rem;
  color: var(--dep-text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 10000;
  white-space: nowrap;
}

.copy-toast i {
  margin-right: 6px;
}

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