/* Layout Container: Main content first (1fr), Sidebar second (280px) */
.projects-layout {
  display: grid;
  /* 1fr for cards, 300px for sidebar on the right */
  grid-template-columns: 1fr 350px; 
  gap: 1.5rem;
  max-width: 1400px; /* Increased for wider card potential */
  margin: 0 auto;
  align-items: start;
}

/* Enable 3D Space */
.project-card {
  position: relative; /* Context for absolute hint */
  perspective: 1000px;
  background-color: transparent;
  padding-bottom: 10px; /* Creates the "space" for the hint below the flipper */
}

/* Ensure the inner flipper doesn't overlap the hint */
.project-card-inner {
  height: 100%; 
  position: relative;
  transition: transform 0.8s;
  transform-style: preserve-3d;
}

/* Positioning the hint in the gutter */
.flip-hint {
  position: absolute;
  bottom: 5px; 
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.65rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--md-default-fg-color--light);
  opacity: 0.6;
  pointer-events: none; /* Let clicks pass through to the card */
}

/* The actual flip action */
.project-card.is-flipped .project-card-inner {
  transform: rotateY(180deg);
}

/* Position faces */
.project-card-front, .project-card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 12px;
  padding: 1.2rem;
  background: var(--md-default-bg-color);
  display: flex;
  flex-direction: column;
}

/* Back Face setup */
.project-card-back {
  transform: rotateY(180deg);
}

.back-content {
  flex-grow: 1;
  font-size: 0.8rem;
  overflow-y: auto; /* Scrollable if text is too long */
}

/* Custom Filter Color Scheme */
:root {
  --filter-bg: #f8fafc;
  --filter-border: #e2e8f0;
  --filter-text: #475569;
  --filter-active-bg: #6366f1; /* Indigo-500 */
  --filter-active-text: #ffffff;
  --filter-hover-border: #6366f1;
}

/* Sidebar Search Box */
#proj-search {
  border: 1px solid var(--filter-border);
  border-radius: 6px;
  background: white;
  transition: border-color 0.2s;
}

#proj-search:focus {
  border-color: var(--filter-active-bg);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Filter Chips */
.tag-chip {
  background-color: var(--filter-bg);
  color: var(--filter-text);
  border: 1px solid var(--filter-border);
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.tag-chip:hover {
  border-color: var(--filter-hover-border);
  transform: translateY(-1px);
}

.tag-chip.is-selected {
  background-color: var(--filter-active-bg) !important;
  color: var(--filter-active-text) !important;
  border-color: var(--filter-active-bg) !important;
  box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.2);
}

/* Clear All Button */
#proj-clear {
  width: 100%;
  margin-top: 1rem;
  background-color: transparent;
  color: #ef4444; /* Red */
  border: 1px solid #fee2e2;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#proj-clear:hover {
  background-color: #fef2f2;
  border-color: #ef4444;
}

/* Sidebar Styling - Now on the right */
.projects-filters {
  position: sticky;
  top: 6rem;
  padding: 1rem;
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 8px;
  background-color: var(--md-default-bg-color);
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  order: 2;
}

/* The Grid for Cards */
.projects-grid {
  display: grid;
  /* Adjust 350px to make cards wider or thinner */
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 2rem;
}

/* Card Styling: Vertical orientation */
.project-card {
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 12px;
  padding: 1.2rem;
  display: flex;
  border-left: 4px solid var(--filter-border); /* Subtle accent bar */
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s;
  min-height: 400px; /* Forces vertical rectangle shape */
  background: var(--md-default-bg-color);
}

.project-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  border-color: var(--md-accent-fg-color);
  border-left-color: var(--filter-active-bg);
}

/* Ensure title and content stack nicely */
.project-card h3 {
  margin-top: 0 !important;
  font-size: 1.1rem !important;
}

.project-card .proj-tags {
  margin-top: auto; /* Pushes tags to the bottom of the card */
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding-top: 1rem;
}

/* Make the icons and bold text stand out */
.project-card strong {
  color: var(--md-typeset-color);
  font-weight: 600;
}

.tag {
  padding: 0.2rem 0.6rem;
  font-size: 0.65rem;
  font-weight: 800;
  border: 1px solid; /* Color handled by JS */
  border-radius: 999px; /* Makes them pill-shaped/circular */
  text-transform: uppercase;
  transition: all 0.2s ease;
}

/* Chip filters in sidebar */
.proj-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 1rem 0;
}

.tag-chip {
  cursor: pointer;
  background: none;
  border: 1px solid var(--md-default-fg-color--lightest);
  border-radius: 20px;
  padding: 0.3rem 0.7rem;
  font-size: 0.7rem;
}

.tag-chip.is-selected {
  background-color: var(--md-accent-fg-color);
  color: var(--md-accent-bg-color);
  border-color: var(--md-accent-fg-color);
}

/* Proj tags */
/* Card Tag Container Fix */
.proj-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 1rem;
  min-height: 30px; 
  align-content: flex-start;
}

/* Tag Directory Styling */
.tag-directory {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--md-default-fg-color--lightest);
  transition: max-height 0.3s ease-out, opacity 0.3s ease;
  display: block;
  overflow: hidden;
  max-height: 1000px; /* Large enough to show content */
  opacity: 1;
}

/* The class the button toggles */
.sidebar-collapsible {
  overflow: hidden;
  max-height: 2000px; /* High enough to show all */
  opacity: 1;
  transition: max-height 0.4s ease, opacity 0.3s ease;
}

.sidebar-minimized .sidebar-collapsible {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

/* Ensure cards widen when sidebar is minimized */
.sidebar-minimized .projects-grid {
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
}

.tag-directory h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
  color: var(--md-default-fg-color--light);
}

/* Use Grid to align the abbreviation and the text */
.tag-directory dl {
  display: grid;
  /* Fixed column for abbreviations, fluid for description */
  grid-template-columns: 60px 1fr; 
  gap: 1.2rem 0.5rem;
  font-size: 0.72rem;
  line-height: 1.4;
  margin-top: 1.5rem;
}
.tag-directory dt {
  font-weight: 800;
  /* Color handled by JS */
}

.tag-directory dl {
  display: grid;
  grid-template-columns: 50px 1fr; /* Fixed width for tags */
  gap: 1rem 0.5rem;
  font-size: 0.75rem;
  margin-top: 1.5rem;
}

/* --- Card & Flip Hint Fix --- */
.project-card {
  position: relative;
  height: 480px; /* Fixed height for a uniform grid */
  padding-bottom: 40px; /* Gutter for the static hint */
}

.project-card-inner {
  height: calc(100% - 40px); /* Card face fills everything above the hint */
}

.flip-hint {
  position: absolute;
  bottom: 10px; /* Locked to bottom of the outer frame */
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.65rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.4;
  color: var(--md-default-fg-color--light);
}

.tag-directory dd {
  margin: 0;
  color: var(--md-default-fg-color--light);
}

.tag-directory dt:hover {
  filter: brightness(1.2);
  cursor: help;
}

/* Mobile Responsiveness */
@media screen and (max-width: 800px) {
  .projects-layout {
    grid-template-columns: 1fr;
  }
  .projects-filters {
    order: -1; /* Move filters to top on small screens */
  }
}