@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&family=Inter:wght@300;400;500;600;700&family=Outfit:wght@500;600;700;800&display=swap');

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #182234;
  --bg-card-hover: #212f46;
  --bg-glass: rgba(30, 41, 59, 0.75);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(139, 92, 246, 0.3);
  
  --accent-purple: #8b5cf6;
  --accent-purple-glow: rgba(139, 92, 246, 0.25);
  --accent-cyan: #06b6d4;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-emerald: #10b981;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.15);
  
  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Inter', sans-serif;
}

/* Base resets & global styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

a {
  color: var(--accent-cyan);
  text-decoration: none;
  transition: all 0.2s ease;
}

a:hover {
  color: #38bdf8;
  text-decoration: none;
}

/* Layout framework */
.app-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
  flex: 1;
}

/* Header Navbar */
.site-header {
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 80px;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-img {
  height: 48px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 0 10px var(--accent-purple-glow));
  transition: transform 0.2s ease;
}

.logo-group:hover .logo-img {
  transform: scale(1.06);
}

.brand-text h1 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(to right, #fff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
}

.brand-text p {
  font-size: 0.75rem;
  color: var(--accent-cyan);
  letter-spacing: 0.5px;
  font-weight: 500;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  list-style: none;
}

.nav-link {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.nav-link:hover, .nav-link.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

.stats-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid var(--border-accent);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.825rem;
  color: var(--accent-purple);
  font-weight: 600;
}

/* Main Grid Layout */
.main-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 2rem;
  padding: 2rem 0;
}

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

/* Sidebar Styles */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sidebar-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
}

.sidebar-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-title span {
  font-size: 0.75rem;
  color: var(--accent-cyan);
  font-weight: 400;
}

/* Quick Search Input */
.search-input-wrapper {
  position: relative;
}

.search-input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px var(--accent-purple-glow);
}

/* Series list in sidebar */
.series-list-scroll {
  position: relative;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.series-list-scroll::-webkit-scrollbar {
  width: 5px;
}
.series-list-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

.series-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.series-item:hover, .series-item.active {
  background: rgba(139, 92, 246, 0.15);
  color: #fff;
  padding-left: 1rem;
}

.series-count-badge {
  font-size: 0.75rem;
  background: var(--bg-secondary);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  color: var(--accent-cyan);
}

/* Latest additions list */
.latest-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.latest-item a {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 4px 0;
  transition: color 0.2s ease;
}

.latest-item a:hover {
  color: var(--accent-amber);
}

/* Main Content Area */
.content-area {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Anime Header Banner Card */
.anime-banner-card {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.95));
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-card), var(--shadow-glow);
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 2rem;
}

.anime-banner-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.anime-poster-wrapper {
  flex-shrink: 0;
  max-width: 220px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border-accent);
  background: var(--bg-secondary);
  cursor: pointer;
  transition: transform 0.25s ease;
  z-index: 2;
}

.anime-poster-wrapper:hover {
  transform: scale(1.04);
}

.anime-poster-img {
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: contain;
  display: block;
}

.anime-banner-card::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -20%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, var(--accent-purple-glow) 0%, transparent 70%);
  pointer-events: none;
}

.anime-titles h2 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.25rem;
}

.anime-jp-title {
  font-size: 1.1rem;
  color: var(--accent-cyan);
  font-weight: 500;
  margin-bottom: 1rem;
}

.meta-tags-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.meta-pill {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.meta-pill.highlight {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--accent-purple);
  color: #d8b4fe;
}

.anime-description {
  font-size: 0.95rem;
  color: #cbd5e1;
  line-height: 1.7;
}

.external-links {
  display: flex;
  gap: 1rem;
  margin-top: 1.25rem;
}

.ext-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.825rem;
  color: #fff;
  font-weight: 500;
  transition: all 0.2s ease;
}

.ext-btn:hover {
  background: var(--accent-purple);
  border-color: var(--accent-purple);
  color: #fff;
}

/* VHS Grid & Tape Cards */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.section-title {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
}

.vhs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

/* Individual VHS Tape Card */
.vhs-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.vhs-card:hover {
  transform: translateY(-4px);
  border-color: var(--border-accent);
}

.vhs-card-top {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 1rem;
}

.vhs-cover-wrapper {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  cursor: pointer;
  height: 135px;
  background: var(--bg-secondary);
}

.vhs-cover-wrapper img,
.vhs-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: right center;
  transition: transform 0.3s ease;
}

.vhs-cover-wrapper:hover img {
  transform: scale(1.08);
}

.vhs-info-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.vhs-title-link {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.3;
}

.vhs-sub-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.badges-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.badge {
  font-size: 0.725rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

.badge-dub { background: rgba(16, 185, 129, 0.2); color: var(--accent-emerald); border: 1px solid rgba(10, 185, 129, 0.3); }
.badge-sub { background: rgba(6, 182, 212, 0.2); color: var(--accent-cyan); border: 1px solid rgba(6, 182, 212, 0.3); }
.badge-age { background: rgba(245, 158, 11, 0.2); color: var(--accent-amber); border: 1px solid rgba(245, 158, 11, 0.3); }

.vhs-details-meta {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Episodes accordion / details box */
.episodes-box {
  background: rgba(15, 23, 42, 0.65);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  font-family: 'Fira Code', ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 0.765rem;
  line-height: 1.5;
  color: #cbd5e1;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-line;
  border-left: 3px solid var(--accent-purple);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.episodes-box::-webkit-scrollbar {
  width: 4px;
}
.episodes-box::-webkit-scrollbar-thumb {
  background: var(--border-color);
}

/* Tape Card Footer / Actions */
.vhs-actions-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
}

.btn-torrent {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.btn-torrent:hover {
  background: var(--accent-emerald);
  color: #fff;
}

.btn-video {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.btn-video:hover {
  background: var(--accent-rose);
  color: #fff;
}

/* Variant release switcher buttons */
.variant-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.variant-links-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.variant-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.775rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: normal;
  text-align: left;
  line-height: 1.35;
}

.variant-btn:hover {
  background: rgba(139, 92, 246, 0.2);
  color: #fff;
  border-color: var(--accent-purple);
}

.variant-btn.active {
  background: var(--accent-purple);
  color: #fff;
  border-color: var(--accent-purple);
  font-weight: 600;
  box-shadow: 0 0 10px var(--accent-purple-glow);
}

/* Advanced Search Form */
.search-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
}

.search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-purple);
}

.btn-submit {
  background: linear-gradient(135deg, var(--accent-purple), #7c3aed);
  color: #fff;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: opacity 0.2s ease;
  align-self: flex-end;
}

.btn-submit:hover {
  opacity: 0.9;
}

/* Modal Lightbox */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  max-width: 90vw;
  max-height: 90vh;
  position: relative;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 15px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}
.modal-close:hover { color: #fff; }

.modal-img {
  max-width: 100%;
  max-height: 75vh;
  border-radius: var(--radius-sm);
}

/* Footer */
.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 2.5rem 0;
  margin-top: auto;
  font-size: 0.875rem;
  color: var(--text-dim);
  text-align: center;
}

.footer-links {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 1rem;
  list-style: none;
}

/* Mobile Toggle Button */
.mobile-menu-btn {
  display: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mobile-menu-btn:hover, .mobile-menu-btn.active {
  background: var(--accent-purple);
  color: #fff;
  border-color: var(--accent-purple);
}

/* Media Queries for Mobile Responsiveness */
@media (max-width: 992px) {
  .site-header {
    margin-bottom: 1.5rem;
  }

  .main-layout {
    display: flex;
    flex-direction: column;
    gap: 1.75rem;
    padding: 0 0 2.5rem 0;
  }

  .main-page-content .anime-banner-card,
  .content-area {
    margin-top: 0.5rem;
  }

  /* Default mobile order: content first, sidebar second */
  .content-area {
    order: 1;
  }

  .sidebar {
    order: 2;
  }

  /* On main frontpage, display Esittely 1st, Sidebar (Pikahaku & Sarjat) 2nd, Latest tapes 3rd */
  .main-page-content {
    display: contents;
  }

  .main-page-content .anime-banner-card {
    order: 1; /* 1. Esittely banner shown FIRST */
  }

  .sidebar {
    order: 2; /* 2. Sidebar with Pikahaku & Series list shown SECOND right after presentation */
  }

  .main-page-content section {
    order: 3; /* 3. Latest tapes grid shown THIRD */
  }
}

@media (max-width: 768px) {
  .header-inner {
    height: 70px;
    position: relative;
  }

  .brand-text h1 {
    font-size: 1.25rem;
  }

  .brand-text p {
    font-size: 0.7rem;
  }

  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 70px;
    left: 0;
    width: 100%;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-accent);
    flex-direction: column;
    padding: 1rem 1.25rem;
    gap: 0.75rem;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.7);
    z-index: 999;
  }

  .nav-links.active {
    display: flex;
  }

  .nav-link {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
  }

  .stats-pill {
    width: 100%;
    justify-content: center;
    padding: 8px 14px;
  }

  .anime-banner-card {
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
  }

  .anime-banner-content {
    width: 100%;
  }

  .anime-poster-wrapper {
    width: 100%;
    max-width: 220px;
    margin: 0 auto;
    align-self: center;
  }
}

@media (max-width: 640px) {
  .main-layout {
    padding-top: 1.5rem;
  }

  .app-container {
    padding: 0 0.75rem;
  }

  .anime-banner-card {
    padding: 1.25rem;
  }

  .anime-titles h2 {
    font-size: 1.4rem;
  }

  .anime-jp-title {
    font-size: 0.95rem;
  }

  .vhs-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .vhs-card {
    padding: 1rem;
  }

  .vhs-card-top {
    grid-template-columns: 80px 1fr;
    gap: 0.75rem;
  }

  .vhs-cover-wrapper {
    height: 120px;
  }

  .variant-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
  }

  .search-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .vhs-actions-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .btn-action {
    width: 100%;
    justify-content: center;
    padding: 10px;
  }

  .footer-links {
    flex-direction: column;
    gap: 0.75rem;
  }
}

/* Admin Quick Edit Buttons */
.btn-admin-edit-series {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(234, 179, 8, 0.18);
  border: 1px solid var(--accent-amber);
  color: #fef08a;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  margin-left: 12px;
  transition: all 0.2s ease;
  vertical-align: middle;
  text-decoration: none;
}
.btn-admin-edit-series:hover {
  background: var(--accent-amber);
  color: #0f172a;
}

.btn-admin-edit-tape {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: rgba(234, 179, 8, 0.15);
  border: 1px solid rgba(234, 179, 8, 0.4);
  color: #fef08a;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: all 0.2s ease;
  margin-left: 6px;
  vertical-align: middle;
  text-decoration: none;
}
.btn-admin-edit-tape:hover {
  background: var(--accent-amber);
  color: #0f172a;
  transform: scale(1.1);
}
