:root {
  /* High-Contrast, Soft Earth Palette */
  --bg-color: #F5EEDB;       /* Warm Cream */
  --card-bg: #FAF8F2;        /* Softened off-white for book cards */
  --header-text: #EAE3D5;    /* Subtly tinted white for header text and icons */
  --text-dark: #2C3E2D;      /* Deep Forest Green */
  --sage-green: #597755;     /* Darkened, richer sage for contrast */
  --terracotta: #A65239;     /* Deep burnt orange/brick for contrast */
  --oak-brown: #8B5E34;      /* Darkened vintage detail line */
  --detail-line: #8B5E34;
  --sheet-bg: #ffffff;

  /* Typography Design Tokens */
  --font-serif: 'Georgia', serif;
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'Courier New', Courier, monospace;

  /* Elevation Shadows */
  --shadow-flat: none;
  --shadow-raised: 0 4px 12px rgba(44, 62, 45, 0.05);
  --shadow-overlay: 0 8px 24px rgba(44, 62, 45, 0.12);
}

* {
  box-sizing: border-box;
}

/* ==========================================
   LOADING SCREEN
   ========================================== */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-color); /* Seamless match with your theme */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999; /* Keeps it on top of the header and grid */
  transition: opacity 0.8s ease-in-out, visibility 0.8s ease-in-out;
}

/* We use this class to smoothly fade out the screen */
.loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
}

#loading-video {
  height: 125%; /* Adjust this based on how large you want the animation */
  pointer-events: none; /* Prevents users from accidentally pausing it */
  transition: opacity 1s ease-in-out;
}

/* Cinematic Skip Loading Screen Button - Circular Arrow */
.skip-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 10000;
  background: rgba(253, 251, 247, 0.8);
  border: 1px solid var(--detail-line);
  color: var(--terracotta);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  display: none; /* Initially hidden until library is fully loaded */
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s, color 0.2s, transform 0.1s;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

.skip-btn:hover {
  background-color: var(--text-dark);
  color: var(--bg-color);
}

.skip-btn:active {
  transform: scale(0.95);
}

body {
  margin: 0; /* Kills the default side gaps instantly! */
  padding-top: 60px; /* Accommodates the fixed header */
  font-family: 'Georgia', serif;
  background-color: var(--bg-color);
  color: var(--text-dark);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Stops the double-scrolling elastic bounce! */
  overscroll-behavior-y: none; 
  overscroll-behavior-x: none;
}

/* --- UNIFIED HEADINGS --- */
.stacks-section-heading {
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.2rem;
  color: var(--text-dark);
  margin: 15px 0 15px 0;
  font-weight: 800;
  padding: 5px 0 5px 0;
  width: 100%;
}

.stacks-subheading {
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.2rem;
  color: var(--text-dark);
  margin: 15px 0 15px 0;
  font-weight: 800;
  border-bottom: 1px solid var(--text-dark);
  padding: 5px 0 5px 0;
  width: 100%;
}

/* --- BATCH 8: GLOBAL POLISH & HEADER --- */

/* Hide Scrollbars Globally (App-like feel) */
::-webkit-scrollbar {
  display: none;
}
* {
  -ms-overflow-style: none; 
  scrollbar-width: none; 
}

/* The Global Header */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 60px;
  background: var(--terracotta); /* Flipped to bold orange */
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1); /* Slightly stronger shadow */
  color: var(--header-text); 
}

.app-header svg, .icon-action-btn {
  color: var(--header-text);
}

/* The Circular Header Logo */
.header-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%; /* This perfectly rounds the image! */
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
.header-logo:hover {
  opacity: 0.9;
}
.header-logo:active {
  transform: scale(0.9);
}

.header-title {
  font-family: 'Courier New', Courier, monospace;
  font-size: 20px;
  color: var(--header-text); /* Flipped to white */
  margin: 0;
  cursor: pointer;
}

/* Ensures the feedback icon in the header turns white */
.app-header .icon-action-btn {
  color: var(--header-text); 
}

/* Feedback Modal UI */
/* OVERLAYS: Grouped with a comma */
.feedback-modal, 
.stacks-modal-overlay {
  position: fixed;
  z-index: 10000; /* Keeps it above the nav header */
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(44, 62, 45, 0.4); 
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* HIDE BEHAVIOR */
.feedback-modal.hidden, 
.stacks-modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* MODAL CARDS: Grouped with a comma */
.feedback-content, 
.stacks-modal-card {
  background-color: var(--card-bg);
  border: 1px solid var(--detail-line);
  border-radius: 12px;
  padding: 25px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  position: relative;
}

.close-modal {
  position: absolute;
  top: 15px;
  right: 15px;
  color: var(--sage-green);
  font-size: 28px;
  line-height: 0.8;
  cursor: pointer;
  transition: color 0.2s;
}
.close-modal:active {
  color: var(--terracotta);
}

/* Modal Form Specifics */
.feedback-content textarea {
  background-color: transparent;
  border: 1px solid var(--detail-line);
  border-radius: 8px;
  color: var(--text-dark);
  font-family: 'Georgia', serif;
  font-size: 15px;
  padding: 15px;
  margin-bottom: 15px;
  width: 100%;
  resize: none;
}
.feedback-content textarea:focus {
  outline: none;
  border-color: var(--sage-green);
}

.feedback-content button, .stacks-btn {
  background-color: var(--terracotta);
  color: var(--bg-color);
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  flex: 1; /* Makes the Cancel and Send buttons exactly the same width */
}
.feedback-content button:active, .stacks-btn:active {
  opacity: 0.8;
  transform: scale(0.98);
}

/* Main Bookshelf Area */
.bookshelf {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  padding: 10px 0 0 0;
  overflow: hidden;
  width: 100%;
}

.hero-wrapper {
  padding: 0 15px;
  margin-bottom: 5px; /* Reduced from 20px */
}

/* Slim Pill Buttons for Hero Section */
.hero-pill-btn {
  background: transparent;
  border: 1px solid var(--sage-green);
  color: var(--sage-green);
  border-radius: 20px;
  padding: 6px 14px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hero-pill-btn:active {
  background: var(--sage-green);
  color: var(--bg-color);
}

/* Persistent active state for when the filter is applied */
.hero-pill-btn.active {
  background: var(--sage-green);
  color: var(--bg-color);
  border-color: var(--sage-green);
}

.section-label {
  font-family: 'Georgia', serif;
  font-size: 18px;
  color: #2c3e50;
  margin-bottom: 15px;
}

/* Give the current book a subtle terracotta glow */
.active-read {
  box-shadow: 0 4px 15px rgba(211, 84, 0, 0.25);
  border: 1px solid rgba(211, 84, 0, 0.3);
}

/* Match the book cover shape and add a subtle paper texture */
.reader-animation {
  aspect-ratio: 2 / 3;
  background-color: var(--card-bg);
  border-radius: 12px;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.05);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

.reader-gif {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Hides the old horizontal lines app-wide */
.shelf-divider {
  display: none !important;
}

/* Physical Book Cover Styling */
.cover-image {
  width: 100%;
  height: auto; /* Forces the browser to calculate height via aspect-ratio without stretching */
  aspect-ratio: 2 / 3; 
  object-fit: cover; 
  border-radius: 2px;
  margin-bottom: 10px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: block; /* Removes any invisible inline spacing below the image */
}

.fab {
  position: fixed;
  bottom: 80px; 
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: var(--terracotta); 
  color: var(--header-text);
  border: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  font-size: 24px;
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  
  /* New rules for the fade effect */
  opacity: 0;
  pointer-events: none; /* Prevents clicking when invisible */
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* The class we will add with JavaScript when scrolled */
.fab.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 70px;
  background-color: var(--bg-color);
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-around; /* Spreads icons evenly */
  padding: 0 30px; /* Adds safe breathing room on the far left and right */
  align-items: center;
  z-index: 10;
}

.nav-item {
  background: none;
  border: none;
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  color: #c4c0b6; /* Inactive color */
  padding: 10px;
  cursor: pointer;
}

/* --- BATCH 7: LIBRARY TOOLBAR --- */


.toolbar-input {
  width: 100%;
  padding: 10px 15px;
  border: none; /* Removed border */
  border-radius: 8px;
  background: var(--bg-color); /* Cream inputs */
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  color: var(--text-dark);
  outline: none;
}

.toolbar-input:focus {
  border-color: var(--terracotta);
}

.toolbar-filters {
  display: flex;
  gap: 10px;
}

/* --- BATCH 8: TOOLBAR ICONS --- */
.toolbar-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.flex-half {
  flex: 1; /* Ensures the filter and sort dropdowns split the row 50/50 */
}

.toolbar-icon {
  position: absolute;
  left: 10px; /* Distance from the left edge */
  color: var(--sage-green);
  pointer-events: none; /* Crucial: Lets her tap "through" the icon to activate the dropdown */
}

/* Add extra padding so the text doesn't hide behind the icons! */
.toolbar-input.with-icon {
  padding-left: 32px;
}

.toolbar-select.with-icon {
  padding-left: 30px;
  width: 100%;
}

.toolbar-select {
  flex: 1;
  padding: 8px 10px;
  border: none; /* Removed border */
  border-radius: 8px;
  background: var(--bg-color); /* Cream dropdowns */
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  color: var(--sage-green); /* Text remains sage for contrast */
  outline: none;
  cursor: pointer;
}

/* The Empty State Container */
.empty-grid-state {
  grid-column: 1 / -1; /* Spans across both columns */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
  color: var(--sage-green);
}

.empty-grid-state img {
  width: 150px;
  opacity: 0.8;
  margin-bottom: 15px;
}

.empty-grid-state h3 {
  color: var(--terracotta);
  font-family: 'Courier New', Courier, monospace;
  margin-bottom: 5px;
}

.nav-item.active {
  color: var(--terracotta);
  font-weight: bold;
}

/* Card Catalog Bottom Sheet */
.card-header {
  padding: 0 20px;
  text-align: center;
}

.bottom-sheet {
  position: fixed;
  bottom: -100%; /* Hidden by default */
  left: 0;
  width: 100%;
  height: 75vh;
  background-color: var(--card-bg);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.1);
  transition: bottom 0.3s ease-in-out;
  z-index: 2000;
  padding: 20px;
  /* Simulating the physical card */
  border-top: 3px solid #e0dcd3;
}

/* Change to bottom: 0 to slide it up */
.bottom-sheet.open {
  bottom: 0; 
}

/* --- PAGE VIEW ARCHITECTURE --- */
.page-view {
  display: none; 
  flex-grow: 1;
  width: 100%;
  overflow-y: auto; /* Makes each view its own scroll container */
  -webkit-overflow-scrolling: touch; /* CRITICAL for smooth iOS scrolling */
  padding-bottom: 120px; /* Accounts for bottom nav bar and safe area space on mobile */
  animation: fadeIn 0.25s ease-out forwards;
}

/* Only show the section with the 'active' class */
.page-view.active {
  display: block;
}

@keyframes fadeIn {
  from { 
    opacity: 0; 
    transform: translateY(10px); 
  }
  to { 
    opacity: 1; 
    transform: translateY(0); 
  }
}

/* --- BATCH 4: SEARCH PAGE STYLES --- */
.search-form-container {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-top: 15px;
}

.search-radio-group {
  display: flex;
  gap: 20px;
  font-family: 'Courier New', Courier, monospace;
  color: var(--sage-green);
  font-size: 14px;
}

.search-radio-group label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

/* Make the radio button itself match the earthy aesthetic */
.search-radio-group input[type="radio"] {
  accent-color: var(--terracotta);
}

#search-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--detail-line);
  border-radius: 8px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 16px;
  background-color: var(--card-bg);
  color: var(--text-dark);
  box-sizing: border-box; /* Prevents padding from pushing it off screen */
}

#search-input:focus {
  outline: 2px solid var(--terracotta);
}

#search-btn {
  width: 100%;
  padding: 12px 20px;
  background-color: var(--terracotta);
  color: var(--header-text);
  border: none;
  border-radius: 8px;
  font-family: 'Georgia', serif;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}

#search-btn:active {
  opacity: 0.8;
}

.search-results-list {
  padding: 0 15px 120px 15px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.search-result-card {
  background-color: var(--card-bg);
  border: 1px solid #e0dcd3;
  border-radius: 8px;
  padding: 15px;
  display: flex;
  gap: 15px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.search-result-info {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.search-result-info h3 {
  font-family: 'Courier New', Courier, monospace;
  font-size: 16px;
  margin: 0 0 5px 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-result-info p {
  font-family: 'Georgia', serif;
  font-size: 14px;
  color: var(--sage-green);
  margin: 0 0 10px 0;
}

.add-book-btn {
  align-self: flex-start;
  background-color: var(--sage-green);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'Courier New', Courier, monospace;
  transition: background-color 0.2s;
}

/* --- BATCH 5: STATS PAGE STYLES --- */
.stats-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  padding: 0 15px 30px 15px;
}

.stat-card {
  background-color: var(--card-bg);
  border: 1px solid #e0dcd3;
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.stat-card.full-width {
  grid-column: span 2;
}

#stats-book-list {
  display: flex !important;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  /* Remove any max-height or height constraints */
}

#stats-book-list.book-grid {
  padding: 0 !important;
  grid-template-columns: unset; /* Override grid layout */
  display: flex;
  flex-direction: column;
}

.stat-card h3 {
  font-family: 'Courier New', Courier, monospace;
  font-size: 32px;
  color: var(--terracotta);
  margin: 0 0 10px 0;
}

.stat-card.full-width h3 {
  font-size: 20px;
}

.stat-card p {
  font-size: 14px;
  color: var(--sage-green);
  margin: 0;
}

.category-list {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
}

.category-list li {
  font-size: 16px;
  padding: 8px 0;
  border-bottom: 1px solid #e0dcd3;
  color: var(--text-dark);
}

.category-list li:last-child {
  border-bottom: none;
}

/* --- BATCH 6: REFRESH ICON --- */
.card-footer-actions {
  display: flex;
  justify-content: flex-end;
  padding: 10px 20px 0;
}

.icon-action-btn {
  background: transparent;
  border: none;
  color: var(--terracotta); /* Accent color to make it pop */
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  transition: transform 0.2s ease, opacity 0.2s ease, color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  
  /* Removes the stuck grey native tap highlight on mobile */
  -webkit-tap-highlight-color: transparent; 
}

/* @media (hover: hover) ensures this only happens if the user has a mouse */
@media (hover: hover) {
  .icon-action-btn:hover {
    transform: rotate(15deg); 
    opacity: 0.8;
  }
}

/* This provides the satisfying physical tap feedback on mobile */
.icon-action-btn:active {
  transform: scale(0.9); 
}

/* --- BATCH 7: NAV ICONS & FOCUS PAGE --- */

/* Nav Overrides */
.nav-item svg {
  width: 26px;
  height: 26px;
  stroke-width: 2.5;
  transition: transform 0.2s ease;
}
.nav-item:active svg {
  transform: scale(0.9);
}

/* Focus Layout */
#view-focus {
  position: fixed; /* Changed from absolute to fixed */
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999; /* Overrides the header's 100 */
  background-color: var(--bg-color);
}
.focus-container {
  position: relative;
  height: 100vh;
  background-color: var(--bg-color); /* Seamless match with your theme */
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999; /* Keeps it on top of the header and grid */
  overflow: hidden;
}
.focus-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.focus-close {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 60;
  background: rgba(253, 251, 247, 0.8);
  border: 1px solid var(--detail-line);
  color: var(--terracotta);
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* --- BATCH 7: FOCUS TIMER UI --- */
.timer-overlay {
  position: absolute;
  top: 120px; /* Adjust this value to perfectly align under the fern */
  left: 20px;
  z-index: 55;
  background: rgba(253, 251, 247, 0.85); /* Frosty glass effect */
  border: 1px solid var(--detail-line);
  padding: 15px 20px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  backdrop-filter: blur(4px);
}

.timer-display {
  font-family: 'Courier New', Courier, monospace;
  font-size: 36px; /* Scaled down slightly to fit the corner */
  font-weight: bold;
  color: var(--text-dark);
  margin-bottom: 5px;
}

.timer-controls {
  display: flex;
  justify-content: center;
  gap: 20px;
  align-items: center;
}

.timer-controls .icon-action-btn {
  color: var(--sage-green);
  padding: 5px;
}

/* The Native Select Trick */
.native-select-wrapper {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sage-green);
  transition: transform 0.2s ease, color 0.2s ease;
}

.hidden-native-select {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0; /* Makes it invisible, but fully interactive */
  cursor: pointer;
  -webkit-appearance: none;
}

@media (hover: hover) {
  .native-select-wrapper:hover {
    color: var(--terracotta);
    transform: scale(1.1);
  }
}

.native-select-wrapper:active {
  transform: scale(0.9);
}

/* --- BATCH 7: HERO CAROUSEL --- */
.current-read-section {
  width: 100%;
  display: block; 
  overflow: hidden; 
  padding: 5px 0 5px 0; /* Reduced bottom padding to tighten the gap */
  margin-bottom: 0; /* Removed the 20px margin */
  position: relative; 
}

.carousel-container {
  display: flex;
  gap: 15px; /* Tightly controlled gap */
  overflow-x: auto;
  scroll-snap-type: x mandatory; 
  /* padding: 0 15px; - Matches the bookshelf grid margins */
  scrollbar-width: none; 
  -ms-overflow-style: none;  
}

.carousel-container::-webkit-scrollbar {
  display: none; 
}

/* Scaled down to fit 2 cards + the slim add button perfectly */
.carousel-item {
  flex: 0 0 auto;
  width: calc(50% - 39px); 
  scroll-snap-align: start; 
  cursor: pointer;
  transition: transform 0.2s ease;
}

.carousel-item:active {
  transform: scale(0.95); 
}

/* Special Cards (See All, TBR, Read Again) */
.special-card {
  width: calc(50% - 39px); /* Matches the scaled book cards */
  aspect-ratio: 2 / 3;
  border: 2px dashed var(--detail-line); /* Dashes restored! */
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--sage-green);
  background: var(--bg-color);
  padding: 10px;
}

.special-card h3 {
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px; /* Scaled down slightly to fit the new width */
  margin-top: 10px;
  color: var(--terracotta);
}

.special-card p {
  font-size: 11px; /* Scaled down slightly */
  margin-top: 5px;
  line-height: 1.2;
  color: var(--text-dark);
}

/* The Slim Add Button */
.slim-add-btn {
  width: 48px;
  aspect-ratio: auto;
  border: 2px dashed var(--detail-line); /* Dashes restored! */
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sage-green);
  background: var(--bg-color); 
}

/* The Subtle Scroll-Back Arrow */
.carousel-back-arrow {
  position: absolute;
  left: 5px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-color);
  border: none;
  color: var(--terracotta);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.1);
  transition: opacity 0.2s ease;
}
.carousel-back-arrow.hidden {
  opacity: 0;
  pointer-events: none;
}

/* --- BATCH 7: BARCODE SCANNER --- */
.search-input-wrapper {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.search-input-wrapper input {
  flex-grow: 1;
  margin-bottom: 0; /* Overrides previous spacing */
}

/* Scanner Container */

.scanner-container {
  margin-top: 15px;
  border: 2px dashed var(--detail-line);
  border-radius: 8px;
  overflow: hidden;
  padding: 10px;
  background: rgba(253, 251, 247, 0.5);
  animation: slideDown 0.3s ease;
}

/* Forces the video feed to fit neatly */
#reader {
  width: 100%;
  border-radius: 4px;
  overflow: hidden;
}

/* Hides the ugly default link the library generates */
#reader a {
  display: none !important; 
}

.stop-scan-btn {
  width: 100%;
  margin-top: 10px;
  color: var(--terracotta);
  border-color: var(--terracotta);
}

.hidden {
  display: none !important;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- BATCH 7: GOOGLE BOOKS LINK --- */
.google-books-link {
  display: inline-block;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  color: var(--sage-green);
  text-decoration: none;
  margin-top: 8px;
  border-bottom: 1px dotted var(--sage-green);
  transition: color 0.2s;
}

.google-books-link:hover {
  color: var(--terracotta);
  border-bottom-color: var(--terracotta);
}

/* --- PHASE 1: THE WANDER DRAWER --- */
.wander {
  /* Unified wander button */
  flex: 0 1 auto; 
  background-color: var(--terracotta); 
  color: var(--header-text); 
  display: flex; 
  align-items: center; 
  justify-content: left; 
  gap: 8px; 
  border: none; 
  padding: 8px; 
  border-radius: 8px; 
  font-size: 8px; 
  cursor: pointer; 
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background-color: #ccc;
  border-radius: 2px;
  margin: 0 auto 20px auto;
}

.punch-hole {
  width: 12px;
  height: 12px;
  background-color: var(--bg-color);
  border-radius: 50%;
  margin: 0 auto 15px auto;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.card-header-line {
  border-top: 1px solid var(--detail-line);
  margin-bottom: 15px;
}

.red-line {
  height: 2px;
  background-color: var(--terracotta);
  margin-bottom: 30px;
  margin-top: 30px;
}
/* Quick Filters grid and buttons */

.quick-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quick-btn {
  background: var(--bg-color);
  border: 1px solid var(--sage-green);
  color: var(--sage-green);
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.quick-btn:active, .quick-btn.active {
  background: var(--sage-green);
  color: var(--header-text);
}

/* --- PHASE 2: JOURNEY LAYOUTS --- */
.layout-toggles .layout-btn {
  background: transparent;
  border: none;
  color: #b3bfae; 
  padding: 0;
  cursor: pointer;
  transition: color 0.2s;
  display: flex;
  align-items: center;
  flex-direction: column;
  align-items: center;
  justify-content: right;
  gap: 10px;
}
.layout-toggles .layout-btn.active {
  color: var(--terracotta);
}

/* Base Grid Transition */
.book-grid {
  display: grid;
  grid-template-columns: calc(50% - 10px) calc(50% - 10px);
  gap: 20px;
  width: 100%;
  background-color: var(--bg-color); 
  padding: 20px 15px 120px 15px; /* Increased bottom padding to clear bottom nav on mobile */
}

/* 1. Default Grid (3-Column Cover Only) */
.book-grid.layout-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.book-grid.layout-grid .book-info {
  display: none; 
}
.book-grid.layout-grid .book-card {
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  border-radius: 4px;
  overflow: hidden;
  aspect-ratio: 2 / 3; 
  cursor: pointer;
}
.book-grid.layout-grid .book-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* Bulletproofing */
  padding: 0; background: transparent; border: none; 
}

/* 2. Cards (The Classic 2-Column View) */
.book-grid.layout-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px; /* Tightened the gap slightly so cards aren't so wide */
}
.book-grid.layout-cards .book-card {
  display: flex;
  flex-direction: column;
  background-color: var(--card-bg); 
  border: 1px solid #e0dcd3; /* Softened the outline to match the list view */
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.04); /* Softened the shadow */
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s ease;
  min-width: 0; /* THE MAGIC FIX: Forces CSS Grid to respect the 50/50 split */
}
.book-grid.layout-cards .book-card:active {
  transform: scale(0.95);
}
.book-grid.layout-cards .book-info {
  display: block; 
  width: 100%;
}
.book-grid.layout-cards .book-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  margin-bottom: 8px;
  padding: 0; background: transparent; border: none; 
}
.book-grid.layout-cards .book-title {
  font-family: 'Georgia', serif;
  font-size: 16px; /* Bumped up */
  font-weight: bold;
  margin: 0 0 4px 0;
  color: var(--text-dark);
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2; 
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: break-word; /* Prevents super long words from breaking the card */
}
.book-grid.layout-cards .book-author {
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px; /* Bumped up */
  color: var(--sage-green);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 3. List View (1-Column, Synced with Search Results) */
.book-grid.layout-list {
  display: flex;
  flex-direction: column;
  gap: 15px; 
}
.book-grid.layout-list .book-card {
  display: flex;
  background-color: var(--card-bg);
  border: 1px solid #e0dcd3;
  border-radius: 8px;
  padding: 15px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  gap: 15px;
  align-items: flex-start;
  cursor: pointer;
  transition: transform 0.2s ease;
}
.book-grid.layout-list .book-card:active {
  transform: scale(0.98);
}
.book-grid.layout-list .book-cover {
  width: 60px;
  height: 90px;
  object-fit: cover;
  border-radius: 2px;
  /* Bulletproofing */
  padding: 0; background: transparent; border: none; 
}
.book-grid.layout-list .book-info {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  padding-top: 2px;
  text-align: left; /* Force left-alignment */
  align-items: flex-start;
  height: 90px; /* Match the cover height exactly to push the stars to the bottom */
}
.book-grid.layout-list .book-title {
  font-family: 'Courier New', Courier, monospace; /* Synced with search result title */
  font-weight: bold;
  font-size: 16px;
  color: var(--text-dark);
  text-align: left;
  width: 100%;
  margin: 0 0 5px 0;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-grid.layout-list .book-author {
  font-family: 'Georgia', serif; /* Synced with search result author */
  font-size: 14px;
  text-align: left;
  width: 100%;
  color: var(--sage-green);
  margin: 0;
}

/* Hide ratings by default so they don't break the 2-column or 3-column views */
.book-grid .book-rating {
  display: none;
}

/* List View Explicit Overrides */

.book-grid.layout-list .book-rating {
  display: block;
  margin-top: auto; /* Pushes the stars to the absolute bottom of the container */
  color: #DDA750; /* A soft, vintage gold color */
  font-size: 12px;
  letter-spacing: 2px;
}

/* --- PHASE 3: READING JOURNAL VIEWS --- */
#view-details {
  background-color: var(--bg-color);
  padding-bottom: 120px; /* Space for the bottom nav and mobile indicators */
}
.journal-meta-card {
  width: 100%;
  background-color: var(--card-bg);
  border: 1px solid var(--detail-line);
  border-radius: 8px;
  margin-top: 15px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.02);
  text-align: left;
  padding: 0 15px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 45px;
  border-bottom: 1px solid rgba(139, 94, 52, 0.2); /* Lined paper effect tied to text length */
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9rem;
}
.meta-row:last-child {
  border-bottom: none;
}
.meta-label {
  color: var(--sage-green);
}
.meta-value {
  color: var(--text-dark);
  font-weight: bold;
  text-align: right;
  flex-grow: 1;
}

/* Inline Edit Inputs & Layout */
.input-with-icon {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-grow: 1;
  color: var(--sage-green); 
}

.inline-edit-input {
  flex-grow: 0; /* Lets the wrapper handle the spacing */
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  color: var(--text-dark);
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9rem;
  font-weight: bold;
  text-align: right;
  outline: none;
  cursor: default;
  pointer-events: none;
  padding: 0;
  width: auto;
  direction: ltr; 
}

.pencil-trigger {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
  pointer-events: auto;
}

.pencil-trigger:hover {
  transform: scale(1.15);
}

.pencil-trigger:hover svg {
  color: var(--terracotta) !important;
  opacity: 1 !important;
}

/* 1. Force iOS/Safari/Chrome text to align right inside the Shadow DOM */
.inline-edit-input::-webkit-datetime-edit {
  display: flex;
  justify-content: flex-end;
  padding: 0;
}

/* 2. Hide the ugly default calendar icon on Desktop */
.inline-edit-input::-webkit-calendar-picker-indicator {
  display: none;
  -webkit-appearance: none;
}

.inline-edit-input:focus {
  color: var(--terracotta);
}

.inline-edit-input option {
  text-align: left;
}

/* Updated Action Buttons: Bolder Icons, No BG */
.journal-action-btn {
  background: transparent;
  border: none;
  color: var(--terracotta);
  width: 45px;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.journal-action-btn:active { 
  transform: scale(0.85); 
  opacity: 0.7; 
}

/* Updated Notes Area: Removed lines */
.journal-notes-input {
  width: 100%;
  min-height: 120px;
  padding: 15px;
  border: 1px solid var(--detail-line);
  border-radius: 8px;
  background: var(--card-bg);
  font-family: 'Georgia', serif;
  font-size: 15px;
  color: var(--text-dark);
  resize: vertical;
  line-height: 1.5;
}

.journal-notes-input:focus { 
  outline: none; 
  border-color: var(--sage-green); 
}

/* Stamps */
.stamp-container {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-top: 15px;
}

.stamp {
  display: inline-flex; 
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Courier New', Courier, monospace;
  font-size: 14px;
  font-weight: bold;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 4px;
  
  /* Top 3px, Right 1px, Bottom 1px, Left 3px */
  border-width: 3px 1px 1px 3px; 
  border-style: solid;
  
  transform: rotate(-12deg);
  opacity: 0.75;
  line-height: 1.2;
  letter-spacing: 2px;
  width: max-content;
  margin-bottom: 4px;
}

.stamp-started {
  color: var(--sage-green); 
  border-color: var(--sage-green); 
  background: transparent;
}
.stamp-finished {
  color: var(--terracotta); 
  border-color: var(--terracotta); 
  background: transparent;
}

/* --- PHASE 5: CHRONOLOGICAL DIVIDERS --- */
.year-divider {
  grid-column: 1 / -1; /* Forces it to span all columns in the grid */
  font-family: 'Courier New', Courier, monospace;
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--terracotta);
  border-bottom: 2px dashed rgba(139, 94, 52, 0.3); /* Soft terracotta dash */
  margin: 15px 0 5px 0;
  padding-bottom: 5px;
  text-align: left;
  width: 100%;
}

/* ==========================================
   AUTHENTICATION SCREEN AND CUSTOM MODAL
   ========================================== */
.auth-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--bg-color);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9998; /* Sits just below the loading screen */
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.auth-screen.hidden {
  display: none;
}

.auth-card {
  width: 90%;
  max-width: 350px;
  padding: 30px 20px;
  text-align: center;
  background: var(--card-bg);
  border: 1px solid var(--detail-line);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.auth-toggle-group {
  display: flex;
  background: var(--bg-color);
  padding: 4px;
  border: 1px solid var(--detail-line);
  border-radius: 30px;
  margin-bottom: 25px;
  gap: 4px;
}

.auth-toggle-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--sage-green);
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

.auth-toggle-btn.active {
  background: var(--sage-green);
  color: var(--bg-color);
  box-shadow: 0 2px 8px rgba(89, 119, 85, 0.3);
}

.auth-toggle-btn:not(.active):hover {
  background: rgba(89, 119, 85, 0.08);
}

.stacks-input {
  width: 100%;
  padding: 12px;
  margin-bottom: 15px;
  border: 1px solid var(--detail-line);
  border-radius: 8px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 15px;
  background-color: var(--card-bg);
  color: var(--text-dark);
  box-sizing: border-box;
}

.stacks-input:focus {
  outline: none;
  border-color: var(--terracotta);
}

.stacks-btn {
  background-color: var(--terracotta);
  color: var(--bg-color);
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
}

.stacks-btn:active {
  opacity: 0.8;
  transform: scale(0.98);
}

.stacks-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 25px;
  justify-content: center;
}

#close-details-btn:hover {
  opacity: 0.7;
}

#close-details-btn:active {
  transform: scale(0.95);
}

/* =========================================================================
   DESIGN SYSTEM - STANDARDIZED CLASSES & ENHANCEMENTS
   ========================================================================= */

/* --- SYSTEM FONTS OVERRIDES --- */
body {
  font-family: var(--font-serif) !important;
}
.stacks-section-heading, .stacks-subheading {
  font-family: var(--font-mono) !important;
}
.stacks-subheading {
  border-bottom: 2px solid var(--detail-line);
  padding-bottom: 5px;
}

/* --- BUTTONS --- */
.btn {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s ease, opacity 0.2s ease, background-color 0.2s ease;
  border: none;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  background-color: var(--terracotta);
  color: var(--header-text);
}
.btn-primary:active {
  opacity: 0.85;
}
.btn-secondary {
  background-color: transparent;
  border: 1px solid var(--sage-green);
  color: var(--sage-green);
}
.btn-secondary:active {
  background-color: rgba(89, 119, 85, 0.1);
}
.btn-danger {
  background-color: transparent;
  border: 1px solid var(--terracotta);
  color: var(--terracotta);
}
.btn-danger:active {
  background-color: rgba(166, 82, 57, 0.1);
}

/* --- FORM CONTROLS --- */
.form-input, .form-select, .form-textarea {
  font-family: var(--font-sans);
  font-size: 0.95rem;
  padding: 12px 15px;
  border: 1px solid var(--detail-line);
  border-radius: 8px;
  background-color: var(--card-bg);
  color: var(--text-dark);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--terracotta);
  box-shadow: 0 0 0 3px rgba(166, 82, 57, 0.15);
}

/* --- COVER ART ASPECT RATIO LOCK --- */
.book-cover-container {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  background-color: rgba(139, 94, 52, 0.05); /* Placeholder tint */
  display: block;
}
.book-cover-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* --- NOTES AUTO-SAVE STATUS --- */
.autosave-status {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--sage-green);
  margin-left: 10px;
  font-style: italic;
  display: none;
}

/* --- NOTECARD STYLING (CORNER FOLD) --- */
.notecard {
  position: relative;
  background-color: var(--card-bg); /* Cream bg */
  padding: 16px;
  background: linear-gradient(315deg, transparent 14px, var(--card-bg) 0);
  box-shadow: 0 4px 10px rgba(44, 62, 45, 0.1);
  margin-bottom: 20px;
  width: 100%;
}
.notecard::before {
  content: "";
  position: absolute;
  bottom: 0;
  right: 0;
  width: 14px;
  height: 14px;
  background-color: #dfd5be; /* Darker fold shade */
  border-top-left-radius: 2px;
}

/* --- DETAILS PAGE OVERLAY TRANSITIONS --- */
#view-details {
  transition: transform 0.35s ease-out, opacity 0.35s ease-out;
  transform: translateX(100%);
  opacity: 0;
}
#view-details.active {
  transform: translateX(0);
  opacity: 1;
}

/* --- LIBRARY SEARCH BAR WHITE BG --- */
#local-search {
  background: #ffffff !important;
  border: 1px solid var(--detail-line) !important;
}

/* --- FILTERED/ACTIVE WANDER BUTTON STYLING --- */
.header-wander-btn.active p,
.header-wander-btn.filtered p {
  color: var(--sage-green) !important;
}
.header-wander-btn.active svg,
.header-wander-btn.filtered svg {
  stroke: var(--sage-green) !important;
  fill: rgba(186, 203, 179, 0.2) !important;
}

/* --- SPIN ANIMATION --- */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
.animate-spin {
  display: inline-block;
  animation: spin 1s linear infinite;
}

/* --- TOAST NOTIFICATION STYLING --- */
.stacks-toast {
  position: fixed;
  bottom: 85px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-dark);
  color: var(--bg-color);
  padding: 8px 16px;
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  z-index: 99999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.stacks-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* =========================================================================
   DESKTOP CONSTRICTOR WRAPPER
   ========================================================================= */
html {
  background-color: #2C3E2D; /* Deep forest green to frame the app on desktop */
  transition: background-color 0.3s ease;
}

@media (min-width: 768px) {
  body {
    max-width: 430px;
    margin: 0 auto;
    border-left: 1px solid var(--detail-line);
    border-right: 1px solid var(--detail-line);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
    transform: translate(0, 0); /* containing block context for fixed position elements */
    min-height: 100vh;
    height: 100vh;
    position: relative;
  }
}

/* --- WANDER BUTTON BLINKING ANIMATION --- */
@keyframes wander-blink-anim {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}
.wander.blinking {
  animation: wander-blink-anim 0.9s ease-in-out 2;
}
