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

:root {
  --bg: #f0f0f0; --card: #fff; --border: #e0e0e0; --text: #222; --muted: #888;
  --accent: #1a73e8; --radius: 10px;
  --fantia: #e91e8c; --fanbox: #f0a500; --patreon: #f96854;
  --gumroad: #1abc9c; --manual: #78909c;
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
.topnav { position: sticky; top: 0; z-index: 100; display: flex; align-items: center; gap: 12px; background: #fff; border-bottom: 1px solid var(--border); padding: 0 20px; height: 52px; }
.nav-logo { font-weight: 700; font-size: 1.1em; color: var(--text); white-space: nowrap; }
.nav-logo:hover { text-decoration: none; }
.nav-search { display: flex; flex: 1; gap: 6px; max-width: 600px; }
.nav-search input { flex: 1; padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9em; }
.nav-search button { padding: 6px 14px; border: none; background: var(--accent); color: #fff; border-radius: 6px; cursor: pointer; }
.nav-logout { padding: 6px 14px; border: 1px solid var(--border); background: none; border-radius: 6px; cursor: pointer; font-size: 0.85em; color: var(--muted); }

/* Layout */
.page { max-width: 1400px; margin: 0 auto; padding: 24px 20px 60px; }
.page-header { margin-bottom: 20px; }
.page-header h1 { font-size: 1.5em; }
.page-header p { color: var(--muted); font-size: 0.9em; margin-top: 4px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 4px rgba(0,0,0,.07); padding: 20px; }

/* Health cards */
.health-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 28px; }
.health-card { background: var(--card); border-radius: var(--radius); padding: 16px 22px; box-shadow: 0 1px 4px rgba(0,0,0,.07); min-width: 140px; }
.health-card .val { font-size: 1.8em; font-weight: 700; color: var(--accent); }
.health-card .lbl { font-size: 0.8em; color: var(--muted); margin-top: 2px; }
.health-card a.tile-link { position: absolute; inset: 0; }
.health-card { position: relative; }
.health-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.13); cursor: pointer; }

/* Section heading */
.section-heading { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.section-heading h2 { font-size: 1.1em; }
.section-heading .count { font-size: 0.85em; color: var(--muted); }

/* Tile grid — responsive */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }

/* Post tile */
.post-tile { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 4px rgba(0,0,0,.07); overflow: hidden; display: flex; flex-direction: column; position: relative; transition: box-shadow .15s; }
.post-tile:hover { box-shadow: 0 4px 14px rgba(0,0,0,.13); }
.post-tile a.tile-link { position: absolute; inset: 0; z-index: 1; }
.tile-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; background: #f5f5f5; display: block; }
.tile-thumb-placeholder { width: 100%; aspect-ratio: 1; background: #f0f0f0; display: flex; align-items: center; justify-content: center; color: #ccc; font-size: 2em; }
.tile-body { padding: 10px 12px 12px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.tile-title { font-size: 0.88em; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-meta { font-size: 0.76em; color: var(--muted); }

/* Service badge */
.service-badge { position: absolute; top: 8px; right: 8px; z-index: 2; font-size: 0.68em; font-weight: 700; color: #fff; padding: 2px 7px; border-radius: 4px; text-transform: uppercase; letter-spacing: .04em; pointer-events: none; }
.badge-fantia  { background: var(--fantia); }
.badge-fanbox  { background: var(--fanbox); }
.badge-patreon { background: var(--patreon); }
.badge-gumroad { background: var(--gumroad); }
.badge-manual  { background: var(--manual); }

/* Creator tile */
.creator-tile { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 4px rgba(0,0,0,.07); padding: 16px; display: flex; flex-direction: column; gap: 8px; position: relative; transition: box-shadow .15s; }
.creator-tile:hover { box-shadow: 0 4px 14px rgba(0,0,0,.13); }
.creator-tile a.tile-link { position: absolute; inset: 0; z-index: 1; }
.creator-name { font-weight: 700; font-size: 0.95em; }
.creator-stats { font-size: 0.78em; color: var(--muted); }
.creator-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.creator-badge { font-size: 0.7em; font-weight: 700; color: #fff; padding: 2px 7px; border-radius: 4px; text-transform: uppercase; }

/* Filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.filter-bar select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.88em; }
.filter-btn { padding: 6px 14px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; font-size: 0.88em; }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.per-page-label { font-size: 0.85em; color: var(--muted); margin-left: auto; display: flex; align-items: center; gap: 6px; }

/* Creator detail header */
.creator-header { background: var(--card); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.07); display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.creator-header-info { flex: 1; min-width: 200px; }
.creator-header h1 { font-size: 1.4em; margin-bottom: 6px; }
.creator-header-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn { display: inline-block; padding: 7px 16px; border-radius: 6px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 0.88em; }
.btn:hover { background: #f5f5f5; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #1557b0; text-decoration: none; }
.btn-danger { background: #e53935; color: #fff; border-color: #e53935; }

/* Post detail */
.post-wrap { max-width: 900px; margin: 0 auto; }
.post-header-card { background: var(--card); border-radius: var(--radius); padding: 24px 28px 18px; margin-bottom: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.post-header-card h1 { font-size: 1.45em; margin-bottom: 10px; }
.post-meta { font-size: 0.85em; color: var(--muted); display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.post-meta strong { color: var(--text); }
.post-section { background: var(--card); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.post-section-label { font-size: 0.8em; font-weight: 700; color: #fff; background: #e91e8c; padding: 7px 18px; }
.post-section-title { font-size: 1.05em; font-weight: 700; padding: 14px 22px 8px; border-bottom: 1px solid #f2f2f2; }
.post-section-body { padding: 18px 22px; white-space: pre-wrap; word-break: break-word; line-height: 1.8; }
.post-images { background: var(--card); border-radius: var(--radius); padding: 16px 28px; margin-bottom: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.post-images img { max-width: 100%; height: auto; border-radius: 6px; margin: 8px 0; display: block; }
.post-files { background: var(--card); border-radius: var(--radius); padding: 16px 28px; margin-bottom: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.07); display: flex; flex-direction: column; gap: 8px; }
.file-row { display: flex; align-items: center; gap: 10px; background: #f0f4ff; border: 1px solid #c5d0f5; border-radius: 6px; padding: 10px 14px; }
.file-row a { color: var(--accent); font-size: 0.9em; word-break: break-all; }

/* Tags & Series */
.tag-area, .series-area { background: var(--card); border-radius: var(--radius); padding: 16px 22px; margin-bottom: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.tag-area h3, .series-area h3 { font-size: 0.8em; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; background: #f0f0f0; border: 1px solid #ddd; border-radius: 4px; padding: 3px 10px; font-size: 0.82em; }
.tag-chip.user-tag { background: #e3f2fd; border-color: #90caf9; }
.tag-chip button { border: none; background: none; cursor: pointer; color: #999; padding: 0; line-height: 1; }
.tag-chip button:hover { color: #e53935; }
.autocomplete-wrap { position: relative; display: inline-block; }
.autocomplete-wrap input { padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.88em; width: 200px; }
.autocomplete-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 12px rgba(0,0,0,.1); z-index: 50; max-height: 200px; overflow-y: auto; display: none; }
.autocomplete-dropdown.open { display: block; }
.autocomplete-item { padding: 8px 12px; cursor: pointer; font-size: 0.88em; }
.autocomplete-item:hover, .autocomplete-item.selected { background: #f0f4ff; }

/* Search */
.search-layout { display: flex; gap: 20px; align-items: flex-start; }
.search-sidebar { width: 240px; flex-shrink: 0; }
.search-results { flex: 1; min-width: 0; }
.search-main-input { width: 100%; padding: 10px 14px; font-size: 1em; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; }
.advanced-toggle { font-size: 0.85em; color: var(--accent); cursor: pointer; background: none; border: none; padding: 0; margin-bottom: 14px; display: block; }
.advanced-panel { display: none; background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.advanced-panel.open { display: block; }
.adv-field { margin-bottom: 12px; }
.adv-field label { display: block; font-size: 0.8em; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-bottom: 4px; }
.adv-field input, .adv-field select { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.88em; }
.exclude-chip { display: inline-flex; align-items: center; gap: 4px; background: #fde8e8; border: 1px solid #f5c6c6; border-radius: 4px; padding: 3px 9px; font-size: 0.82em; margin: 2px; }
.search-meta { font-size: 0.85em; color: var(--muted); margin-bottom: 14px; }

/* Load more */
.load-more-wrap { text-align: center; margin-top: 28px; }
.btn-load-more { padding: 10px 32px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; font-size: 0.95em; }
.btn-load-more:hover { background: #f5f5f5; }

/* Merge modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; display: none; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 28px; width: 400px; max-width: 95vw; box-shadow: 0 8px 32px rgba(0,0,0,.2); }
.modal h2 { margin-bottom: 14px; }
.modal input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.95em; margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { background: #fff; border-radius: var(--radius); padding: 36px 32px; width: 340px; box-shadow: 0 2px 16px rgba(0,0,0,.1); }
.login-box h1 { font-size: 1.4em; margin-bottom: 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.85em; font-weight: 600; margin-bottom: 5px; color: var(--muted); }
.field input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.95em; }
.login-error { background: #fde8e8; border: 1px solid #f5c6c6; border-radius: 6px; padding: 10px 14px; font-size: 0.88em; color: #c62828; margin-bottom: 16px; }

/* Viewer */
.viewer-wrap { background: var(--card); border-radius: var(--radius); padding: 0; margin-bottom: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.07); overflow: hidden; }
.viewer-toolbar { padding: 10px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; font-size: 0.88em; }
.pdf-embed { width: 100%; height: 80vh; border: none; display: block; }
.archive-img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; padding: 14px 16px; }
.archive-img-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.archive-file-list { list-style: none; padding: 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.archive-file-list li { padding: 8px 10px; background: #f5f5f5; border-radius: 6px; font-size: 0.88em; }

/* Misc */
.back-link { font-size: 0.88em; color: var(--muted); display: inline-block; margin-bottom: 14px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }
@media (max-width: 640px) {
  .search-layout { flex-direction: column; }
  .search-sidebar { width: 100%; }
  .tile-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
