/* -------------------------
   Theme variables
   ------------------------- */
:root {
  --bg: #0b0b0c;
  --fg: #eaeaea;
  --muted: #9a9a9a;
  --card: #141416;
  --border: #232327;
}

/* -------------------------
   Base reset / body
   ------------------------- */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* -------------------------
   Header (title / search / lang)
   ------------------------- */
header {
  position: sticky;
  top: 0;
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(11,11,12,0.9);
  backdrop-filter: blur(10px);
  z-index: 20;
}

.title {
  color: var(--fg);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.3px;
}

#search {
  margin-left: auto;
  width: min(420px, 60vw);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  outline: none;
}

.lang {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  outline: none;
  cursor: pointer;
}

/* -------------------------
   Page layout
   ------------------------- */
main {
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

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

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--fg);
}

.thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  background: #0f0f10;
  border: 1px solid var(--border);
  object-fit: cover;
}

.card h3 { margin: 0; font-size: 16px; }
.card p { margin: 0; color: var(--muted); font-size: 13px; }

/* -------------------------
   Breadcrumbs
   ------------------------- */
.breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.breadcrumbs a { color: var(--muted); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }

/* -------------------------
   Article / content area
   ------------------------- */
.article {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.article a {
  color: var(--accent, #00b4d8 ); 
}

.article a:hover {
  text-decoration: underline;
}
/* images inside articles */
.article img {
  max-width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
}

/* paragraphs / lists spacing */
.article p, .article ul, .article ol {
  margin: 0 0 12px 0;
}

/* code blocks & inline code (monospace & highlighting) */
.article pre {
  overflow: auto;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0f0f10;
  margin: 12px 0;
}

.article code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, "Roboto Mono", monospace;
  font-size: 0.95em;
}

/* subtle hljs tweaks (theme controls colors) */
.hljs {
  background: transparent;
  color: inherit;
  border-radius: 8px;
  padding: 8px 10px;
}

/* -------------------------
   Lightbox (image zoom) styles
   ------------------------- */
#lb-overlay {
  position: fixed;
  inset: 0;
  display: none; /* toggled with .open */
  align-items: center;
  justify-content: center;
  background: rgba(4,4,6,0.85);
  z-index: 9999;
  cursor: zoom-out;
}

#lb-overlay.open { display: flex; }

#lb-frame {
  max-width: 95%;
  max-height: 95%;
  overflow: hidden;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#lb-img {
  max-width: 100%;
  max-height: 100%;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 0.08s ease;
  cursor: grab;
  border-radius: 8px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.6);
}

#lb-img.dragging { cursor: grabbing; }

#lb-close-hint {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 10000;
  color: #ddd;
  font-size: 13px;
  opacity: 0.9;
  user-select: none;
}

/* -------------------------
   Nerd font (icons & code)
   ------------------------- */
/* NOTE: this is CSS-only; font files must exist at /fonts/... */
@font-face {
  font-family: "FiraCode Nerd";
  src: url("/fonts/FiraCodeNerdFontMono-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "FiraCode Nerd";
  src: url("/fonts/FiraCodeNerdFontMono-Regular.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* single-character icon helper (1ch) */
.nerdfont {
  font-family: "FiraCode Nerd", ui-monospace, "SFMono-Regular", Menlo, Monaco, "Roboto Mono", monospace;
  display: inline-block;
  width: 1ch;
  text-align: center;
  vertical-align: -0.1em;
  line-height: 1;
  font-size: 1em;
  font-variant-ligatures: none;
  color: inherit; /* follow surrounding text color */
}

/* make code blocks / inline code use the Nerd font (monospace fallback chain) */
.article code,
.article pre {
  font-family: "FiraCode Nerd", ui-monospace, "SFMono-Regular", Menlo, Monaco, "Roboto Mono", monospace;
  font-size: 0.95em;
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ensure highlight.js uses the same font */
.hljs, .hljs * {
  font-family: "FiraCode Nerd", ui-monospace, "SFMono-Regular", Menlo, Monaco, "Roboto Mono", monospace !important;
}

/* small layout niceties */
.nerdfont + code,
code + .nerdfont {
  vertical-align: middle;
}

/* -------------------------
   Responsive / small tweaks
   ------------------------- */
@media (max-width: 520px) {
  header { padding: 10px; gap: 8px; }
  #search { width: 48vw; }
  .card { padding: 10px; border-radius: 12px; }
  main { padding: 12px; }
}

/* -------------------------
   Folder Preview Tooltip
   ------------------------- */
.folder-preview-tooltip {
  position: fixed;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--fg);
  font-size: 13px;
  line-height: 1.6;
  max-width: 280px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  white-space: pre-line;
}

.folder-preview-tooltip.visible {
  opacity: 1;
}

.folder-preview-tooltip::before {
  content: "Contents:";
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--fg);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.folder-preview-tooltip .preview-icon {
  font-family: "FiraCode Nerd", ui-monospace, "SFMono-Regular", Menlo, Monaco, "Roboto Mono", monospace;
  color: #00b4d8;
  margin-right: 4px;
  font-variant-ligatures: none;
  font-weight: 700;
}

.folder-preview-tooltip .preview-more {
  color: var(--muted);
  font-style: italic;
}

/* -------------------------
   Collapsible Sections - Clean & Smooth
   ------------------------- */

.collapsible {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 16px 0;
  overflow: hidden;
  background: var(--card);
  position: relative;
}

.collapsible-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px 16px;
  background: var(--card);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease;
  position: relative;
}

.collapsible-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.collapsible-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  color: var(--fg);
  flex: 1;
}

.collapsible-arrow {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  color: var(--muted);
  font-size: 14px;
  font-family: "FiraCode Nerd", monospace;
  margin-left: 8px;
  min-width: 14px;
  text-align: center;
}

.collapsible.open .collapsible-arrow {
  transform: rotate(90deg);
}

/* Blue line that appears when opening */
.collapsible::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, 
    transparent 0%, 
    #00b4d8 20%, 
    #0077b6 50%, 
    #00b4d8 80%, 
    transparent 100%
  );
  opacity: 0;
  transform: scaleX(0);
  transform-origin: left;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1;
}

.collapsible.open::before {
  opacity: 1;
  transform: scaleX(1);
}

.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: max-height; /* Helps with smooth animations */
}

.collapsible-content-inner {
  padding: 16px;
  background: var(--card);
  opacity: 0;
  transform: translateY(-5px);
  transition: opacity 0.2s ease 0.1s, transform 0.2s ease 0.1s;
}

.collapsible.open .collapsible-content-inner {
  opacity: 1;
  transform: translateY(0);
}

/* Ensure content inside collapsible is styled properly */
.collapsible-content-inner .article {
  background: transparent;
  border: none;
  padding: 0;
  border-radius: 0;
  margin: 0;
}

.collapsible-content-inner p:last-child {
  margin-bottom: 0;
}

/* Remove bottom padding from last element */
.collapsible-content-inner > *:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
}

/* Prevent layout shifts during animation */
.collapsible {
  will-change: transform;
}
