:root {
  --bg-color: #e0d8c8;
  --spine-color: #2c2a29;
  --paper-color: #f7f1e3;
  --text-main: #2c2c2c;
  --text-light: #5d5d5d;
  --accent-color: #8b3a3a;
  --line-color: #dcd3b2;
  --font-serif: 'Noto Serif SC', 'Songti SC', serif;
  --font-calli: 'Ma Shan Zheng', cursive;
  --font-hand: 'LXGW WenKai Screen', sans-serif;
}

* { box-sizing: border-box; }

body {
  background-color: #cfc6b5;
  font-family: var(--font-serif);
  color: var(--text-main);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  padding: 20px 0;
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
}

.font-calligraphy { font-family: var(--font-calli); }
.font-hand { font-family: var(--font-hand); }

.paper-texture {
  background-color: var(--paper-color);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
  position: relative;
}

.spine-texture {
  background-color: var(--spine-color);
  background-image: url("data:image/svg+xml,%3Csvg width='4' height='4' viewBox='0 0 4 4' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 3h1v1H1V3zm2-2h1v1H3V1z' fill='%23000000' fill-opacity='0.2' fill-rule='evenodd'/%3E%3C/svg%3E");
  box-shadow: inset -5px 0 15px rgba(0,0,0,0.3);
}

.book-shadow {
  box-shadow:
    0 20px 50px rgba(0,0,0,0.2),
    inset 15px 0 20px -10px rgba(0,0,0,0.1);
}

.menu-item-text {
  font-family: var(--font-serif);
  font-weight: 700;
  letter-spacing: 0.15em;
  color: #c4b9a8;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  transition: all 0.3s ease;
}

.group:hover .menu-item-text {
  color: #dcd3b2;
  text-shadow: 0 0 8px rgba(220, 211, 178, 0.3);
}

.menu-active .menu-item-text {
  color: #e0d8c8;
  text-shadow: 0 0 5px rgba(224, 216, 200, 0.4);
}

.admin-menu {
  transition: all 0.5s ease-in-out;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transform: translateY(10px);
}

.admin-menu.show {
  opacity: 1;
  max-height: 300px;
  transform: translateY(0);
}

.index-link {
  position: relative;
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.2s ease;
  cursor: pointer;
}

.index-link:hover {
  color: #8b3a3a;
  background-color: rgba(139, 58, 58, 0.05);
}

.index-link.active {
  color: #8b3a3a;
  font-weight: bold;
  background-image: linear-gradient(to top, rgba(139, 58, 58, 0.1) 0%, rgba(139, 58, 58, 0.1) 40%, transparent 40%);
}

.vintage-search {
  background: transparent;
  border: none;
  border-bottom: 1px dashed #dcd3b2;
  font-family: var(--font-hand);
  color: #2c2c2c;
  padding: 4px 0;
  width: 140px;
  font-size: 0.9rem;
  outline: none;
  transition: all 0.3s ease;
}

.vintage-search:focus {
  border-bottom: 1px solid #8b3a3a;
  width: 200px;
}

.vintage-search::placeholder {
  color: #a8a8a8;
  font-family: var(--font-serif);
  font-style: italic;
}

.pagination-link {
  font-family: var(--font-serif);
  color: #5d5d5d;
  padding: 4px 8px;
  margin: 0 2px;
  text-decoration: none;
  transition: color 0.2s;
}

.pagination-link:hover, .pagination-link.active {
  color: #8b3a3a;
  font-weight: bold;
}

#password-modal {
  transition: opacity 0.3s ease, visibility 0.3s;
}

#password-modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-paper-bg {
  background-color: #fdfbf6;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  border: 1px solid #dcd3b2;
}

body:not(.is-admin) .admin-only { display: none !important; }

.perm-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-family: var(--font-hand);
  white-space: nowrap;
}

.perm-public { background: rgba(74, 107, 101, 0.08); color: #4a6b65; }
.perm-encrypted { background: rgba(212, 172, 13, 0.1); color: #b7950b; }
.perm-private { background: rgba(0,0,0,0.04); color: #888; }

.perm-badge i { font-size: 0.65rem; }

.entry-encrypted {
  cursor: pointer;
  position: relative;
}

.entry-encrypted:hover .entry-title { color: #b7950b; }

body:not(.is-admin) .entry-private { display: none !important; }

.entry-private {
  opacity: 0.5;
  transition: opacity 0.5s ease;
}

.entry-private:hover { opacity: 0.8; }

.status-icon { display: inline-flex; align-items: center; margin-left: 6px; font-size: 1rem; vertical-align: middle; }
.status-lock { color: #bfa57d; }
.status-lock-key { color: #d4ac0d; }
.status-private { color: #a8a8a8; }

#encrypt-password-modal {
  transition: opacity 0.3s ease, visibility 0.3s;
  z-index: 2000;
}

#encrypt-password-modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.watermark {
  position: absolute;
  font-family: var(--font-calli);
  font-size: 8rem;
  color: rgba(139, 58, 58, 0.04);
  pointer-events: none;
  user-select: none;
  z-index: 0;
}

.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, #8b3a3a, #c4493c);
  z-index: 9999;
  width: 0%;
  transition: width 0.15s linear;
  box-shadow: 0 1px 4px rgba(139, 58, 58, 0.3);
}

#back-to-top {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fdfbf6;
  border: 2px solid #dcd3b2;
  color: #8b3a3a;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
  z-index: 999;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

#back-to-top.visible {
  opacity: 0.85;
  transform: translateY(0);
}

#back-to-top:hover {
  opacity: 1;
  background: #8b3a3a;
  color: #fff;
  border-color: #8b3a3a;
  transform: translateY(-3px);
  box-shadow: 0 6px 16px rgba(139, 58, 58, 0.3);
}

.hamburger-btn {
  display: none;
  background: none;
  border: none;
  color: #c4b9a8;
  font-size: 1.6rem;
  cursor: pointer;
  padding: 4px;
  transition: color 0.2s;
}

.hamburger-btn:hover { color: #e0d8c8; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 998;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: #b0a89a;
  text-align: center;
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state .empty-text {
  font-family: var(--font-hand);
  font-size: 1.1rem;
  line-height: 1.8;
  color: #999;
}

.empty-state .empty-hint {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  color: #c0b8a8;
  margin-top: 0.5rem;
}

@media (max-width: 768px) {
  body { padding: 0; }

  .book-container {
    flex-direction: column;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100vh !important;
  }

  .sidebar {
    width: 100% !important;
    min-height: auto;
    padding: 0;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 999;
    box-shadow: 0 2px 16px rgba(0,0,0,0.3);
  }

  .sidebar-top {
    border-bottom: none !important;
    padding: 0.55rem 1rem !important;
    width: 100%;
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    justify-content: space-between;
    gap: 0;
  }

  .sidebar-top > .flex.items-center.justify-between {
    width: 100%;
    gap: 0.5rem;
    margin-bottom: 0 !important;
  }

  .sidebar-top h1 {
    font-size: 1.3rem !important;
    letter-spacing: 0.2em;
    flex-shrink: 0;
  }

  .sidebar-top .w-full.text-center { display: none; }
  .sidebar-top p { display: none; }
  .sidebar-top .mb-3 { margin-bottom: 0 !important; }
  .sidebar-top .border-t { display: none; }
  .sidebar-top .mt-3 { display: none; }

  .hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: none;
    border: none;
    color: #c4b9a8;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0;
    transition: color 0.2s;
    flex-shrink: 0;
    order: -1;
  }

  .hamburger-btn:hover { color: #e0d8c8; }

  .sidebar button[onclick*="showPasswordModal"],
  .sidebar button[onclick*="toggleLogin"] {
    flex-shrink: 0;
  }

  .sidebar button[onclick*="showPasswordModal"] div,
  .sidebar button[onclick*="toggleLogin"] div {
    width: 32px;
    height: 32px;
    font-size: 0.7rem;
  }

  nav {
    position: fixed;
    top: 0;
    left: -290px;
    width: 275px;
    height: 100vh;
    height: 100dvh;
    background: linear-gradient(175deg, #2c2a29 0%, #1f1d1c 50%, #1a1817 100%);
    z-index: 999;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: left 0.32s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-shadow: 0 0 0 0 rgba(0,0,0,0);
    display: flex;
    flex-direction: column;
  }

  nav.open {
    left: 0;
    box-shadow: 8px 0 40px rgba(0,0,0,0.55);
  }

  nav .drawer-header {
    padding: 1.5rem 1.25rem 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    text-align: center;
    flex-shrink: 0;
  }

  nav .drawer-header .drawer-logo {
    font-family: var(--font-calli);
    font-size: 1.6rem;
    color: #e0d8c8;
    letter-spacing: 0.3em;
  }

  nav .drawer-header .drawer-sub {
    font-size: 0.65rem;
    color: #666;
    font-family: var(--font-serif);
    margin-top: 4px;
    letter-spacing: 0.2em;
  }

  nav ul {
    display: flex !important;
    flex-direction: column;
    gap: 2px;
    padding: 0.75rem 10px;
    margin: 0;
    list-style: none;
    flex: 1;
  }

  nav ul li { margin: 0; }

  nav ul li.admin-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 8px 10px;
    padding: 0;
  }

  nav ul li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 14px;
    color: #b8aea0;
    text-decoration: none;
    font-family: var(--font-serif);
    font-weight: 600;
    font-size: 0.88rem;
    letter-spacing: 0.06em;
    border-radius: 8px;
    transition: all 0.18s ease;
    position: relative;
  }

  nav ul li a i {
    font-size: 1.1rem;
    width: 22px;
    text-align: center;
    opacity: 0.6;
    transition: all 0.18s;
  }

  nav ul li a:active,
  nav ul li a:hover {
    background: rgba(255,255,255,0.06);
    color: #e0d8c8;
  }

  nav ul li a:active i,
  nav ul li a:hover i {
    opacity: 1;
  }

  nav ul li.menu-active a {
    background: rgba(139, 58, 58, 0.12);
    color: #e0d8c8;
    border-left: none;
  }

  nav ul li.menu-active a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    background: #8b3a3a;
    border-radius: 0 2px 2px 0;
  }

  nav ul li.menu-active a i {
    opacity: 1;
    color: #c08070;
  }

  nav .close-drawer {
    display: flex !important;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 12px;
    right: 10px;
    width: 38px;
    height: 38px;
    color: #8a8070;
    font-size: 1.3rem;
    cursor: pointer;
    background: transparent;
    border: none;
    border-radius: 50%;
    z-index: 10;
    transition: all 0.15s;
  }

  nav .close-drawer:active,
  nav .close-drawer:hover {
    background: rgba(255,255,255,0.08);
    color: #e0d8c8;
  }

  .sidebar .sidebar-top .hamburger-btn {
    margin-left: 0;
    margin-right: auto;
  }

  nav ul li.admin-menu {
    margin: 0;
    padding: 0;
  }

  nav ul li.admin-menu.show {
    margin: 0;
  }

  nav ul li.admin-menu a {
    color: #c89080;
  }

  nav ul li.admin-menu a i {
    color: #c08070;
    opacity: 0.8;
  }

  nav ul li.admin-menu a:active,
  nav ul li.admin-menu a:hover {
    color: #e0b0a0;
    background: rgba(169, 50, 38, 0.08);
  }

  .sidebar-overlay { display: block; }

  .content { width: 100% !important; padding: 1.25rem 1rem !important; }

  .sidebar > :not(.sidebar-top):not(nav) { display: none; }

  #back-to-top {
    bottom: 20px;
    right: 16px;
    width: 40px;
    height: 40px;
    font-size: 1rem;
  }
}
