:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-hover: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-green: #3fb950;
  --accent-orange: #d29922;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
  --sidebar-width: 280px;
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* Header */
header {
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 600;
}

header h1 a { color: var(--text); }
header h1 a:hover { text-decoration: none; }

header nav { display: flex; gap: 16px; align-items: center; }
header nav a { font-size: 0.85rem; color: var(--text-muted); }
header nav a:hover { color: var(--text); }

/* Layout: sidebar + main */
.main {
  margin-left: 0;
  transition: margin-left 0.2s;
  min-height: calc(100vh - 52px);
}

.content-overview {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 52px;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg);
  border-right: 1px solid var(--border);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.2s;
}

.sidebar.open {
  transform: translateX(0);
}

.main.shifted {
  margin-left: var(--sidebar-width);
}

@media (min-width: 900px) {
  .sidebar {
    transform: translateX(0);
  }
  .main {
    margin-left: var(--sidebar-width);
  }
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header .logo {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
}

.sidebar-header .logo:hover { color: var(--accent); }

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: none;
}

.sidebar-toggle:hover { color: var(--text); }

@media (max-width: 899px) {
  .sidebar-toggle { display: block; }
}

.sidebar-search {
  padding: 10px 14px;
  position: relative;
  border-bottom: 1px solid var(--border);
}

.sidebar-search-icon {
  position: absolute;
  left: 22px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.sidebar-search input {
  width: 100%;
  padding: 7px 10px 7px 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.82rem;
  font-family: var(--font);
  outline: none;
}

.sidebar-search input:focus { border-color: var(--accent); }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-section-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  user-select: none;
}

.nav-section-header:hover { color: var(--text); }
.nav-section-header .chevron { transition: transform 0.15s; flex-shrink: 0; }
.nav-section-header.collapsed .chevron { transform: rotate(-90deg); }
.nav-section-header .count {
  margin-left: auto;
  font-size: 0.72rem;
  background: var(--bg-card);
  padding: 1px 7px;
  border-radius: 10px;
  color: var(--text-muted);
}

.nav-items { padding: 0; }
.nav-section-header.collapsed + .nav-items { display: none; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 18px;
  font-size: 0.82rem;
  color: var(--text);
  text-decoration: none;
  transition: background 0.1s;
}

.nav-item:hover { background: var(--bg-hover); text-decoration: none; }
.nav-item.active { background: var(--bg-hover); border-left: 2px solid var(--accent); }

.nav-thumb {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  background-color: #0d1117;
  flex-shrink: 0;
}

.nav-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { font-size: 0.7rem; color: var(--text-muted); }

/* Stats bar */
.stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat strong { color: var(--text); }

/* Search */
.search-wrap {
  position: relative;
  margin-bottom: 24px;
}

.search-wrap input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.search-wrap input:focus { border-color: var(--accent); }

.search-wrap::before {
  content: '\1F50D';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  opacity: 0.5;
}

/* Model grid */
.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.model-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.model-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.model-card .thumb {
  width: 100%;
  height: 100px;
  object-fit: contain;
  background: #0d1117;
  border-radius: 4px;
  margin-bottom: 10px;
  display: block;
}

.model-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.model-card .meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.model-card .colors {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #444;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s;
}

.color-dot:hover {
  transform: scale(1.2);
  z-index: 2;
}

.color-dot[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: var(--text);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  white-space: nowrap;
  z-index: 10;
}

/* Detail modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 100;
  overflow-y: auto;
  padding: 40px 20px;
  backdrop-filter: blur(4px);
}

.modal-overlay.open { display: block; }

.modal {
  background: var(--bg);
  max-width: 900px;
  margin: 0 auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 28px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  font-size: 1.6rem;
  cursor: pointer;
  color: var(--text-muted);
  background: none;
  border: none;
  font-family: var(--font);
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal h2 { font-size: 1.4rem; margin-bottom: 4px; }
.modal .subtitle { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 20px; }

.color-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.color-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.color-card h4 {
  font-size: 0.9rem;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-card .cp {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #555;
  flex-shrink: 0;
}

.color-card img {
  width: 100%;
  max-height: 100px;
  object-fit: contain;
  background: #0d1117;
  border-radius: 4px;
  margin-bottom: 6px;
}

.image-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.image-links a {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: #1c2333;
  color: var(--accent);
  border: 1px solid #30363d;
}

.image-links a:hover {
  background: var(--accent);
  color: #fff;
  text-decoration: none;
}

.meta-details {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

/* Footer */
footer {
  border-top: 1px solid var(--border);
  padding: 20px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 40px;
}

footer a { color: var(--text-muted); }
footer a:hover { color: var(--text); }

/* Color names below dots */
.color-names {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Model detail page */
.model-detail-page { padding-top: 16px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.back-link:hover { color: var(--accent); text-decoration: none; }

.model-detail-page h1 { font-size: 1.6rem; margin-bottom: 4px; }
.model-detail-page .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 20px; }

/* Enlarge image on click */
.enlarge-link {
  display: block;
  position: relative;
  cursor: zoom-in;
}

.enlarge-link img {
  width: 100%;
  max-height: 120px;
  object-fit: contain;
  background: #0d1117;
  border-radius: 4px;
  display: block;
  transition: filter 0.15s;
}

.enlarge-link:hover img { filter: brightness(0.7); }

.enlarge-icon {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  opacity: 0;
  transition: opacity 0.15s;
}

.enlarge-link:hover .enlarge-icon { opacity: 1; }

/* Image badges (anime, wp_left, etc.) */
.img-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--accent);
  border: 1px solid var(--border);
}

.img-badge:hover { background: var(--accent); color: #fff; border-color: var(--accent); text-decoration: none; }

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 200;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.lightbox.open { display: flex; }

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 24px;
  font-size: 2.5rem;
  color: #fff;
  opacity: 0.7;
  cursor: pointer;
  line-height: 1;
}

.lightbox-close:hover { opacity: 1; }

/* Protocol info box */
.protocol-info {
  margin-top: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.protocol-info h3 {
  font-size: 1.1rem;
  margin-bottom: 12px;
}

.protocol-info table {
  width: 100%;
  border-collapse: collapse;
}

.protocol-info td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  vertical-align: top;
}

.protocol-info td:first-child {
  color: var(--text-muted);
  width: 140px;
  white-space: nowrap;
}

.protocol-info td:last-child {
  color: var(--text);
}

.protocol-info code {
  font-family: var(--mono);
  font-size: 0.82rem;
  background: var(--bg-hover);
  padding: 1px 6px;
  border-radius: 3px;
}

.protocol-info a { color: var(--accent); }

/* Error page */
.error-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 12px;
}

.error-page h1 { font-size: 4rem; font-weight: 800; color: var(--text-muted); }
.error-page p { color: var(--text-muted); }

.btn {
  display: inline-block;
  padding: 8px 20px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
}

.btn:hover { background: #79b8ff; text-decoration: none; }

/* Responsive */
@media (max-width: 600px) {
  .model-grid { grid-template-columns: 1fr; }
  .color-cards { grid-template-columns: 1fr; }
  header { flex-direction: column; align-items: flex-start; }
  .container { padding: 16px 12px; }
}
