/* ========== Base Reset ========== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --paper: #FBF7EC;
  --ink: #3A3128;
  --ink-soft: #6B5D52;
  --terra: #C97D4F;
  --terra-soft: #E8B98C;
  --sage: #7A9A6E;
  --blue: #6B8FA3;
  --pink: #E5B5A8;
  --dark-bg: #2D2620;
  --cream: #F5E8D3;
  --amber: #D9985C;
  --card-bg: #FFFCF5;
  --card-border: #E8DFD0;
  --card-hover: #FFF8ED;
  --sidebar-bg: #F7F0E3;
  --sidebar-active: #EDE4D3;
  --shadow-sm: 0 1px 3px rgba(58, 49, 40, 0.08);
  --shadow-md: 0 4px 12px rgba(58, 49, 40, 0.1);
  --shadow-lg: 0 8px 24px rgba(58, 49, 40, 0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'EB Garamond', 'Noto Serif SC', Georgia, serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ========== Tear Layer ========== */
.tear-layer {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

.tear-layer.active {
  pointer-events: auto;
  cursor: grab;
}

.tear-layer.active:active {
  cursor: grabbing;
}

/* ========== Tools Wall ========== */
.tools-wall {
  min-height: 100vh;
  opacity: 0;
  transition: opacity 0.8s ease;
  background: var(--paper);
}

.tools-wall.visible {
  opacity: 1;
}

/* ========== Hero Section ========== */
.hero {
  padding: 60px 40px 40px;
  text-align: center;
  background: linear-gradient(180deg, #F5EDE0 0%, var(--paper) 100%);
  border-bottom: 1px solid var(--card-border);
}

.hero-title {
  font-family: 'Noto Serif SC', serif;
  font-weight: 900;
  font-size: 2.5rem;
  color: var(--ink);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 1.2rem;
  color: var(--ink-soft);
  margin-bottom: 24px;
}

.hero-count {
  display: inline-block;
  background: var(--terra);
  color: white;
  padding: 6px 16px;
  border-radius: 20px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 24px;
}

/* ========== Search Bar ========== */
.search-container {
  max-width: 600px;
  margin: 0 auto;
  position: relative;
}

.search-input {
  width: 100%;
  padding: 14px 20px 14px 48px;
  border: 2px solid var(--card-border);
  border-radius: var(--radius-lg);
  background: white;
  font-family: 'EB Garamond', 'Noto Serif SC', serif;
  font-size: 1rem;
  color: var(--ink);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-input::placeholder {
  color: #B8A99A;
}

.search-input:focus {
  border-color: var(--terra);
  box-shadow: 0 0 0 3px rgba(201, 125, 79, 0.15);
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: #B8A99A;
  font-size: 1.2rem;
  pointer-events: none;
}

/* ========== Main Layout ========== */
.main-layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 200px);
}

/* ========== Sidebar ========== */
.sidebar {
  width: 260px;
  min-width: 260px;
  padding: 24px 16px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--card-border);
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-title {
  font-family: 'Noto Serif SC', serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--ink);
  padding: 8px 12px;
  margin-bottom: 8px;
}

.category-group {
  margin-bottom: 4px;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
}

.category-header:hover {
  background: var(--sidebar-active);
}

.category-header.active {
  background: var(--sidebar-active);
  font-weight: 600;
}

.category-icon {
  font-size: 1.1rem;
  margin-right: 10px;
  width: 24px;
  text-align: center;
}

.category-name {
  flex: 1;
  font-size: 0.95rem;
  color: var(--ink);
}

.category-count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  color: var(--ink-soft);
  background: rgba(58, 49, 40, 0.06);
  padding: 2px 8px;
  border-radius: 10px;
}

.category-arrow {
  font-size: 0.7rem;
  color: var(--ink-soft);
  margin-left: 8px;
  transition: transform var(--transition);
}

.category-header.expanded .category-arrow {
  transform: rotate(90deg);
}

.subcategories {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.subcategories.open {
  max-height: 500px;
}

.subcategory-item {
  padding: 8px 12px 8px 46px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.subcategory-item:hover {
  background: var(--sidebar-active);
  color: var(--ink);
}

.subcategory-item.active {
  background: var(--terra);
  color: white;
  font-weight: 500;
}

/* ========== Cards Grid ========== */
.content-area {
  flex: 1;
  padding: 24px 32px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

/* ========== Card ========== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--terra-soft);
}

.card-cover {
  width: 100%;
  height: 160px;
  overflow: hidden;
  background: linear-gradient(135deg, #E8DFD0 0%, #D4C9B8 100%);
  position: relative;
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top;
  transition: transform 0.3s ease;
}

.card:hover .card-cover img {
  transform: scale(1.05);
}

.card-cover-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  background: linear-gradient(135deg, #E8DFD0 0%, #D4C9B8 100%);
}

.card-body {
  padding: 16px;
}

.card-category {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--terra);
  background: rgba(201, 125, 79, 0.1);
  padding: 3px 10px;
  border-radius: 12px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-title {
  font-family: 'Noto Serif SC', serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  margin-bottom: 6px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-desc {
  font-size: 0.88rem;
  color: var(--ink-soft);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 12px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.card-tag {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem;
  color: var(--ink-soft);
  background: rgba(58, 49, 40, 0.05);
  padding: 2px 8px;
  border-radius: 8px;
  border: 1px solid rgba(58, 49, 40, 0.08);
}

.card-link {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 80px 40px;
  color: var(--ink-soft);
}

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

.empty-state-text {
  font-size: 1.1rem;
  font-style: italic;
}

/* ========== Footer ========== */
.footer {
  text-align: center;
  padding: 40px;
  border-top: 1px solid var(--card-border);
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-style: italic;
}

.footer a {
  color: var(--terra);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

/* ========== Loading State ========== */
.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--dark-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s ease;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-text {
  font-family: 'Noto Serif SC', serif;
  font-size: 1.5rem;
  color: var(--cream);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .sidebar {
    display: none;
  }
  
  .main-layout {
    flex-direction: column;
  }
  
  .hero {
    padding: 40px 20px 30px;
  }
  
  .hero-title {
    font-size: 1.8rem;
  }
  
  .content-area {
    padding: 16px;
  }
  
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
  }
}

@media (max-width: 600px) {
  .cards-grid {
    grid-template-columns: 1fr;
  }
  
  .hero-title {
    font-size: 1.5rem;
  }
}

/* ========== Teal Hint Overlay ========== */
.tear-hint {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 101;
  text-align: center;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.tear-hint-text {
  font-family: 'Caveat', cursive;
  font-size: 1.2rem;
  color: var(--cream);
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.tear-progress {
  width: 180px;
  height: 3px;
  background: rgba(245, 232, 211, 0.3);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
}

.tear-progress-bar {
  height: 100%;
  background: var(--amber);
  border-radius: 2px;
  transition: width 0.3s ease;
  width: 0%;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(58, 49, 40, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(58, 49, 40, 0.25);
}
