/* ================================================
   Design Tokens
   ================================================ */
:root {
  --bg-base: #fafaf9;
  --bg-surface: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --text-primary: #1c1917;
  --text-secondary: #57534e;
  --text-muted: #a8a29e;
  --accent: #ea580c;
  --accent-hover: #c2410c;
  --accent-soft: rgba(234, 88, 12, 0.08);
  --accent-glow: rgba(234, 88, 12, 0.2);
  --border: rgba(0, 0, 0, 0.06);
  --border-strong: rgba(0, 0, 0, 0.1);
  --gradient: linear-gradient(135deg, #ea580c 0%, #7c3aed 50%, #0891b2 100%);
  --glow: 0 4px 32px rgba(234, 88, 12, 0.12);
  --blob-1: rgba(234, 88, 12, 0.06);
  --blob-2: rgba(124, 58, 237, 0.05);
  --blob-3: rgba(8, 145, 178, 0.04);

  --font-display: "hm", Georgia, serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;
  --font-body: "hm", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.08);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="dark"] {
  --bg-base: #0a0e1a;
  --bg-surface: rgba(15, 23, 42, 0.85);
  --bg-card: rgba(255, 255, 255, 0.04);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #f97316;
  --accent-hover: #ea580c;
  --accent-soft: rgba(249, 115, 22, 0.1);
  --accent-glow: rgba(249, 115, 22, 0.3);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.12);
  --gradient: linear-gradient(135deg, #f97316 0%, #a855f7 50%, #06b6d4 100%);
  --glow: 0 0 60px rgba(249, 115, 22, 0.2);
  --blob-1: rgba(249, 115, 22, 0.08);
  --blob-2: rgba(168, 85, 247, 0.07);
  --blob-3: rgba(6, 182, 212, 0.05);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.35s ease, color 0.35s ease;
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 15% 15%, var(--blob-1), transparent 60%),
    radial-gradient(ellipse 50% 40% at 85% 85%, var(--blob-2), transparent 50%),
    radial-gradient(ellipse 40% 30% at 50% 50%, var(--blob-3), transparent 50%);
  background-color: var(--bg-base);
  z-index: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

/* ================================================
   Layout
   ================================================ */
.book-container {
  position: relative;
  z-index: 1;
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-xl);
  width: 100%;
}

/* ================================================
   Header
   ================================================ */
.book-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2xl);
  animation: fadeInUp 0.6s var(--ease-out-expo) backwards;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

.home-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}

.home-link:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

.home-link svg {
  transition: transform 0.2s ease;
}

.home-link:hover svg {
  transform: translateX(-2px);
}

.site-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.3s var(--ease-out-expo);
  backdrop-filter: blur(10px);
}

.theme-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--glow);
}

/* Hide theme button on desktop — T key is enough */
@media (min-width: 768px) {
  .theme-btn { display: none; }
}

/* ================================================
   Book Grid (Library)
   ================================================ */
.library {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-lg);
  animation: fadeInUp 0.6s var(--ease-out-expo) 0.1s backwards;
}

/* ================================================
   Book Card - Cover with Title + Content
   ================================================ */
.library__book {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  backdrop-filter: blur(20px);
  transition: all 0.35s var(--ease-out-expo);
}

.library__book:hover {
  transform: translateY(-6px);
  border-color: var(--accent);
  box-shadow: var(--glow);
}

.book__cover-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
}

.book__cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s var(--ease-out-expo);
}

.library__book:hover .book__cover {
  transform: scale(1.05);
}

.book__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.1) 0%,
    rgba(0, 0, 0, 0.6) 50%,
    rgba(0, 0, 0, 0.85) 100%
  );
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: var(--space-md);
}

.book__title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.3;
  margin-bottom: var(--space-xs);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.book__excerpt {
  font-family: var(--font-body);
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.book__date {
  color: var(--text-secondary);
}

.book__reading-time {
  color: var(--accent);
}

/* ================================================
   Preview Panel
   ================================================ */
.preview-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;
  max-width: 100%;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  padding: var(--space-2xl);
  transform: translateX(100%);
  transition: transform 0.45s var(--ease-out-expo);
  z-index: 1000;
  overflow-y: auto;
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.1);
}

.preview-panel.open {
  transform: translateX(0);
}

.preview-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.35s ease;
  z-index: 999;
}

.preview-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.preview-close {
  position: absolute;
  top: var(--space-lg);
  right: var(--space-lg);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.25s var(--ease-out-expo);
}

.preview-close:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: rotate(90deg);
}

.preview-content {
  padding-top: var(--space-xl);
}

.preview-meta {
  display: flex;
  gap: var(--space-md);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: var(--space-md);
}

.preview-time::before {
  content: '·';
  margin-right: var(--space-md);
}

.preview-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
  margin-bottom: var(--space-lg);
}

.preview-banner {
  width: calc(100% + var(--space-2xl) * 2);
  margin-left: calc(var(--space-2xl) * -1);
  height: 220px;
  margin-bottom: var(--space-lg);
  overflow: hidden;
}

.preview-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-excerpt {
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.8;
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
  padding-left: var(--space-md);
  border-left: 3px solid var(--accent);
}

.preview-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--accent);
  color: white;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 0.3s var(--ease-out-expo);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.preview-link:hover {
  background: var(--accent-hover);
  transform: translateY(-3px);
  box-shadow: 0 8px 30px var(--accent-glow);
}

.preview-link svg {
  transition: transform 0.3s ease;
}

.preview-link:hover svg {
  transform: translateX(4px);
}

/* ================================================
   Responsive
   ================================================ */
@media (max-width: 768px) {
  .book-container {
    padding: var(--space-lg);
  }

  .library {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-md);
  }

  .book__overlay {
    padding: var(--space-sm);
  }

  .book__title {
    font-size: 0.9rem;
  }

  .book__excerpt {
    font-size: 0.6rem;
    -webkit-line-clamp: 3;
  }

  .preview-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    height: 85vh;
    top: auto;
    bottom: 0;
    transform: translateY(100%);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .preview-panel.open {
    transform: translateY(0);
  }

  .preview-banner {
    height: 160px;
  }
}

@media (max-width: 480px) {
  .book-header {
    margin-bottom: var(--space-lg);
  }

  .site-title {
    font-size: 1.1rem;
  }

  .library {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }
}

/* ================================================
   Reduced Motion
   ================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Theme keyboard shortcut hint (bottom-right) */
.theme-hint {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  line-height: 1;
  color: var(--text-primary, #1c1917);
  background: var(--bg-surface, #ffffff);
  border: 1px solid var(--border-strong, rgba(0, 0, 0, 0.12));
  border-radius: 999px;
  padding: 7px 13px 7px 11px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow:
    0 2px 10px rgba(0, 0, 0, 0.08),
    0 1px 0 var(--border-strong, rgba(0, 0, 0, 0.12));
  user-select: none;
  pointer-events: none;
}

.theme-hint-key {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent, #ea580c);
  letter-spacing: 0.02em;
}

.theme-hint-icon {
  width: 13px;
  height: 13px;
  display: none;
  flex-shrink: 0;
  color: var(--text-secondary, #57534e);
}

[data-theme="light"] .theme-hint-moon { display: inline-block; }
[data-theme="dark"]  .theme-hint-sun  { display: inline-block; }

@media (max-width: 480px) {
  .theme-hint { display: none; }
}
