/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #181818;
  --surface2: #272727;
  --surface3: #333;
  --text: #f1f1f1;
  --text-dim: #aaa;
  --text-muted: #666;
  --accent: #ff4444;
  --accent2: #cc3333;
  --accent-glow: rgba(255, 68, 68, 0.15);
  --green: #4caf50;
  --yellow: #ff9800;
  --red: #f44336;
  --blue: #2196f3;
  --purple: #9c27b0;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
  --transition: 0.2s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: #ff6666; }
img { max-width: 100%; display: block; }

/* Custom scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface3); }

.container { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem 2rem; }

/* === Navbar === */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(24, 24, 24, 0.95);
}

.nav-brand {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.nav-brand:hover { color: var(--accent); }

.nav-links { display: flex; gap: 1.5rem; }
.nav-links a {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.4rem 0;
  position: relative;
  transition: color var(--transition);
}
.nav-links a:hover { color: var(--text); }
.nav-links a.nav-active {
  color: var(--text);
}
.nav-links a.nav-active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 1px;
}

/* Hamburger */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  flex-direction: column;
  gap: 5px;
}
.nav-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}
.nav-toggle.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.nav-toggle.open span:nth-child(2) { opacity: 0; }
.nav-toggle.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* === Hero === */
.hero {
  text-align: center;
  padding: 3rem 1rem 2rem;
  position: relative;
}
.hero::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 200px;
  background: radial-gradient(ellipse at center top, var(--accent-glow) 0%, transparent 70%);
  pointer-events: none;
}
.hero h1 { font-size: 2.4rem; margin-bottom: 0.5rem; position: relative; }
.hero-sub { color: var(--text-dim); font-size: 1.05rem; margin-bottom: 1.5rem; position: relative; }

.stats {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  position: relative;
}
.stat {
  background: var(--surface);
  padding: 1rem 1.5rem;
  border-radius: var(--radius);
  text-align: center;
  border: 1px solid var(--surface2);
  transition: border-color var(--transition), transform var(--transition);
  min-width: 100px;
}
.stat:hover {
  border-color: var(--surface3);
  transform: translateY(-1px);
}
.stat-num {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

/* === Sections === */
.section { margin-top: 2.5rem; }
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.section-header h2 { font-size: 1.4rem; }
.section-desc { color: var(--text-dim); margin-bottom: 1rem; font-size: 0.95rem; }
.view-all {
  color: var(--text-dim);
  font-size: 0.85rem;
  transition: color var(--transition);
}
.view-all:hover { color: var(--text); }

/* === Search & Sort Bar === */
.filter-bar {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1.2rem;
  align-items: center;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 200px;
  padding: 0.6rem 1rem;
  padding-left: 2.4rem;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 0.8rem center;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.sort-select {
  padding: 0.6rem 1rem;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}
.sort-select:focus { border-color: var(--accent); }
.sort-select option { background: var(--surface); }

.search-count {
  font-size: 0.8rem;
  color: var(--text-dim);
  min-width: 80px;
}

/* === Video Grid === */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.2rem;
}

.shorts-grid {
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

.video-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
  color: var(--text);
  border: 1px solid transparent;
}
.video-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--surface2);
  color: var(--text);
}

.thumb-wrap {
  position: relative;
  aspect-ratio: 16/9;
  background: var(--surface2);
  overflow: hidden;
}
.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}
.video-card:hover .thumb-wrap img { transform: scale(1.03); }

.thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 3rem;
  background: var(--surface2);
}

.short-thumb { aspect-ratio: 9/16; }

.duration {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.85);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.card-info { padding: 0.75rem 0.85rem; }
.card-info h3 {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.meta { color: var(--text-dim); font-size: 0.8rem; margin-top: 0.3rem; }

/* === Badges === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-complete { background: var(--green); color: white; }
.badge-downloaded { background: var(--blue); color: white; }
.badge-downloading { background: var(--yellow); color: black; }
.badge-summarizing { background: var(--purple); color: white; }
.badge-pending { background: var(--surface2); color: var(--text-dim); }
.badge-error { background: var(--red); color: white; }
.badge-short { background: var(--accent); color: white; }

/* === Video Detail === */
.video-detail { padding-top: 1rem; }

.player-wrap {
  max-width: 900px;
  margin: 0 auto 1.5rem;
}
.player-wrap video {
  width: 100%;
  border-radius: var(--radius);
  background: black;
}
.player-placeholder {
  aspect-ratio: 16/9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--surface2);
}

.video-info { max-width: 900px; margin: 0 auto; }
.video-info h1 { font-size: 1.5rem; margin-bottom: 0.5rem; line-height: 1.3; }
.video-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.video-actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.download-btn, .yt-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  transition: background var(--transition), transform var(--transition);
}
.download-btn {
  background: var(--accent);
  color: white;
}
.download-btn:hover { background: var(--accent2); transform: translateY(-1px); color: white; }

.yt-link-btn {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--surface2);
}
.yt-link-btn:hover { color: var(--text); border-color: var(--surface3); }

.summary-section,
.transcript-section,
.description-section,
.video-history-section {
  max-width: 900px;
  margin: 1.5rem auto;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--surface2);
}
.summary-section h2,
.transcript-section h2,
.description-section h2,
.video-history-section h2 {
  margin-bottom: 0.8rem;
  font-size: 1.15rem;
}
.summary-text {
  color: var(--text-dim);
  line-height: 1.8;
}
.summary-text p { margin-bottom: 0.8rem; }
.summary-text p:last-child { margin-bottom: 0; }

/* Markdown body styles */
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  color: var(--text);
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}
.markdown-body h1 { font-size: 1.4rem; }
.markdown-body h2 { font-size: 1.25rem; }
.markdown-body h3 { font-size: 1.1rem; }
.markdown-body h4, .markdown-body h5, .markdown-body h6 { font-size: 1rem; }
.markdown-body ul, .markdown-body ol {
  padding-left: 1.5em;
  margin-bottom: 0.8rem;
}
.markdown-body li { margin-bottom: 0.3rem; }
.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.5em 1em;
  margin: 0.8rem 0;
  background: var(--surface2);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-dim);
}
.markdown-body code {
  background: var(--surface2);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}
.markdown-body pre {
  background: var(--surface2);
  padding: 1em;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 0.8rem;
}
.markdown-body pre code {
  background: none;
  padding: 0;
}
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--surface3);
  margin: 1.2rem 0;
}
.markdown-body strong { color: var(--text); }
.markdown-body a { color: var(--accent); text-decoration: underline; }
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0.8rem;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--surface3);
  padding: 0.5em 0.8em;
  text-align: left;
}
.markdown-body th { background: var(--surface2); color: var(--text); }
.markdown-body img { max-width: 100%; border-radius: var(--radius); }

.transcript-text,
.description-text {
  color: var(--text-dim);
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 0.9rem;
}

/* Related videos */
.related-section {
  max-width: 900px;
  margin: 2rem auto;
}
.related-section h2 {
  font-size: 1.15rem;
  margin-bottom: 1rem;
}
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

/* === Status Page === */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.status-card {
  background: var(--surface);
  padding: 1.2rem;
  border-radius: var(--radius);
  text-align: center;
  border: 1px solid var(--surface2);
  transition: border-color var(--transition);
}
.status-card:hover { border-color: var(--surface3); }
.status-card h3 { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 0.5rem; text-transform: uppercase; letter-spacing: 0.05em; }
.status-card .stat-num { font-size: 2rem; }
.status-card.good .stat-num { color: var(--green); }
.status-card.warn .stat-num { color: var(--yellow); }
.status-card.bad .stat-num { color: var(--red); }
.status-card.info .stat-num { color: var(--blue); }
.status-card.accent .stat-num { color: var(--accent); }

.error-list, .processing-list { margin-top: 1rem; }
.error-item, .processing-item {
  background: var(--surface);
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  border: 1px solid var(--surface2);
}
.error-msg { color: var(--red); font-size: 0.85rem; margin-top: 0.3rem; word-break: break-word; }

/* === Empty state === */
.empty { text-align: center; padding: 3rem 1rem; color: var(--text-dim); }

/* === History Made === */
.history-header {
  display: flex;
  align-items: baseline;
  gap: 1.2rem;
  margin: 2rem 0 0.5rem;
}
.history-header h1 { font-size: 1.8rem; }
.history-total {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  background: var(--surface);
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  border: 1px solid var(--surface2);
}

.history-stats {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.history-list {
  margin-top: 1.5rem;
  position: relative;
}
/* Timeline line */
.history-list::before {
  content: '';
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--surface2);
}

.history-date-group {
  padding-left: 2rem;
  margin-bottom: 2rem;
  position: relative;
}
/* Timeline dot */
.history-date-group::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  border: 3px solid var(--bg);
  z-index: 1;
}

.history-date-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 1rem;
}
.history-date {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}
.history-count {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  background: var(--surface2);
  padding: 0.15rem 0.6rem;
  border-radius: 10px;
}

.history-video-block {
  margin-bottom: 1.2rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--surface2);
  overflow: hidden;
  transition: border-color var(--transition);
}
.history-video-block:hover { border-color: var(--surface3); }

.history-video-header {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.8rem;
}
.history-thumb {
  width: 80px;
  min-width: 80px;
  aspect-ratio: 16/9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface2);
}
.history-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-video-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.3;
}
.history-video-title:hover { color: #ff6666; }

.history-records-list {
  padding: 0 0.8rem 0.8rem;
}

.history-record {
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface2);
}
.history-record:last-child { margin-bottom: 0; }

.history-event-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.15rem;
  line-height: 1.3;
}

.history-event-desc {
  font-size: 0.85rem;
  color: var(--text-dim);
  line-height: 1.5;
}

/* History records on video detail page */
.video-history-record {
  padding: 0.6rem 0.8rem;
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface2);
}

/* === Load More === */
.load-more-wrap {
  text-align: center;
  margin-top: 2rem;
}
.load-more-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface2);
  padding: 0.7rem 2.5rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.load-more-btn:hover { background: var(--surface2); border-color: var(--surface3); }
.load-more-btn:disabled { opacity: 0.5; cursor: wait; }

/* === Back to Top === */
.back-to-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 40px;
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: 50%;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s, background var(--transition);
  pointer-events: none;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.back-to-top:hover { background: var(--surface2); }

/* === 404 Error Page === */
.error-page {
  text-align: center;
  padding: 5rem 1rem;
}
.error-code {
  font-size: 6rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  margin-bottom: 0.5rem;
}
.error-message {
  font-size: 1.5rem;
  color: var(--text);
  margin-bottom: 0.5rem;
}
.error-hint {
  color: var(--text-dim);
  margin-bottom: 2rem;
}
.error-home-btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 0.6rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 600;
  transition: background var(--transition);
}
.error-home-btn:hover { background: var(--accent2); color: white; }

/* === Footer === */
.footer {
  text-align: center;
  padding: 2rem;
  border-top: 1px solid var(--surface2);
  margin-top: 3rem;
}
.footer-content p { color: var(--text-dim); font-size: 0.85rem; }
.footer-content p:first-child { font-weight: 600; color: var(--text); font-size: 0.9rem; }
.footer-sub { margin-top: 0.3rem; }
.footer-credits { margin-top: 0.5rem; font-size: 0.75rem; color: var(--text-muted); }

/* === Focus states for accessibility === */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* === Responsive === */
@media (max-width: 768px) {
  .nav-toggle { display: flex; }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--surface2);
    flex-direction: column;
    padding: 0.5rem 0;
  }
  .nav-links.open { display: flex; }
  .nav-links a {
    padding: 0.8rem 2rem;
    border-bottom: 1px solid var(--surface2);
  }
  .nav-links a:last-child { border-bottom: none; }

  .hero h1 { font-size: 1.8rem; }
  .stats { gap: 0.6rem; }
  .stat { padding: 0.8rem 1rem; min-width: 80px; }
  .stat-num { font-size: 1.4rem; }

  .video-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .shorts-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }

  .filter-bar { flex-direction: column; }
  .search-input { min-width: unset; }

  .history-list::before { left: 4px; }
  .history-date-group::before { left: -2px; width: 12px; height: 12px; }

  .related-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
