/* =====================================================
   ROITX REFBOOK ENGINE — CLEAN & FINAL CSS EDITION
   ===================================================== */

/* --- Base Setup --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

input, textarea {
  user-select: text;
}

body {
  background: #0d0f14;
  color: #f8fafc;
  min-height: 100vh;
  line-height: 1.45;
  overflow-x: hidden;
  padding-bottom: 80px;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(0, 210, 255, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(117, 121, 255, 0.04) 0%, transparent 40%);
}

/* --- Topbar --- */
.topbar {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  background: rgba(18, 21, 28, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 1000;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  gap: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.nav-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

.back, .home-nav {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 16px;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.back:hover, .home-nav:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(0, 210, 255, 0.3);
  color: #00d2ff;
}

.back:active, .home-nav:active {
  transform: scale(0.92);
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #f1f5f9;
  letter-spacing: 0.3px;
}

/* --- Optimized 3-Column Compact Grid --- */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
  width: 100%;
  box-sizing: border-box;
  background: transparent;
}

/* --- Compact Card (Glassmorphic) --- */
.card {
  background: rgba(22, 25, 32, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 12px 4px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 130px;
  border-radius: 12px;
  position: relative;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  animation: fadeIn 0.4s ease forwards;
  opacity: 0;
}

.card:hover {
  transform: translateY(-3px);
  border-color: rgba(0, 210, 255, 0.25);
  background: rgba(28, 33, 44, 0.85);
  box-shadow: 0 10px 28px rgba(0, 210, 255, 0.1);
}

.card:active {
  transform: scale(0.96);
}

/* --- Compact Book Icon for 3 Columns --- */
.book-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  margin-bottom: 8px;
  height: 40px;
  position: relative;
}

/* Hardcover Book Element */
.realistic-book {
  width: 28px;
  height: 38px;
  border-radius: 3px 6px 6px 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 3px 5px 12px rgba(0,0,0,0.6), inset -2px 0 4px rgba(0,0,0,0.3);
  position: relative;
  z-index: 2;
  transition: transform 0.3s ease;
}

/* Hardcover Spine Highlight */
.book-spine-line {
  position: absolute;
  left: 3px;
  top: 0;
  width: 2px;
  height: 100%;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 2px 0 0 2px;
}

.realistic-book span {
  font-size: 9.5px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
  z-index: 3;
}

/* --- Ribbon Bookmark --- */
.realistic-ribbon {
  position: absolute;
  top: -5px;
  right: 6px;
  width: 5px;
  height: 12px;
  border-radius: 0 0 2px 2px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
  z-index: 4;
}

/* --- Realistic Page Blocks (Side Stack Effect) --- */
.page-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 8px;
}

.page-block span {
  display: block;
  height: 2px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

.left-pages span:nth-child(1) { width: 4px; align-self: flex-end; }
.left-pages span:nth-child(2) { width: 8px; align-self: flex-end; }
.left-pages span:nth-child(3) { width: 3px; align-self: flex-end; }

.right-pages span:nth-child(1) { width: 4px; align-self: flex-start; }
.right-pages span:nth-child(2) { width: 8px; align-self: flex-start; }
.right-pages span:nth-child(3) { width: 3px; align-self: flex-start; }

/* --- Compact Card Title --- */
.card-title {
  font-size: 10.5px;
  font-weight: 600;
  color: #f1f5f9;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  width: 100%;
  padding: 0 2px;
}

/* Fade In Animation */
@keyframes fadeIn {
  from { 
    opacity: 0; 
    transform: translateY(6px);
  }
  to { 
    opacity: 1; 
    transform: translateY(0);
  }
}

/* Extra small devices fallback */
@media (max-width: 330px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
