/* RAIL (icon column) */
.rail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 4px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  border-radius: 8px;
  transition: background-color 140ms ease, color 140ms ease;
}
.rail-btn span {
  font-size: 16px;
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 600;
}
.rail-btn:hover { background: var(--bg-elev-2); color: var(--text); }
.rail-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* PANEL */
.rail-panel {
  padding: 16px 14px;
  overflow-y: auto;
}
.rail-panel h3 {
  font-size: 13px;
  font-family: "Bricolage Grotesque", sans-serif;
  margin: 0 0 12px;
}
.rail-panel .hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.template-grid, .shape-grid, .photo-grid, .bg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.tpl-card, .shape-card, .photo-card, .bg-card {
  aspect-ratio: 3 / 4;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: transform 160ms ease, border-color 160ms ease;
}
.tpl-card:hover, .shape-card:hover, .photo-card:hover, .bg-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.tpl-card .thumb {
  position: absolute; inset: 0;
  transform-origin: 0 0;
}
.tpl-card .label {
  position: absolute;
  bottom: 4px; left: 4px; right: 4px;
  font-size: 10px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 3px 6px;
  border-radius: 6px;
  text-align: center;
}
.shape-card { aspect-ratio: 1 / 1; display: grid; place-items: center; padding: 12px; }
.shape-card svg { width: 100%; height: 100%; color: var(--text); }
.photo-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.bg-card { aspect-ratio: 1 / 1; }

.text-preset {
  padding: 10px 12px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 140ms ease;
}
.text-preset:hover { border-color: var(--accent); }
.text-preset .h { font-family: "Bricolage Grotesque", sans-serif; font-weight: 600; }

/* LAYERS PANEL */
.layer-list { display: flex; flex-direction: column; gap: 4px; }
.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.layer-item.active { border-color: var(--accent); background: var(--accent-soft); }
.layer-item .icon { color: var(--text-muted); font-size: 12px; width: 14px; text-align: center; }
.layer-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-item button {
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; padding: 2px 4px; font-size: 12px; border-radius: 4px;
}
.layer-item button:hover { background: var(--bg-elev-3); color: var(--text); }

.upload-drop {
  border: 2px dashed var(--border-strong);
  border-radius: 12px;
  padding: 30px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 140ms ease, background-color 140ms ease;
}
.upload-drop:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Responsive breakpoints */
@media (max-width: 1200px) {
  .main-grid { grid-template-columns: 280px 1fr 260px; }
  .sidebar { grid-template-columns: 68px 1fr; }
}

/* =========================================
   MOBILE RESPONSIVE: BOTTOM NAV & CARDS
========================================= */
@media (max-width: 768px) {
  /* Turn the vertical rail into a horizontally scrollable bottom nav */
  .rail {
    flex-direction: row;
    width: 100%;
    height: 100%; /* Fills the 64px wrapper defined in layout.css */
    padding: 0 8px;
    border-right: none;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
  }
  .rail::-webkit-scrollbar { 
    display: none; /* Chrome/Safari */
  }

  .rail-btn {
    flex: 0 0 auto;
    min-width: 72px;
    height: 100%;
    padding: 8px 4px;
  }
  
  .rail-btn span {
    font-size: 20px;
  }

  /* The panel becomes a sliding bottom sheet */
  .rail-panel {
    position: fixed;
    bottom: 64px; /* Sits right above the bottom nav */
    left: 0;
    width: 100%;
    height: 50vh; /* Takes up half the screen */
    background: var(--bg-elev-1);
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.4);
    z-index: 95;
    padding-top: 24px; /* Make room for the drag handle */
    
    /* Animation setup */
    transform: translateY(120%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s ease;
  }

  /* Add a visual "drag handle" line at the top of the sheet */
  .rail-panel::before {
    content: '';
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--border-strong);
    border-radius: 4px;
  }

  /* When a tab is tapped, JS adds this class to slide the sheet up */
  .rail-panel.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }

  /* Make grids 3 columns on mobile so more items fit */
  .template-grid, .shape-grid, .photo-grid, .bg-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }
}