/* === CSS Variables === */
:root {
  --primary: #b71c1c;
  --dark: #1a3a3a;
  --dark2: #1e3535;
  --white: #fff;
  --light: #f5f5f5;
  --gray: #666;
  --border: #ddd;
  --shadow: 0 2px 8px rgba(0,0,0,.1);
  --navbar-h: 42px;
  --toolbar-h: 50px;
}

/* === Reset === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: var(--light);
  color: #333;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Header === */
.header-top {
  background: var(--primary);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.header-top .logo-img { height: 48px; }
.header-top .site-title { color: var(--white); font-size: 26px; font-weight: 700; text-align: center; }

/* === Navbar === */
.navbar {
  background: var(--dark);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--navbar-h);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-links {
  display: flex;
  align-items: center;
}
.nav-links a {
  color: var(--white);
  text-decoration: none;
  padding: 0 14px;
  font-size: 13px;
  line-height: var(--navbar-h);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: opacity .2s;
}
.nav-links a:hover { opacity: .8; }
.nav-links .home-icon { width: 16px; height: 16px; }
.nav-links .nav-login {
  background: rgba(255,255,255,.15);
  border-radius: 4px;
  padding: 0 12px;
  margin-left: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
}
.nav-links .nav-login:hover { background: rgba(255,255,255,.25); }
.nav-right { display: flex; align-items: center; gap: 12px; }
.nav-date { color: #4caf50; font-family: 'Courier New', monospace; font-size: 13px; }
.nav-time { color: var(--white); font-family: 'Courier New', monospace; font-size: 13px; }
.nav-icon { background: none; border: none; cursor: pointer; padding: 4px; }
.nav-icon svg { width: 20px; height: 20px; fill: var(--white); }

/* Hamburger - hidden on desktop */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--white);
  cursor: pointer;
  padding: 4px;
}
.nav-toggle svg { width: 24px; height: 24px; }

/* === Main Content === */
.main-content {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 30px 20px;
  width: 100%;
}
.category-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 22px;
  padding-bottom: 8px;
  border-bottom: 3px solid var(--primary);
  display: inline-block;
}

/* === Edition Grid === */
.editions-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 22px;
  margin-bottom: 30px;
}
.edition-card {
  background: var(--white);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .2s, box-shadow .2s;
}
.edition-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0,0,0,.15);
}
.edition-card a { text-decoration: none; color: inherit; display: block; }
.edition-thumb {
  position: relative;
  overflow: hidden;
  aspect-ratio: 3/4;
  background: #eee;
}
.edition-thumb img { width: 100%; height: 100%; object-fit: cover; }
.edition-thumb .read-badge {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.6);
  color: var(--white);
  text-align: center;
  padding: 8px;
  font-size: 13px;
  opacity: 0;
  transition: opacity .3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.edition-card:hover .read-badge { opacity: 1; }
.edition-info { padding: 10px; text-align: center; }
.edition-info h3 { font-size: 13px; font-weight: 600; margin-bottom: 3px; text-transform: uppercase; }
.edition-info p { font-size: 12px; color: var(--gray); }
.no-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: #ddd;
  color: #999;
  font-size: 13px;
}
.today-badge {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* === Pagination === */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  margin-top: 28px;
}
.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: #333;
  font-size: 13px;
  transition: all .2s;
}
.pagination a:hover { background: var(--primary); color: var(--white); border-color: var(--primary); }
.pagination .active { background: var(--primary); color: var(--white); border-color: var(--primary); }
.pagination .disabled { opacity: .4; pointer-events: none; }

/* === Viewer Toolbar === */
.viewer-toolbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  position: sticky;
  top: var(--navbar-h);
  z-index: 90;
  flex-wrap: nowrap;
  min-height: var(--toolbar-h);
}
.vt-left, .vt-center, .vt-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.vt-center { flex: 1; justify-content: center; overflow: hidden; }
.vt-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 13px;
  color: #333;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.vt-btn:hover { background: #f0f0f0; }
.vt-btn:disabled { opacity: .35; cursor: default; }
.vt-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.vt-page-info { font-size: 13px; color: #333; white-space: nowrap; }
.vt-meta { font-size: 13px; color: var(--gray); display: flex; align-items: center; gap: 8px; overflow: hidden; }
.vt-meta .sep { color: var(--border); flex-shrink: 0; }
.vt-meta .cat-name { font-weight: 500; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* === Viewer Layout === */
.viewer-wrap {
  display: flex;
  min-height: calc(100vh - var(--navbar-h) - var(--toolbar-h) - 80px);
  width: 100%;
}
.viewer-sidebar {
  width: 110px;
  min-width: 110px;
  background: #f9f9f9;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100vh - var(--navbar-h) - var(--toolbar-h));
  position: sticky;
  top: calc(var(--navbar-h) + var(--toolbar-h));
  align-self: flex-start;
  transition: all .2s;
}
.viewer-sidebar.hidden {
  width: 0; min-width: 0; padding: 0;
  overflow: hidden; opacity: 0;
}
.thumb-item {
  border: 2px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color .2s;
  text-align: center;
  position: relative;
}
.thumb-item.active { border-color: var(--primary); }
.thumb-item canvas { width: 100%; display: block; }
.thumb-item .thumb-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.55);
  color: var(--white);
  font-size: 10px;
  padding: 2px 0;
}
.thumb-item .thumb-num { display: block; font-size: 10px; padding: 2px 0; color: var(--gray); }
.viewer-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  overflow: auto;
  background: #e8e8e8;
  position: relative;
  min-width: 0;
}
.viewer-main canvas {
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  max-width: 100%;
  display: block;
}

/* === Page Pagination === */
.page-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 12px 4px;
  width: 100%;
  max-width: 100%;
}
.page-dot, .page-nav-btn {
  min-width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--white);
  cursor: pointer;
  font-size: 13px;
  color: #333;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  padding: 0 6px;
  flex-shrink: 0;
}
.page-dot:hover, .page-nav-btn:hover { background: #f0f0f0; }
.page-dot.active { background: var(--primary); color: var(--white); border-color: var(--primary); }
.page-nav-btn.disabled { opacity: .35; pointer-events: none; }
.page-ellipsis { padding: 0 4px; color: var(--gray); font-size: 13px; }

/* === Share Popup === */
.share-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  display: none;
}
.share-backdrop.show { display: block; }
.share-popup {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--white);
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
  z-index: 501;
  display: none;
  width: 320px;
  max-width: calc(100vw - 32px);
}
.share-popup.show { display: block; }
.share-popup h3 { margin-bottom: 14px; font-size: 16px; }
.share-popup .share-link {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.share-popup .share-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.share-popup .share-btns a, .share-popup .share-btns button {
  padding: 8px 14px;
  border-radius: 4px;
  color: var(--white);
  text-decoration: none;
  font-size: 12px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.share-popup .share-btns .wa { background: #25d366; }
.share-popup .share-btns .fb { background: #1877f2; }
.share-popup .share-btns .tw { background: #000; }
.share-popup .share-btns .cp { background: #555; }
.share-close {
  position: absolute;
  top: 8px; right: 12px;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  color: #555;
}
.share-close:hover { color: #000; }

/* === Footer === */
.footer { background: var(--dark2); color: var(--white); padding: 35px 20px 0; margin-top: auto; }
.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 35px;
  padding-bottom: 25px;
}
.footer-about p { color: #aaa; font-size: 13px; line-height: 1.6; margin-top: 8px; }
.footer h3 { font-size: 15px; margin-bottom: 12px; text-transform: uppercase; letter-spacing: 1px; }
.footer-links { list-style: none; }
.footer-links li { margin-bottom: 7px; }
.footer-links a { color: #aaa; text-decoration: none; font-size: 13px; transition: color .2s; }
.footer-links a:hover { color: var(--white); }
.social-icons { display: flex; gap: 8px; flex-wrap: wrap; }
.social-icons a {
  width: 36px; height: 36px;
  background: rgba(255,255,255,.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  text-decoration: none;
  font-size: 14px;
  transition: background .2s;
}
.social-icons a:hover { background: var(--primary); }
.footer-bottom {
  border-top: 1px solid rgba(255,255,255,.1);
  padding: 14px 0;
  display: flex;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  font-size: 12px;
  color: #888;
}

/* ===========================
   RESPONSIVE - Tablet
   =========================== */
@media (max-width: 1024px) {
  .editions-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ===========================
   RESPONSIVE - Small Tablet
   =========================== */
@media (max-width: 900px) {
  .editions-grid { grid-template-columns: repeat(2, 1fr); }
  .footer-inner { grid-template-columns: 1fr; }
}

/* ===========================
   RESPONSIVE - Mobile
   =========================== */
@media (max-width: 768px) {
  /* Header */
  .header-top { padding: 10px 15px; gap: 8px; }
  .header-top .site-title { font-size: 18px; }

  /* Navbar: hamburger + vertical dropdown */
  .navbar {
    height: auto;
    min-height: var(--navbar-h);
    padding: 0;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
  }
  .nav-toggle {
    display: flex;
    align-items: center;
    padding: 10px 15px;
  }
  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    background: var(--dark);
    padding: 0;
  }
  .nav-links.show { display: flex; }
  .nav-links a {
    padding: 12px 20px;
    font-size: 14px;
    line-height: 1.4;
    border-top: 1px solid rgba(255,255,255,.08);
  }
  .nav-right { display: none; }

  /* Viewer toolbar - mobile: 2 rows */
  .viewer-toolbar {
    top: 0;
    padding: 5px 8px;
    gap: 4px;
    flex-wrap: wrap;
    height: auto;
    min-height: auto;
  }
  .viewer-toolbar .vt-center { display: none !important; }
  .vt-left { order: 1; }
  .vt-right { order: 2; margin-left: auto; }
  .vt-btn { padding: 5px 7px; font-size: 12px; }
  .vt-btn svg { width: 15px; height: 15px; }
  .vt-page-info { font-size: 12px; }
  .vt-btn span.btn-label { display: none; }

  /* Viewer layout: no sidebar, full width */
  .viewer-sidebar { display: none !important; }
  .viewer-main { padding: 8px; }

  /* Page pagination - compact on mobile */
  .page-dots { padding: 8px 0; gap: 3px; }
  .page-dot, .page-nav-btn { min-width: 30px; height: 30px; font-size: 12px; padding: 0 5px; }

  /* Share popup */
  .share-popup { width: calc(100vw - 32px); max-width: 340px; padding: 20px; }

  /* Footer */
  .footer-bottom { flex-direction: column; text-align: center; gap: 4px; }
  .footer-inner { gap: 24px; }
}

/* ===========================
   RESPONSIVE - Small Mobile
   =========================== */
@media (max-width: 480px) {
  .editions-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .header-top .site-title { font-size: 16px; }
  .main-content { padding: 16px 12px; }
  .category-title { font-size: 18px; }
  .edition-info h3 { font-size: 12px; }
  .edition-info p { font-size: 11px; }

  /* Even more compact toolbar buttons */
  .vt-btn { padding: 4px 6px; }
  .vt-btn svg { width: 14px; height: 14px; }
}

/* ===========================
   RESPONSIVE - Extra Small
   =========================== */
@media (max-width: 360px) {
  .editions-grid { grid-template-columns: 1fr; }
  .vt-btn { padding: 4px 5px; }
}
