:root {
  --bg: #0a0e1a;
  --bg-elev: #131826;
  --bg-code: #0f172a;
  --border: #1f2937;
  --border-strong: #2a364a;
  --text: #e5e7eb;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --yt-red: #ef4444;
  --yt-red-hover: #dc2626;
  --hl-key: #7dd3fc;
  --hl-string: #86efac;
  --hl-number: #fbbf24;
  --hl-keyword: #f472b6;
  --hl-comment: #6b7280;
  --hl-section: #c4b5fd;
  --hl-tag: #93c5fd;
  --hl-attr: #fcd34d;
  --hl-meta: #a78bfa;
  --success: #22c55e;
  --error: #f87171;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

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

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(10, 14, 26, 0.85);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  font-weight: 600;
}
.brand:hover {
  text-decoration: none;
}

.logo {
  height: 36px;
  width: auto;
  border-radius: 0;
  background: transparent;
}

.brand-name {
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.yt-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--yt-red);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.15s ease;
}
.yt-button:hover {
  background: var(--yt-red-hover);
  text-decoration: none;
}

/* ---------- Main ---------- */

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px 64px;
  min-height: calc(100vh - 140px);
}

.loading {
  text-align: center;
  color: var(--text-muted);
  padding: 64px 0;
}

/* ---------- Home ---------- */

.home-hero {
  text-align: center;
  padding: 24px 0 32px;
}

.home-hero h1 {
  font-size: 2.25rem;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.home-hero p {
  color: var(--text-muted);
  margin: 0;
  font-size: 1.05rem;
}

.search-wrap {
  position: relative;
  max-width: 520px;
  margin: 0 auto 32px;
}

.search-input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  padding: 12px 16px 12px 44px;
  border-radius: var(--radius);
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-input::placeholder {
  color: var(--text-dim);
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.video-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  display: flex;
  flex-direction: column;
  color: var(--text);
}
.video-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  background: #161c2d;
  text-decoration: none;
}

.video-card-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg);
  overflow: hidden;
}
.video-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-card-body {
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.video-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.video-card-meta {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.video-card-desc {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.video-card-footer {
  margin-top: auto;
  padding-top: 12px;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.empty-state strong {
  color: var(--text);
  display: block;
  margin-bottom: 4px;
  font-size: 1.05rem;
}

/* ---------- Video View ---------- */

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

.video-header {
  margin-bottom: 24px;
}

.video-title {
  font-size: 1.75rem;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.video-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.video-meta-row .dot {
  width: 3px;
  height: 3px;
  background: var(--text-dim);
  border-radius: 50%;
}

.video-yt-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--yt-red);
  color: #fff;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}
.video-yt-button:hover {
  background: var(--yt-red-hover);
  text-decoration: none;
}

.video-description {
  color: var(--text-muted);
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.95rem;
  max-width: 800px;
}

.video-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  margin-top: 8px;
}

@media (max-width: 820px) {
  .video-layout {
    grid-template-columns: 1fr;
  }
}

.file-list {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  max-height: 70vh;
  overflow-y: auto;
  align-self: start;
  position: sticky;
  top: 80px;
}

.file-list-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 8px 12px 6px;
  margin: 0;
}

.file-list-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-list-group + .file-list-group {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.file-item.is-extra {
  color: var(--text-muted);
}
.file-item.is-extra:hover {
  color: var(--text);
}
.file-item.is-extra.active {
  color: var(--accent);
}

.file-item-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 2px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.file-item-wrap:hover {
  background: #1c2336;
}

.file-item-wrap:has(.file-item.active) {
  background: rgba(59, 130, 246, 0.15);
}

.file-item {
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: color 0.1s ease;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}
.file-item-label {
  overflow-wrap: anywhere;
}
.file-item.active {
  color: var(--hl-key);
}
.file-item-icon {
  flex-shrink: 0;
  color: var(--text-dim);
}
.file-item.active .file-item-icon {
  color: var(--accent);
}

.file-item-copy {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 0 12px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
  opacity: 0;
  position: relative;
}
.file-item-wrap:hover .file-item-copy,
.file-item-wrap:focus-within .file-item-copy,
.file-item-copy:focus-visible {
  opacity: 1;
}
.file-item-copy:hover {
  background: rgba(59, 130, 246, 0.2);
  color: var(--accent);
}
.file-item-copy .file-item-copy-check {
  display: none;
}
.file-item-copy.copied {
  opacity: 1;
  background: var(--success);
  color: #fff;
}
.file-item-copy.copied .file-item-copy-icon {
  display: none;
}
.file-item-copy.copied .file-item-copy-check {
  display: block;
}

/* Always show copy button on touch devices */
@media (hover: none) {
  .file-item-copy {
    opacity: 1;
  }
}

/* ---------- Viewer ---------- */

.viewer {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 320px;
  display: flex;
  flex-direction: column;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: #0c1322;
  border-bottom: 1px solid var(--border);
}

.viewer-filename {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-filename-icon {
  color: var(--text-dim);
  flex-shrink: 0;
}

.copy-button {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
.copy-button:hover {
  background: var(--bg-elev);
  color: var(--text);
  border-color: var(--text-dim);
}
.copy-button.copied {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.viewer-body {
  padding: 16px;
  overflow: auto;
  max-height: 70vh;
  flex: 1;
}

.viewer-empty {
  padding: 64px 24px;
  text-align: center;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.viewer-placeholder {
  padding: 64px 24px;
  text-align: center;
  color: var(--text-dim);
}
.viewer-placeholder svg {
  margin-bottom: 12px;
  color: var(--text-dim);
}
.viewer-placeholder p {
  margin: 0;
  font-size: 0.95rem;
}

pre.code-block {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre;
  tab-size: 2;
}

/* Syntax tokens */
.hl-key { color: var(--hl-key); }
.hl-string { color: var(--hl-string); }
.hl-number { color: var(--hl-number); }
.hl-keyword { color: var(--hl-keyword); }
.hl-comment { color: var(--hl-comment); font-style: italic; }
.hl-section { color: var(--hl-section); font-weight: 600; }
.hl-tag { color: var(--hl-tag); }
.hl-attr { color: var(--hl-attr); }
.hl-meta { color: var(--hl-meta); }

/* ---------- Error ---------- */

.error-state {
  text-align: center;
  padding: 48px 16px;
}
.error-state h2 {
  margin: 0 0 8px;
  color: var(--error);
}
.error-state p {
  color: var(--text-muted);
  margin: 0 0 16px;
}
.error-state code {
  background: var(--bg-elev);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* ---------- Snapshot (static HTML) ---------- */

.snapshot-mods {
  margin-top: 8px;
}

.snapshot-section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin: 24px 0 12px;
}

.snapshot-mod {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.snapshot-mod-title {
  font-size: 1.1rem;
  margin: 0 0 4px;
  font-weight: 600;
  color: var(--text);
}

.snapshot-mod-meta {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-dim);
  margin: 0 0 12px;
}

.snapshot-mod pre.code-block {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  max-height: 480px;
  overflow-y: auto;
  font-size: 0.8rem;
  line-height: 1.5;
  margin: 0;
}

.snapshot-interactive-link {
  display: inline-block;
  color: var(--accent);
  font-weight: 600;
}
.snapshot-interactive-link:hover {
  text-decoration: underline;
}

.snapshot-extras {
  margin-top: 24px;
}

.snapshot-extra {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.snapshot-extra-title {
  font-size: 1.1rem;
  margin: 0 0 12px;
  font-weight: 600;
  color: var(--text);
}

/* ---------- Prose (rendered markdown / notes) ---------- */

.prose {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.65;
  word-wrap: break-word;
}
.prose > *:first-child {
  margin-top: 0;
}
.prose > *:last-child {
  margin-bottom: 0;
}
.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  margin: 1.4em 0 0.6em;
  font-weight: 600;
  line-height: 1.3;
}
.prose h1 { font-size: 1.5rem; }
.prose h2 { font-size: 1.3rem; }
.prose h3 { font-size: 1.1rem; }
.prose h4 { font-size: 1rem; }
.prose h5 { font-size: 0.95rem; }
.prose h6 { font-size: 0.85rem; color: var(--text-muted); }
.prose p {
  margin: 0.8em 0;
}
.prose a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.prose a:hover {
  color: var(--hl-key);
}
.prose strong {
  color: var(--text);
  font-weight: 600;
}
.prose em {
  font-style: italic;
}
.prose code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  color: var(--hl-key);
}
.prose pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 1em 0;
}
.prose pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--text);
  font-size: inherit;
}
.prose ul,
.prose ol {
  margin: 0.8em 0;
  padding-left: 1.6em;
}
.prose li {
  margin: 0.3em 0;
}
.prose blockquote {
  margin: 1em 0;
  padding: 0.4em 1em;
  border-left: 3px solid var(--accent);
  background: rgba(59, 130, 246, 0.06);
  color: var(--text-muted);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.prose hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5em 0;
}

.prose-pre {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text-muted);
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 24px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.site-footer p {
  margin: 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 600px) {
  .header-inner {
    padding: 12px 16px;
  }
  .app {
    padding: 20px 16px 48px;
  }
  .home-hero h1 {
    font-size: 1.7rem;
  }
  .home-hero p {
    font-size: 0.95rem;
  }
  .video-title {
    font-size: 1.35rem;
  }
  .yt-button span {
    display: none;
  }
  .file-list {
    position: static;
    max-height: none;
  }
}

/* ---------- Scrollbars ---------- */

.viewer-body::-webkit-scrollbar,
.file-list::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.viewer-body::-webkit-scrollbar-track,
.file-list::-webkit-scrollbar-track {
  background: transparent;
}
.viewer-body::-webkit-scrollbar-thumb,
.file-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 5px;
}
.viewer-body::-webkit-scrollbar-thumb:hover,
.file-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}
